Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/lock-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#include <platform/CHIPDeviceLayer.h>

// Side Channel
#include "BLEChannelImpl.h"

#define SYSTEM_STATE_LED 0
#define LOCK_STATE_LED 1

#define APP_FUNCTION_BUTTON 0
#define APP_LOCK_SWITCH 1

// Side Channel
chip::DeviceLayer::Internal::BLEChannelImpl sBleSideChannel;

using chip::app::Clusters::DoorLock::DlLockState;
using chip::app::Clusters::DoorLock::OperationErrorEnum;
using chip::app::Clusters::DoorLock::OperationSourceEnum;
Expand Down Expand Up @@ -111,6 +118,7 @@ void StartUnlatchTimer(uint32_t timeoutMs)

} // namespace


using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

Expand Down Expand Up @@ -253,6 +261,12 @@ void AppTask::AppTaskMain(void * pvParameter)
sAppTask.StartStatusLEDTimer();
#endif

// Side Channel
sBleSideChannel.Init();
DeviceLayer::Internal::BLEMgrImpl().InjectSideChannel(&sBleSideChannel);
sBleSideChannel.ConfigureAdvertisingDefaultData();
sBleSideChannel.StartAdvertising();

SILABS_LOG("App Task started");

// Users and credentials should be checked once from nvm flash on boot
Expand Down
21 changes: 4 additions & 17 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@

#include <app/server/OnboardingCodesUtil.h>

#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
#include <platform/internal/BLEManager.h>
#include <platform/silabs/efr32/BLEChannelImpl.h>
#if SL_USE_INTERNAL_BLE_SIDE_CHANNEL
#ifdef ENABLE_CHIP_SHELL
#include <BLEShellCommands.h>
#endif // ENABLE_CHIP_SHELL
#endif // defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
#endif // SL_USE_INTERNAL_BLE_SIDE_CHANNEL

#include <app/util/attribute-storage.h>
#include <assert.h>
Expand Down Expand Up @@ -134,9 +132,6 @@ using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;

using TimeTraceOperation = chip::Tracing::Silabs::TimeTraceOperation;
#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
using BLEChannelImpl = chip::DeviceLayer::Internal::BLEChannelImpl;
#endif // defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
namespace {

/**********************************************************
Expand Down Expand Up @@ -200,10 +195,6 @@ Identify gIdentify = {

#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER

#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
BLEChannelImpl sBleSideChannel;
#endif // defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED

} // namespace

bool BaseApplication::sIsProvisioned = false;
Expand Down Expand Up @@ -406,9 +397,9 @@ CHIP_ERROR BaseApplication::BaseInit()
#if MATTER_TRACING_ENABLED
TracingCommands::RegisterCommands();
#endif // MATTER_TRACING_ENABLED
#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
#if SL_USE_INTERNAL_BLE_SIDE_CHANNEL
BLEShellCommands::RegisterCommands();
#endif // defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
#endif // SL_USE_INTERNAL_BLE_SIDE_CHANNEL
#endif // ENABLE_CHIP_SHELL

#ifdef PERFORMANCE_TEST_ENABLED
Expand All @@ -422,10 +413,6 @@ CHIP_ERROR BaseApplication::BaseInit()
#if CHIP_ENABLE_OPENTHREAD
BaseApplication::sIsProvisioned = ConnectivityMgr().IsThreadProvisioned();
#endif
#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
ReturnErrorOnFailure(sBleSideChannel.Init());
DeviceLayer::Internal::BLEMgrImpl().InjectSideChannel(&sBleSideChannel);
#endif

err = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppDelegate);
return err;
Expand Down
36 changes: 22 additions & 14 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
{

public:
enum class EventFilter : uint8_t
{
UnprocessedEvent,
SharableEvent,
MatterReservedEvent
};

void HandleBootEvent(void);

#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
Expand All @@ -63,24 +70,25 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
void HandleSoftTimerEvent(void);
int32_t SendBLEAdvertisementCommand(void);
#else
void HandleConnectEvent(volatile sl_bt_msg_t * evt);
void HandleConnectParams(volatile sl_bt_msg_t * evt);
void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt);
void HandleWriteEvent(volatile sl_bt_msg_t * evt);
void UpdateMtu(volatile sl_bt_msg_t * evt);
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
void HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt);
void HandleSoftTimerEvent(volatile sl_bt_msg_t * evt);
EventFilter HandleConnectEvent(volatile sl_bt_msg_t * evt);
EventFilter HandleConnectParams(volatile sl_bt_msg_t * evt);
EventFilter HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt);
EventFilter HandleWriteEvent(volatile sl_bt_msg_t * evt);
EventFilter UpdateMtu(volatile sl_bt_msg_t * evt);
EventFilter HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
EventFilter HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt);
EventFilter HandleSoftTimerEvent(volatile sl_bt_msg_t * evt);
bool CanHandleEvent(uint32_t event);
void ParseEvent(volatile sl_bt_msg_t * evt);
#endif // RSI_BLE_ENABLEHandleConnectEvent
EventFilter ParseEvent(volatile sl_bt_msg_t * evt);
#endif // SLI_SI91X_ENABLE_BLE
CHIP_ERROR StartAdvertising(void);
CHIP_ERROR StopAdvertising(void);

#if defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
void HandleReadEvent(volatile sl_bt_msg_t * evt);
#if SL_BLE_SIDE_CHANNEL_ENABLED
EventFilter HandleReadEvent(volatile sl_bt_msg_t * evt);

// Side Channel
BLEChannel * GetSideChannel() { return mBleSideChannel; }
CHIP_ERROR InjectSideChannel(BLEChannel * channel);
CHIP_ERROR SideChannelConfigureAdvertisingDefaultData(void);
CHIP_ERROR SideChannelConfigureAdvertising(ByteSpan advData, ByteSpan responseData, uint32_t intervalMin, uint32_t intervalMax,
Expand Down Expand Up @@ -148,13 +156,13 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
BLEConState SideChannelGetConnectionState(void) { return mBleSideChannel->GetConnectionState(); }
uint8_t SideChannelGetAdvHandle(void) { return mBleSideChannel->GetAdvHandle(); }
uint8_t SideChannelGetConnHandle(void) { return mBleSideChannel->GetConnectionHandle(); }
#endif // defined(SL_BLE_SIDE_CHANNEL_ENABLED) && SL_BLE_SIDE_CHANNEL_ENABLED
#endif // SL_BLE_SIDE_CHANNEL_ENABLED

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
static void HandleC3ReadRequest(const SilabsBleWrapper::sl_wfx_msg_t & rsi_ble_read_req);
#else
static void HandleC3ReadRequest(volatile sl_bt_msg_t * evt);
static EventFilter HandleC3ReadRequest(volatile sl_bt_msg_t * evt);
#endif
#endif

Expand Down
123 changes: 118 additions & 5 deletions src/platform/silabs/efr32/BLEChannelImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ CHIP_ERROR BLEChannelImpl::IndicateCharacteristic(uint16_t characteristicHandle)
dataSpan.data());
return MapBLEError(ret);
}

void BLEChannelImpl::HandleIndicationTimeout(volatile sl_bt_msg_t * evt)
{
sl_bt_evt_gatt_server_indication_timeout_t * indicationTimeout =
Expand All @@ -242,6 +243,7 @@ void BLEChannelImpl::HandleIndicationTimeout(volatile sl_bt_msg_t * evt)
VerifyOrReturn(indicationTimeout->connection == mConnectionState.connectionHandle);
ChipLogProgress(DeviceLayer, "Indication timeout for connection: %d", indicationTimeout->connection);
}

void BLEChannelImpl::HandleIndicationConfirmation(volatile sl_bt_msg_t * evt)
{
sl_bt_evt_gatt_server_characteristic_status_t * indicationConfirmation =
Expand All @@ -252,6 +254,75 @@ void BLEChannelImpl::HandleIndicationConfirmation(volatile sl_bt_msg_t * evt)
indicationConfirmation->connection, indicationConfirmation->characteristic);
}

bool BLEChannelImpl::CanHandleEvent(uint32_t event)
{
return (event == sl_bt_evt_system_boot_id || event == sl_bt_evt_connection_opened_id ||
event == sl_bt_evt_connection_closed_id || event == sl_bt_evt_gatt_mtu_exchanged_id ||
event == sl_bt_evt_gatt_server_attribute_value_id || event == sl_bt_evt_gatt_server_user_read_request_id ||
event == sl_bt_evt_gatt_server_characteristic_status_id);
}

void BLEChannelImpl::ParseEvent(volatile sl_bt_msg_t * evt)
{
VerifyOrReturn(CanHandleEvent(SL_BT_MSG_ID(evt->header)));
switch (SL_BT_MSG_ID(evt->header))
{
case sl_bt_evt_system_boot_id: {
ChipLogProgress(DeviceLayer, "BLE boot event received by SideChannel");
}
break;
case sl_bt_evt_connection_opened_id: {
sl_bt_evt_connection_opened_t * conn_evt = (sl_bt_evt_connection_opened_t *) &(evt->data);
ChipLogProgress(DeviceLayer, "Connect Event for SideChannel on handle : %d", conn_evt->connection);
AddConnection(conn_evt->connection, conn_evt->bonding);
}
break;
case sl_bt_evt_connection_closed_id: {
sl_bt_evt_connection_closed_t * conn_evt = (sl_bt_evt_connection_closed_t *) &(evt->data);
ChipLogProgress(DeviceLayer, "Disconnect Event for the Side Channel on handle : %d", conn_evt->connection);
RemoveConnection(conn_evt->connection);
}
break;
case sl_bt_evt_gatt_mtu_exchanged_id: {
UpdateMtu(evt);
}
break;
case sl_bt_evt_gatt_server_attribute_value_id: {
uint8_t dataBuff[255] = { 0 };
MutableByteSpan dataSpan(dataBuff);
HandleWriteRequest(evt);

// Buffered (&Deleted) the following data:
ChipLogProgress(DeviceLayer, "Buffered (&Deleted) the following data:");
ChipLogByteSpan(DeviceLayer, dataSpan);
}
break;
case sl_bt_evt_gatt_server_characteristic_status_id: {
sl_bt_gatt_server_characteristic_status_flag_t StatusFlags;

StatusFlags = (sl_bt_gatt_server_characteristic_status_flag_t) evt->data.evt_gatt_server_characteristic_status.status_flags;
if (StatusFlags != sl_bt_gatt_server_confirmation)
{
LogErrorOnFailure(HandleCCCDWriteRequest(evt));
}
}
break;
case sl_bt_evt_gatt_server_user_read_request_id: {

ChipLogProgress(DeviceLayer, "Char Read Req, char : %d", evt->data.evt_gatt_server_user_read_request.characteristic);

char dataBuff[] = "You are reading the Si-Channel TX characteristic";
ByteSpan dataSpan((const uint8_t *) dataBuff, sizeof(dataBuff));
HandleReadRequest(evt);
}
break;
default: {
ChipLogProgress(DeviceLayer, "BLESideChannel Unknown Event id = %08" PRIx32, SL_BT_MSG_ID(evt->header));
break;
}
}
}

void BLEChannelImpl::AddConnection(uint8_t connectionHandle, uint8_t bondingHandle)
{
// We currently only support one connection at a time on our side channel
Expand Down Expand Up @@ -328,11 +399,6 @@ void BLEChannelImpl::HandleWriteRequest(volatile sl_bt_msg_t * evt)
}
}

bool BLEChannelImpl::CanHandleEvent(uint32_t event)
{
// Check if the event is one that this channel can handle
return (event == sl_bt_evt_gatt_server_indication_timeout_id);
}

CHIP_ERROR BLEChannelImpl::HandleCCCDWriteRequest(volatile sl_bt_msg_t * evt)
{
Expand Down Expand Up @@ -556,6 +622,53 @@ CHIP_ERROR BLEChannelImpl::SetCharacteristicValue(uint16_t charHandle, const Byt
return CHIP_NO_ERROR;
}

CHIP_ERROR BLEChannelImpl::ConfigureAdvertisingDefaultData(void)
{

#define SIDE_CHANNEL_MAX_ADV_DATA_LEN 31
#define SIDE_CHANNEL_CHIP_ADV_DATA_TYPE_FLAGS 0x01
#define SIDE_CHANNEL_CHIP_ADV_DATA_TYPE_UUID 0x03
#define SIDE_CHANNEL_MAX_RESPONSE_DATA_LEN 31
#define SIDE_CHANNEL_BLE_CONFIG_MIN_INTERVAL_SC (32) // Time = Value * 0.625 ms = 20ms
#define SIDE_CHANNEL_BLE_CONFIG_MAX_INTERVAL_SC (8000) // Time = Value * 0.625 ms = 5s

uint8_t advData[SIDE_CHANNEL_MAX_ADV_DATA_LEN];
uint32_t index = 0;

// Flags
advData[index++] = 2; // Length
advData[index++] = SIDE_CHANNEL_CHIP_ADV_DATA_TYPE_FLAGS; // Flags AD Type
advData[index++] = 0x06; // LE General Discoverable Mode, BR/EDR not supported

// Service UUID
advData[index++] = 3; // Length
advData[index++] = SIDE_CHANNEL_CHIP_ADV_DATA_TYPE_UUID; // 16-bit UUID
advData[index++] = 0x34; // UUID 0x1234 (little endian)
advData[index++] = 0x12;
ByteSpan advDataSpan(advData, index);

uint8_t responseData[SIDE_CHANNEL_MAX_RESPONSE_DATA_LEN];
index = 0;

const char * sideChannelName = "Si-Channel";
size_t sideChannelNameLen = strlen(sideChannelName);

responseData[index++] = static_cast<uint8_t>(sideChannelNameLen + 1);
responseData[index++] = 0x09; // Complete Local Name
memcpy(&responseData[index], sideChannelName, sideChannelNameLen);
index += sideChannelNameLen;
ByteSpan responseDataSpan(responseData, index);

AdvConfigStruct config = { advDataSpan,
responseDataSpan,
SIDE_CHANNEL_BLE_CONFIG_MIN_INTERVAL_SC,
SIDE_CHANNEL_BLE_CONFIG_MAX_INTERVAL_SC,
sl_bt_advertiser_connectable_scannable,
0,
0 };
return ConfigureAdvertising(config);
}

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
2 changes: 2 additions & 0 deletions src/platform/silabs/efr32/BLEChannelImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class BLEChannelImpl : public BLEChannel
CHIP_ERROR StopAdvertising(void) override;
CHIP_ERROR NotifyCharacteristic(uint16_t characteristicHandle) override;
CHIP_ERROR IndicateCharacteristic(uint16_t characteristicHandle) override;
CHIP_ERROR ConfigureAdvertisingDefaultData(void);

void HandleIndicationTimeout(volatile sl_bt_msg_t * evt) override;
void HandleIndicationConfirmation(volatile sl_bt_msg_t * evt) override;

void ParseEvent(volatile sl_bt_msg_t * evt) override;
void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle) override;
bool RemoveConnection(uint8_t connectionHandle) override;
void HandleReadRequest(volatile sl_bt_msg_t * evt) override;
Expand Down
Loading
Loading