diff --git a/src/app/clusters/descriptor/descriptor.cpp b/src/app/clusters/descriptor/descriptor.cpp index 43c4bf4dc5e089..571ab466fc47de 100644 --- a/src/app/clusters/descriptor/descriptor.cpp +++ b/src/app/clusters/descriptor/descriptor.cpp @@ -34,8 +34,6 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::Descriptor::Attributes; -constexpr const char * kErrorStr = "Descriptor cluster (0x%02x) Error setting '%s' attribute: 0x%02x"; - namespace { class DescriptorAttrAccess : public AttributeAccessInterface @@ -141,101 +139,8 @@ CHIP_ERROR DescriptorAttrAccess::Read(const ConcreteAttributePath & aPath, Attri } } // anonymous namespace -EmberAfStatus writeAttribute(EndpointId endpoint, AttributeId attributeId, uint8_t * buffer, int32_t index = -1) -{ - EmberAfAttributeSearchRecord record; - record.endpoint = endpoint; - record.clusterId = Descriptor::Id; - record.clusterMask = CLUSTER_MASK_SERVER; - record.manufacturerCode = EMBER_AF_NULL_MANUFACTURER_CODE; - record.attributeId = attributeId; - - // When reading or writing a List attribute the 'index' value could have 3 types of values: - // -1: Read/Write the whole list content, including the number of elements in the list - // 0: Read/Write the number of elements in the list, represented as a uint16_t - // n: Read/Write the nth element of the list - // - // Since the first 2 bytes of the attribute are used to store the number of elements, elements indexing starts - // at 1. In order to hide this to the rest of the code of this file, the element index is incremented by 1 here. - // This also allows calling writeAttribute() with no index arg to mean "write the length". - return emAfReadOrWriteAttribute(&record, NULL, buffer, 0, true, index + 1); -} - -EmberAfStatus writeClientServerAttribute(EndpointId endpoint, bool server) -{ - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - AttributeId attributeId = server ? Descriptor::Attributes::ServerList::Id : Descriptor::Attributes::ClientList::Id; - - uint16_t clusterCount = emberAfClusterCount(endpoint, server); - - EmberAfCluster * cluster; - for (uint8_t clusterIndex = 0; clusterIndex < clusterCount; clusterIndex++) - { - cluster = emberAfGetNthCluster(endpoint, clusterIndex, server); - status = writeAttribute(endpoint, attributeId, (uint8_t *) &cluster->clusterId, clusterIndex); - VerifyOrReturnError(status == EMBER_ZCL_STATUS_SUCCESS, status); - } - - return writeAttribute(endpoint, attributeId, (uint8_t *) &clusterCount); -} - -EmberAfStatus writeServerAttribute(EndpointId endpoint) -{ - return writeClientServerAttribute(endpoint, true); -} - -EmberAfStatus writeClientAttribute(EndpointId endpoint) -{ - return writeClientServerAttribute(endpoint, false); -} - -EmberAfStatus writeDeviceAttribute(EndpointId endpoint, uint16_t index) -{ - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - AttributeId attributeId = Descriptor::Attributes::DeviceList::Id; - - uint16_t deviceTypeCount = 1; - DeviceTypeId deviceTypeId = emberAfDeviceIdFromIndex(index); - uint16_t revision = emberAfDeviceVersionFromIndex(index); - - DeviceType deviceType; - deviceType.type = deviceTypeId; - deviceType.revision = revision; - - status = writeAttribute(endpoint, attributeId, (uint8_t *) &deviceType, 0); - VerifyOrReturnError(status == EMBER_ZCL_STATUS_SUCCESS, status); - - return writeAttribute(endpoint, attributeId, (uint8_t *) &deviceTypeCount); -} - -EmberAfStatus writePartsAttribute(EndpointId endpoint) -{ - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - AttributeId attributeId = Descriptor::Attributes::PartsList::Id; - - uint16_t partsCount = 0; - - if (endpoint == 0x00) - { - for (uint16_t endpointIndex = 1; endpointIndex < emberAfEndpointCount(); endpointIndex++) - { - if (emberAfEndpointIndexIsEnabled(endpointIndex)) - { - EndpointId endpointId = emberAfEndpointFromIndex(endpointIndex); - status = writeAttribute(endpoint, attributeId, (uint8_t *) &endpointId, partsCount); - VerifyOrReturnError(status == EMBER_ZCL_STATUS_SUCCESS, status); - partsCount++; - } - } - } - - return writeAttribute(endpoint, attributeId, (uint8_t *) &partsCount); -} - void MatterDescriptorPluginServerInitCallback(void) { - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - #if CHIP_CLUSTER_CONFIG_ENABLE_COMPLEX_ATTRIBUTE_READ static bool attrAccessRegistered = false; @@ -245,35 +150,4 @@ void MatterDescriptorPluginServerInitCallback(void) attrAccessRegistered = true; } #endif - - /* - To prevent reporting from being broken, we still need to keep following part in case - CHIP_CLUSTER_CONFIG_ENABLE_COMPLEX_ATTRIBUTE_READ is true. The old setup has the emberAfPluginDescriptorServerInitCallback - called in emberAfEndpointEnableDisable which updates the stored values for the new topology. - */ - for (uint16_t index = 0; index < emberAfEndpointCount(); index++) - { - if (!emberAfEndpointIndexIsEnabled(index)) - { - continue; - } - - EndpointId endpoint = emberAfEndpointFromIndex(index); - if (!emberAfContainsCluster(endpoint, Descriptor::Id)) - { - continue; - } - - status = writeDeviceAttribute(endpoint, index); - VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "device", status)); - - status = writeServerAttribute(endpoint); - VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "server", status)); - - status = writeClientAttribute(endpoint); - VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "client", status)); - - status = writePartsAttribute(endpoint); - VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "parts", status)); - } } diff --git a/src/app/reporting/reporting.h b/src/app/reporting/reporting.h index 5fbc969f19f336..df86c588b284ba 100644 --- a/src/app/reporting/reporting.h +++ b/src/app/reporting/reporting.h @@ -58,3 +58,8 @@ */ void MatterReportingAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t mask, uint16_t manufacturerCode, EmberAfAttributeType type, uint8_t * data); + +/* + * Same but with just an attribute path and no data available. + */ +void MatterReportingAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 6b7ceb907b70b6..d600c92748d997 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -40,6 +40,7 @@ ******************************************************************************/ #include "app/util/common.h" +#include #include #include #include @@ -47,6 +48,7 @@ #include #include #include +#include using namespace chip; @@ -997,10 +999,15 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable) } } -#ifdef ZCL_USING_DESCRIPTOR_CLUSTER_SERVER - // Rebuild descriptor attributes on all endpoints - MatterDescriptorPluginServerInitCallback(); -#endif + // TODO: We should notify about the fact that all the attributes for + // this endpoint have appeared/disappeared, but the reporting engine has + // no way to do that right now. + + // TODO: Once endpoints are in parts lists other than that of endpoint + // 0, something more complicated might need to happen here. + + MatterReportingAttributeChangeCallback(/* EndpointId = */ 0, app::Clusters::Descriptor::Id, + app::Clusters::Descriptor::Attributes::PartsList::Id); } return true; diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 04ab430a5ace6e..3d7d6e4d368cd4 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -491,6 +492,11 @@ void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clust IgnoreUnusedVariable(data); IgnoreUnusedVariable(mask); + MatterReportingAttributeChangeCallback(endpoint, clusterId, attributeId); +} + +void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId) +{ ClusterInfo info; info.mClusterId = clusterId; info.mFieldId = attributeId;