| /* |
| * |
| * Copyright (c) 2021 Project CHIP Authors |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| // THIS FILE IS GENERATED BY ZAP |
| |
| #include <cinttypes> |
| #include <cstdint> |
| |
| #include "app/util/util.h" |
| #include <app-common/zap-generated/af-structs.h> |
| #include <app-common/zap-generated/callback.h> |
| #include <app-common/zap-generated/cluster-objects.h> |
| #include <app-common/zap-generated/ids/Clusters.h> |
| #include <app-common/zap-generated/ids/Commands.h> |
| |
| #include <app/InteractionModelEngine.h> |
| |
| // Currently we need some work to keep compatible with ember lib. |
| #include <app/util/ember-compatibility-functions.h> |
| |
| namespace chip { |
| namespace app { |
| |
| namespace { |
| void ReportCommandUnsupported(Command * aCommandObj, const ConcreteCommandPath & aCommandPath) |
| { |
| aCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kNotFound, Protocols::SecureChannel::Id, |
| Protocols::InteractionModel::Status::UnsupportedCommand); |
| ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI, |
| ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId)); |
| } |
| } // anonymous namespace |
| |
| // Cluster specific command parsing |
| |
| namespace Clusters { |
| |
| namespace AccountLogin { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::GetSetupPIN::Id: { |
| Commands::GetSetupPIN::DecodableType commandData; |
| expectArgumentCount = 1; |
| const uint8_t * tempAccountIdentifier; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(tempAccountIdentifier); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = |
| emberAfAccountLoginClusterGetSetupPINCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| const_cast<uint8_t *>(tempAccountIdentifier), commandData); |
| } |
| break; |
| } |
| case Commands::Login::Id: { |
| Commands::Login::DecodableType commandData; |
| expectArgumentCount = 2; |
| const uint8_t * tempAccountIdentifier; |
| const uint8_t * setupPIN; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(tempAccountIdentifier); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(setupPIN); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfAccountLoginClusterLoginCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| const_cast<uint8_t *>(tempAccountIdentifier), |
| const_cast<uint8_t *>(setupPIN), commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace AccountLogin |
| |
| namespace AdministratorCommissioning { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::OpenBasicCommissioningWindow::Id: { |
| Commands::OpenBasicCommissioningWindow::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint16_t CommissioningTimeout; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(CommissioningTimeout); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, CommissioningTimeout, commandData); |
| } |
| break; |
| } |
| case Commands::OpenCommissioningWindow::Id: { |
| Commands::OpenCommissioningWindow::DecodableType commandData; |
| expectArgumentCount = 6; |
| uint16_t CommissioningTimeout; |
| chip::ByteSpan PAKEVerifier; |
| uint16_t Discriminator; |
| uint32_t Iterations; |
| chip::ByteSpan Salt; |
| uint16_t PasscodeID; |
| bool argExists[6]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 6) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(CommissioningTimeout); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(PAKEVerifier); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(Discriminator); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(Iterations); |
| break; |
| case 4: |
| TLVUnpackError = aDataTlv.Get(Salt); |
| break; |
| case 5: |
| TLVUnpackError = aDataTlv.Get(PasscodeID); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 6 == validArgumentCount) |
| { |
| wasHandled = emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, CommissioningTimeout, PAKEVerifier, Discriminator, |
| Iterations, Salt, PasscodeID, commandData); |
| } |
| break; |
| } |
| case Commands::RevokeCommissioning::Id: { |
| Commands::RevokeCommissioning::DecodableType commandData; |
| |
| wasHandled = emberAfAdministratorCommissioningClusterRevokeCommissioningCallback(apCommandObj, aCommandPath, |
| aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace AdministratorCommissioning |
| |
| namespace ApplicationBasic { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::ChangeStatus::Id: { |
| Commands::ChangeStatus::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t status; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(status); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfApplicationBasicClusterChangeStatusCallback(apCommandObj, aCommandPath, |
| aCommandPath.mEndpointId, status, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace ApplicationBasic |
| |
| namespace ApplicationLauncher { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::LaunchApp::Id: { |
| Commands::LaunchApp::DecodableType commandData; |
| expectArgumentCount = 3; |
| const uint8_t * data; |
| uint16_t catalogVendorId; |
| const uint8_t * applicationId; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(data); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(catalogVendorId); |
| break; |
| case 2: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(applicationId); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfApplicationLauncherClusterLaunchAppCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, const_cast<uint8_t *>(data), catalogVendorId, |
| const_cast<uint8_t *>(applicationId), commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace ApplicationLauncher |
| |
| namespace AudioOutput { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::RenameOutput::Id: { |
| Commands::RenameOutput::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t index; |
| const uint8_t * name; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(index); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(name); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfAudioOutputClusterRenameOutputCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| index, const_cast<uint8_t *>(name), commandData); |
| } |
| break; |
| } |
| case Commands::SelectOutput::Id: { |
| Commands::SelectOutput::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t index; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(index); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfAudioOutputClusterSelectOutputCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| index, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace AudioOutput |
| |
| namespace Basic { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| } |
| |
| } // namespace Basic |
| |
| namespace Binding { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::Bind::Id: { |
| Commands::Bind::DecodableType commandData; |
| expectArgumentCount = 4; |
| chip::NodeId nodeId; |
| chip::GroupId groupId; |
| chip::EndpointId endpointId; |
| chip::ClusterId clusterId; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(nodeId); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(groupId); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(endpointId); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(clusterId); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfBindingClusterBindCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, nodeId, |
| groupId, endpointId, clusterId, commandData); |
| } |
| break; |
| } |
| case Commands::Unbind::Id: { |
| Commands::Unbind::DecodableType commandData; |
| expectArgumentCount = 4; |
| chip::NodeId nodeId; |
| chip::GroupId groupId; |
| chip::EndpointId endpointId; |
| chip::ClusterId clusterId; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(nodeId); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(groupId); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(endpointId); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(clusterId); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfBindingClusterUnbindCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, nodeId, |
| groupId, endpointId, clusterId, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace Binding |
| |
| namespace ContentLauncher { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::LaunchContent::Id: { |
| Commands::LaunchContent::DecodableType commandData; |
| expectArgumentCount = 2; |
| bool autoPlay; |
| const uint8_t * data; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(autoPlay); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(data); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfContentLauncherClusterLaunchContentCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, autoPlay, const_cast<uint8_t *>(data), commandData); |
| } |
| break; |
| } |
| case Commands::LaunchURL::Id: { |
| Commands::LaunchURL::DecodableType commandData; |
| expectArgumentCount = 2; |
| const uint8_t * contentURL; |
| const uint8_t * displayString; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(contentURL); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(displayString); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfContentLauncherClusterLaunchURLCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| const_cast<uint8_t *>(contentURL), |
| const_cast<uint8_t *>(displayString), commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace ContentLauncher |
| |
| namespace DiagnosticLogs { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::RetrieveLogsRequest::Id: { |
| Commands::RetrieveLogsRequest::DecodableType commandData; |
| expectArgumentCount = 3; |
| uint8_t intent; |
| uint8_t requestedProtocol; |
| chip::ByteSpan transferFileDesignator; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(intent); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(requestedProtocol); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(transferFileDesignator); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfDiagnosticLogsClusterRetrieveLogsRequestCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, intent, requestedProtocol, transferFileDesignator, |
| commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace DiagnosticLogs |
| |
| namespace GeneralCommissioning { |
| |
| void DispatchClientCommand(CommandSender * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::ArmFailSafeResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfGeneralCommissioningClusterArmFailSafeResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::CommissioningCompleteResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfGeneralCommissioningClusterCommissioningCompleteResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::SetRegulatoryConfigResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfGeneralCommissioningClusterSetRegulatoryConfigResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace GeneralCommissioning |
| |
| namespace GeneralCommissioning { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::ArmFailSafe::Id: { |
| Commands::ArmFailSafe::DecodableType commandData; |
| expectArgumentCount = 3; |
| uint16_t expiryLengthSeconds; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(expiryLengthSeconds); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfGeneralCommissioningClusterArmFailSafeCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, expiryLengthSeconds, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::CommissioningComplete::Id: { |
| Commands::CommissioningComplete::DecodableType commandData; |
| |
| wasHandled = emberAfGeneralCommissioningClusterCommissioningCompleteCallback(apCommandObj, aCommandPath, |
| aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::SetRegulatoryConfig::Id: { |
| Commands::SetRegulatoryConfig::DecodableType commandData; |
| expectArgumentCount = 4; |
| uint8_t location; |
| const uint8_t * countryCode; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(location); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(countryCode); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, location, const_cast<uint8_t *>(countryCode), breadcrumb, |
| timeoutMs, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace GeneralCommissioning |
| |
| namespace KeypadInput { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::SendKey::Id: { |
| Commands::SendKey::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t keyCode; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(keyCode); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfKeypadInputClusterSendKeyCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, keyCode, |
| commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace KeypadInput |
| |
| namespace LevelControl { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::Move::Id: { |
| Commands::Move::DecodableType commandData; |
| expectArgumentCount = 4; |
| uint8_t moveMode; |
| uint8_t rate; |
| uint8_t optionMask; |
| uint8_t optionOverride; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(moveMode); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(rate); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(optionMask); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(optionOverride); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfLevelControlClusterMoveCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, moveMode, |
| rate, optionMask, optionOverride, commandData); |
| } |
| break; |
| } |
| case Commands::MoveToLevel::Id: { |
| Commands::MoveToLevel::DecodableType commandData; |
| expectArgumentCount = 4; |
| uint8_t level; |
| uint16_t transitionTime; |
| uint8_t optionMask; |
| uint8_t optionOverride; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(level); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(transitionTime); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(optionMask); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(optionOverride); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = |
| emberAfLevelControlClusterMoveToLevelCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, level, |
| transitionTime, optionMask, optionOverride, commandData); |
| } |
| break; |
| } |
| case Commands::MoveToLevelWithOnOff::Id: { |
| Commands::MoveToLevelWithOnOff::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t level; |
| uint16_t transitionTime; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(level); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(transitionTime); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfLevelControlClusterMoveToLevelWithOnOffCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, level, transitionTime, commandData); |
| } |
| break; |
| } |
| case Commands::MoveWithOnOff::Id: { |
| Commands::MoveWithOnOff::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t moveMode; |
| uint8_t rate; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(moveMode); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(rate); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfLevelControlClusterMoveWithOnOffCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| moveMode, rate, commandData); |
| } |
| break; |
| } |
| case Commands::Step::Id: { |
| Commands::Step::DecodableType commandData; |
| expectArgumentCount = 5; |
| uint8_t stepMode; |
| uint8_t stepSize; |
| uint16_t transitionTime; |
| uint8_t optionMask; |
| uint8_t optionOverride; |
| bool argExists[5]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 5) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(stepMode); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(stepSize); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(transitionTime); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(optionMask); |
| break; |
| case 4: |
| TLVUnpackError = aDataTlv.Get(optionOverride); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 5 == validArgumentCount) |
| { |
| wasHandled = |
| emberAfLevelControlClusterStepCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, stepMode, stepSize, |
| transitionTime, optionMask, optionOverride, commandData); |
| } |
| break; |
| } |
| case Commands::StepWithOnOff::Id: { |
| Commands::StepWithOnOff::DecodableType commandData; |
| expectArgumentCount = 3; |
| uint8_t stepMode; |
| uint8_t stepSize; |
| uint16_t transitionTime; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(stepMode); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(stepSize); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(transitionTime); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfLevelControlClusterStepWithOnOffCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| stepMode, stepSize, transitionTime, commandData); |
| } |
| break; |
| } |
| case Commands::Stop::Id: { |
| Commands::Stop::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t optionMask; |
| uint8_t optionOverride; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(optionMask); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(optionOverride); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfLevelControlClusterStopCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| optionMask, optionOverride, commandData); |
| } |
| break; |
| } |
| case Commands::StopWithOnOff::Id: { |
| Commands::StopWithOnOff::DecodableType commandData; |
| |
| wasHandled = |
| emberAfLevelControlClusterStopWithOnOffCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace LevelControl |
| |
| namespace LowPower { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::Sleep::Id: { |
| Commands::Sleep::DecodableType commandData; |
| |
| wasHandled = emberAfLowPowerClusterSleepCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace LowPower |
| |
| namespace MediaInput { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::HideInputStatus::Id: { |
| Commands::HideInputStatus::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaInputClusterHideInputStatusCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::RenameInput::Id: { |
| Commands::RenameInput::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t index; |
| const uint8_t * name; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(index); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(name); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfMediaInputClusterRenameInputCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| index, const_cast<uint8_t *>(name), commandData); |
| } |
| break; |
| } |
| case Commands::SelectInput::Id: { |
| Commands::SelectInput::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t index; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(index); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfMediaInputClusterSelectInputCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| index, commandData); |
| } |
| break; |
| } |
| case Commands::ShowInputStatus::Id: { |
| Commands::ShowInputStatus::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaInputClusterShowInputStatusCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace MediaInput |
| |
| namespace MediaPlayback { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::MediaFastForward::Id: { |
| Commands::MediaFastForward::DecodableType commandData; |
| |
| wasHandled = emberAfMediaPlaybackClusterMediaFastForwardCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| commandData); |
| break; |
| } |
| case Commands::MediaNext::Id: { |
| Commands::MediaNext::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaNextCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::MediaPause::Id: { |
| Commands::MediaPause::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaPauseCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::MediaPlay::Id: { |
| Commands::MediaPlay::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaPlayCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::MediaPrevious::Id: { |
| Commands::MediaPrevious::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaPreviousCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::MediaRewind::Id: { |
| Commands::MediaRewind::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaRewindCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::MediaSeek::Id: { |
| Commands::MediaSeek::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint64_t position; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(position); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfMediaPlaybackClusterMediaSeekCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| position, commandData); |
| } |
| break; |
| } |
| case Commands::MediaSkipBackward::Id: { |
| Commands::MediaSkipBackward::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint64_t deltaPositionMilliseconds; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(deltaPositionMilliseconds); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfMediaPlaybackClusterMediaSkipBackwardCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, deltaPositionMilliseconds, commandData); |
| } |
| break; |
| } |
| case Commands::MediaSkipForward::Id: { |
| Commands::MediaSkipForward::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint64_t deltaPositionMilliseconds; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(deltaPositionMilliseconds); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfMediaPlaybackClusterMediaSkipForwardCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, deltaPositionMilliseconds, commandData); |
| } |
| break; |
| } |
| case Commands::MediaStartOver::Id: { |
| Commands::MediaStartOver::DecodableType commandData; |
| |
| wasHandled = emberAfMediaPlaybackClusterMediaStartOverCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| commandData); |
| break; |
| } |
| case Commands::MediaStop::Id: { |
| Commands::MediaStop::DecodableType commandData; |
| |
| wasHandled = |
| emberAfMediaPlaybackClusterMediaStopCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace MediaPlayback |
| |
| namespace NetworkCommissioning { |
| |
| void DispatchClientCommand(CommandSender * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::AddThreadNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterAddThreadNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::AddWiFiNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterAddWiFiNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::DisableNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterDisableNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::EnableNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterEnableNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::RemoveNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterRemoveNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::ScanNetworksResponse::Id: { |
| expectArgumentCount = 4; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| /* TYPE WARNING: array array defaults to */ uint8_t * wifiScanResults; |
| /* TYPE WARNING: array array defaults to */ uint8_t * threadScanResults; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| case 2: |
| // Just for compatibility, we will add array type support in IM later. |
| TLVUnpackError = aDataTlv.GetDataPtr(const_cast<const uint8_t *&>(wifiScanResults)); |
| break; |
| case 3: |
| // Just for compatibility, we will add array type support in IM later. |
| TLVUnpackError = aDataTlv.GetDataPtr(const_cast<const uint8_t *&>(threadScanResults)); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterScanNetworksResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText), wifiScanResults, |
| threadScanResults); |
| } |
| break; |
| } |
| case Commands::UpdateThreadNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterUpdateThreadNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| case Commands::UpdateWiFiNetworkResponse::Id: { |
| expectArgumentCount = 2; |
| uint8_t errorCode; |
| const uint8_t * debugText; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(errorCode); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(debugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterUpdateWiFiNetworkResponseCallback( |
| aCommandPath.mEndpointId, apCommandObj, errorCode, const_cast<uint8_t *>(debugText)); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace NetworkCommissioning |
| |
| namespace NetworkCommissioning { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::AddThreadNetwork::Id: { |
| Commands::AddThreadNetwork::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan operationalDataset; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(operationalDataset); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterAddThreadNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, operationalDataset, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::AddWiFiNetwork::Id: { |
| Commands::AddWiFiNetwork::DecodableType commandData; |
| expectArgumentCount = 4; |
| chip::ByteSpan ssid; |
| chip::ByteSpan credentials; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(ssid); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(credentials); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterAddWiFiNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, ssid, credentials, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::DisableNetwork::Id: { |
| Commands::DisableNetwork::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan networkID; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(networkID); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterDisableNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, networkID, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::EnableNetwork::Id: { |
| Commands::EnableNetwork::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan networkID; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(networkID); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterEnableNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, networkID, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::GetLastNetworkCommissioningResult::Id: { |
| Commands::GetLastNetworkCommissioningResult::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint32_t timeoutMs; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::RemoveNetwork::Id: { |
| Commands::RemoveNetwork::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan NetworkID; |
| uint64_t Breadcrumb; |
| uint32_t TimeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(NetworkID); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(Breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(TimeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterRemoveNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, NetworkID, Breadcrumb, TimeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::ScanNetworks::Id: { |
| Commands::ScanNetworks::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan ssid; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(ssid); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterScanNetworksCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, ssid, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::UpdateThreadNetwork::Id: { |
| Commands::UpdateThreadNetwork::DecodableType commandData; |
| expectArgumentCount = 3; |
| chip::ByteSpan operationalDataset; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(operationalDataset); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, operationalDataset, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| case Commands::UpdateWiFiNetwork::Id: { |
| Commands::UpdateWiFiNetwork::DecodableType commandData; |
| expectArgumentCount = 4; |
| chip::ByteSpan ssid; |
| chip::ByteSpan credentials; |
| uint64_t breadcrumb; |
| uint32_t timeoutMs; |
| bool argExists[4]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 4) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(ssid); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(credentials); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(breadcrumb); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(timeoutMs); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount) |
| { |
| wasHandled = emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, ssid, credentials, breadcrumb, timeoutMs, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace NetworkCommissioning |
| |
| namespace OtaSoftwareUpdateProvider { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::ApplyUpdateRequest::Id: { |
| Commands::ApplyUpdateRequest::DecodableType commandData; |
| expectArgumentCount = 2; |
| chip::ByteSpan updateToken; |
| uint32_t newVersion; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(updateToken); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(newVersion); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfOtaSoftwareUpdateProviderClusterApplyUpdateRequestCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, updateToken, newVersion, commandData); |
| } |
| break; |
| } |
| case Commands::NotifyUpdateApplied::Id: { |
| Commands::NotifyUpdateApplied::DecodableType commandData; |
| expectArgumentCount = 2; |
| chip::ByteSpan updateToken; |
| uint32_t softwareVersion; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(updateToken); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(softwareVersion); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfOtaSoftwareUpdateProviderClusterNotifyUpdateAppliedCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, updateToken, softwareVersion, commandData); |
| } |
| break; |
| } |
| case Commands::QueryImage::Id: { |
| Commands::QueryImage::DecodableType commandData; |
| expectArgumentCount = 8; |
| uint16_t vendorId; |
| uint16_t productId; |
| uint16_t hardwareVersion; |
| uint32_t softwareVersion; |
| uint8_t protocolsSupported; |
| const uint8_t * location; |
| bool requestorCanConsent; |
| chip::ByteSpan metadataForProvider; |
| bool argExists[8]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 8) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(vendorId); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(productId); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(hardwareVersion); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(softwareVersion); |
| break; |
| case 4: |
| TLVUnpackError = aDataTlv.Get(protocolsSupported); |
| break; |
| case 5: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(location); |
| break; |
| case 6: |
| TLVUnpackError = aDataTlv.Get(requestorCanConsent); |
| break; |
| case 7: |
| TLVUnpackError = aDataTlv.Get(metadataForProvider); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 8 == validArgumentCount) |
| { |
| wasHandled = emberAfOtaSoftwareUpdateProviderClusterQueryImageCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, vendorId, productId, hardwareVersion, softwareVersion, |
| protocolsSupported, const_cast<uint8_t *>(location), requestorCanConsent, metadataForProvider, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace OtaSoftwareUpdateProvider |
| |
| namespace OnOff { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::Off::Id: { |
| Commands::Off::DecodableType commandData; |
| |
| wasHandled = emberAfOnOffClusterOffCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::On::Id: { |
| Commands::On::DecodableType commandData; |
| |
| wasHandled = emberAfOnOffClusterOnCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| case Commands::Toggle::Id: { |
| Commands::Toggle::DecodableType commandData; |
| |
| wasHandled = emberAfOnOffClusterToggleCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, commandData); |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace OnOff |
| |
| namespace OperationalCredentials { |
| |
| void DispatchClientCommand(CommandSender * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::AttestationResponse::Id: { |
| expectArgumentCount = 2; |
| chip::ByteSpan AttestationElements; |
| chip::ByteSpan Signature; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(AttestationElements); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(Signature); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterAttestationResponseCallback(aCommandPath.mEndpointId, apCommandObj, |
| AttestationElements, Signature); |
| } |
| break; |
| } |
| case Commands::CertificateChainResponse::Id: { |
| expectArgumentCount = 1; |
| chip::ByteSpan Certificate; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(Certificate); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterCertificateChainResponseCallback(aCommandPath.mEndpointId, |
| apCommandObj, Certificate); |
| } |
| break; |
| } |
| case Commands::NOCResponse::Id: { |
| expectArgumentCount = 3; |
| uint8_t StatusCode; |
| uint8_t FabricIndex; |
| chip::ByteSpan DebugText; |
| bool argExists[3]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 3) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(StatusCode); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(FabricIndex); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(DebugText); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterNOCResponseCallback(aCommandPath.mEndpointId, apCommandObj, |
| StatusCode, FabricIndex, DebugText); |
| } |
| break; |
| } |
| case Commands::OpCSRResponse::Id: { |
| expectArgumentCount = 2; |
| chip::ByteSpan NOCSRElements; |
| chip::ByteSpan AttestationSignature; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(NOCSRElements); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(AttestationSignature); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterOpCSRResponseCallback(aCommandPath.mEndpointId, apCommandObj, |
| NOCSRElements, AttestationSignature); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace OperationalCredentials |
| |
| namespace OperationalCredentials { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::AddNOC::Id: { |
| Commands::AddNOC::DecodableType commandData; |
| expectArgumentCount = 5; |
| chip::ByteSpan NOCValue; |
| chip::ByteSpan ICACValue; |
| chip::ByteSpan IPKValue; |
| chip::NodeId CaseAdminNode; |
| uint16_t AdminVendorId; |
| bool argExists[5]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 5) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(NOCValue); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(ICACValue); |
| break; |
| case 2: |
| TLVUnpackError = aDataTlv.Get(IPKValue); |
| break; |
| case 3: |
| TLVUnpackError = aDataTlv.Get(CaseAdminNode); |
| break; |
| case 4: |
| TLVUnpackError = aDataTlv.Get(AdminVendorId); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 5 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterAddNOCCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, NOCValue, ICACValue, IPKValue, CaseAdminNode, |
| AdminVendorId, commandData); |
| } |
| break; |
| } |
| case Commands::AddTrustedRootCertificate::Id: { |
| Commands::AddTrustedRootCertificate::DecodableType commandData; |
| expectArgumentCount = 1; |
| chip::ByteSpan RootCertificate; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(RootCertificate); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterAddTrustedRootCertificateCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, RootCertificate, commandData); |
| } |
| break; |
| } |
| case Commands::AttestationRequest::Id: { |
| Commands::AttestationRequest::DecodableType commandData; |
| expectArgumentCount = 1; |
| chip::ByteSpan AttestationNonce; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(AttestationNonce); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterAttestationRequestCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, AttestationNonce, commandData); |
| } |
| break; |
| } |
| case Commands::CertificateChainRequest::Id: { |
| Commands::CertificateChainRequest::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t CertificateType; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(CertificateType); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterCertificateChainRequestCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, CertificateType, commandData); |
| } |
| break; |
| } |
| case Commands::OpCSRRequest::Id: { |
| Commands::OpCSRRequest::DecodableType commandData; |
| expectArgumentCount = 1; |
| chip::ByteSpan CSRNonce; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(CSRNonce); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterOpCSRRequestCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, CSRNonce, commandData); |
| } |
| break; |
| } |
| case Commands::RemoveFabric::Id: { |
| Commands::RemoveFabric::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint8_t FabricIndex; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(FabricIndex); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterRemoveFabricCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, FabricIndex, commandData); |
| } |
| break; |
| } |
| case Commands::RemoveTrustedRootCertificate::Id: { |
| Commands::RemoveTrustedRootCertificate::DecodableType commandData; |
| expectArgumentCount = 1; |
| chip::ByteSpan TrustedRootIdentifier; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(TrustedRootIdentifier); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterRemoveTrustedRootCertificateCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, TrustedRootIdentifier, commandData); |
| } |
| break; |
| } |
| case Commands::UpdateFabricLabel::Id: { |
| Commands::UpdateFabricLabel::DecodableType commandData; |
| expectArgumentCount = 1; |
| const uint8_t * Label; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(Label); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterUpdateFabricLabelCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, const_cast<uint8_t *>(Label), commandData); |
| } |
| break; |
| } |
| case Commands::UpdateNOC::Id: { |
| Commands::UpdateNOC::DecodableType commandData; |
| expectArgumentCount = 2; |
| chip::ByteSpan NOCValue; |
| chip::ByteSpan ICACValue; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(NOCValue); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(ICACValue); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfOperationalCredentialsClusterUpdateNOCCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, NOCValue, ICACValue, commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace OperationalCredentials |
| |
| namespace TvChannel { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::ChangeChannel::Id: { |
| Commands::ChangeChannel::DecodableType commandData; |
| expectArgumentCount = 1; |
| const uint8_t * match; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(match); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfTvChannelClusterChangeChannelCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, |
| const_cast<uint8_t *>(match), commandData); |
| } |
| break; |
| } |
| case Commands::ChangeChannelByNumber::Id: { |
| Commands::ChangeChannelByNumber::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint16_t majorNumber; |
| uint16_t minorNumber; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(majorNumber); |
| break; |
| case 1: |
| TLVUnpackError = aDataTlv.Get(minorNumber); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfTvChannelClusterChangeChannelByNumberCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, majorNumber, minorNumber, commandData); |
| } |
| break; |
| } |
| case Commands::SkipChannel::Id: { |
| Commands::SkipChannel::DecodableType commandData; |
| expectArgumentCount = 1; |
| uint16_t Count; |
| bool argExists[1]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 1) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(Count); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount) |
| { |
| wasHandled = emberAfTvChannelClusterSkipChannelCallback(apCommandObj, aCommandPath, aCommandPath.mEndpointId, Count, |
| commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace TvChannel |
| |
| namespace TargetNavigator { |
| |
| void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv) |
| { |
| // We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV |
| // When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error. |
| // Any error value TLVUnpackError means we have received an illegal value. |
| // The following variables are used for all commands to save code size. |
| CHIP_ERROR TLVError = CHIP_NO_ERROR; |
| CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR; |
| uint32_t validArgumentCount = 0; |
| uint32_t expectArgumentCount = 0; |
| uint32_t currentDecodeTagId = 0; |
| bool wasHandled = false; |
| { |
| switch (aCommandPath.mCommandId) |
| { |
| case Commands::NavigateTarget::Id: { |
| Commands::NavigateTarget::DecodableType commandData; |
| expectArgumentCount = 2; |
| uint8_t target; |
| const uint8_t * data; |
| bool argExists[2]; |
| |
| memset(argExists, 0, sizeof argExists); |
| |
| while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR) |
| { |
| // Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element. |
| // Skip this element if it is not a ContextTag, not consider it as an error if other values are valid. |
| if (!TLV::IsContextTag(aDataTlv.GetTag())) |
| { |
| continue; |
| } |
| currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag()); |
| if (currentDecodeTagId < 2) |
| { |
| if (argExists[currentDecodeTagId]) |
| { |
| ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag())); |
| TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT; |
| break; |
| } |
| else |
| { |
| argExists[currentDecodeTagId] = true; |
| validArgumentCount++; |
| } |
| } |
| switch (currentDecodeTagId) |
| { |
| case 0: |
| TLVUnpackError = aDataTlv.Get(target); |
| break; |
| case 1: |
| // TODO(#5542): The cluster handlers should accept a ByteSpan for all string types. |
| TLVUnpackError = aDataTlv.GetDataPtr(data); |
| break; |
| default: |
| // Unsupported tag, ignore it. |
| ChipLogProgress(Zcl, "Unknown TLV tag during processing."); |
| break; |
| } |
| if (CHIP_NO_ERROR != TLVUnpackError) |
| { |
| break; |
| } |
| } |
| |
| if (CHIP_END_OF_TLV == TLVError) |
| { |
| // CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error. |
| TLVError = CHIP_NO_ERROR; |
| } |
| |
| if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 2 == validArgumentCount) |
| { |
| wasHandled = emberAfTargetNavigatorClusterNavigateTargetCallback( |
| apCommandObj, aCommandPath, aCommandPath.mEndpointId, target, const_cast<uint8_t *>(data), commandData); |
| } |
| break; |
| } |
| default: { |
| // Unrecognized command ID, error status will apply. |
| ReportCommandUnsupported(apCommandObj, aCommandPath); |
| return; |
| } |
| } |
| } |
| |
| if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled) |
| { |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, |
| Protocols::SecureChannel::Id, Protocols::InteractionModel::Status::InvalidCommand); |
| ChipLogProgress(Zcl, |
| "Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT |
| ", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32, |
| validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId); |
| // A command with no arguments would never write currentDecodeTagId. If |
| // progress logging is also disabled, it would look unused. Silence that |
| // warning. |
| UNUSED_VAR(currentDecodeTagId); |
| } |
| } |
| |
| } // namespace TargetNavigator |
| |
| } // namespace Clusters |
| |
| void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aReader, CommandHandler * apCommandObj) |
| { |
| ChipLogDetail(Zcl, "Received Cluster Command: Endpoint=%" PRIx16 " Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI, |
| aCommandPath.mEndpointId, ChipLogValueMEI(aCommandPath.mClusterId), ChipLogValueMEI(aCommandPath.mCommandId)); |
| |
| Compatibility::SetupEmberAfObjects(apCommandObj, aCommandPath); |
| |
| TLV::TLVType dataTlvType; |
| SuccessOrExit(aReader.EnterContainer(dataTlvType)); |
| switch (aCommandPath.mClusterId) |
| { |
| case Clusters::AccountLogin::Id: |
| Clusters::AccountLogin::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::AdministratorCommissioning::Id: |
| Clusters::AdministratorCommissioning::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::ApplicationBasic::Id: |
| Clusters::ApplicationBasic::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::ApplicationLauncher::Id: |
| Clusters::ApplicationLauncher::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::AudioOutput::Id: |
| Clusters::AudioOutput::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::Basic::Id: |
| Clusters::Basic::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::Binding::Id: |
| Clusters::Binding::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::ContentLauncher::Id: |
| Clusters::ContentLauncher::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::DiagnosticLogs::Id: |
| Clusters::DiagnosticLogs::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::GeneralCommissioning::Id: |
| Clusters::GeneralCommissioning::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::KeypadInput::Id: |
| Clusters::KeypadInput::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::LevelControl::Id: |
| Clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::LowPower::Id: |
| Clusters::LowPower::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::MediaInput::Id: |
| Clusters::MediaInput::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::MediaPlayback::Id: |
| Clusters::MediaPlayback::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::NetworkCommissioning::Id: |
| Clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::OtaSoftwareUpdateProvider::Id: |
| Clusters::OtaSoftwareUpdateProvider::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::OnOff::Id: |
| Clusters::OnOff::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::OperationalCredentials::Id: |
| Clusters::OperationalCredentials::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::TvChannel::Id: |
| Clusters::TvChannel::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::TargetNavigator::Id: |
| Clusters::TargetNavigator::DispatchServerCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| default: |
| ChipLogError(Zcl, "Unknown cluster " ChipLogFormatMEI, ChipLogValueMEI(aCommandPath.mClusterId)); |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kNotFound, |
| Protocols::InteractionModel::Id, Protocols::InteractionModel::Status::UnsupportedCluster); |
| break; |
| } |
| |
| exit: |
| aReader.ExitContainer(dataTlvType); |
| Compatibility::ResetEmberAfObjects(); |
| } |
| |
| void DispatchSingleClusterResponseCommand(const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aReader, |
| CommandSender * apCommandObj) |
| { |
| ChipLogDetail(Zcl, "Received Cluster Command: Endpoint=%" PRIx16 " Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI, |
| aCommandPath.mEndpointId, ChipLogValueMEI(aCommandPath.mClusterId), ChipLogValueMEI(aCommandPath.mCommandId)); |
| |
| Compatibility::SetupEmberAfObjects(apCommandObj, aCommandPath); |
| |
| TLV::TLVType dataTlvType; |
| SuccessOrExit(aReader.EnterContainer(dataTlvType)); |
| switch (aCommandPath.mClusterId) |
| { |
| case Clusters::GeneralCommissioning::Id: |
| Clusters::GeneralCommissioning::DispatchClientCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::NetworkCommissioning::Id: |
| Clusters::NetworkCommissioning::DispatchClientCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| case Clusters::OperationalCredentials::Id: |
| Clusters::OperationalCredentials::DispatchClientCommand(apCommandObj, aCommandPath, aReader); |
| break; |
| default: |
| ChipLogError(Zcl, "Unknown cluster " ChipLogFormatMEI, ChipLogValueMEI(aCommandPath.mClusterId)); |
| apCommandObj->AddStatusCode(aCommandPath, Protocols::SecureChannel::GeneralStatusCode::kNotFound, |
| Protocols::InteractionModel::Id, Protocols::InteractionModel::Status::UnsupportedCluster); |
| break; |
| } |
| |
| exit: |
| aReader.ExitContainer(dataTlvType); |
| Compatibility::ResetEmberAfObjects(); |
| } |
| |
| } // namespace app |
| } // namespace chip |