diff --git a/examples/chip-tool/commands/tests/TestCommand.h b/examples/chip-tool/commands/tests/TestCommand.h index bb5d2b82cb7632..396835a1fdb03f 100644 --- a/examples/chip-tool/commands/tests/TestCommand.h +++ b/examples/chip-tool/commands/tests/TestCommand.h @@ -161,6 +161,8 @@ class TestCommand : public CHIPCommand template bool CheckValueAsListLength(const char * itemName, chip::app::DataModel::DecodableList list, uint64_t expectedLength) { + // We don't just use list.ComputeSize(), because we want to check that + // all the values in the list correctly decode to our type too. auto iter = list.begin(); uint64_t count = 0; while (iter.Next()) diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index 635b955879b0c5..c6b5642cfa5673 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -139,16 +139,12 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttri ModelCommand * command = static_cast(context); size_t count = 0; - { - auto iter = list.begin(); - while (iter.Next()) { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -180,8 +176,7 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttri {{/if}} {{/if}} } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } {{/if}} diff --git a/src/app/clusters/test-cluster-server/test-cluster-server.cpp b/src/app/clusters/test-cluster-server/test-cluster-server.cpp index 01bec699d75ef7..b9b895bcee718a 100644 --- a/src/app/clusters/test-cluster-server/test-cluster-server.cpp +++ b/src/app/clusters/test-cluster-server/test-cluster-server.cpp @@ -394,15 +394,9 @@ bool emberAfTestClusterClusterTestListInt8UReverseRequestCallback( CommandHandler * commandObj, ConcreteCommandPath const & commandPath, Commands::TestListInt8UReverseRequest::DecodableType const & commandData) { - size_t count = 0; - { - auto iter = commandData.arg1.begin(); - while (iter.Next()) - { - ++count; - } - VerifyOrExit(iter.GetStatus() == CHIP_NO_ERROR, ); - } + size_t count = 0; + CHIP_ERROR err = commandData.arg1.ComputeSize(&count); + VerifyOrExit(err == CHIP_NO_ERROR, ); { auto iter = commandData.arg1.begin(); diff --git a/src/app/data-model/DecodableList.h b/src/app/data-model/DecodableList.h index 023b09b2abb65e..ac1075c9ab594f 100644 --- a/src/app/data-model/DecodableList.h +++ b/src/app/data-model/DecodableList.h @@ -127,6 +127,14 @@ class DecodableList Iterator begin() const { return Iterator(mReader); } + /* + * Compute the size of the list. This can fail if the TLV is malformed. If + * this succeeds, that does not guarantee that the individual items can be + * successfully decoded; consumers should check Iterator::GetStatus() when + * actually decoding them. + */ + CHIP_ERROR ComputeSize(size_t * size) const { return mReader.CountRemainingInContainer(size); } + private: TLV::TLVReader mReader; }; diff --git a/src/controller/python/chip/clusters/CHIPClusters.cpp b/src/controller/python/chip/clusters/CHIPClusters.cpp index 8778d989815c4b..457049fd50bd64 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -105,12 +105,8 @@ static void OnApplicationLauncherApplicationLauncherListListAttributeResponse(vo const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -132,6 +128,14 @@ static void OnApplicationLauncherApplicationLauncherListListAttributeResponse(vo #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu16 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -148,12 +152,8 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -179,6 +179,14 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( ChipLogProgress(Zcl, " name: %.*s,", static_cast(entry.name.size()), entry.name.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -193,12 +201,8 @@ static void OnContentLauncherAcceptsHeaderListListAttributeResponse(void * conte const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -220,6 +224,14 @@ static void OnContentLauncherAcceptsHeaderListListAttributeResponse(void * conte #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %s,", ByteSpanToString(entry).c_str()); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -233,12 +245,8 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -260,6 +268,14 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu8 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -274,12 +290,8 @@ static void OnDescriptorDeviceListListAttributeResponse( void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -304,6 +316,14 @@ static void OnDescriptorDeviceListListAttributeResponse( ChipLogProgress(Zcl, " revision: %" PRIu16 ",", entry.revision); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -317,12 +337,8 @@ chip::Callback::Callback gDescriptorD static void OnDescriptorServerListListAttributeResponse(void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -344,6 +360,14 @@ static void OnDescriptorServerListListAttributeResponse(void * context, const Da #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu32 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -357,12 +381,8 @@ chip::Callback::Callback gDescriptorS static void OnDescriptorClientListListAttributeResponse(void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -384,6 +404,14 @@ static void OnDescriptorClientListListAttributeResponse(void * context, const Da #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu32 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -397,12 +425,8 @@ chip::Callback::Callback gDescriptorC static void OnDescriptorPartsListListAttributeResponse(void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -424,6 +448,14 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, const Dat #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu16 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -438,12 +470,8 @@ static void OnFixedLabelLabelListListAttributeResponse( void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -468,6 +496,14 @@ static void OnFixedLabelLabelListListAttributeResponse( ChipLogProgress(Zcl, " value: %.*s,", static_cast(entry.value.size()), entry.value.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -484,12 +520,8 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -513,6 +545,14 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons ChipLogProgress(Zcl, " FailSafeExpiryLengthMs: %" PRIu32 ",", entry.failSafeExpiryLengthMs); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -529,12 +569,8 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -563,6 +599,14 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( ChipLogProgress(Zcl, " Type: %" PRIu8 ",", entry.type); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -578,12 +622,8 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -609,6 +649,14 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( ChipLogProgress(Zcl, " GroupKeySetIndex: %" PRIu16 ",", entry.groupKeySetIndex); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -624,12 +672,8 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -657,6 +701,14 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( ChipLogProgress(Zcl, " GroupKeySecurityPolicy: %" PRIu8 ",", entry.groupKeySecurityPolicy); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -671,12 +723,8 @@ static void OnMediaInputMediaInputListListAttributeResponse( void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -703,6 +751,14 @@ static void OnMediaInputMediaInputListListAttributeResponse( ChipLogProgress(Zcl, " description: %.*s,", static_cast(entry.description.size()), entry.description.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -718,12 +774,8 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -752,6 +804,14 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( ChipLogProgress(Zcl, " Label: %.*s,", static_cast(entry.label.size()), entry.label.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -764,12 +824,8 @@ chip::Callback::Callback static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -791,6 +847,14 @@ static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu8 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -805,12 +869,8 @@ static void OnTvChannelTvChannelListListAttributeResponse( void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -839,6 +899,14 @@ static void OnTvChannelTvChannelListListAttributeResponse( entry.affiliateCallSign.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -854,12 +922,8 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -884,6 +948,14 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( ChipLogProgress(Zcl, " name: %.*s,", static_cast(entry.name.size()), entry.name.data()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -896,12 +968,8 @@ chip::Callback::Callback & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -923,6 +991,14 @@ static void OnTestClusterListInt8uListAttributeResponse(void * context, const Da #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu8 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -936,12 +1012,8 @@ chip::Callback::Callback gTestCluster static void OnTestClusterListOctetStringListAttributeResponse(void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -963,6 +1035,14 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, co #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %s,", ByteSpanToString(entry).c_str()); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -978,12 +1058,8 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1008,6 +1084,14 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( ChipLogProgress(Zcl, " operationalCert: %s,", ByteSpanToString(entry.operationalCert).c_str()); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -1022,12 +1106,8 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1064,6 +1144,14 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( ChipLogProgress(Zcl, " IsChild: %d,", entry.isChild); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -1080,12 +1168,8 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1118,6 +1202,14 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( ChipLogProgress(Zcl, " LinkEstablished: %d,", entry.linkEstablished); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -1133,12 +1225,8 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1163,6 +1251,14 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( ChipLogProgress(Zcl, " Flags: %" PRIu16 ",", entry.flags); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -1179,12 +1275,8 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR chip::app::Clusters::ThreadNetworkDiagnostics::Structs::OperationalDatasetComponents::DecodableType> & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1219,6 +1311,14 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR ChipLogProgress(Zcl, " ChannelMaskPresent: %d,", entry.channelMaskPresent); ChipLogProgress(Zcl, " },"); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); @@ -1234,12 +1334,8 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon void * context, const DataModel::DecodableList & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1261,6 +1357,14 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon #endif // CHIP_PROGRESS_LOGGING ChipLogProgress(Zcl, " %" PRIu8 ",", entry); } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); diff --git a/src/controller/python/templates/python-CHIPClusters-cpp.zapt b/src/controller/python/templates/python-CHIPClusters-cpp.zapt index f75cb2feea4717..8f04de284e56f0 100644 --- a/src/controller/python/templates/python-CHIPClusters-cpp.zapt +++ b/src/controller/python/templates/python-CHIPClusters-cpp.zapt @@ -91,12 +91,8 @@ void OnAttributeResponse(void * /* context */, bool value) static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, const DataModel::DecodableList<{{zapTypeToDecodableClusterObjectType type ns=parent.name}}> & list) { uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -136,6 +132,14 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttri ChipLogProgress(Zcl, " {{asPrintFormat type}},", entry); {{/if}} } + if (iter.GetStatus() != CHIP_NO_ERROR) + { + if (gFailureResponseDelegate != nullptr) + { + gFailureResponseDelegate(EMBER_ZCL_STATUS_INVALID_VALUE); + } + return; + } if (count > 0) ChipLogProgress(Zcl, " ]"); diff --git a/src/lib/core/CHIPTLV.h b/src/lib/core/CHIPTLV.h index 930607ddc74993..b7fd1115ce24e0 100644 --- a/src/lib/core/CHIPTLV.h +++ b/src/lib/core/CHIPTLV.h @@ -862,6 +862,15 @@ class DLL_EXPORT TLVReader */ CHIP_ERROR FindElementWithTag(Tag tagInApiForm, TLVReader & destReader) const; + /** + * Count how many elements remain in the currently-open container. Will + * fail with CHIP_ERROR_INCORRECT_STATE if not currently in a container. + * + * @param[out] On success, set to the number of items following the current + * reader position in the container. + */ + CHIP_ERROR CountRemainingInContainer(size_t * size) const; + /** * The profile id to be used for profile tags encoded in implicit form. * diff --git a/src/lib/core/CHIPTLVReader.cpp b/src/lib/core/CHIPTLVReader.cpp index 6fb6ca06d803e8..31f67bf7d494e9 100644 --- a/src/lib/core/CHIPTLVReader.cpp +++ b/src/lib/core/CHIPTLVReader.cpp @@ -949,6 +949,28 @@ CHIP_ERROR TLVReader::FindElementWithTag(Tag tag, TLVReader & destReader) const return err; } +CHIP_ERROR TLVReader::CountRemainingInContainer(size_t * size) const +{ + if (mContainerType == kTLVType_NotSpecified) + { + return CHIP_ERROR_INCORRECT_STATE; + } + + TLVReader tempReader(*this); + size_t count = 0; + CHIP_ERROR err; + while ((err = tempReader.Next()) == CHIP_NO_ERROR) + { + ++count; + }; + if (err == CHIP_END_OF_TLV) + { + *size = count; + return CHIP_NO_ERROR; + } + return err; +} + CHIP_ERROR ContiguousBufferTLVReader::OpenContainer(ContiguousBufferTLVReader & containerReader) { // We are going to initialize containerReader by calling our superclass diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 3c89b0b6325385..983b3a320004e3 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -158,19 +158,14 @@ OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnApplicationLauncherApplicationLauncherListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -183,8 +178,7 @@ OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context ++i; ChipLogProgress(chipTool, "INT16U[%" PRIu16 "]: %" PRIu16 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnAudioOutputAudioOutputListListAttributeResponse( @@ -193,19 +187,14 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnAudioOutputAudioOutputListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -221,8 +210,7 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( ChipLogProgress(chipTool, " outputType: %" PRIu8 "", entry.outputType); ChipLogProgress(Zcl, " name: %.*s", static_cast(entry.name.size()), entry.name.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void @@ -231,19 +219,14 @@ OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnContentLauncherAcceptsHeaderListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -256,8 +239,7 @@ OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, ++i; ChipLogProgress(Zcl, " : %zu", entry.size()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( @@ -266,19 +248,14 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnContentLauncherSupportedStreamingTypesListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -291,8 +268,7 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( ++i; ChipLogProgress(chipTool, "ContentLaunchStreamingType[%" PRIu16 "]: %" PRIu8 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnDescriptorDeviceListListAttributeResponse( @@ -301,19 +277,14 @@ static void OnDescriptorDeviceListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnDescriptorDeviceListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -328,8 +299,7 @@ static void OnDescriptorDeviceListListAttributeResponse( ChipLogProgress(chipTool, " type: %" PRIu32 "", entry.type); ChipLogProgress(chipTool, " revision: %" PRIu16 "", entry.revision); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnDescriptorServerListListAttributeResponse(void * context, @@ -337,19 +307,14 @@ static void OnDescriptorServerListListAttributeResponse(void * context, { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnDescriptorServerListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -362,8 +327,7 @@ static void OnDescriptorServerListListAttributeResponse(void * context, ++i; ChipLogProgress(chipTool, "CLUSTER_ID[%" PRIu16 "]: %" PRIu32 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnDescriptorClientListListAttributeResponse(void * context, @@ -371,19 +335,14 @@ static void OnDescriptorClientListListAttributeResponse(void * context, { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnDescriptorClientListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -396,8 +355,7 @@ static void OnDescriptorClientListListAttributeResponse(void * context, ++i; ChipLogProgress(chipTool, "CLUSTER_ID[%" PRIu16 "]: %" PRIu32 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnDescriptorPartsListListAttributeResponse(void * context, @@ -405,19 +363,14 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnDescriptorPartsListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -430,8 +383,7 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, ++i; ChipLogProgress(chipTool, "ENDPOINT_NO[%" PRIu16 "]: %" PRIu16 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnFixedLabelLabelListListAttributeResponse( @@ -440,19 +392,14 @@ static void OnFixedLabelLabelListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnFixedLabelLabelListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -467,8 +414,7 @@ static void OnFixedLabelLabelListListAttributeResponse( ChipLogProgress(Zcl, " label: %.*s", static_cast(entry.label.size()), entry.label.data()); ChipLogProgress(Zcl, " value: %.*s", static_cast(entry.value.size()), entry.value.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeResponse( @@ -478,19 +424,14 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnGeneralCommissioningBasicCommissioningInfoListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -504,8 +445,7 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons ChipLogProgress(chipTool, "BasicCommissioningInfoType[%" PRIu16 "]:", i); ChipLogProgress(chipTool, " failSafeExpiryLengthMs: %" PRIu32 "", entry.failSafeExpiryLengthMs); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( @@ -515,19 +455,14 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -546,8 +481,7 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( ChipLogProgress(Zcl, " HardwareAddress: %zu", entry.hardwareAddress.size()); ChipLogProgress(chipTool, " type: %" PRIu8 "", entry.type); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnGroupKeyManagementGroupsListAttributeResponse( @@ -556,19 +490,14 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnGroupKeyManagementGroupsListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -584,8 +513,7 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( ChipLogProgress(chipTool, " vendorGroupId: %" PRIu16 "", entry.vendorGroupId); ChipLogProgress(chipTool, " groupKeySetIndex: %" PRIu16 "", entry.groupKeySetIndex); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnGroupKeyManagementGroupKeysListAttributeResponse( @@ -594,19 +522,14 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnGroupKeyManagementGroupKeysListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -624,8 +547,7 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( ChipLogProgress(chipTool, " groupKeyEpochStartTime: %" PRIu64 "", entry.groupKeyEpochStartTime); ChipLogProgress(chipTool, " groupKeySecurityPolicy: %" PRIu8 "", entry.groupKeySecurityPolicy); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnMediaInputMediaInputListListAttributeResponse( @@ -634,19 +556,14 @@ static void OnMediaInputMediaInputListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnMediaInputMediaInputListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -663,8 +580,7 @@ static void OnMediaInputMediaInputListListAttributeResponse( ChipLogProgress(Zcl, " name: %.*s", static_cast(entry.name.size()), entry.name.data()); ChipLogProgress(Zcl, " description: %.*s", static_cast(entry.description.size()), entry.description.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnOperationalCredentialsFabricsListListAttributeResponse( @@ -674,19 +590,14 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnOperationalCredentialsFabricsListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -705,8 +616,7 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( ChipLogProgress(chipTool, " nodeId: %" PRIu64 "", entry.nodeId); ChipLogProgress(Zcl, " Label: %.*s", static_cast(entry.label.size()), entry.label.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context, @@ -714,19 +624,14 @@ static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnPowerSourceActiveBatteryFaultsListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -739,8 +644,7 @@ static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context ++i; ChipLogProgress(chipTool, "ENUM8[%" PRIu16 "]: %" PRIu8 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnTvChannelTvChannelListListAttributeResponse( @@ -749,19 +653,14 @@ static void OnTvChannelTvChannelListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnTvChannelTvChannelListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -780,8 +679,7 @@ static void OnTvChannelTvChannelListListAttributeResponse( ChipLogProgress(Zcl, " affiliateCallSign: %.*s", static_cast(entry.affiliateCallSign.size()), entry.affiliateCallSign.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( @@ -791,19 +689,14 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnTargetNavigatorTargetNavigatorListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -818,27 +711,21 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( ChipLogProgress(chipTool, " identifier: %" PRIu8 "", entry.identifier); ChipLogProgress(Zcl, " name: %.*s", static_cast(entry.name.size()), entry.name.data()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnTestClusterListInt8uListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnTestClusterListInt8uListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -851,8 +738,7 @@ static void OnTestClusterListInt8uListAttributeResponse(void * context, const ch ++i; ChipLogProgress(chipTool, "INT8U[%" PRIu16 "]: %" PRIu8 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnTestClusterListOctetStringListAttributeResponse(void * context, @@ -860,19 +746,14 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnTestClusterListOctetStringListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -885,8 +766,7 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, ++i; ChipLogProgress(Zcl, " : %zu", entry.size()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnTestClusterListStructOctetStringListAttributeResponse( @@ -895,19 +775,14 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnTestClusterListStructOctetStringListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -922,8 +797,7 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( ChipLogProgress(chipTool, " fabricIndex: %" PRIu64 "", entry.fabricIndex); ChipLogProgress(Zcl, " operationalCert: %zu", entry.operationalCert.size()); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( @@ -933,19 +807,14 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -972,8 +841,7 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( ChipLogProgress(chipTool, " fullNetworkData: %d", entry.fullNetworkData); ChipLogProgress(chipTool, " isChild: %d", entry.isChild); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( @@ -983,19 +851,14 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -1018,8 +881,7 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( ChipLogProgress(chipTool, " allocated: %d", entry.allocated); ChipLogProgress(chipTool, " linkEstablished: %d", entry.linkEstablished); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( @@ -1029,19 +891,14 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -1056,8 +913,7 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( ChipLogProgress(chipTool, " rotationTime: %" PRIu16 "", entry.rotationTime); ChipLogProgress(chipTool, " flags: %" PRIu16 "", entry.flags); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeResponse( @@ -1067,19 +923,14 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -1104,8 +955,7 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR ChipLogProgress(chipTool, " securityPolicyPresent: %d", entry.securityPolicyPresent); ChipLogProgress(chipTool, " channelMaskPresent: %d", entry.channelMaskPresent); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeResponse( @@ -1113,19 +963,14 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon { ModelCommand * command = static_cast(context); - size_t count = 0; + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) - { - command->SetCommandExitStatus(iter.GetStatus()); - return; - } + command->SetCommandExitStatus(err); + return; } + ChipLogProgress(chipTool, "OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeResponse: %zu entries", count); auto iter = list.begin(); @@ -1138,8 +983,7 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon ++i; ChipLogProgress(chipTool, "NetworkFault[%" PRIu16 "]: %" PRIu8 "", i, entry); } - - command->SetCommandExitStatus(CHIP_NO_ERROR); + command->SetCommandExitStatus(iter.GetStatus()); } static void OnAccountLoginGetSetupPINResponseSuccess(