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

fabric-bridge-app: Prevent crash when reading CADMIN cluster on bridge node #34790

Merged
Merged
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 @@ -26,6 +26,7 @@ using namespace ::chip;
using namespace ::chip::app::Clusters;

#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
#define ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION (1u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)

Expand All @@ -37,9 +38,14 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
AttributeId attributeId = attributeMetadata->attributeId;

BridgedDevice * dev = BridgeDeviceMgr().GetDevice(endpoint);
if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
if (dev == nullptr)
{
using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
return Protocols::InteractionModel::Status::Failure;
}

if (clusterId == BridgedDeviceBasicInformation::Id)
{
using namespace BridgedDeviceBasicInformation::Attributes;
ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId,
maxReadLength);

Expand Down Expand Up @@ -69,6 +75,21 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
return Protocols::InteractionModel::Status::Success;
}

if (clusterId == AdministratorCommissioning::Id)
{
// TODO(#34791) This is a workaround to prevent crash. CADMIN is still reading incorrect
// Attribute values on dynamic endpoint as it only reads the root node and not the actual bridge
// device we are representing here, when addressing the issue over there we can more easily
// resolve this workaround.
if ((attributeId == AdministratorCommissioning::Attributes::ClusterRevision::Id) && (maxReadLength == 2))
{
uint16_t rev = ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION;
memcpy(buffer, &rev, sizeof(rev));
return Protocols::InteractionModel::Status::Success;
}
return Protocols::InteractionModel::Status::Failure;
}

return Protocols::InteractionModel::Status::Failure;
}

Expand Down
Loading