Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: Fixed writing the bridged device node label #15817

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ void BleEnvironmentalDataProvider::NotifyUpdateState(chip::ClusterId clusterId,
CHIP_ERROR BleEnvironmentalDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

return CHIP_NO_ERROR;
}

int BleEnvironmentalDataProvider::ParseDiscoveredData(bt_gatt_dm *discoveredData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static const bt_uuid *sUuidButton = BT_UUID_LBS_BUTTON;
static const bt_uuid *sUuidCcc = BT_UUID_GATT_CCC;

#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_SWITCH_BRIDGED_DEVICE
void ProcessCommand(const EmberBindingTableEntry &aBinding, OperationalDeviceProxy *aDevice, Nrf::Matter::BindingHandler::BindingData &aData)
void ProcessCommand(const EmberBindingTableEntry &aBinding, OperationalDeviceProxy *aDevice,
Nrf::Matter::BindingHandler::BindingData &aData)
{
CHIP_ERROR ret = CHIP_NO_ERROR;

Expand Down Expand Up @@ -142,7 +143,7 @@ void BleLBSDataProvider::GattWriteCallback(bt_conn *conn, uint8_t err, bt_gatt_w

CHIP_ERROR BleLBSDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer)
{
if (clusterId != Clusters::OnOff::Id) {
if (clusterId != Clusters::OnOff::Id && clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand Down Expand Up @@ -170,6 +171,10 @@ CHIP_ERROR BleLBSDataProvider::UpdateState(chip::ClusterId clusterId, chip::Attr

return CHIP_NO_ERROR;
}
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ class GenericSwitchDevice : public Nrf::MatterBridgedDevice {
public:
GenericSwitchDevice(const char *nodeLabel);

uint16_t GetDeviceType() const override
{
return Nrf::MatterBridgedDevice::DeviceType::GenericSwitch;
}
uint16_t GetDeviceType() const override { return Nrf::MatterBridgedDevice::DeviceType::GenericSwitch; }
CHIP_ERROR HandleRead(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
uint16_t maxReadLength) override;
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
size_t dataSize) override;
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
size_t size) override
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != chip::app::Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case chip::app::Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
};

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ class HumiditySensorDevice : public Nrf::MatterBridgedDevice {
uint16_t maxReadLength) override;
CHIP_ERROR HandleReadRelativeHumidityMeasurement(chip::AttributeId attributeId, uint8_t *buffer,
uint16_t maxReadLength);
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
size_t size) override
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != chip::app::Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case chip::app::Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
size_t dataSize) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::OnOff::Id, BOOLEAN, 1, 0)
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::FeatureMap::Id, BITMAP32, 4, 0),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::GlobalSceneControl::Id, BOOLEAN, 1, 0),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::OnTime::Id, INT16U, 2, ZAP_ATTRIBUTE_MASK(WRITABLE)),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::OffWaitTime::Id, INT16U, 2, ZAP_ATTRIBUTE_MASK(WRITABLE)),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::StartUpOnOff::Id, ENUM8, 1, ZAP_ATTRIBUTE_MASK(WRITABLE)),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::OffWaitTime::Id, INT16U, 2,
ZAP_ATTRIBUTE_MASK(WRITABLE)),
DECLARE_DYNAMIC_ATTRIBUTE(Clusters::OnOff::Attributes::StartUpOnOff::Id, ENUM8, 1,
ZAP_ATTRIBUTE_MASK(WRITABLE)),
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();

constexpr CommandId onOffIncomingCommands[] = {
Expand Down Expand Up @@ -167,9 +169,9 @@ CHIP_ERROR OnOffLightDevice::HandleReadGroups(AttributeId attributeId, uint8_t *
}
}

CHIP_ERROR OnOffLightDevice::HandleWrite(ClusterId clusterId, AttributeId attributeId, uint8_t *buffer)
CHIP_ERROR OnOffLightDevice::HandleWrite(ClusterId clusterId, AttributeId attributeId, uint8_t *buffer, size_t size)
{
if (clusterId != Clusters::OnOff::Id) {
if (clusterId != Clusters::OnOff::Id && clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand All @@ -186,6 +188,8 @@ CHIP_ERROR OnOffLightDevice::HandleWrite(ClusterId clusterId, AttributeId attrib
case Clusters::OnOff::Attributes::StartUpOnOff::Id:
mStartUpOnOff = static_cast<Clusters::OnOff::StartUpOnOffEnum>(*buffer);
break;
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OnOffLightDevice : public Nrf::MatterBridgedDevice {
uint16_t maxReadLength) override;
CHIP_ERROR HandleReadOnOff(chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength);
CHIP_ERROR HandleReadGroups(chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength);
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override;
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer, size_t size) override;
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
size_t dataSize) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ class OnOffLightSwitchDevice : public Nrf::MatterBridgedDevice {
uint16_t maxReadLength) override;
CHIP_ERROR HandleReadOnOff(chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength);
CHIP_ERROR HandleReadBinding(chip::AttributeId attributeId, uint8_t *buffer, uint16_t maxReadLength);
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
size_t size) override
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != chip::app::Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case chip::app::Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
size_t dataSize) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ class TemperatureSensorDevice : public Nrf::MatterBridgedDevice {
uint16_t maxReadLength) override;
CHIP_ERROR HandleReadTemperatureMeasurement(chip::AttributeId attributeId, uint8_t *buffer,
uint16_t maxReadLength);
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override
CHIP_ERROR HandleWrite(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer,
size_t size) override
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != chip::app::Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case chip::app::Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
return HandleWriteDeviceBasicInformation(clusterId, attributeId, buffer, size);
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR HandleAttributeChange(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
size_t dataSize) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void SimulatedGenericSwitchDataProvider::NotifyUpdateState(chip::ClusterId clust
CHIP_ERROR SimulatedGenericSwitchDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
if (clusterId != Clusters::Switch::Id) {
if (clusterId != Clusters::Switch::Id && clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand All @@ -46,6 +46,10 @@ CHIP_ERROR SimulatedGenericSwitchDataProvider::UpdateState(chip::ClusterId clust
NotifyUpdateState(clusterId, attributeId, &mCurrentSwitchPosition, sizeof(mCurrentSwitchPosition));
return CHIP_NO_ERROR;
}
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ void SimulatedHumiditySensorDataProvider::NotifyUpdateState(chip::ClusterId clus
CHIP_ERROR SimulatedHumiditySensorDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

return CHIP_NO_ERROR;
}

void SimulatedHumiditySensorDataProvider::TimerTimeoutCallback(k_timer *timer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void SimulatedOnOffLightDataProvider::NotifyUpdateState(chip::ClusterId clusterI
CHIP_ERROR SimulatedOnOffLightDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
if (clusterId != Clusters::OnOff::Id) {
if (clusterId != Clusters::OnOff::Id && clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand All @@ -48,6 +48,10 @@ CHIP_ERROR SimulatedOnOffLightDataProvider::UpdateState(chip::ClusterId clusterI
NotifyUpdateState(clusterId, attributeId, &mOnOff, sizeof(mOnOff));
return CHIP_NO_ERROR;
}
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,28 @@ void ProcessCommand(const EmberBindingTableEntry &aBinding, OperationalDevicePro
CHIP_ERROR SimulatedOnOffLightSwitchDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
if (clusterId != Clusters::OnOff::Id) {
if (clusterId != Clusters::OnOff::Id && clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

if (attributeId != Clusters::OnOff::Attributes::OnOff::Id) {
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

bool mOnOff;
memcpy(&mOnOff, buffer, sizeof(mOnOff));
switch (attributeId) {
case Clusters::OnOff::Attributes::OnOff::Id: {
bool mOnOff;
memcpy(&mOnOff, buffer, sizeof(mOnOff));

chip::CommandId commandId = mOnOff ? Clusters::OnOff::Commands::On::Id : Clusters::OnOff::Commands::Off::Id;
chip::CommandId commandId =
mOnOff ? Clusters::OnOff::Commands::On::Id : Clusters::OnOff::Commands::Off::Id;

if (mInvokeCommandCallback) {
mInvokeCommandCallback(*this, Clusters::OnOff::Id, commandId, ProcessCommand);
if (mInvokeCommandCallback) {
mInvokeCommandCallback(*this, Clusters::OnOff::Id, commandId, ProcessCommand);
}
break;
}
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

return CHIP_NO_ERROR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ void SimulatedTemperatureSensorDataProvider::NotifyUpdateState(chip::ClusterId c
CHIP_ERROR SimulatedTemperatureSensorDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
if (clusterId != Clusters::BridgedDeviceBasicInformation::Id) {
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (attributeId) {
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
/* Node label is just updated locally and there is no need to propagate the information to the end
* device. */
break;
default:
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

return CHIP_NO_ERROR;
}

void SimulatedTemperatureSensorDataProvider::TimerTimeoutCallback(k_timer *timer)
Expand Down
26 changes: 25 additions & 1 deletion samples/matter/common/src/bridge/bridge_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,31 @@ CHIP_ERROR BridgeManager::HandleWrite(uint16_t index, ClusterId clusterId,
return device->HandleWriteIdentify(attributeMetadata->attributeId, buffer, attributeMetadata->size);
}

CHIP_ERROR err = device->HandleWrite(clusterId, attributeMetadata->attributeId, buffer);
uint8_t *data;
size_t dataLen;

/* The buffer content differs depending on the attribute type, so there are some conversions required. */
switch (attributeMetadata->attributeType) {
case ZCL_OCTET_STRING_ATTRIBUTE_TYPE:
case ZCL_CHAR_STRING_ATTRIBUTE_TYPE:
/* These are pascal strings that contain length encoded as a first byte of data. */
data = buffer + 1;
memcpy(&dataLen, buffer, 1);
break;
case ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE:
case ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE:
/* These are pascal long strings that contain length encoded as a first two bytes of data. */
data = buffer + 2;
memcpy(&dataLen, buffer, 2);
break;
default:
/* Other numerical attribute types are represented in a normal way. */
data = buffer;
dataLen = attributeMetadata->size;
break;
}

CHIP_ERROR err = device->HandleWrite(clusterId, attributeMetadata->attributeId, data, dataLen);

/* After updating MatterBridgedDevice state, forward request to the non-Matter device. */
if (err == CHIP_NO_ERROR) {
Expand Down
14 changes: 13 additions & 1 deletion samples/matter/common/src/bridge/matter_bridged_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
using namespace ::chip;
using namespace ::chip::app;

namespace Nrf {
namespace Nrf
{

CHIP_ERROR MatterBridgedDevice::CopyAttribute(const void *attribute, size_t attributeSize, void *buffer,
uint16_t maxBufferSize)
Expand All @@ -25,6 +26,13 @@ CHIP_ERROR MatterBridgedDevice::CopyAttribute(const void *attribute, size_t attr
return CHIP_NO_ERROR;
}

void MatterBridgedDevice::SetNodeLabel(void *data, size_t size)
{
/* Clean the buffer and fill it with the new data. */
memset(mNodeLabel, 0, sizeof(mNodeLabel));
memcpy(mNodeLabel, data, size);
}

CHIP_ERROR MatterBridgedDevice::HandleWriteDeviceBasicInformation(chip::ClusterId clusterId,
chip::AttributeId attributeId, void *data,
size_t dataSize)
Expand All @@ -35,6 +43,10 @@ CHIP_ERROR MatterBridgedDevice::HandleWriteDeviceBasicInformation(chip::ClusterI
SetIsReachable(*reinterpret_cast<bool *>(data));
return CHIP_NO_ERROR;
}
case Clusters::BridgedDeviceBasicInformation::Attributes::NodeLabel::Id:
SetNodeLabel(data, dataSize);
return CHIP_NO_ERROR;

default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
Expand Down
Loading
Loading