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..04e4e69fd641cf 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -104,13 +104,9 @@ void OnAttributeResponse(void * /* context */, bool value) static void OnApplicationLauncherApplicationLauncherListListAttributeResponse(void * context, const 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) { @@ -124,7 +120,7 @@ static void OnApplicationLauncherApplicationLauncherListListAttributeResponse(vo if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -147,13 +151,9 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( void * context, const 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) { @@ -167,7 +167,7 @@ static void OnAudioOutputAudioOutputListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -192,13 +200,9 @@ chip::Callback::Callback gAudio static void OnContentLauncherAcceptsHeaderListListAttributeResponse(void * context, const 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) { @@ -212,7 +216,7 @@ static void OnContentLauncherAcceptsHeaderListListAttributeResponse(void * conte if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -232,13 +244,9 @@ chip::Callback::Callback 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -252,7 +260,7 @@ static void OnContentLauncherSupportedStreamingTypesListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -273,13 +289,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) { @@ -293,7 +305,7 @@ static void OnDescriptorDeviceListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -316,13 +336,9 @@ 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -336,7 +352,7 @@ static void OnDescriptorServerListListAttributeResponse(void * context, const Da if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -356,13 +380,9 @@ 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -376,7 +396,7 @@ static void OnDescriptorClientListListAttributeResponse(void * context, const Da if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -396,13 +424,9 @@ 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -416,7 +440,7 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, const Dat if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -437,13 +469,9 @@ chip::Callback::Callback gDescriptorPa 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -457,7 +485,7 @@ static void OnFixedLabelLabelListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -483,13 +519,9 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons const 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) { @@ -503,7 +535,7 @@ static void OnGeneralCommissioningBasicCommissioningInfoListListAttributeRespons if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -528,13 +568,9 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( void * context, const 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) { @@ -548,7 +584,7 @@ static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -577,13 +621,9 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( void * context, const 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) { @@ -597,7 +637,7 @@ static void OnGroupKeyManagementGroupsListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -623,13 +671,9 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( void * context, const 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) { @@ -643,7 +687,7 @@ static void OnGroupKeyManagementGroupKeysListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -670,13 +722,9 @@ chip::Callback::Callback gGrou 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -690,7 +738,7 @@ static void OnMediaInputMediaInputListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -717,13 +773,9 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( void * context, const 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) { @@ -737,7 +789,7 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -763,13 +823,9 @@ chip::Callback::Callback gOperationalCredentialsFabricsListListAttributeCallback{ OnOperationalCredentialsFabricsListListAttributeResponse, nullptr }; 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -783,7 +839,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 @@ -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, " ]"); @@ -804,13 +868,9 @@ chip::Callback::Callback gP 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -824,7 +884,7 @@ static void OnTvChannelTvChannelListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -853,13 +921,9 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( void * context, const 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) { @@ -873,7 +937,7 @@ static void OnTargetNavigatorTargetNavigatorListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -895,13 +967,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) { @@ -915,7 +983,7 @@ static void OnTestClusterListInt8uListAttributeResponse(void * context, const Da if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -935,13 +1011,9 @@ 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) + size_t count = 0; + CHIP_ERROR err = list.ComputeSize(&count); + if (err != CHIP_NO_ERROR) { if (gFailureResponseDelegate != nullptr) { @@ -955,7 +1027,7 @@ static void OnTestClusterListOctetStringListAttributeResponse(void * context, co if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -977,13 +1057,9 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( void * context, const 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) { @@ -997,7 +1073,7 @@ static void OnTestClusterListStructOctetStringListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -1021,13 +1105,9 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( void * context, const 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) { @@ -1041,7 +1121,7 @@ static void OnThreadNetworkDiagnosticsNeighborTableListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -1079,13 +1167,9 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( void * context, const 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) { @@ -1099,7 +1183,7 @@ static void OnThreadNetworkDiagnosticsRouteTableListListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -1132,13 +1224,9 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( void * context, const 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) { @@ -1152,7 +1240,7 @@ static void OnThreadNetworkDiagnosticsSecurityPolicyListAttributeResponse( if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -1178,13 +1274,9 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR const 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) { @@ -1198,7 +1290,7 @@ static void OnThreadNetworkDiagnosticsOperationalDatasetComponentsListAttributeR if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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, " ]"); @@ -1233,13 +1333,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) { @@ -1253,7 +1349,7 @@ static void OnThreadNetworkDiagnosticsActiveNetworkFaultsListListAttributeRespon if (count > 0) ChipLogProgress(Zcl, " ["); - iter = list.begin(); + auto iter = list.begin(); while (iter.Next()) { #if CHIP_PROGRESS_LOGGING @@ -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..fd1ec0a2e2613b 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, 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) + 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 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(