From a1a392912e8307e86ca8afe46e09db080eca801e Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Mon, 5 Aug 2024 23:59:29 +0000 Subject: [PATCH 1/2] Fix ecosystem information cluster when reading cluster revision --- .../ecosystem-information-server.cpp | 48 ++++++++++++------- .../ecosystem-information-server.h | 9 ++-- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp index 4d7f7b8ddf754e..98826d81156fec 100644 --- a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp +++ b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp @@ -26,6 +26,9 @@ namespace Clusters { namespace EcosystemInformation { namespace { +#define ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION (1u) +#define ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP (0u) + constexpr size_t kDeviceNameMaxSize = 64; constexpr size_t kUniqueLocationIdMaxSize = 64; constexpr size_t kUniqueLocationIdsListMaxSize = 64; @@ -46,18 +49,7 @@ class AttrAccess : public AttributeAccessInterface CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { VerifyOrDie(aPath.mClusterId == Clusters::EcosystemInformation::Id); - switch (aPath.mAttributeId) - { - case Attributes::RemovedOn::Id: - return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder); - case Attributes::DeviceDirectory ::Id: - return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder); - case Attributes::LocationDirectory ::Id: - return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder); - default: - break; - } - return CHIP_NO_ERROR; + return EcosystemInformationServer::Instance().ReadAttribute(aPath, aEncoder); } // WARNING: caller is expected to use the returned LocationDescriptorStruct::Type immediately. Caller must @@ -66,8 +58,7 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa // TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private // memeber method where we explicitly delete member method for the parameter that matches // (LocationDescriptorStruct && aLocationDescriptor). -Globals::Structs::LocationDescriptorStruct::Type -GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) +Globals::Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) { Globals::Structs::LocationDescriptorStruct::Type locationDescriptor; // This would imply data is either not properly validated before being @@ -200,8 +191,7 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum return *this; } -EcosystemLocationStruct::Builder & -EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) +EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) { VerifyOrDie(!mIsAlreadyBuilt); mLocationDescriptor.mAreaType = aAreaTypeTag; @@ -285,6 +275,32 @@ CHIP_ERROR EcosystemInformationServer::RemoveDevice(EndpointId aEndpoint, uint64 return CHIP_NO_ERROR; } +CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + switch (aPath.mAttributeId) + { + case Attributes::RemovedOn::Id: + return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder); + case Attributes::DeviceDirectory::Id: + return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder); + case Attributes::LocationDirectory::Id: + return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder); + case Attributes::ClusterRevision::Id: + { + uint16_t rev = ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION; + return aEncoder.Encode(rev); + } + case Attributes::FeatureMap::Id: + { + uint32_t featureMap = ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP; + return aEncoder.Encode(featureMap); + } + default: + break; + } + return CHIP_NO_ERROR; +} + CHIP_ERROR EcosystemInformationServer::EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder) { auto it = mDevicesMap.find(aEndpoint); diff --git a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h index 58c64262166403..daa6f0124d9e39 100644 --- a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h +++ b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h @@ -182,9 +182,7 @@ class EcosystemInformationServer CHIP_ERROR RemoveDevice(EndpointId aEndpoint, uint64_t aEpochUs); // TODO(#33223) Add removal and update counterparts to AddDeviceInfo and AddLocationInfo. - CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); - CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); - CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); private: struct DeviceInfo @@ -194,6 +192,11 @@ class EcosystemInformationServer // Map key is using the UniqueLocationId std::map> mLocationDirectory; }; + + CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder); + std::map mDevicesMap; static EcosystemInformationServer mInstance; From 69ceb80b08c576e60b5c78a3ed53e76e270d4ef1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 6 Aug 2024 00:01:37 +0000 Subject: [PATCH 2/2] Restyled by clang-format --- .../ecosystem-information-server.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp index 98826d81156fec..74a27f21779ff9 100644 --- a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp +++ b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp @@ -58,7 +58,8 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa // TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private // memeber method where we explicitly delete member method for the parameter that matches // (LocationDescriptorStruct && aLocationDescriptor). -Globals::Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) +Globals::Structs::LocationDescriptorStruct::Type +GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) { Globals::Structs::LocationDescriptorStruct::Type locationDescriptor; // This would imply data is either not properly validated before being @@ -191,7 +192,8 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum return *this; } -EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) +EcosystemLocationStruct::Builder & +EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) { VerifyOrDie(!mIsAlreadyBuilt); mLocationDescriptor.mAreaType = aAreaTypeTag; @@ -285,16 +287,14 @@ CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttribute return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder); case Attributes::LocationDirectory::Id: return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder); - case Attributes::ClusterRevision::Id: - { - uint16_t rev = ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION; - return aEncoder.Encode(rev); - } - case Attributes::FeatureMap::Id: - { - uint32_t featureMap = ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP; - return aEncoder.Encode(featureMap); - } + case Attributes::ClusterRevision::Id: { + uint16_t rev = ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION; + return aEncoder.Encode(rev); + } + case Attributes::FeatureMap::Id: { + uint32_t featureMap = ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP; + return aEncoder.Encode(featureMap); + } default: break; }