From fec3cdd5aa2113101d8440941cf0dfbc2906fab2 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 28 Apr 2022 16:39:53 -0400 Subject: [PATCH] Remove the concept of client attributes from EmberAfAttributeSearchRecord. (#17825) All attributes in Matter are server attributes. --- src/app/util/af-types.h | 7 ------- src/app/util/af.h | 10 +--------- src/app/util/attribute-metadata.h | 4 +--- src/app/util/attribute-storage.cpp | 10 +++------- src/app/util/attribute-table.cpp | 20 ++++++++++++------- .../util/ember-compatibility-functions.cpp | 6 ++---- src/app/util/util.cpp | 14 +++++++++---- 7 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/app/util/af-types.h b/src/app/util/af-types.h index 31ba518ccfdf2a..7bae467385e664 100644 --- a/src/app/util/af-types.h +++ b/src/app/util/af-types.h @@ -158,13 +158,6 @@ typedef struct */ chip::ClusterId clusterId; - /** - * Cluster mask for the cluster, used to determine if it is - * the server or client version of the cluster. See CLUSTER_MASK_ - * macros defined in att-storage.h - */ - EmberAfClusterMask clusterMask; - /** * The identifier for the attribute. */ diff --git a/src/app/util/af.h b/src/app/util/af.h index 55e4a3aef1a681..62260001a9c47c 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -90,12 +90,11 @@ static constexpr uint16_t kEmberInvalidEndpointIndex = 0xFFFF; * @param endpoint Zigbee endpoint number. * @param clusterId Cluster ID of the sought cluster. * @param attributeId Attribute ID of the sought attribute. - * @param mask CLUSTER_MASK_SERVER or CLUSTER_MASK_CLIENT * * @return Returns pointer to the attribute metadata location. */ const EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(chip::EndpointId endpoint, chip::ClusterId clusterId, - chip::AttributeId attributeId, uint8_t mask); + chip::AttributeId attributeId); /** * @brief Returns true if endpoint contains the ZCL cluster with specified id. @@ -249,13 +248,6 @@ uint8_t emberAfGetDataSize(uint8_t dataType); */ #define emberAfClusterIsManufacturerSpecific(cluster) ((cluster)->clusterId >= 0xFC00) -/** - * @brief macro that returns true if client attribute, and false if server. - * - * @param metadata EmberAfAttributeMetadata* to consider. - */ -#define emberAfAttributeIsClient(metadata) (((metadata)->mask & ATTRIBUTE_MASK_CLIENT) != 0) - /** * @brief macro that returns true if attribute is saved in external storage. * diff --git a/src/app/util/attribute-metadata.h b/src/app/util/attribute-metadata.h index 01987935589115..c9765679e94446 100644 --- a/src/app/util/attribute-metadata.h +++ b/src/app/util/attribute-metadata.h @@ -136,10 +136,8 @@ union EmberAfDefaultOrMinMaxAttributeValue #define ATTRIBUTE_MASK_EXTERNAL_STORAGE (0x10) // Attribute is singleton #define ATTRIBUTE_MASK_SINGLETON (0x20) -// Attribute is a client attribute -#define ATTRIBUTE_MASK_CLIENT (0x40) // Attribute is nullable -#define ATTRIBUTE_MASK_NULLABLE (0x80) +#define ATTRIBUTE_MASK_NULLABLE (0x40) /** * @brief Each attribute has it's metadata stored in such struct. diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index cc5630847c4cfc..ec2c0f12bc823f 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -415,14 +415,12 @@ void emAfCallInits(void) } // Returns the pointer to metadata, or null if it is not found -const EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, - uint8_t mask) +const EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId) { const EmberAfAttributeMetadata * metadata = nullptr; EmberAfAttributeSearchRecord record; record.endpoint = endpoint; record.clusterId = clusterId; - record.clusterMask = mask; record.attributeId = attributeId; emAfReadOrWriteAttribute(&record, &metadata, nullptr, // buffer @@ -512,12 +510,11 @@ static EmberAfStatus typeSensitiveMemCopy(ClusterId clusterId, uint8_t * dest, u * * Clusters match if: * 1. Cluster ids match AND - * 2. Cluster directions match as defined by cluster->mask - * and attRecord->clusterMask + * 2. Cluster is a server cluster (because there are no client attributes). */ bool emAfMatchCluster(const EmberAfCluster * cluster, EmberAfAttributeSearchRecord * attRecord) { - return (cluster->clusterId == attRecord->clusterId && cluster->mask & attRecord->clusterMask); + return (cluster->clusterId == attRecord->clusterId && (cluster->mask & CLUSTER_MASK_SERVER)); } /** @@ -1244,7 +1241,6 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional EmberAfAttributeSearchRecord record; record.endpoint = de->endpoint; record.clusterId = cluster->clusterId; - record.clusterMask = (emberAfAttributeIsClient(am) ? CLUSTER_MASK_CLIENT : CLUSTER_MASK_SERVER); record.attributeId = am->attributeId; if (ptr == nullptr) diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index 13e2efc42bfe83..4bbf7889cce0dd 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -159,7 +159,7 @@ void emberAfPrintAttributeTable(void) { EmberAfDefinedEndpoint * ep = &(emAfEndpoints[endpointIndex]); emberAfAttributesPrintln("ENDPOINT %x", ep->endpoint); - emberAfAttributesPrintln("clus / side / attr / mfg /type(len)/ rw / storage / data (raw)"); + emberAfAttributesPrintln("clus / attr / mfg /type(len)/ rw / storage / data (raw)"); emberAfAttributesFlush(); for (clusterIndex = 0; clusterIndex < ep->endpointType->clusterCount; clusterIndex++) { @@ -174,8 +174,7 @@ void emberAfPrintAttributeTable(void) // manually reset the watchdog. // halResetWatchdog(); - emberAfAttributesPrint(ChipLogFormatMEI " / %p / " ChipLogFormatMEI " / ", ChipLogValueMEI(cluster->clusterId), - (emberAfAttributeIsClient(metaData) ? "clnt" : "srvr"), + emberAfAttributesPrint(ChipLogFormatMEI " / " ChipLogFormatMEI " / ", ChipLogValueMEI(cluster->clusterId), ChipLogValueMEI(metaData->attributeId)); emberAfAttributesPrint("----"); emberAfAttributesPrint( @@ -183,8 +182,7 @@ void emberAfPrintAttributeTable(void) (metaData->IsReadOnly() ? "RO" : "RW"), (metaData->IsNonVolatile() ? " nonvolatile " : (metaData->IsExternal() ? " extern " : " RAM "))); emberAfAttributesFlush(); - status = emAfReadAttribute(ep->endpoint, cluster->clusterId, metaData->attributeId, - (emberAfAttributeIsClient(metaData) ? CLUSTER_MASK_CLIENT : CLUSTER_MASK_SERVER), data, + status = emAfReadAttribute(ep->endpoint, cluster->clusterId, metaData->attributeId, CLUSTER_MASK_SERVER, data, ATTRIBUTE_LARGEST, nullptr); if (status == EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE) { @@ -299,11 +297,15 @@ static bool IsNullValue(const uint8_t * data, uint16_t dataLen, bool isAttribute EmberAfStatus emAfWriteAttribute(EndpointId endpoint, ClusterId cluster, AttributeId attributeID, uint8_t mask, uint8_t * data, EmberAfAttributeType dataType, bool overrideReadOnlyAndDataType, bool justTest) { + if (mask != CLUSTER_MASK_SERVER) + { + return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE; + } + const EmberAfAttributeMetadata * metadata = nullptr; EmberAfAttributeSearchRecord record; record.endpoint = endpoint; record.clusterId = cluster; - record.clusterMask = mask; record.attributeId = attributeID; emAfReadOrWriteAttribute(&record, &metadata, nullptr, // buffer @@ -444,12 +446,16 @@ EmberAfStatus emAfWriteAttribute(EndpointId endpoint, ClusterId cluster, Attribu EmberAfStatus emAfReadAttribute(EndpointId endpoint, ClusterId cluster, AttributeId attributeID, uint8_t mask, uint8_t * dataPtr, uint16_t readLength, EmberAfAttributeType * dataType) { + if (mask != CLUSTER_MASK_SERVER) + { + return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE; + } + const EmberAfAttributeMetadata * metadata = nullptr; EmberAfAttributeSearchRecord record; EmberAfStatus status; record.endpoint = endpoint; record.clusterId = cluster; - record.clusterMask = mask; record.attributeId = attributeID; status = emAfReadOrWriteAttribute(&record, &metadata, dataPtr, readLength, false); // write? diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 8f1bb851ca6380..2c0b960970fea0 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -540,8 +540,7 @@ CHIP_ERROR ReadSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, b attributeCluster = emberAfFindCluster(aPath.mEndpointId, aPath.mClusterId, CLUSTER_MASK_SERVER); break; default: - attributeMetadata = - emberAfLocateAttributeMetadata(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId, CLUSTER_MASK_SERVER); + attributeMetadata = emberAfLocateAttributeMetadata(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId); } if (attributeCluster == nullptr && attributeMetadata == nullptr) @@ -611,7 +610,6 @@ CHIP_ERROR ReadSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, b EmberAfAttributeSearchRecord record; record.endpoint = aPath.mEndpointId; record.clusterId = aPath.mClusterId; - record.clusterMask = CLUSTER_MASK_SERVER; record.attributeId = aPath.mAttributeId; EmberAfStatus emberStatus = emAfReadOrWriteAttribute(&record, &attributeMetadata, attributeData, sizeof(attributeData), /* write = */ false); @@ -965,7 +963,7 @@ CHIP_ERROR prepareWriteData(const EmberAfAttributeMetadata * attributeMetadata, const EmberAfAttributeMetadata * GetAttributeMetadata(const ConcreteAttributePath & aConcreteClusterPath) { return emberAfLocateAttributeMetadata(aConcreteClusterPath.mEndpointId, aConcreteClusterPath.mClusterId, - aConcreteClusterPath.mAttributeId, CLUSTER_MASK_SERVER); + aConcreteClusterPath.mAttributeId); } CHIP_ERROR WriteSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, const ConcreteDataAttributePath & aPath, diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 0c5dcc0fb6c348..3644d45ad51b04 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -771,15 +771,21 @@ uint8_t emberAfMake8bitEncodedChanPg(uint8_t page, uint8_t channel) bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, bool asServer) { - uint8_t mask = asServer ? CLUSTER_MASK_SERVER : CLUSTER_MASK_CLIENT; - return (emberAfLocateAttributeMetadata(endpoint, clusterId, attributeId, mask) != nullptr); + if (!asServer) + { + return false; + } + return (emberAfLocateAttributeMetadata(endpoint, clusterId, attributeId) != nullptr); } bool emberAfIsNonVolatileAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, bool asServer) { - uint8_t mask = asServer ? CLUSTER_MASK_SERVER : CLUSTER_MASK_CLIENT; - const EmberAfAttributeMetadata * metadata = emberAfLocateAttributeMetadata(endpoint, clusterId, attributeId, mask); + if (!asServer) + { + return false; + } + const EmberAfAttributeMetadata * metadata = emberAfLocateAttributeMetadata(endpoint, clusterId, attributeId); if (metadata == nullptr) {