Skip to content

Commit

Permalink
Address review comments on PR 13172. (#13600)
Browse files Browse the repository at this point in the history
* Address review comments on PR 13172.

Changes:

* Remove length anotations on some lists that are always handled via
  AttributeAccessInterface so should not count toward
  ATTRIBUTE_LARGEST.  Reduces ATTRIBUTE_LARGEST from 401 to 255/259
  for most apps.

* Fix some .zap files that did not have those lists marked as External
  storage.

* Add a way for applications to static_assert via a config variable
  that ATTRIBUTE_LARGEST is not larger than expected.

* Stop using %zu for logging in Server.h

* Add checks + logging for a missing attribute persistence provider in
  attribute-storage.

* Address review comments.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 9, 2023
1 parent 0b0a46a commit 9131957
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 228 deletions.
4 changes: 2 additions & 2 deletions examples/log-source-app/log-source-common/log-source-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down Expand Up @@ -1625,7 +1625,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down
2 changes: 1 addition & 1 deletion examples/placeholder/linux/apps/app1/config.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down
2 changes: 1 addition & 1 deletion examples/placeholder/linux/apps/app2/config.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Server
ReturnErrorOnFailure(DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(key, buffer, size, &bytesRead));
if (!CanCastTo<uint16_t>(bytesRead))
{
ChipLogDetail(AppServer, "%zu is too big to fit in uint16_t", bytesRead);
ChipLogDetail(AppServer, "0x%" PRIx32 " is too big to fit in uint16_t", static_cast<uint32_t>(bytesRead));
return CHIP_ERROR_BUFFER_TOO_SMALL;
}
ChipLogProgress(AppServer, "Retrieved from server storage: %s", key);
Expand Down
14 changes: 12 additions & 2 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,8 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional
uint16_t epCount = emberAfEndpointCount();
uint8_t attrData[ATTRIBUTE_LARGEST];
auto * attrStorage = ignoreStorage ? nullptr : app::GetAttributePersistenceProvider();
// Don't check whether we actually have an attrStorage here, because it's OK
// to have one if none of our attributes have NVM storage.

for (ep = 0; ep < epCount; ep++)
{
Expand Down Expand Up @@ -1211,6 +1213,7 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional
// First check for a persisted value.
if (!ignoreStorage && am->IsNonVolatile())
{
VerifyOrDie(attrStorage && "Attribute persistence needs a persistence provider");
MutableByteSpan bytes(attrData);
CHIP_ERROR err = attrStorage->ReadValue(
app::ConcreteAttributePath(de->endpoint, cluster->clusterId, am->attributeId), am, bytes);
Expand Down Expand Up @@ -1331,8 +1334,15 @@ void emAfSaveAttributeToStorageIfNeeded(uint8_t * data, EndpointId endpoint, Clu
}

auto * attrStorage = app::GetAttributePersistenceProvider();
attrStorage->WriteValue(app::ConcreteAttributePath(endpoint, clusterId, metadata->attributeId), metadata,
ByteSpan(data, dataSize));
if (attrStorage)
{
attrStorage->WriteValue(app::ConcreteAttributePath(endpoint, clusterId, metadata->attributeId), metadata,
ByteSpan(data, dataSize));
}
else
{
ChipLogProgress(DataManagement, "Can't store attribute value: no persistence provider");
}
}

// This function returns the actual function point from the array,
Expand Down
6 changes: 5 additions & 1 deletion src/app/zap-templates/templates/app/endpoint_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Prevent multiple inclusion
#pragma once

{{#endpoint_config}}
#include <lib/core/CHIPConfig.h>

{{#endpoint_config}}

// Default values for the attributes longer than a pointer,
// in a form of a binary blob
Expand Down Expand Up @@ -73,6 +74,9 @@
// Largest attribute size is needed for various buffers
#define ATTRIBUTE_LARGEST ({{endpoint_largest_attribute_size}})

static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE,
"ATTRIBUTE_LARGEST larger than expected");

// Total size of singleton attributes
#define ATTRIBUTE_SINGLETONS_SIZE ({{endpoint_singletons_size}})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ limitations under the License.
<code>0x001d</code>
<define>DESCRIPTOR_CLUSTER</define>
<description>The Descriptor Cluster is meant to replace the support from the Zigbee Device Object (ZDO) for describing a node, its endpoints and clusters.</description>
<attribute side="server" code="0x0000" define="DEVICE_LIST" type="ARRAY" entryType="DeviceType" length="254" writable="false" optional="false">device list</attribute>
<attribute side="server" code="0x0001" define="SERVER_LIST" type="ARRAY" entryType="CLUSTER_ID" length="254" writable="false" optional="false">server list</attribute>
<attribute side="server" code="0x0002" define="CLIENT_LIST" type="ARRAY" entryType="CLUSTER_ID" length="254" writable="false" optional="false">client list</attribute>
<attribute side="server" code="0x0003" define="PARTS_LIST" type="ARRAY" entryType="ENDPOINT_NO" length="254" writable="false" optional="false">parts list</attribute>
<attribute side="server" code="0x0000" define="DEVICE_LIST" type="ARRAY" entryType="DeviceType" writable="false" optional="false">device list</attribute>
<attribute side="server" code="0x0001" define="SERVER_LIST" type="ARRAY" entryType="CLUSTER_ID" writable="false" optional="false">server list</attribute>
<attribute side="server" code="0x0002" define="CLIENT_LIST" type="ARRAY" entryType="CLUSTER_ID" writable="false" optional="false">client list</attribute>
<attribute side="server" code="0x0003" define="PARTS_LIST" type="ARRAY" entryType="ENDPOINT_NO" writable="false" optional="false">parts list</attribute>
</cluster>
</configurator>
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ limitations under the License.
<description>This cluster is used to add or remove Operational Credentials on a Commissionee or Node, as well as manage the associated Fabrics.</description>

<attribute side="server" code="0x0000" define="NOCS" type="ARRAY" entryType="NOCStruct" writable="false" optional="false">NOCs</attribute>
<attribute side="server" code="0x0001" define="FABRICS" type="ARRAY" entryType="FabricDescriptor" length="320" writable="false" optional="false">fabrics list</attribute>
<attribute side="server" code="0x0001" define="FABRICS" type="ARRAY" entryType="FabricDescriptor" writable="false" optional="false">fabrics list</attribute>
<attribute side="server" code="0x0002" define="SUPPORTED_FABRICS" type="INT8U" writable="false" optional="false">SupportedFabrics</attribute>
<attribute side="server" code="0x0003" define="COMMISSIONED_FABRICS" type="INT8U" writable="false" optional="false">CommissionedFabrics</attribute>
<!-- 400 = 400 bytes for root cert -->
<attribute side="server" code="0x0004" define="TRUSTED_ROOTS" type="ARRAY" entryType="OCTET_STRING" length="400" writable="false" optional="false">TrustedRootCertificates</attribute>
<attribute side="server" code="0x0004" define="TRUSTED_ROOTS" type="ARRAY" entryType="OCTET_STRING" writable="false" optional="false">TrustedRootCertificates</attribute>
<attribute side="server" code="0x0005" define="CURRENT_FABRIC_INDEX" type="fabric_idx" writable="false" optional="false">CurrentFabricIndex</attribute>

<command source="client" code="0x00" name="AttestationRequest" response="AttestationResponse" optional="false">
Expand Down
17 changes: 17 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,23 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#ifndef CHIP_RESUBSCRIBE_WAIT_TIME_MULTIPLIER_MS
#define CHIP_RESUBSCRIBE_WAIT_TIME_MULTIPLIER_MS 10000
#endif

/*
* @def CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE
*
* @brief Safety limit to ensure that we don't end up with a
* larger-than-expected buffer for temporary attribute storage (on the stack or
* in .bss). The SDK will fail to compile if this value is set below the value
* it thinks it needs for a buffer size that can store any simple (not list or
* struct) attribute value.
*/
#ifndef CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE
// I can't figure out how to get all-clusters-app to sanely use a different
// value here, and that app includes TestCluster, which has very large string
// attributes (1000 octets, leading to a 1003 octet buffer).
#define CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE 1003
#endif // CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE

/**
* @}
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion zzz_generated/bridge-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion zzz_generated/door-lock-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion zzz_generated/lighting-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion zzz_generated/lock-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9131957

Please sign in to comment.