Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/platform/silabs/SiWx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static_library("SiWx") {
"${chip_root}/src/app/icd/server:icd-server-config",
"${chip_root}/src/platform:platform_base",

# BLE refactor skeleton (Matter channel)
"${silabs_platform_dir}/ble:ble",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this be part of ${silabs_platform_dir}/ble/SiWx:ble-siwx and ${silabs_platform_dir}/ble/efr32:ble-efr32

"${silabs_platform_dir}/ble/SiWx:ble-siwx",

# sl_matter_enable_siwx_ble
"${silabs_platform_dir}/SiWx/ble:siwx-ble",
"${silabs_platform_dir}/platformAbstraction:wisemcu",
Expand Down
22 changes: 22 additions & 0 deletions src/platform/silabs/ble/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2025 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

# Shared BLE channel interface and types (headers only).
# Platform implementations: ble/efr32 (BleChannelMatterEfr32), ble/SiWx (BleChannelMatterSiWx).
source_set("ble") {
public_deps = [ "${chip_root}/src/platform:platform_base" ]
include_dirs = [ "${chip_root}/src/platform/silabs/ble" ]
}
89 changes: 89 additions & 0 deletions src/platform/silabs/ble/BleChannel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Abstract interface for a BLE channel (Matter BLE or side channel).
* BLEManagerImpl holds a Matter channel and an optional side channel;
* all platform BLE operations are delegated to the channel.
* No native stack headers in this interface.
*/

#pragma once

#include <cstddef>
#include <cstdint>

#include "BlePlatformTypes.h"
#include <lib/core/CHIPError.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

/**
* Abstract base for any BLE channel (Matter BLE or side channel).
* Platform implementations: BleChannelMatterEfr32, BleChannelMatterSiWx (Matter);
* BleSideChannelEfr32, BleSideChannelSiWx (side channel).
*/
class BleChannel
{
public:
virtual ~BleChannel() = default;

// ----- Initialization -----
virtual CHIP_ERROR Init() = 0;
virtual CHIP_ERROR Shutdown() = 0;

// ----- Advertising -----
virtual CHIP_ERROR StartAdvertising(const BleAdvertisingParams & params) = 0;
virtual CHIP_ERROR StopAdvertising() = 0;
virtual CHIP_ERROR SetAdvertisingData(const uint8_t * data, size_t length) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you have a AdvConfigStruct ? I see it use in the BleSideChannel.h


// ----- Connection -----
virtual CHIP_ERROR CloseConnection(BleConnectionHandle conId) = 0;
virtual CHIP_ERROR UpdateConnectionParams(BleConnectionHandle conId, const BleConnectionParams & params) = 0;

// ----- GATT -----
virtual CHIP_ERROR SendIndication(BleConnectionHandle conId, uint16_t charHandle, const uint8_t * data, size_t length) = 0;
virtual CHIP_ERROR SendWriteRequest(BleConnectionHandle conId, uint16_t charHandle, const uint8_t * data, size_t length) = 0;
virtual CHIP_ERROR SubscribeCharacteristic(BleConnectionHandle conId, uint16_t charHandle) = 0;
virtual CHIP_ERROR UnsubscribeCharacteristic(BleConnectionHandle conId, uint16_t charHandle) = 0;
virtual uint16_t GetMTU(BleConnectionHandle conId) const = 0;

// ----- Event handling -----
/** Callback invoked when channel parses an event and produces a BleEvent (e.g. for Matter BLE). */
virtual void SetEventCallback(BleEventCallback callback, void * context) = 0;
/** Returns true if this channel handles the given platform event id. */
virtual bool CanHandleEvent(uint32_t eventId) const = 0;
/** Single entry point: parse platform event, optionally build BleEvent and invoke callback. */
virtual void ParseEvent(void * platformEvent) = 0;

// ----- Address / identity -----
virtual CHIP_ERROR GetAddress(uint8_t * addr, size_t * length) = 0;
virtual CHIP_ERROR GetDeviceName(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR SetDeviceName(const char * name) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe provide a length too


// ----- Indication timer -----
virtual CHIP_ERROR StartIndicationTimer(BleConnectionHandle conId, uint32_t timeoutMs, void (*callback)(void *),
void * context) = 0;
virtual CHIP_ERROR CancelIndicationTimer(BleConnectionHandle conId) = 0;
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
119 changes: 119 additions & 0 deletions src/platform/silabs/ble/BlePlatformTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Platform-agnostic BLE types used by BleChannel and BLEManagerImpl.
* Shared across Matter BLE and side channel implementations.
*/

#pragma once

#include <cstddef>
#include <cstdint>

#include <lib/core/CHIPError.h>
#include <lib/support/Span.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

/**
* Connection handle type for BLE operations. Platform code casts to/from
* BLE_CONNECTION_OBJECT where required by the Matter BleLayer.
*/
using BleConnectionHandle = void *;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a void pointer? I think we should infer the type from the implementing driver/channel.

For example, for efr32 this is plainly a uint8


/**
* BLE event types delivered from platform stack to channel (ParseEvent)
* and then to BLEManagerImpl via callback (OnMatterBleEvent).
*/
enum class BleEventType : uint32_t
{
kConnectionOpened,
kConnectionClosed,
kConnectionParameters,
kMtuExchanged,
kGattWrite,
kGattRead,
kIndicationConfirmation,
kSoftTimerExpired,
kBoot,
kUnknown
};

/**
* Unified BLE event passed from channel to BLEManagerImpl.
*/
struct BleEvent
{
BleEventType type = BleEventType::kUnknown;
BleConnectionHandle connection = nullptr;
void * data = nullptr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must this be a void * ?

size_t dataLength = 0;
uint16_t attributeHandle = 0;
uint32_t timerId = 0;
};

/**
* Advertising parameters for StartAdvertising.
*/
struct BleAdvertisingParams
{
uint16_t minInterval = 0;
uint16_t maxInterval = 0;
bool connectable = true;
uint8_t * customData = nullptr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

management of this pointer could be added to this struct.. I don't see yet how it is used but else we need to cleanly manage it at the caller level

size_t customDataLength = 0;
};

/**
* Connection parameters for UpdateConnectionParams.
*/
struct BleConnectionParams
{
uint16_t minInterval = 0;
uint16_t maxInterval = 0;
uint16_t latency = 0;
uint16_t timeout = 0;
};

/**
* Event callback type: channel calls this when it has parsed a platform event
* and produced a BleEvent (e.g. for Matter BLE).
*/
using BleEventCallback = void (*)(const BleEvent & event, void * context);

/**
* Side-channel advertising configuration (aligns with existing BLEChannel
* AdvConfigStruct). Used by BleSideChannel::ConfigureAdvertising().
*/
struct AdvConfigStruct
{
ByteSpan advData;
ByteSpan responseData;
uint32_t intervalMin = 0;
uint32_t intervalMax = 0;
uint8_t advConnectableMode = 0;
uint16_t duration = 0;
uint8_t maxEvents = 0;
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
95 changes: 95 additions & 0 deletions src/platform/silabs/ble/BleSideChannel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Abstract base for side channel implementations (e.g. provisioning CLI).
* Aligns with existing BLEChannel.h / BLEChannelImpl in efr32 for refactor.
* Extends BleChannel with side-channel-specific API (GATT read/write/CCCD,
* connection state, CLI GAP/GATT methods, getters).
*/

#pragma once

#include "BleChannel.h"
#include "BlePlatformTypes.h"
#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>
#include <lib/support/Span.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

/**
* Abstract base for side channel. Implements BleChannel and adds the same
* surface as the existing BLEChannel (efr32): ConfigureAdvertising with
* AdvConfigStruct, StartAdvertising() (no params), AddConnection/RemoveConnection,
* HandleReadRequest/HandleWriteRequest (ByteSpan/MutableByteSpan), HandleCCCDWriteRequest,
* UpdateMtu, and CLI methods (GAP/GATT client) plus getters.
*/
class BleSideChannel : public BleChannel
{
public:
~BleSideChannel() override = default;

// ----- Side-channel advertising (matches existing BLEChannel) -----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ----- Side-channel advertising (matches existing BLEChannel) -----
// ----- Side-channel advertising -----

/** Configure advertising data and parameters; must be called before StartAdvertising(). */
virtual CHIP_ERROR ConfigureAdvertising(const AdvConfigStruct & config) = 0;
/** Start advertising using configured parameters. */
virtual CHIP_ERROR StartAdvertising(void) = 0;
virtual CHIP_ERROR StopAdvertising(void) = 0;

// ----- Connection state (side channel) -----
virtual void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle) = 0;
virtual bool RemoveConnection(uint8_t connectionHandle) = 0;

// ----- GATT server (side channel) -----
virtual void HandleReadRequest(void * platformEvent, ByteSpan data) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't platformEvent have a type?

virtual void HandleWriteRequest(void * platformEvent, MutableByteSpan data) = 0;
virtual CHIP_ERROR HandleCCCDWriteRequest(void * platformEvent, bool & isNewSubscription) = 0;
virtual void UpdateMtu(void * platformEvent) = 0;

// ----- Event handling (side channel) -----
virtual bool CanHandleEvent(uint32_t eventId) { return false; }
virtual void ParseEvent(void * platformEvent) {}

// ----- CLI: GAP -----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why CLI ?

virtual CHIP_ERROR GeneratAdvertisingData(uint8_t discoverMove, uint8_t connectMode, const Optional<uint16_t> & maxEvents) = 0;
virtual CHIP_ERROR SetAdvertisingParams(uint32_t intervalMin, uint32_t intervalMax, uint16_t duration,
const Optional<uint16_t> & maxEvents, const Optional<uint8_t> & channelMap) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is MaxEvents and ChannelMap? is this a 917 thing?

virtual CHIP_ERROR OpenConnection(const uint8_t * address, size_t addressLen, uint8_t addrType) = 0;
virtual CHIP_ERROR SetConnectionParams(const Optional<uint8_t> & connectionHandle, uint32_t intervalMin, uint32_t intervalMax,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is connectionHandle optional and why pass it as reference? We only need the value

uint16_t latency, uint16_t timeout) = 0;
virtual CHIP_ERROR CloseConnection(void) = 0;
virtual CHIP_ERROR SetAdvHandle(uint8_t handle) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum why a setAdvHandle? The handle is provided by the ble API. we don't know it before we create the adv set


// ----- CLI: GATT (client) -----
virtual CHIP_ERROR DiscoverServices() = 0;
virtual CHIP_ERROR DiscoverCharacteristics(uint32_t serviceHandle) = 0;
virtual CHIP_ERROR SetCharacteristicNotification(uint8_t characteristicHandle, uint8_t flags) = 0;
virtual CHIP_ERROR SetCharacteristicValue(uint8_t characteristicHandle, const ByteSpan & value) = 0;

// ----- Getters (matches existing BLEChannel) -----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ----- Getters (matches existing BLEChannel) -----

virtual uint8_t GetAdvHandle(void) const { return 0xff; }
virtual uint8_t GetConnectionHandle(void) const { return 0; }
virtual uint8_t GetBondingHandle(void) const { return 0; }
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
31 changes: 31 additions & 0 deletions src/platform/silabs/ble/SiWx/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2025 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

# Matter BLE channel implementation for SiWx917 (skeleton).
source_set("ble-siwx") {
sources =
[ "${chip_root}/src/platform/silabs/ble/SiWx/BleChannelMatterSiWx.cpp" ]

public_deps = [
"${chip_root}/src/platform:platform_base",
"${chip_root}/src/platform/silabs/ble:ble",
]

include_dirs = [
"${chip_root}/src/platform/silabs/ble",
"${chip_root}/src/platform/silabs/ble/SiWx",
]
}
Loading
Loading