Skip to content

Commit 5f31a99

Browse files
committed
Prevent crash when reading CADMIN cluster on dynamic bridge node endpoints
1 parent d31f7be commit 5f31a99

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

examples/fabric-bridge-app/fabric-bridge-common/src/ZCLCallbacks.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace ::chip;
2626
using namespace ::chip::app::Clusters;
2727

2828
#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
29+
#define ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION (1u)
2930
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
3031
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
3132

@@ -37,9 +38,13 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
3738
AttributeId attributeId = attributeMetadata->attributeId;
3839

3940
Device * dev = DeviceMgr().GetDevice(endpoint);
40-
if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
41+
if (dev == nullptr) {
42+
return Protocols::InteractionModel::Status::Failure;
43+
}
44+
45+
if (clusterId == BridgedDeviceBasicInformation::Id)
4146
{
42-
using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
47+
using namespace BridgedDeviceBasicInformation::Attributes;
4348
ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId,
4449
maxReadLength);
4550

@@ -69,6 +74,20 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
6974
return Protocols::InteractionModel::Status::Success;
7075
}
7176

77+
if (clusterId == AdministratorCommissioning::Id)
78+
{
79+
// TODO(Add issue # here) This is a workaround to prevent crash. CADMIN is still reading incorrect
80+
// Attribute values on dynamic endpoint as it only reads the root node and not the actual bridge
81+
// device we are representing here.
82+
if ((attributeId == AdministratorCommissioning::Attributes::ClusterRevision::Id) && (maxReadLength == 2))
83+
{
84+
uint16_t rev = ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION;
85+
memcpy(buffer, &rev, sizeof(rev));
86+
return Protocols::InteractionModel::Status::Success;
87+
}
88+
return Protocols::InteractionModel::Status::Failure;
89+
}
90+
7291
return Protocols::InteractionModel::Status::Failure;
7392
}
7493

0 commit comments

Comments
 (0)