Skip to content

Commit

Permalink
Stop storing descriptor list attribute values in the attribute store. (
Browse files Browse the repository at this point in the history
…#10793)

We are handling these via AttributeAccessInterface now.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 4, 2021
1 parent 7709a7c commit 2298608
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 130 deletions.
126 changes: 0 additions & 126 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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));
}
}
5 changes: 5 additions & 0 deletions src/app/reporting/reporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 11 additions & 4 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
******************************************************************************/

#include "app/util/common.h"
#include <app/reporting/reporting.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/support/logging/CHIPLogging.h>

#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/callbacks/PluginCallbacks.h>
#include <app-common/zap-generated/ids/Attributes.h>

using namespace chip;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <app/ConcreteAttributePath.h>
#include <app/InteractionModelEngine.h>
#include <app/reporting/Engine.h>
#include <app/reporting/reporting.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/attribute-table.h>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2298608

Please sign in to comment.