From 8ba39aeea281a63751e68e40483096cb28a439fd Mon Sep 17 00:00:00 2001 From: yunhanw Date: Thu, 26 May 2022 16:09:01 -0700 Subject: [PATCH] Improve IM MessageDef --- src/app/CommandHandler.cpp | 6 +- src/app/CommandHandler.h | 2 +- src/app/CommandSender.cpp | 4 +- src/app/CommandSender.h | 2 +- src/app/MessageDef/ArrayParser.cpp | 3 +- src/app/MessageDef/AttributeDataIB.cpp | 10 ++- src/app/MessageDef/AttributeDataIBs.cpp | 24 +++---- src/app/MessageDef/AttributePathIB.cpp | 3 +- src/app/MessageDef/AttributePathIBs.cpp | 3 +- src/app/MessageDef/AttributeReportIB.cpp | 13 ++-- src/app/MessageDef/AttributeReportIBs.cpp | 3 +- src/app/MessageDef/AttributeStatusIB.cpp | 13 ++-- src/app/MessageDef/AttributeStatusIBs.cpp | 15 +---- src/app/MessageDef/CommandDataIB.cpp | 26 ++++---- src/app/MessageDef/CommandDataIB.h | 8 +-- src/app/MessageDef/CommandPathIB.cpp | 63 +++++++++---------- src/app/MessageDef/CommandPathIB.h | 8 +-- src/app/MessageDef/CommandStatusIB.cpp | 9 +-- src/app/MessageDef/DataVersionFilterIB.cpp | 3 + src/app/MessageDef/DataVersionFilterIBs.cpp | 11 +--- src/app/MessageDef/EventDataIB.cpp | 11 ++-- src/app/MessageDef/EventFilterIB.cpp | 7 ++- src/app/MessageDef/EventFilterIBs.cpp | 14 +---- src/app/MessageDef/EventPathIB.cpp | 3 +- src/app/MessageDef/EventPathIBs.cpp | 3 +- src/app/MessageDef/EventReportIB.cpp | 9 +-- src/app/MessageDef/EventReportIBs.cpp | 3 +- src/app/MessageDef/EventStatusIB.cpp | 13 ++-- src/app/MessageDef/InvokeRequestMessage.cpp | 6 +- src/app/MessageDef/InvokeRequests.cpp | 3 +- src/app/MessageDef/InvokeResponseIB.cpp | 9 +-- src/app/MessageDef/InvokeResponseIBs.cpp | 5 +- src/app/MessageDef/InvokeResponseMessage.cpp | 3 +- src/app/MessageDef/ListParser.cpp | 3 +- src/app/MessageDef/MessageBuilder.cpp | 5 +- src/app/MessageDef/StatusIB.cpp | 3 +- src/app/MessageDef/StatusResponseMessage.cpp | 6 +- src/app/MessageDef/StructParser.cpp | 3 +- .../MessageDef/SubscribeRequestMessage.cpp | 28 +-------- src/app/MessageDef/SubscribeRequestMessage.h | 15 ----- src/app/MessageDef/WriteResponseMessage.cpp | 11 +--- src/app/WriteClient.cpp | 29 ++++----- src/app/tests/TestCommandInteraction.cpp | 6 +- src/app/tests/TestMessageDef.cpp | 11 +--- src/app/tests/TestReadInteraction.cpp | 3 - .../python/chip/clusters/command.cpp | 2 +- src/lib/core/CHIPError.cpp | 26 +++++--- src/lib/core/CHIPError.h | 58 +++++++++++++---- src/lib/core/tests/TestCHIPErrorStr.cpp | 12 ++-- 49 files changed, 236 insertions(+), 303 deletions(-) diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index ea5ee0068646b8..306cd854bc2489 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -302,7 +302,7 @@ CHIP_ERROR CommandHandler::ProcessCommandDataIB(CommandDataIB::Parser & aCommand return AddStatus(concretePath, Protocols::InteractionModel::Status::NeedsTimedInteraction); } - err = aCommandElement.GetData(&commandDataReader); + err = aCommandElement.GetFields(&commandDataReader); if (CHIP_END_OF_TLV == err) { ChipLogDetail(DataManagement, @@ -359,7 +359,7 @@ CHIP_ERROR CommandHandler::ProcessGroupCommandDataIB(CommandDataIB::Parser & aCo ChipLogDetail(DataManagement, "Received group command for Group=%u Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI, groupId, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId)); - err = aCommandElement.GetData(&commandDataReader); + err = aCommandElement.GetFields(&commandDataReader); if (CHIP_END_OF_TLV == err) { ChipLogDetail(DataManagement, @@ -488,7 +488,7 @@ CHIP_ERROR CommandHandler::PrepareCommand(const ConcreteCommandPath & aCommandPa ReturnErrorOnFailure(path.Encode(aCommandPath)); if (aStartDataStruct) { - ReturnErrorOnFailure(commandData.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), + ReturnErrorOnFailure(commandData.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), TLV::kTLVType_Structure, mDataElementContainerType)); } MoveToState(State::AddingCommand); diff --git a/src/app/CommandHandler.h b/src/app/CommandHandler.h index 3c5a4c45616c11..e983e15a2feee9 100644 --- a/src/app/CommandHandler.h +++ b/src/app/CommandHandler.h @@ -319,7 +319,7 @@ class CommandHandler ReturnErrorOnFailure(PrepareCommand(path, false)); TLV::TLVWriter * writer = GetCommandDataIBTLVWriter(); VerifyOrReturnError(writer != nullptr, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), aData)); + ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), aData)); return FinishCommand(/* aEndDataStruct = */ false); } diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp index 94f1ac28e96b40..53cb5e8b1daab4 100644 --- a/src/app/CommandSender.cpp +++ b/src/app/CommandSender.cpp @@ -274,7 +274,7 @@ CHIP_ERROR CommandSender::ProcessInvokeResponseIB(InvokeResponseIB::Parser & aIn ReturnErrorOnFailure(commandPath.GetEndpointId(&endpointId)); ReturnErrorOnFailure(commandPath.GetClusterId(&clusterId)); ReturnErrorOnFailure(commandPath.GetCommandId(&commandId)); - commandData.GetData(&commandDataReader); + commandData.GetFields(&commandDataReader); err = CHIP_NO_ERROR; hasDataResponse = true; } @@ -336,7 +336,7 @@ CHIP_ERROR CommandSender::PrepareCommand(const CommandPathParams & aCommandPathP if (aStartDataStruct) { - ReturnErrorOnFailure(invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), + ReturnErrorOnFailure(invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), TLV::kTLVType_Structure, mDataElementContainerType)); } diff --git a/src/app/CommandSender.h b/src/app/CommandSender.h index 1e9985eaf8338a..4f5ab9ac0a06de 100644 --- a/src/app/CommandSender.h +++ b/src/app/CommandSender.h @@ -196,7 +196,7 @@ class CommandSender final : public Messaging::ExchangeDelegate ReturnErrorOnFailure(PrepareCommand(aCommandPath, /* aStartDataStruct = */ false)); TLV::TLVWriter * writer = GetCommandDataIBTLVWriter(); VerifyOrReturnError(writer != nullptr, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), aData)); + ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), aData)); return FinishCommand(aTimedInvokeTimeoutMs); } diff --git a/src/app/MessageDef/ArrayParser.cpp b/src/app/MessageDef/ArrayParser.cpp index e7356c20a6eb02..8f5980afc43e34 100644 --- a/src/app/MessageDef/ArrayParser.cpp +++ b/src/app/MessageDef/ArrayParser.cpp @@ -24,8 +24,7 @@ CHIP_ERROR ArrayParser::Init(const TLV::TLVReader & aReader) { mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_Array == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return mReader.EnterContainer(mOuterContainerType); } } // namespace app } // namespace chip diff --git a/src/app/MessageDef/AttributeDataIB.cpp b/src/app/MessageDef/AttributeDataIB.cpp index 072b5671ad5059..2290455dc19b94 100644 --- a/src/app/MessageDef/AttributeDataIB.cpp +++ b/src/app/MessageDef/AttributeDataIB.cpp @@ -35,7 +35,7 @@ AttributeDataIB::Parser::ParseData(TLV::TLVReader & aReader, int aDepth) const if (aDepth == 0) { - PRETTY_PRINT("\tData = "); + PRETTY_PRINT("Data = "); } else { @@ -261,12 +261,11 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const } else { - err = CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT; + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_DATA_ELEMENT; } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -274,8 +273,7 @@ CHIP_ERROR AttributeDataIB::Parser::GetPath(AttributePathIB::Parser * const apPa { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); - ReturnErrorOnFailure(apPath->Init(reader)); - return CHIP_NO_ERROR; + return apPath->Init(reader); } CHIP_ERROR AttributeDataIB::Parser::GetDataVersion(chip::DataVersion * const apVersion) const diff --git a/src/app/MessageDef/AttributeDataIBs.cpp b/src/app/MessageDef/AttributeDataIBs.cpp index 53dba2d517a38b..412e5e64311b93 100644 --- a/src/app/MessageDef/AttributeDataIBs.cpp +++ b/src/app/MessageDef/AttributeDataIBs.cpp @@ -40,7 +40,7 @@ namespace app { CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; - size_t NumDataElement = 0; + size_t numDataElement = 0; chip::TLV::TLVReader reader; PRETTY_PRINT("AttributeDataIBs ="); @@ -51,21 +51,19 @@ CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrExit(chip::TLV::AnonymousTag() == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); - VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); { AttributeDataIB::Parser data; - err = data.Init(reader); - SuccessOrExit(err); + ReturnErrorOnFailure(data.Init(reader)); PRETTY_PRINT_INCDEPTH(); - err = data.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(data.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } - ++NumDataElement; + ++numDataElement; } PRETTY_PRINT("],"); @@ -75,17 +73,13 @@ CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { // if we have at least one data element - if (NumDataElement > 0) + if (numDataElement > 0) { err = CHIP_NO_ERROR; } } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; + ReturnErrorOnFailure(err); + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/AttributePathIB.cpp b/src/app/MessageDef/AttributePathIB.cpp index c8fbb03e67a7a2..8acda5afbf6079 100644 --- a/src/app/MessageDef/AttributePathIB.cpp +++ b/src/app/MessageDef/AttributePathIB.cpp @@ -161,8 +161,7 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/AttributePathIBs.cpp b/src/app/MessageDef/AttributePathIBs.cpp index b3f824d6ca25c7..4a04dc0e47be0e 100644 --- a/src/app/MessageDef/AttributePathIBs.cpp +++ b/src/app/MessageDef/AttributePathIBs.cpp @@ -68,8 +68,7 @@ CHIP_ERROR AttributePathIBs::Parser::CheckSchemaValidity() const } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/AttributeReportIB.cpp b/src/app/MessageDef/AttributeReportIB.cpp index 40add8b660cdea..f631eea9be09ab 100644 --- a/src/app/MessageDef/AttributeReportIB.cpp +++ b/src/app/MessageDef/AttributeReportIB.cpp @@ -94,12 +94,12 @@ CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const if ((TagPresenceMask & CheckDataField) == CheckDataField && (TagPresenceMask & CheckStatusField) == CheckStatusField) { // kAttributeData and kAttributeStatus both exist - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_MESSAGE; + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB; } else if ((TagPresenceMask & CheckDataField) != CheckDataField && (TagPresenceMask & CheckStatusField) != CheckStatusField) { // kPath and kErrorStatus not exist - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_MESSAGE; + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB; } else { @@ -108,8 +108,7 @@ CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -117,16 +116,14 @@ CHIP_ERROR AttributeReportIB::Parser::GetAttributeStatus(AttributeStatusIB::Pars { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kAttributeStatus)), reader)); - ReturnErrorOnFailure(apAttributeStatus->Init(reader)); - return CHIP_NO_ERROR; + return apAttributeStatus->Init(reader); } CHIP_ERROR AttributeReportIB::Parser::GetAttributeData(AttributeDataIB::Parser * const apAttributeData) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kAttributeData)), reader)); - ReturnErrorOnFailure(apAttributeData->Init(reader)); - return CHIP_NO_ERROR; + return apAttributeData->Init(reader); } AttributeStatusIB::Builder & AttributeReportIB::Builder::CreateAttributeStatus() diff --git a/src/app/MessageDef/AttributeReportIBs.cpp b/src/app/MessageDef/AttributeReportIBs.cpp index 2d231b8e004968..d80fbc42b6c1b4 100644 --- a/src/app/MessageDef/AttributeReportIBs.cpp +++ b/src/app/MessageDef/AttributeReportIBs.cpp @@ -65,8 +65,7 @@ CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/AttributeStatusIB.cpp b/src/app/MessageDef/AttributeStatusIB.cpp index 9a3bf1ee980dc0..5be63360438cb0 100644 --- a/src/app/MessageDef/AttributeStatusIB.cpp +++ b/src/app/MessageDef/AttributeStatusIB.cpp @@ -92,11 +92,14 @@ CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_IB; + } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -104,16 +107,14 @@ CHIP_ERROR AttributeStatusIB::Parser::GetPath(AttributePathIB::Parser * const ap { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); - ReturnErrorOnFailure(apPath->Init(reader)); - return CHIP_NO_ERROR; + return apPath->Init(reader); } CHIP_ERROR AttributeStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kErrorStatus)), reader)); - ReturnErrorOnFailure(apErrorStatus->Init(reader)); - return CHIP_NO_ERROR; + return apErrorStatus->Init(reader); } AttributePathIB::Builder & AttributeStatusIB::Builder::CreatePath() diff --git a/src/app/MessageDef/AttributeStatusIBs.cpp b/src/app/MessageDef/AttributeStatusIBs.cpp index f9d4de4ed1b223..cb0bc14ee95558 100644 --- a/src/app/MessageDef/AttributeStatusIBs.cpp +++ b/src/app/MessageDef/AttributeStatusIBs.cpp @@ -77,21 +77,10 @@ CHIP_ERROR AttributeStatusIBs::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // if we have at least one data element - if (NumAttributeStatus > 0) - { - err = CHIP_NO_ERROR; - } - // NOTE: temporarily disable this check, to allow test to continue - else - { - ChipLogError(DataManagement, "PROTOCOL ERROR: Empty attribute statuses"); - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif }; // namespace app diff --git a/src/app/MessageDef/CommandDataIB.cpp b/src/app/MessageDef/CommandDataIB.cpp index 5f24d1c828da2a..680baf87dea199 100644 --- a/src/app/MessageDef/CommandDataIB.cpp +++ b/src/app/MessageDef/CommandDataIB.cpp @@ -29,13 +29,13 @@ namespace chip { namespace app { CHIP_ERROR -CommandDataIB::Parser::ParseData(TLV::TLVReader & aReader, int aDepth) const +CommandDataIB::Parser::ParseFields(TLV::TLVReader & aReader, int aDepth) const { CHIP_ERROR err = CHIP_NO_ERROR; if (aDepth == 0) { - PRETTY_PRINT("\tCommandData = "); + PRETTY_PRINT("\tCommandFields = "); } else { @@ -183,7 +183,7 @@ CommandDataIB::Parser::ParseData(TLV::TLVReader & aReader, int aDepth) const { PRETTY_PRINT_INCDEPTH(); - err = ParseData(aReader, aDepth + 1); + err = ParseFields(aReader, aDepth + 1); SuccessOrExit(err); PRETTY_PRINT_DECDEPTH(); @@ -235,11 +235,11 @@ CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const } break; - case to_underlying(Tag::kData): + case to_underlying(Tag::kFields): // check if this tag has appeared before - VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kData))), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << to_underlying(Tag::kData)); - ReturnErrorOnFailure(ParseData(reader, 0)); + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kFields))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kFields)); + ReturnErrorOnFailure(ParseFields(reader, 0)); break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); @@ -260,13 +260,12 @@ CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const } else { - err = CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_MESSAGE; + err = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB; } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -274,13 +273,12 @@ CHIP_ERROR CommandDataIB::Parser::GetPath(CommandPathIB::Parser * const apPath) { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); - ReturnErrorOnFailure(apPath->Init(reader)); - return CHIP_NO_ERROR; + return apPath->Init(reader); } -CHIP_ERROR CommandDataIB::Parser::GetData(TLV::TLVReader * const apReader) const +CHIP_ERROR CommandDataIB::Parser::GetFields(TLV::TLVReader * const apReader) const { - ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kData)), *apReader)); + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kFields)), *apReader)); return CHIP_NO_ERROR; } diff --git a/src/app/MessageDef/CommandDataIB.h b/src/app/MessageDef/CommandDataIB.h index 3b1eca9f91e623..54c60987a56891 100644 --- a/src/app/MessageDef/CommandDataIB.h +++ b/src/app/MessageDef/CommandDataIB.h @@ -36,7 +36,7 @@ namespace CommandDataIB { enum class Tag : uint8_t { kPath = 0, - kData = 1, + kFields = 1, }; class Parser : public StructParser @@ -71,18 +71,18 @@ class Parser : public StructParser CHIP_ERROR GetPath(CommandPathIB::Parser * const apPath) const; /** - * @brief Get a TLVReader for the Data. Next() must be called before accessing them. + * @brief Get a TLVReader for the Fields. Next() must be called before accessing them. * * @param [in] apReader A pointer to apReader * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetData(TLV::TLVReader * const apReader) const; + CHIP_ERROR GetFields(TLV::TLVReader * const apReader) const; protected: // A recursively callable function to parse a data element and pretty-print it. - CHIP_ERROR ParseData(TLV::TLVReader & aReader, int aDepth) const; + CHIP_ERROR ParseFields(TLV::TLVReader & aReader, int aDepth) const; }; class Builder : public StructBuilder diff --git a/src/app/MessageDef/CommandPathIB.cpp b/src/app/MessageDef/CommandPathIB.cpp index f947b221083812..9d7411a53a30a8 100644 --- a/src/app/MessageDef/CommandPathIB.cpp +++ b/src/app/MessageDef/CommandPathIB.cpp @@ -36,7 +36,7 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; int TagPresenceMask = 0; - chip::TLV::TLVReader reader; + TLV::TLVReader reader; PRETTY_PRINT("CommandPathIB ="); PRETTY_PRINT("{"); @@ -49,50 +49,52 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const { continue; } - switch (chip::TLV::TagNumFromTag(reader.GetTag())) + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - case kCsTag_EndpointId: + case to_underlying(Tag::kEndpointId): // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EndpointId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EndpointId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEndpointId))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEndpointId)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t endpointId; - reader.Get(endpointId); + ReturnErrorOnFailure(reader.Get(endpointId)); PRETTY_PRINT("\tEndpointId = 0x%x,", endpointId); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_ClusterId: + case to_underlying(Tag::kClusterId): // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_ClusterId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_ClusterId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kClusterId))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kClusterId)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { chip::ClusterId clusterId; - reader.Get(clusterId); + ReturnErrorOnFailure(reader.Get(clusterId)); PRETTY_PRINT("\tClusterId = 0x%" PRIx32 ",", clusterId); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_CommandId: + case to_underlying(Tag::kCommandId): // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_CommandId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_CommandId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kCommandId))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kCommandId)); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { chip::CommandId commandId; - reader.Get(commandId); + ReturnErrorOnFailure(reader.Get(commandId)); PRETTY_PRINT("\tCommandId = 0x%x,", commandId); } #endif // CHIP_DETAIL_LOGGING break; default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } PRETTY_PRINT("},"); @@ -101,7 +103,8 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { // check for required fields: - const uint16_t RequiredFields = (1 << kCsTag_CommandId) | (1 << kCsTag_ClusterId); + const uint16_t RequiredFields = + (1 << to_underlying(Tag::kEndpointId)) | (1 << to_underlying(Tag::kCommandId)) | (1 << to_underlying(Tag::kClusterId)); if ((TagPresenceMask & RequiredFields) == RequiredFields) { @@ -109,31 +112,27 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const } else { - err = CHIP_ERROR_IM_MALFORMED_COMMAND_PATH; + err = CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB; } } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; + ReturnErrorOnFailure(err); + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR CommandPathIB::Parser::GetEndpointId(chip::EndpointId * const apEndpointID) const { - return GetUnsignedInteger(kCsTag_EndpointId, apEndpointID); + return GetUnsignedInteger(to_underlying(Tag::kEndpointId), apEndpointID); } CHIP_ERROR CommandPathIB::Parser::GetClusterId(chip::ClusterId * const apClusterId) const { - return GetUnsignedInteger(kCsTag_ClusterId, apClusterId); + return GetUnsignedInteger(to_underlying(Tag::kClusterId), apClusterId); } CHIP_ERROR CommandPathIB::Parser::GetCommandId(chip::CommandId * const apCommandId) const { - return GetUnsignedInteger(kCsTag_CommandId, apCommandId); + return GetUnsignedInteger(to_underlying(Tag::kCommandId), apCommandId); } CommandPathIB::Builder & CommandPathIB::Builder::EndpointId(const chip::EndpointId aEndpointId) @@ -141,7 +140,7 @@ CommandPathIB::Builder & CommandPathIB::Builder::EndpointId(const chip::Endpoint // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_EndpointId), aEndpointId); + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kEndpointId)), aEndpointId); } return *this; } @@ -151,7 +150,7 @@ CommandPathIB::Builder & CommandPathIB::Builder::ClusterId(const chip::ClusterId // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_ClusterId), aClusterId); + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kClusterId)), aClusterId); } return *this; } @@ -161,7 +160,7 @@ CommandPathIB::Builder & CommandPathIB::Builder::CommandId(const chip::CommandId // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_CommandId), aCommandId); + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kCommandId)), aCommandId); } return *this; } diff --git a/src/app/MessageDef/CommandPathIB.h b/src/app/MessageDef/CommandPathIB.h index 35d0bad6f94451..1b823efb65e67b 100644 --- a/src/app/MessageDef/CommandPathIB.h +++ b/src/app/MessageDef/CommandPathIB.h @@ -33,11 +33,11 @@ namespace chip { namespace app { namespace CommandPathIB { -enum +enum class Tag : uint8_t { - kCsTag_EndpointId = 0, - kCsTag_ClusterId = 1, - kCsTag_CommandId = 2, + kEndpointId = 0, + kClusterId = 1, + kCommandId = 2, }; class Parser : public ListParser diff --git a/src/app/MessageDef/CommandStatusIB.cpp b/src/app/MessageDef/CommandStatusIB.cpp index 8be31797735ef6..8ba1a39292cffe 100644 --- a/src/app/MessageDef/CommandStatusIB.cpp +++ b/src/app/MessageDef/CommandStatusIB.cpp @@ -99,8 +99,7 @@ CHIP_ERROR CommandStatusIB::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -108,16 +107,14 @@ CHIP_ERROR CommandStatusIB::Parser::GetPath(CommandPathIB::Parser * const apPath { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); - ReturnErrorOnFailure(apPath->Init(reader)); - return CHIP_NO_ERROR; + return apPath->Init(reader); } CHIP_ERROR CommandStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kErrorStatus)), reader)); - ReturnErrorOnFailure(apErrorStatus->Init(reader)); - return CHIP_NO_ERROR; + return apErrorStatus->Init(reader); } CommandPathIB::Builder & CommandStatusIB::Builder::CreatePath() diff --git a/src/app/MessageDef/DataVersionFilterIB.cpp b/src/app/MessageDef/DataVersionFilterIB.cpp index c68db041297d8e..fee0ace6e4154a 100644 --- a/src/app/MessageDef/DataVersionFilterIB.cpp +++ b/src/app/MessageDef/DataVersionFilterIB.cpp @@ -80,6 +80,9 @@ CHIP_ERROR DataVersionFilterIB::Parser::CheckSchemaValidity() const } #endif // CHIP_DETAIL_LOGGING break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } PRETTY_PRINT("},"); diff --git a/src/app/MessageDef/DataVersionFilterIBs.cpp b/src/app/MessageDef/DataVersionFilterIBs.cpp index efbc00e29e6cc8..cd1251bc420790 100644 --- a/src/app/MessageDef/DataVersionFilterIBs.cpp +++ b/src/app/MessageDef/DataVersionFilterIBs.cpp @@ -29,8 +29,7 @@ namespace app { #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR DataVersionFilterIBs::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - size_t numDataVersionFilters = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("DataVersionFilterIBs ="); @@ -49,8 +48,6 @@ CHIP_ERROR DataVersionFilterIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(DataVersionFilter.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } - - ++numDataVersionFilters; } PRETTY_PRINT("],"); @@ -59,11 +56,7 @@ CHIP_ERROR DataVersionFilterIBs::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // if we have at least one event filter - if (numDataVersionFilters > 0) - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); diff --git a/src/app/MessageDef/EventDataIB.cpp b/src/app/MessageDef/EventDataIB.cpp index 5e8a076b69b4e0..0f1efb93fdb20a 100644 --- a/src/app/MessageDef/EventDataIB.cpp +++ b/src/app/MessageDef/EventDataIB.cpp @@ -331,12 +331,11 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const } else { - err = CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT; + err = CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB; } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -414,7 +413,7 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventTimestamp(EventHeader & aEventHeader } else if (err == CHIP_NO_ERROR) { - VerifyOrReturnError(aEventHeader.mTimestamp.IsSystem(), CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT); + VerifyOrReturnError(aEventHeader.mTimestamp.IsSystem(), CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB); aEventHeader.mTimestamp.mValue += timeStampVal; hasDeltaSystemTimestamp = true; } @@ -427,7 +426,7 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventTimestamp(EventHeader & aEventHeader } else if (err == CHIP_NO_ERROR) { - VerifyOrReturnError(aEventHeader.mTimestamp.IsEpoch(), CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT); + VerifyOrReturnError(aEventHeader.mTimestamp.IsEpoch(), CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB); aEventHeader.mTimestamp.mValue += timeStampVal; hasDeltaEpochTimestamp = true; } @@ -462,7 +461,7 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventTimestamp(EventHeader & aEventHeader { return CHIP_NO_ERROR; } - return CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT; + return CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB; } CHIP_ERROR EventDataIB::Parser::DecodeEventHeader(EventHeader & aEventHeader) diff --git a/src/app/MessageDef/EventFilterIB.cpp b/src/app/MessageDef/EventFilterIB.cpp index 5fc1824d7a7d07..6868d7821d3c06 100644 --- a/src/app/MessageDef/EventFilterIB.cpp +++ b/src/app/MessageDef/EventFilterIB.cpp @@ -94,11 +94,14 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB; + } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/EventFilterIBs.cpp b/src/app/MessageDef/EventFilterIBs.cpp index cff764eff356e9..b7cc412baa93da 100644 --- a/src/app/MessageDef/EventFilterIBs.cpp +++ b/src/app/MessageDef/EventFilterIBs.cpp @@ -29,8 +29,7 @@ namespace app { #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR EventFilterIBs::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - size_t numEventFilters = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventFilterIBs ="); @@ -49,8 +48,6 @@ CHIP_ERROR EventFilterIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(eventFilter.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } - - ++numEventFilters; } PRETTY_PRINT("],"); @@ -59,15 +56,10 @@ CHIP_ERROR EventFilterIBs::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // if we have at least one event filter - if (numEventFilters > 0) - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/EventPathIB.cpp b/src/app/MessageDef/EventPathIB.cpp index 3a2e13b1d84eda..29df4104ca6982 100644 --- a/src/app/MessageDef/EventPathIB.cpp +++ b/src/app/MessageDef/EventPathIB.cpp @@ -134,8 +134,7 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return err; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/EventPathIBs.cpp b/src/app/MessageDef/EventPathIBs.cpp index fc541ad4610ac6..98687f6db8b576 100644 --- a/src/app/MessageDef/EventPathIBs.cpp +++ b/src/app/MessageDef/EventPathIBs.cpp @@ -67,8 +67,7 @@ CHIP_ERROR EventPathIBs::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/EventReportIB.cpp b/src/app/MessageDef/EventReportIB.cpp index b9ac47d75da332..d2ff49e8bac7c5 100644 --- a/src/app/MessageDef/EventReportIB.cpp +++ b/src/app/MessageDef/EventReportIB.cpp @@ -108,8 +108,7 @@ CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -117,16 +116,14 @@ CHIP_ERROR EventReportIB::Parser::GetEventStatus(EventStatusIB::Parser * const a { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventStatus)), reader)); - ReturnErrorOnFailure(apEventStatus->Init(reader)); - return CHIP_NO_ERROR; + return apEventStatus->Init(reader); } CHIP_ERROR EventReportIB::Parser::GetEventData(EventDataIB::Parser * const apEventData) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventData)), reader)); - ReturnErrorOnFailure(apEventData->Init(reader)); - return CHIP_NO_ERROR; + return apEventData->Init(reader); } EventStatusIB::Builder & EventReportIB::Builder::CreateEventStatus() diff --git a/src/app/MessageDef/EventReportIBs.cpp b/src/app/MessageDef/EventReportIBs.cpp index 027af6f69476a4..f071333aa0c589 100644 --- a/src/app/MessageDef/EventReportIBs.cpp +++ b/src/app/MessageDef/EventReportIBs.cpp @@ -65,8 +65,7 @@ CHIP_ERROR EventReportIBs::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/EventStatusIB.cpp b/src/app/MessageDef/EventStatusIB.cpp index 84188a16370f9d..feff195ac884aa 100644 --- a/src/app/MessageDef/EventStatusIB.cpp +++ b/src/app/MessageDef/EventStatusIB.cpp @@ -92,11 +92,14 @@ CHIP_ERROR EventStatusIB::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB; + } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -104,16 +107,14 @@ CHIP_ERROR EventStatusIB::Parser::GetPath(EventPathIB::Parser * const apPath) co { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); - ReturnErrorOnFailure(apPath->Init(reader)); - return CHIP_NO_ERROR; + return apPath->Init(reader); } CHIP_ERROR EventStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kErrorStatus)), reader)); - ReturnErrorOnFailure(apErrorStatus->Init(reader)); - return CHIP_NO_ERROR; + return apErrorStatus->Init(reader); } EventPathIB::Builder & EventStatusIB::Builder::CreatePath() diff --git a/src/app/MessageDef/InvokeRequestMessage.cpp b/src/app/MessageDef/InvokeRequestMessage.cpp index 2610a4d4e7ca5a..b423fe91531394 100644 --- a/src/app/MessageDef/InvokeRequestMessage.cpp +++ b/src/app/MessageDef/InvokeRequestMessage.cpp @@ -113,8 +113,7 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -132,8 +131,7 @@ CHIP_ERROR InvokeRequestMessage::Parser::GetInvokeRequests(InvokeRequests::Parse { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kInvokeRequests)), reader)); - ReturnErrorOnFailure(apInvokeRequests->Init(reader)); - return CHIP_NO_ERROR; + return apInvokeRequests->Init(reader); } InvokeRequestMessage::Builder & InvokeRequestMessage::Builder::SuppressResponse(const bool aSuppressResponse) diff --git a/src/app/MessageDef/InvokeRequests.cpp b/src/app/MessageDef/InvokeRequests.cpp index 2e74397fecaa19..d91b3f5e0a389e 100644 --- a/src/app/MessageDef/InvokeRequests.cpp +++ b/src/app/MessageDef/InvokeRequests.cpp @@ -66,8 +66,7 @@ CHIP_ERROR InvokeRequests::Parser::CheckSchemaValidity() const } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/InvokeResponseIB.cpp b/src/app/MessageDef/InvokeResponseIB.cpp index d28dc49ccad6e3..8d9763505f23a5 100644 --- a/src/app/MessageDef/InvokeResponseIB.cpp +++ b/src/app/MessageDef/InvokeResponseIB.cpp @@ -106,8 +106,7 @@ CHIP_ERROR InvokeResponseIB::Parser::CheckSchemaValidity() const } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -115,16 +114,14 @@ CHIP_ERROR InvokeResponseIB::Parser::GetCommand(CommandDataIB::Parser * const ap { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kCommand)), reader)); - ReturnErrorOnFailure(apCommand->Init(reader)); - return CHIP_NO_ERROR; + return apCommand->Init(reader); } CHIP_ERROR InvokeResponseIB::Parser::GetStatus(CommandStatusIB::Parser * const apStatus) const { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kStatus)), reader)); - ReturnErrorOnFailure(apStatus->Init(reader)); - return CHIP_NO_ERROR; + return apStatus->Init(reader); } CommandDataIB::Builder & InvokeResponseIB::Builder::CreateCommand() diff --git a/src/app/MessageDef/InvokeResponseIBs.cpp b/src/app/MessageDef/InvokeResponseIBs.cpp index 4a148b889ae500..40a2c2649c829c 100644 --- a/src/app/MessageDef/InvokeResponseIBs.cpp +++ b/src/app/MessageDef/InvokeResponseIBs.cpp @@ -59,15 +59,14 @@ CHIP_ERROR InvokeResponseIBs::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // if we have at least one data element + // if we have at least one response if (numInvokeResponses > 0) { err = CHIP_NO_ERROR; } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/InvokeResponseMessage.cpp b/src/app/MessageDef/InvokeResponseMessage.cpp index 80c22a960a5f91..c1f0513c719bd5 100644 --- a/src/app/MessageDef/InvokeResponseMessage.cpp +++ b/src/app/MessageDef/InvokeResponseMessage.cpp @@ -99,8 +99,7 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/ListParser.cpp b/src/app/MessageDef/ListParser.cpp index fce62c3143a6d9..09ab78d2228d4c 100644 --- a/src/app/MessageDef/ListParser.cpp +++ b/src/app/MessageDef/ListParser.cpp @@ -24,8 +24,7 @@ CHIP_ERROR ListParser::Init(const TLV::TLVReader & aReader) { mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_List == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return mReader.EnterContainer(mOuterContainerType); } } // namespace app } // namespace chip diff --git a/src/app/MessageDef/MessageBuilder.cpp b/src/app/MessageDef/MessageBuilder.cpp index 4ea0e418bbf24e..b9ad0e58968d23 100644 --- a/src/app/MessageDef/MessageBuilder.cpp +++ b/src/app/MessageDef/MessageBuilder.cpp @@ -24,9 +24,8 @@ namespace chip { namespace app { CHIP_ERROR MessageBuilder::EncodeInteractionModelRevision() { - ReturnErrorOnFailure(mpWriter->Put(TLV::ContextTag(kInteractionModelRevisionTag), - static_cast(CHIP_DEVICE_INTERACTION_MODEL_REVISION))); - return CHIP_NO_ERROR; + return mpWriter->Put(TLV::ContextTag(kInteractionModelRevisionTag), + static_cast(CHIP_DEVICE_INTERACTION_MODEL_REVISION)); } } // namespace app } // namespace chip diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index 7707011dfb017e..a171bcb9decdb0 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -130,8 +130,7 @@ CHIP_ERROR StatusIB::Parser::CheckSchemaValidity() const } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK diff --git a/src/app/MessageDef/StatusResponseMessage.cpp b/src/app/MessageDef/StatusResponseMessage.cpp index 0b09592f015bb6..a9af045280f8cf 100644 --- a/src/app/MessageDef/StatusResponseMessage.cpp +++ b/src/app/MessageDef/StatusResponseMessage.cpp @@ -40,7 +40,8 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const { continue; } - switch (TLV::TagNumFromTag(reader.GetTag())) + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { case to_underlying(Tag::kStatus): VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kStatus))), CHIP_ERROR_INVALID_TLV_TAG); @@ -58,7 +59,8 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; default: - ReturnErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } PRETTY_PRINT("}"); diff --git a/src/app/MessageDef/StructParser.cpp b/src/app/MessageDef/StructParser.cpp index b6150b677efe25..daf2156437557a 100644 --- a/src/app/MessageDef/StructParser.cpp +++ b/src/app/MessageDef/StructParser.cpp @@ -23,8 +23,7 @@ CHIP_ERROR StructParser::Init(const TLV::TLVReader & aReader) mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - ReturnErrorOnFailure(CheckSchemaOrdering()); - return CHIP_NO_ERROR; + return CheckSchemaOrdering(); } CHIP_ERROR StructParser::CheckSchemaOrdering() const diff --git a/src/app/MessageDef/SubscribeRequestMessage.cpp b/src/app/MessageDef/SubscribeRequestMessage.cpp index a30f577a3ad61b..1ff061f8ed87d3 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.cpp +++ b/src/app/MessageDef/SubscribeRequestMessage.cpp @@ -131,18 +131,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const PRETTY_PRINT_DECDEPTH(); } break; - case to_underlying(Tag::kIsProxy): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kIsProxy))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kIsProxy)); - VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); -#if CHIP_DETAIL_LOGGING - { - bool isProxy; - ReturnErrorOnFailure(reader.Get(isProxy)); - PRETTY_PRINT("\tIsProxy = %s, ", isProxy ? "true" : "false"); - } -#endif // CHIP_DETAIL_LOGGING - break; case to_underlying(Tag::kIsFabricFiltered): // check if this tag has appeared before VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kIsFabricFiltered))), CHIP_ERROR_INVALID_TLV_TAG); @@ -169,7 +157,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int RequiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)) | + const int RequiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)) | (1 << to_underlying(Tag::kKeepSubscriptions)) | (1 << to_underlying(Tag::kMinIntervalFloorSeconds)) | (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds)); if ((tagPresenceMask & RequiredFields) == RequiredFields) @@ -230,11 +218,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::GetEventFilters(EventFilterIBs::Pars return apEventFilters->Init(reader); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetIsProxy(bool * const apIsProxy) const -{ - return GetSimpleValue(to_underlying(Tag::kIsProxy), TLV::kTLVType_Boolean, apIsProxy); -} - CHIP_ERROR SubscribeRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const { return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered); @@ -306,15 +289,6 @@ EventFilterIBs::Builder & SubscribeRequestMessage::Builder::CreateEventFilters() return mEventFilters; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsProxy(const bool aIsProxy) -{ - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kIsProxy)), aIsProxy); - } - return *this; -} - SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered) { // skip if error has already been set diff --git a/src/app/MessageDef/SubscribeRequestMessage.h b/src/app/MessageDef/SubscribeRequestMessage.h index d70451e5677da4..25529cc3870c69 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.h +++ b/src/app/MessageDef/SubscribeRequestMessage.h @@ -41,7 +41,6 @@ enum class Tag : uint8_t kAttributeRequests = 3, kEventRequests = 4, kEventFilters = 5, - kIsProxy = 6, kIsFabricFiltered = 7, kDataVersionFilters = 8, }; @@ -118,13 +117,6 @@ class Parser : public MessageParser */ CHIP_ERROR GetEventFilters(EventFilterIBs::Parser * const apEventFilters) const; - /** - * @brief Get GetIsProxy boolean . - * @return #CHIP_NO_ERROR on success - * #CHIP_END_OF_TLV if there is no such element - */ - CHIP_ERROR GetIsProxy(bool * const apIsProxy) const; - /** * @brief Get IsFabricFiltered boolean * @@ -151,13 +143,6 @@ class Builder : public MessageBuilder EventPathIBs::Builder & CreateEventRequests(); EventFilterIBs::Builder & CreateEventFilters(); - /** - * @brief This is set to true by the subscriber if it is a proxy-type device proxying for another client. This - * confers it special privileges on the publisher that might result in evictions of other non-proxy subscriptions - * to make way for the proxy. - */ - SubscribeRequestMessage::Builder & IsProxy(const bool aIsProxy); - /** * @brief limits the data written within fabric-scoped lists to the accessing fabric * @return A reference to *this diff --git a/src/app/MessageDef/WriteResponseMessage.cpp b/src/app/MessageDef/WriteResponseMessage.cpp index 5beaed04e87a11..0e4c9026b60aac 100644 --- a/src/app/MessageDef/WriteResponseMessage.cpp +++ b/src/app/MessageDef/WriteResponseMessage.cpp @@ -71,16 +71,7 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int RequiredFields = (1 << to_underlying(Tag::kWriteResponses)); - - if ((tagPresenceMask & RequiredFields) == RequiredFields) - { - err = CHIP_NO_ERROR; - } - else - { - err = CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index 56969167c8ca63..dfcd160bc45172 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -85,29 +85,29 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & reader.Init(std::move(payload)); - err = writeResponse.Init(reader); - SuccessOrExit(err); + ReturnErrorOnFailure(writeResponse.Init(reader)); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - err = writeResponse.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(writeResponse.CheckSchemaValidity()); #endif + err = writeResponse.GetWriteResponses(&attributeStatusesParser); - SuccessOrExit(err); + if (err == CHIP_END_OF_TLV) + { + return CHIP_NO_ERROR; + } + ReturnErrorOnFailure(err); attributeStatusesParser.GetReader(&attributeStatusesReader); while (CHIP_NO_ERROR == (err = attributeStatusesReader.Next())) { - VerifyOrExit(TLV::AnonymousTag() == attributeStatusesReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(TLV::AnonymousTag() == attributeStatusesReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); AttributeStatusIB::Parser element; - err = element.Init(attributeStatusesReader); - SuccessOrExit(err); - - err = ProcessAttributeStatusIB(element); - SuccessOrExit(err); + ReturnErrorOnFailure(element.Init(attributeStatusesReader)); + ReturnErrorOnFailure(ProcessAttributeStatusIB(element)); } // if we have exhausted this container @@ -115,11 +115,8 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & { err = CHIP_NO_ERROR; } - SuccessOrExit(err); - ReturnErrorOnFailure(writeResponse.ExitContainer()); - -exit: - return err; + ReturnErrorOnFailure(err); + return writeResponse.ExitContainer(); } CHIP_ERROR WriteClient::PrepareAttributeIB(const ConcreteDataAttributePath & aPath) diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index 298896ac3d69ff..07b695e7eb3ccc 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -258,7 +258,7 @@ void TestCommandInteraction::GenerateInvokeRequest(nlTestSuite * apSuite, void * { chip::TLV::TLVWriter * pWriter = commandDataIBBuilder.GetWriter(); chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; - err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kData)), + err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kFields)), chip::TLV::kTLVType_Structure, dummyType); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -315,7 +315,7 @@ void TestCommandInteraction::GenerateInvokeResponse(nlTestSuite * apSuite, void { chip::TLV::TLVWriter * pWriter = commandDataIBBuilder.GetWriter(); chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; - err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kData)), + err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kFields)), chip::TLV::kTLVType_Structure, dummyType); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -857,7 +857,7 @@ void TestCommandInteraction::TestCommandHandlerRejectMultipleCommands(nlTestSuit NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == path.Encode(commandPathParams)); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == - invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), + invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), TLV::kTLVType_Structure, commandSender.mDataElementContainerType)); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == invokeRequest.GetWriter()->PutBoolean(chip::TLV::ContextTag(1), true)); diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index 745e167e5032a7..4235e5356b4ae0 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -763,7 +763,7 @@ void BuildCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Builder & aCommand { chip::TLV::TLVWriter * pWriter = aCommandDataIBBuilder.GetWriter(); chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; - err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kData)), + err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kFields)), chip::TLV::kTLVType_Structure, dummyType); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -793,7 +793,7 @@ void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandD chip::TLV::TLVReader reader; bool val = false; chip::TLV::TLVType container; - aCommandDataIBParser.GetData(&reader); + aCommandDataIBParser.GetFields(&reader); err = reader.EnterContainer(container); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1262,9 +1262,6 @@ void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventFilters(apSuite, eventFilters); - subscribeRequestBuilder.IsProxy(true); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - subscribeRequestBuilder.IsFabricFiltered(true); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); @@ -1288,7 +1285,6 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & uint16_t MinIntervalFloorSeconds = 0; uint16_t MaxIntervalCeilingSeconds = 0; bool keepExistingSubscription = false; - bool isProxy = false; bool isFabricFiltered = false; err = subscribeRequestParser.Init(aReader); @@ -1318,9 +1314,6 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & err = subscribeRequestParser.GetKeepSubscriptions(&keepExistingSubscription); NL_TEST_ASSERT(apSuite, keepExistingSubscription && err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetIsProxy(&isProxy); - NL_TEST_ASSERT(apSuite, isProxy && err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetIsFabricFiltered(&isFabricFiltered); NL_TEST_ASSERT(apSuite, isFabricFiltered && err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, subscribeRequestParser.ExitContainer() == CHIP_NO_ERROR); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index ee10fb4e68e4c4..0a2c322ebd83ed 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -1458,9 +1458,6 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi err = attributePathListBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - subscribeRequestBuilder.IsProxy(true); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - subscribeRequestBuilder.IsFabricFiltered(false).EndOfSubscribeRequestMessage(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); diff --git a/src/controller/python/chip/clusters/command.cpp b/src/controller/python/chip/clusters/command.cpp index b3ddbfba04b583..e87a2252048b26 100644 --- a/src/controller/python/chip/clusters/command.cpp +++ b/src/controller/python/chip/clusters/command.cpp @@ -146,7 +146,7 @@ chip::ChipError::StorageType pychip_CommandSender_SendCommand(void * appContext, VerifyOrExit(writer != nullptr, err = CHIP_ERROR_INCORRECT_STATE); reader.Init(payload, length); reader.Next(); - SuccessOrExit(writer->CopyContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), reader)); + SuccessOrExit(writer->CopyContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kFields)), reader)); } SuccessOrExit(err = sender->FinishCommand(timedRequestTimeoutMs != 0 ? Optional(timedRequestTimeoutMs) diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index e7006ba8c0b70a..3ace8958b7faca 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -582,13 +582,13 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) desc = "mDNS collision"; break; case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH.AsInteger(): - desc = "Malformed Interacton Model Attribute Path"; + desc = "Malformed Interacton Model Attribute Path IB"; break; case CHIP_ERROR_IM_MALFORMED_EVENT_PATH.AsInteger(): - desc = "Malformed Interacton Model Event Path"; + desc = "Malformed Interacton Model Event Path IB"; break; - case CHIP_ERROR_IM_MALFORMED_COMMAND_PATH.AsInteger(): - desc = "Malformed Interacton Model Command Path"; + case CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB.AsInteger(): + desc = "Malformed Interacton Model Command Path IB"; break; case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_ELEMENT.AsInteger(): desc = "Malformed Interacton Model Attribute DataElement"; @@ -596,7 +596,7 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT.AsInteger(): desc = "Malformed Interacton Model Attribute DataElement"; break; - case CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT.AsInteger(): + case CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB.AsInteger(): desc = "Malformed Interacton Model Event DataElement"; break; case CHIP_ERROR_IM_MALFORMED_STATUS_CODE.AsInteger(): @@ -665,8 +665,8 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE.AsInteger(): desc = "Malformed Interaction Model Write Request Message"; break; - case CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE.AsInteger(): - desc = "Malformed Interaction Model Write Response Message"; + case CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB.AsInteger(): + desc = "Malformed Interaction Model Event Filter IB"; break; case CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE.AsInteger(): desc = "Malformed Interaction Model Read Request Message"; @@ -716,6 +716,18 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_IM_MALFORMED_STATUS_RESPONSE_MESSAGE.AsInteger(): desc = "Malformed Interaction Model Status Response Message"; break; + case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB.AsInteger(): + desc = "Malformed Interaction Model Attribute Report IB"; + break; + case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_IB.AsInteger(): + desc = "Malformed Interaction Model Attribute Status IB"; + break; + case CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB.AsInteger(): + desc = "Malformed Interaction Model Command Data IB"; + break; + case CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB.AsInteger(): + desc = "Malformed Interaction Model Event Status IB"; + break; } #endif // !CHIP_CONFIG_SHORT_ERROR_STR diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index 52c5ff047dec6a..59c2a292defc1c 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -2010,28 +2010,28 @@ using CHIP_ERROR = ::chip::ChipError; * @def CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH * * @brief - * The Attribute path is malformed: it either does not contain + * The Attribute path IB is malformed: it either does not contain * the required path */ -#define CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH CHIP_CORE_ERROR(0xb5) +#define CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH CHIP_CORE_ERROR(0xb5) /** * @def CHIP_ERROR_IM_MALFORMED_EVENT_PATH * * @brief - * The Attribute Path is malformed: it either does not contain + * The Event Path IB is malformed: it either does not contain * the required elements */ #define CHIP_ERROR_IM_MALFORMED_EVENT_PATH CHIP_CORE_ERROR(0xb6) /** - * @def CHIP_ERROR_IM_MALFORMED_COMMAND_PATH + * @def CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB * * @brief - * The Attribute DataElement is malformed: it either does not contain + * The Command Path IB is malformed: it either does not contain * the required elements */ -#define CHIP_ERROR_IM_MALFORMED_COMMAND_PATH CHIP_CORE_ERROR(0xb7) +#define CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB CHIP_CORE_ERROR(0xb7) /** * @def CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_ELEMENT @@ -2052,13 +2052,13 @@ using CHIP_ERROR = ::chip::ChipError; #define CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT CHIP_CORE_ERROR(0xb9) /** - * @def CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT + * @def CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB * * @brief * The Event DataElement is malformed: it either does not contain * the required elements */ -#define CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT CHIP_CORE_ERROR(0xba) +#define CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB CHIP_CORE_ERROR(0xba) /** * @def CHIP_ERROR_IM_MALFORMED_STATUS_CODE @@ -2249,13 +2249,13 @@ using CHIP_ERROR = ::chip::ChipError; #define CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE CHIP_CORE_ERROR(0xd0) /** - * @def CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE + * @def CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB * * @brief - * The WriteResponseMessage is malformed: it either does not contain + * The EventFilter IB is malformed: it either does not contain * the required elements */ -#define CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE CHIP_CORE_ERROR(0xd1) +#define CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB CHIP_CORE_ERROR(0xd1) /** * @def CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE @@ -2395,6 +2395,42 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_IM_MALFORMED_STATUS_RESPONSE_MESSAGE CHIP_CORE_ERROR(0xe1) +/** + * @def CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB + * + * @brief + * The AttributeReportIB is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB CHIP_CORE_ERROR(0xe2) + +/** + * @def CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB + * + * @brief + * The AttributeStatusIB is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_IB CHIP_CORE_ERROR(0xe3) + +/** + * @def CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB + * + * @brief + * The CommandDataIB is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB CHIP_CORE_ERROR(0xe4) + +/** + * @def CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB + * + * @brief + * The Event Status IB is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB CHIP_CORE_ERROR(0xe5) + // clang-format on // !!!!! IMPORTANT !!!!! If you add new CHIP errors, please update the translation diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp index ba3101f3c8a4b7..eb009e397ba9b9 100644 --- a/src/lib/core/tests/TestCHIPErrorStr.cpp +++ b/src/lib/core/tests/TestCHIPErrorStr.cpp @@ -223,10 +223,10 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_MDNS_COLLISION, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH, CHIP_ERROR_IM_MALFORMED_EVENT_PATH, - CHIP_ERROR_IM_MALFORMED_COMMAND_PATH, + CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_ELEMENT, CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT, - CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT, + CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB, CHIP_ERROR_IM_MALFORMED_STATUS_CODE, CHIP_ERROR_PEER_NODE_NOT_FOUND, CHIP_ERROR_HSM, @@ -237,7 +237,7 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_MESSAGE, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_MESSAGE, CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE, - CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE, + CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB, CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE, CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE, CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE, @@ -256,7 +256,11 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_IM_MALFORMED_STATUS_RESPONSE_MESSAGE, CHIP_ERROR_IM_MALFORMED_TIMED_REQUEST_MESSAGE, CHIP_ERROR_INVALID_FILE_IDENTIFIER, - CHIP_ERROR_BUSY + CHIP_ERROR_BUSY, + CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB, + CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_IB, + CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB, + CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB, }; // clang-format on