From 420489336c05f00720ab8572e012734a14b1d4fe Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 25 Oct 2021 12:03:46 -0400 Subject: [PATCH] Add a lighweight size-computation method on DecodableList. (#10801) Just computes an optimistic size, without checking whether the individual items decode properly. --- .../chip-tool/commands/tests/TestCommand.h | 2 + examples/chip-tool/templates/commands.zapt | 17 +- .../test-cluster-server.cpp | 12 +- src/app/data-model/DecodableList.h | 8 + .../python/chip/clusters/CHIPClusters.cpp | 520 +++++++++++------- .../templates/python-CHIPClusters-cpp.zapt | 20 +- src/lib/core/CHIPTLV.h | 9 + src/lib/core/CHIPTLVReader.cpp | 22 + .../zap-generated/cluster/Commands.h | 520 ++++++------------ 9 files changed, 556 insertions(+), 574 deletions(-) diff --git a/examples/chip-tool/commands/tests/TestCommand.h b/examples/chip-tool/commands/tests/TestCommand.h index 80054e2b9feb0e..b31e5efd058d7a 100644 --- a/examples/chip-tool/commands/tests/TestCommand.h +++ b/examples/chip-tool/commands/tests/TestCommand.h @@ -162,6 +162,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 dbad28584e6855..65d66564f6ec0a 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 4e93af6c5a5141..eabbac2decd5b2 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -105,13 +105,9 @@ static void OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -125,7 +121,7 @@ OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -133,6 +129,14 @@ OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context #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,13 +152,9 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -168,7 +168,7 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -180,6 +180,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, " ]"); @@ -194,13 +202,9 @@ static void OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -214,7 +218,7 @@ OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -222,6 +226,14 @@ OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, #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, " ]"); @@ -235,13 +247,9 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -255,7 +263,7 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -263,6 +271,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, " ]"); @@ -277,13 +293,9 @@ static void OnDescriptorDeviceListListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -297,7 +309,7 @@ static void OnDescriptorDeviceListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -308,6 +320,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, " ]"); @@ -321,13 +341,9 @@ chip::Callback::Callback gDescriptorD static void OnDescriptorServerListListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -341,7 +357,7 @@ static void OnDescriptorServerListListAttributeResponse(void * context, if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -349,6 +365,14 @@ static void OnDescriptorServerListListAttributeResponse(void * context, #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, " ]"); @@ -362,13 +386,9 @@ chip::Callback::Callback gDescriptorS static void OnDescriptorClientListListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -382,7 +402,7 @@ static void OnDescriptorClientListListAttributeResponse(void * context, if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -390,6 +410,14 @@ static void OnDescriptorClientListListAttributeResponse(void * context, #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, " ]"); @@ -403,13 +431,9 @@ chip::Callback::Callback gDescriptorC static void OnDescriptorPartsListListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -423,7 +447,7 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -431,6 +455,14 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, #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, " ]"); @@ -445,13 +477,9 @@ static void OnFixedLabelLabelListListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -465,7 +493,7 @@ static void OnFixedLabelLabelListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -476,6 +504,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, " ]"); @@ -491,13 +527,9 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons const chip::app::DataModel::DecodableList< chip::app::Clusters::GeneralCommissioning::Structs::BasicCommissioningInfoType::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -511,7 +543,7 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -521,6 +553,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, " ]"); @@ -537,13 +577,9 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( const chip::app::DataModel::DecodableList< chip::app::Clusters::GeneralDiagnostics::Structs::NetworkInterfaceType::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -557,7 +593,7 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -572,6 +608,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, " ]"); @@ -586,13 +630,9 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -606,7 +646,7 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -618,6 +658,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, " ]"); @@ -632,13 +680,9 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -652,7 +696,7 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -666,6 +710,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, " ]"); @@ -680,13 +732,9 @@ static void OnMediaInputMediaInputListListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -700,7 +748,7 @@ static void OnMediaInputMediaInputListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -713,6 +761,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, " ]"); @@ -728,13 +784,9 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( const chip::app::DataModel::DecodableList< chip::app::Clusters::OperationalCredentials::Structs::FabricDescriptor::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -748,7 +800,7 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -763,6 +815,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, " ]"); @@ -775,13 +835,9 @@ chip::Callback::Callback static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -795,7 +851,7 @@ static void OnPowerSourceActiveBatteryFaultsListAttributeResponse(void * context if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -803,6 +859,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, " ]"); @@ -817,13 +881,9 @@ static void OnTvChannelTvChannelListListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -837,7 +897,7 @@ static void OnTvChannelTvChannelListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -852,6 +912,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, " ]"); @@ -867,13 +935,9 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( const chip::app::DataModel::DecodableList< chip::app::Clusters::TargetNavigator::Structs::NavigateTargetTargetInfo::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -887,7 +951,7 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -898,6 +962,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, " ]"); @@ -909,13 +981,9 @@ chip::Callback::Callback & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -929,7 +997,7 @@ static void OnTestClusterListInt8uListAttributeResponse(void * context, const ch if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -937,6 +1005,14 @@ static void OnTestClusterListInt8uListAttributeResponse(void * context, const ch #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, " ]"); @@ -950,13 +1026,9 @@ chip::Callback::Callback gTestCluster static void OnTestClusterListOctetStringListAttributeResponse(void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -970,7 +1042,7 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -978,6 +1050,14 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, #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, " ]"); @@ -992,13 +1072,9 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( void * context, const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1012,7 +1088,7 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1023,6 +1099,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, " ]"); @@ -1037,13 +1121,9 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( const chip::app::DataModel::DecodableList< chip::app::Clusters::ThreadNetworkDiagnostics::Structs::NeighborTable::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1057,7 +1137,7 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1080,6 +1160,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, " ]"); @@ -1096,13 +1184,9 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( const chip::app::DataModel::DecodableList & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1116,7 +1200,7 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1135,6 +1219,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, " ]"); @@ -1150,13 +1242,9 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( const chip::app::DataModel::DecodableList< chip::app::Clusters::ThreadNetworkDiagnostics::Structs::SecurityPolicy::DecodableType> & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1170,7 +1258,7 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1181,6 +1269,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, " ]"); @@ -1196,13 +1292,9 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR const chip::app::DataModel::DecodableList< 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1216,7 +1308,7 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1237,6 +1329,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, " ]"); @@ -1251,13 +1351,9 @@ chip::Callback::Callback & list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -1271,7 +1367,7 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -1279,6 +1375,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 cce7d71f3e7fa0..3bf3017ff65295 100644 --- a/src/controller/python/templates/python-CHIPClusters-cpp.zapt +++ b/src/controller/python/templates/python-CHIPClusters-cpp.zapt @@ -90,13 +90,9 @@ void OnAttributeResponse(void * /* context */, bool value) {{#if isList}} static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list) { - uint16_t count = 0; - auto iter = list.begin(); - while (iter.Next()) - { - ++count; - } - if (iter.GetStatus() != CHIP_NO_ERROR) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -110,7 +106,7 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttri if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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..b68d59bdeb87c5 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] size 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 e218cad687e28d..703cbf9d782a8a 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(