From 206757310d8b3d69772edd1ef37faa040e488a22 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Wed, 17 Nov 2021 12:01:02 -0800 Subject: [PATCH] update encoding for read/subscribe/write request (#11856) --- src/app/MessageDef/ReadRequestMessage.cpp | 271 +++++++---------- src/app/MessageDef/ReadRequestMessage.h | 70 ++--- .../MessageDef/SubscribeRequestMessage.cpp | 272 +++++++++--------- src/app/MessageDef/SubscribeRequestMessage.h | 97 +++---- .../MessageDef/SubscribeResponseMessage.cpp | 4 + src/app/MessageDef/WriteRequestMessage.cpp | 214 +++++++------- src/app/MessageDef/WriteRequestMessage.h | 68 +++-- src/app/MessageDef/WriteResponseMessage.cpp | 10 +- src/app/ReadClient.cpp | 33 ++- src/app/ReadHandler.cpp | 13 +- src/app/ReadHandler.h | 1 + src/app/WriteClient.cpp | 17 +- src/app/WriteHandler.cpp | 8 +- src/app/WriteHandler.h | 4 +- src/app/tests/TestMessageDef.cpp | 105 +++---- src/app/tests/TestReadInteraction.cpp | 31 +- src/app/tests/TestReportingEngine.cpp | 4 +- src/app/tests/TestWriteInteraction.cpp | 4 +- src/lib/core/CHIPError.cpp | 19 +- src/lib/core/CHIPError.h | 44 +++ 20 files changed, 656 insertions(+), 633 deletions(-) diff --git a/src/app/MessageDef/ReadRequestMessage.cpp b/src/app/MessageDef/ReadRequestMessage.cpp index efe0693b91b29b..4fbec503a8f099 100644 --- a/src/app/MessageDef/ReadRequestMessage.cpp +++ b/src/app/MessageDef/ReadRequestMessage.cpp @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines ReadRequestMessage parser and builder in CHIP interaction model - * - */ #include "ReadRequestMessage.h" #include "MessageDefHelper.h" @@ -28,20 +23,15 @@ #include -using namespace chip; -using namespace chip::TLV; - namespace chip { namespace app { #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - AttributePathIBs::Parser AttributePathIBs; - EventPaths::Parser eventPathList; - AttributeDataVersionList::Parser attributeDataVersionList; + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + PRETTY_PRINT("ReadRequestMessage ="); PRETTY_PRINT("{"); @@ -50,206 +40,151 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - const Tag tag = reader.GetTag(); - - if (chip::TLV::ContextTag(kCsTag_AttributePathList) == tag) - { - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributePathList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributePathList); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - AttributePathIBs.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - - err = AttributePathIBs.CheckSchemaValidity(); - SuccessOrExit(err); - - PRETTY_PRINT_DECDEPTH(); - } - else if (chip::TLV::ContextTag(kCsTag_EventPaths) == tag) - { - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EventPaths)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventPaths); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - eventPathList.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - - err = eventPathList.CheckSchemaValidity(); - SuccessOrExit(err); - - PRETTY_PRINT_DECDEPTH(); - } - else if (chip::TLV::ContextTag(kCsTag_AttributeDataVersionList) == tag) + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributeDataVersionList); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - attributeDataVersionList.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - - err = attributeDataVersionList.CheckSchemaValidity(); - SuccessOrExit(err); - - PRETTY_PRINT_DECDEPTH(); - } - else if (chip::TLV::ContextTag(kCsTag_AttributePathList) == tag) - { - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributePathList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributePathList); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - AttributePathIBs.Init(reader); + case to_underlying(Tag::kAttributeRequests): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kAttributeRequests))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kAttributeRequests)); + { + AttributePathIBs::Parser attributeRequests; + ReturnErrorOnFailure(attributeRequests.Init(reader)); - PRETTY_PRINT_INCDEPTH(); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventRequests): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventRequests))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventRequests)); + { + EventPaths::Parser eventRequests; + ReturnErrorOnFailure(eventRequests.Init(reader)); - err = AttributePathIBs.CheckSchemaValidity(); - SuccessOrExit(err); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventFilters): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventFilters))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventFilters)); + { + EventFilters::Parser eventFilters; + ReturnErrorOnFailure(eventFilters.Init(reader)); - PRETTY_PRINT_DECDEPTH(); - } - else if (chip::TLV::ContextTag(kCsTag_EventNumber) == tag) - { - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EventNumber)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventNumber); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + 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); + TagPresenceMask |= (1 << to_underlying(Tag::kIsFabricFiltered)); #if CHIP_DETAIL_LOGGING { - uint64_t eventNumber; - err = reader.Get(eventNumber); - SuccessOrExit(err); - PRETTY_PRINT("\tEventNumber = 0x%" PRIx64 ",", eventNumber); + bool isFabricFiltered; + ReturnErrorOnFailure(reader.Get(isFabricFiltered)); + PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING + break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } - PRETTY_PRINT("}"); + PRETTY_PRINT("},"); PRETTY_PRINT(""); - // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); + const int RequiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)); -exit: + if ((TagPresenceMask & RequiredFields) == RequiredFields) + { + err = CHIP_NO_ERROR; + } + else + { + err = CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE; + } + } - return err; + ReturnErrorOnFailure(err); + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR ReadRequestMessage::Parser::GetPathList(AttributePathIBs::Parser * const apAttributePathList) const +CHIP_ERROR ReadRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePathList), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributePathList->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kAttributeRequests)), reader)); + return apAttributeRequests->Init(reader); } -CHIP_ERROR ReadRequestMessage::Parser::GetEventPaths(EventPaths::Parser * const apEventPaths) const +CHIP_ERROR ReadRequestMessage::Parser::GetEventRequests(EventPaths::Parser * const apEventRequests) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventPaths), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apEventPaths->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventRequests)), reader)); + return apEventRequests->Init(reader); } -CHIP_ERROR -ReadRequestMessage::Parser::GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const +CHIP_ERROR ReadRequestMessage::Parser::GetEventFilters(EventFilters::Parser * const apEventFilters) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataVersionList), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributeDataVersionList->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventFilters)), reader)); + return apEventFilters->Init(reader); } -CHIP_ERROR ReadRequestMessage::Parser::GetEventNumber(uint64_t * const apEventNumber) const +CHIP_ERROR ReadRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const { - return GetUnsignedInteger(kCsTag_EventNumber, apEventNumber); + return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered); } -AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributePathListBuilder() +AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributeRequests() { // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mAttributePathListBuilder.ResetError(mError)); - - mError = mAttributePathListBuilder.Init(mpWriter, kCsTag_AttributePathList); - -exit: - // on error, mAttributePathListBuilder would be un-/partial initialized and cannot be used to write anything - return mAttributePathListBuilder; + if (mError == CHIP_NO_ERROR) + { + mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests)); + } + return mAttributeRequests; } -EventPaths::Builder & ReadRequestMessage::Builder::CreateEventPathsBuilder() +EventPaths::Builder & ReadRequestMessage::Builder::CreateEventRequests() { // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mEventPathsBuilder.ResetError(mError)); - - mError = mEventPathsBuilder.Init(mpWriter, kCsTag_EventPaths); - -exit: - // on error, mEventPathsBuilder would be un-/partial initialized and cannot be used to write anything - return mEventPathsBuilder; + if (mError == CHIP_NO_ERROR) + { + mError = mEventRequests.Init(mpWriter, to_underlying(Tag::kEventRequests)); + } + return mEventRequests; } -AttributeDataVersionList::Builder & ReadRequestMessage::Builder::CreateAttributeDataVersionListBuilder() +EventFilters::Builder & ReadRequestMessage::Builder::CreateEventFilters() { // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mAttributeDataVersionListBuilder.ResetError(mError)); - - mError = mAttributeDataVersionListBuilder.Init(mpWriter, kCsTag_AttributeDataVersionList); - -exit: - // on error, mAttributeDataVersionListBuilder would be un-/partial initialized and cannot be used to write anything - return mAttributeDataVersionListBuilder; + if (mError == CHIP_NO_ERROR) + { + mError = mEventFilters.Init(mpWriter, to_underlying(Tag::kEventFilters)); + } + return mEventFilters; } -ReadRequestMessage::Builder & ReadRequestMessage::Builder::EventNumber(const uint64_t aEventNumber) +ReadRequestMessage::Builder & ReadRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered) { // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_EventNumber), aEventNumber); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kIsFabricFiltered)), aIsFabricFiltered); } return *this; } @@ -259,5 +194,5 @@ ReadRequestMessage::Builder & ReadRequestMessage::Builder::EndOfReadRequestMessa EndOfContainer(); return *this; } -}; // namespace app -}; // namespace chip +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/ReadRequestMessage.h b/src/app/MessageDef/ReadRequestMessage.h index b065ce4d317686..b3fe54d71cc518 100644 --- a/src/app/MessageDef/ReadRequestMessage.h +++ b/src/app/MessageDef/ReadRequestMessage.h @@ -15,21 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines ReadRequestMessage parser and builder in CHIP interaction model - * - */ #pragma once -#include "AttributeDataVersionList.h" #include "AttributePathIBs.h" -#include "Builder.h" +#include "EventFilters.h" #include "EventPaths.h" -#include "Parser.h" - #include #include #include @@ -40,12 +32,13 @@ namespace chip { namespace app { namespace ReadRequestMessage { -enum +enum class Tag : uint8_t { - kCsTag_AttributePathList = 0, - kCsTag_AttributeDataVersionList = 1, - kCsTag_EventPaths = 2, - kCsTag_EventNumber = 3, + kAttributeRequests = 0, + kEventRequests = 1, + kDataVersionFilters = 2, + kEventFilters = 3, + kIsFabricFiltered = 4, }; class Parser : public StructParser @@ -71,42 +64,40 @@ class Parser : public StructParser /** * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them. * - * @param [in] apAttributePathList A pointer to an attribute path list parser. + * @param [in] apAttributeRequests A pointer to an attribute path list parser. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetPathList(AttributePathIBs::Parser * const apAttributePathList) const; + CHIP_ERROR GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const; /** - * @brief Get a TLVReader for the EventPaths. Next() must be called before accessing them. + * @brief Get a TLVReader for the EventRequests. Next() must be called before accessing them. * * @param [in] apEventPaths A pointer to apEventPaths * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventPaths(EventPaths::Parser * const apEventPaths) const; + CHIP_ERROR GetEventRequests(EventPaths::Parser * const apEventRequests) const; /** - * @brief Get a parser for the AttributeDataVersionList. Next() must be called before accessing them. - * - * @param [in] apAttributeDataVersionList A pointer to apAttributeDataVersionList + * @brief Get a TLVReader for the EventFilters. Next() must be called before accessing them. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const; + CHIP_ERROR GetEventFilters(EventFilters::Parser * const apEventFilters) const; /** - * @brief Get Event Number. Next() must be called before accessing them. + * @brief Get IsFabricFiltered boolean * - * @param [in] apEventNumber A pointer to apEventNumber + * @param [in] apIsFabricFiltered A pointer to apIsFabricFiltered * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventNumber(uint64_t * const apEventNumber) const; + CHIP_ERROR GetIsFabricFiltered(bool * const apIsFabricFiltered) const; }; class Builder : public StructBuilder @@ -117,29 +108,28 @@ class Builder : public StructBuilder * * @return A reference to AttributePathIBs::Builder */ - AttributePathIBs::Builder & CreateAttributePathListBuilder(); + AttributePathIBs::Builder & CreateAttributeRequests(); /** * @brief Initialize a EventPaths::Builder for writing into the TLV stream * * @return A reference to EventPaths::Builder */ - EventPaths::Builder & CreateEventPathsBuilder(); + EventPaths::Builder & CreateEventRequests(); /** - * @brief Initialize a AttributeDataVersionList::Builder for writing into the TLV stream + * @brief Initialize a EventFilters::Builder for writing into the TLV stream * - * @return A reference to AttributeDataVersionList::Builder + * @return A reference to EventFilters::Builder */ - AttributeDataVersionList::Builder & CreateAttributeDataVersionListBuilder(); + EventFilters::Builder & CreateEventFilters(); /** - * @brief An initiator can optionally specify an EventNumber it has already to limit the - * set of retrieved events on the server for optimization purposes. - * @param [in] aEventNumber The event number + * @brief limits the data written within fabric-scoped lists to the accessing fabric * @return A reference to *this */ - ReadRequestMessage::Builder & EventNumber(const uint64_t aEventNumber); + ReadRequestMessage::Builder & IsFabricFiltered(const bool aIsFabricFiltered); + /** * @brief Mark the end of this ReadRequestMessage * @@ -148,10 +138,10 @@ class Builder : public StructBuilder ReadRequestMessage::Builder & EndOfReadRequestMessage(); private: - AttributePathIBs::Builder mAttributePathListBuilder; - EventPaths::Builder mEventPathsBuilder; - AttributeDataVersionList::Builder mAttributeDataVersionListBuilder; + AttributePathIBs::Builder mAttributeRequests; + EventPaths::Builder mEventRequests; + EventFilters::Builder mEventFilters; }; -}; // namespace ReadRequestMessage -}; // namespace app -}; // namespace chip +} // namespace ReadRequestMessage +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/SubscribeRequestMessage.cpp b/src/app/MessageDef/SubscribeRequestMessage.cpp index d529ab644e3e37..6ba07eaff71e16 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.cpp +++ b/src/app/MessageDef/SubscribeRequestMessage.cpp @@ -22,12 +22,10 @@ namespace app { #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - AttributePathIBs::Parser AttributePathIBs; - EventPaths::Parser eventPathList; - AttributeDataVersionList::Parser attributeDataVersionList; + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + PRETTY_PRINT("SubscribeRequestMessage ="); PRETTY_PRINT("{"); @@ -36,247 +34,257 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrReturnError(chip::TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - case kCsTag_AttributePathList: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_AttributePathList)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributePathList); - VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - - AttributePathIBs.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(AttributePathIBs.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - break; - case kCsTag_EventPaths: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_EventPaths)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventPaths); - VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - - eventPathList.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - - ReturnErrorOnFailure(eventPathList.CheckSchemaValidity()); - - PRETTY_PRINT_DECDEPTH(); - break; - case kCsTag_AttributeDataVersionList: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributeDataVersionList); - VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - - attributeDataVersionList.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(attributeDataVersionList.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - break; - case kCsTag_EventNumber: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_EventNumber)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EventNumber); - VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + case to_underlying(Tag::kKeepSubscriptions): + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kKeepSubscriptions))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kKeepSubscriptions)); + VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { - uint64_t eventNumber; - ReturnErrorOnFailure(reader.Get(eventNumber)); - PRETTY_PRINT("\tEventNumber = 0x%" PRIx64 ",", eventNumber); + bool keepSubscriptions; + ReturnErrorOnFailure(reader.Get(keepSubscriptions)); + PRETTY_PRINT("\tKeepSubscriptions = %s, ", keepSubscriptions ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_MinIntervalSeconds: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MinIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_MinIntervalSeconds); - VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + case to_underlying(Tag::kMinIntervalFloorSeconds): + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kMinIntervalFloorSeconds))), + CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kMinIntervalFloorSeconds)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { - uint16_t minIntervalSeconds; - ReturnErrorOnFailure(reader.Get(minIntervalSeconds)); - PRETTY_PRINT("\tMinIntervalSeconds = 0x%" PRIx16 ",", minIntervalSeconds); + uint16_t MinIntervalFloorSeconds; + ReturnErrorOnFailure(reader.Get(MinIntervalFloorSeconds)); + PRETTY_PRINT("\tMinIntervalFloorSeconds = 0x%" PRIx16 ",", MinIntervalFloorSeconds); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_MaxIntervalSeconds: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MaxIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_MaxIntervalSeconds); - VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + case to_underlying(Tag::kMaxIntervalCeilingSeconds): + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds))), + CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { - uint16_t maxIntervalSeconds; - ReturnErrorOnFailure(reader.Get(maxIntervalSeconds)); - PRETTY_PRINT("\tkMaxInterval = 0x%" PRIx16 ",", maxIntervalSeconds); + uint16_t MaxIntervalCeilingSeconds; + ReturnErrorOnFailure(reader.Get(MaxIntervalCeilingSeconds)); + PRETTY_PRINT("\tMaxIntervalCeilingSeconds = 0x%" PRIx16 ",", MaxIntervalCeilingSeconds); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_KeepSubscriptions: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_KeepSubscriptions)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_KeepSubscriptions); - VerifyOrReturnError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); -#if CHIP_DETAIL_LOGGING + case to_underlying(Tag::kAttributeRequests): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kAttributeRequests))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kAttributeRequests)); { - bool keepSubscriptions; - ReturnErrorOnFailure(reader.Get(keepSubscriptions)); - PRETTY_PRINT("\tKeepSubscriptions = %s, ", keepSubscriptions ? "true" : "false"); + AttributePathIBs::Parser attributeRequests; + ReturnErrorOnFailure(attributeRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventRequests): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventRequests))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventRequests)); + { + EventPaths::Parser eventRequests; + ReturnErrorOnFailure(eventRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventFilters): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEventFilters))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEventFilters)); + { + EventFilters::Parser eventFilters; + ReturnErrorOnFailure(eventFilters.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); } -#endif // CHIP_DETAIL_LOGGING break; - case kCsTag_IsProxy: - VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_IsProxy)), CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_IsProxy); - VerifyOrReturnError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + 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); + TagPresenceMask |= (1 << to_underlying(Tag::kIsFabricFiltered)); +#if CHIP_DETAIL_LOGGING + { + bool isFabricFiltered; + ReturnErrorOnFailure(reader.Get(isFabricFiltered)); + PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING break; default: - ReturnErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } - PRETTY_PRINT("}"); + PRETTY_PRINT("},"); PRETTY_PRINT(""); + if (CHIP_END_OF_TLV == err) { - const uint16_t RequiredFields = (1 << kCsTag_MinIntervalSeconds) | (1 << kCsTag_MaxIntervalSeconds); + const int RequiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)) | + (1 << to_underlying(Tag::kMinIntervalFloorSeconds)) | (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds)); if ((TagPresenceMask & RequiredFields) == RequiredFields) { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE; + } } + ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR SubscribeRequestMessage::Parser::GetPathList(AttributePathIBs::Parser * const apAttributePathList) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetKeepSubscriptions(bool * const apKeepExistingSubscription) const { - TLV::TLVReader reader; - ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePathList), reader)); - VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - return apAttributePathList->Init(reader); + return GetSimpleValue(to_underlying(Tag::kKeepSubscriptions), TLV::kTLVType_Boolean, apKeepExistingSubscription); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetEventPaths(EventPaths::Parser * const apEventPaths) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetMinIntervalFloorSeconds(uint16_t * const apMinIntervalFloorSeconds) const { - TLV::TLVReader reader; - ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventPaths), reader)); - VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - return apEventPaths->Init(reader); + return GetUnsignedInteger(to_underlying(Tag::kMinIntervalFloorSeconds), apMinIntervalFloorSeconds); } -CHIP_ERROR -SubscribeRequestMessage::Parser::GetAttributeDataVersionList( - AttributeDataVersionList::Parser * const apAttributeDataVersionList) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetMaxIntervalCeilingSeconds(uint16_t * const apMaxIntervalCeilingSeconds) const { - TLV::TLVReader reader; - ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataVersionList), reader)); - VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - return apAttributeDataVersionList->Init(reader); + return GetUnsignedInteger(to_underlying(Tag::kMaxIntervalCeilingSeconds), apMaxIntervalCeilingSeconds); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetEventNumber(uint64_t * const apEventNumber) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const { - return GetUnsignedInteger(kCsTag_EventNumber, apEventNumber); + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kAttributeRequests)), reader)); + return apAttributeRequests->Init(reader); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetMinIntervalSeconds(uint16_t * const apMinIntervalSeconds) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetEventRequests(EventPaths::Parser * const apEventRequests) const { - return GetUnsignedInteger(kCsTag_MinIntervalSeconds, apMinIntervalSeconds); + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventRequests)), reader)); + return apEventRequests->Init(reader); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetMaxIntervalSeconds(uint16_t * const apMaxIntervalSeconds) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetEventFilters(EventFilters::Parser * const apEventFilters) const { - return GetUnsignedInteger(kCsTag_MaxIntervalSeconds, apMaxIntervalSeconds); + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kEventFilters)), reader)); + return apEventFilters->Init(reader); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetKeepSubscriptions(bool * const apKeepExistingSubscription) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetIsProxy(bool * const apIsProxy) const { - return GetSimpleValue(kCsTag_KeepSubscriptions, chip::TLV::kTLVType_Boolean, apKeepExistingSubscription); + return GetSimpleValue(to_underlying(Tag::kIsProxy), TLV::kTLVType_Boolean, apIsProxy); } -CHIP_ERROR SubscribeRequestMessage::Parser::GetIsProxy(bool * const apIsProxy) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const { - return GetSimpleValue(kCsTag_IsProxy, chip::TLV::kTLVType_Boolean, apIsProxy); + return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered); } -AttributePathIBs::Builder & SubscribeRequestMessage::Builder::CreateAttributePathListBuilder() +SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::KeepSubscriptions(const bool aKeepSubscriptions) { if (mError == CHIP_NO_ERROR) { - mError = mAttributePathListBuilder.Init(mpWriter, kCsTag_AttributePathList); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kKeepSubscriptions)), aKeepSubscriptions); } - - return mAttributePathListBuilder; + return *this; } -EventPaths::Builder & SubscribeRequestMessage::Builder::CreateEventPathsBuilder() +SubscribeRequestMessage::Builder & +SubscribeRequestMessage::Builder::MinIntervalFloorSeconds(const uint16_t aMinIntervalFloorSeconds) { if (mError == CHIP_NO_ERROR) { - mError = mEventPathsBuilder.Init(mpWriter, kCsTag_EventPaths); + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kMinIntervalFloorSeconds)), aMinIntervalFloorSeconds); } - - return mEventPathsBuilder; + return *this; } -AttributeDataVersionList::Builder & SubscribeRequestMessage::Builder::CreateAttributeDataVersionListBuilder() +SubscribeRequestMessage::Builder & +SubscribeRequestMessage::Builder::MaxIntervalCeilingSeconds(const uint16_t aMaxIntervalCeilingSeconds) { if (mError == CHIP_NO_ERROR) { - mError = mAttributeDataVersionListBuilder.Init(mpWriter, kCsTag_AttributeDataVersionList); + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kMaxIntervalCeilingSeconds)), aMaxIntervalCeilingSeconds); } - - return mAttributeDataVersionListBuilder; + return *this; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::EventNumber(const uint64_t aEventNumber) +AttributePathIBs::Builder & SubscribeRequestMessage::Builder::CreateAttributeRequests() { if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_EventNumber), aEventNumber); + mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests)); } - return *this; + return mAttributeRequests; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::MinIntervalSeconds(const uint16_t aMinIntervalSeconds) +EventPaths::Builder & SubscribeRequestMessage::Builder::CreateEventRequests() { if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_MinIntervalSeconds), aMinIntervalSeconds); + mError = mEventRequests.Init(mpWriter, to_underlying(Tag::kEventRequests)); } - return *this; + return mEventRequests; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::MaxIntervalSeconds(const uint16_t aMaxIntervalSeconds) +EventFilters::Builder & SubscribeRequestMessage::Builder::CreateEventFilters() { if (mError == CHIP_NO_ERROR) { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_MaxIntervalSeconds), aMaxIntervalSeconds); + mError = mEventFilters.Init(mpWriter, to_underlying(Tag::kEventFilters)); } - return *this; + return mEventFilters; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::KeepSubscriptions(const bool aKeepSubscriptions) +SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsProxy(const bool aIsProxy) { if (mError == CHIP_NO_ERROR) { - mError = mpWriter->PutBoolean(chip::TLV::ContextTag(kCsTag_KeepSubscriptions), aKeepSubscriptions); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kIsProxy)), aIsProxy); } return *this; } -SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsProxy(const bool aIsProxy) +SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered) { + // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->PutBoolean(chip::TLV::ContextTag(kCsTag_IsProxy), aIsProxy); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kIsFabricFiltered)), aIsFabricFiltered); } return *this; } diff --git a/src/app/MessageDef/SubscribeRequestMessage.h b/src/app/MessageDef/SubscribeRequestMessage.h index ea1802cf46afc1..924060e9d8a6d3 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.h +++ b/src/app/MessageDef/SubscribeRequestMessage.h @@ -19,6 +19,7 @@ #include "AttributeDataVersionList.h" #include "AttributePathIBs.h" +#include "EventFilters.h" #include "EventPaths.h" #include "StructBuilder.h" #include "StructParser.h" @@ -32,16 +33,17 @@ namespace chip { namespace app { namespace SubscribeRequestMessage { -enum +enum class Tag : uint8_t { - kCsTag_AttributePathList = 0, - kCsTag_EventPaths = 1, - kCsTag_AttributeDataVersionList = 2, - kCsTag_EventNumber = 3, - kCsTag_MinIntervalSeconds = 4, - kCsTag_MaxIntervalSeconds = 5, - kCsTag_KeepSubscriptions = 6, - kCsTag_IsProxy = 7, + kKeepSubscriptions = 0, + kMinIntervalFloorSeconds = 1, + kMaxIntervalCeilingSeconds = 2, + kAttributeRequests = 3, + kDataVersionFilters = 4, + kEventRequests = 5, + kEventFilters = 6, + kIsProxy = 7, + kIsFabricFiltered = 8, }; class Parser : public StructParser @@ -63,97 +65,82 @@ class Parser : public StructParser #endif /** - * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them. - * + * @brief Check if subscription is kept. * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetPathList(AttributePathIBs::Parser * const apAttributePathList) const; + CHIP_ERROR GetKeepSubscriptions(bool * const apKeepExistingSubscription) const; /** - * @brief Get a TLVReader for the EventPaths. Next() must be called before accessing them. + * @brief Get MinIntervalFloorSeconds. Next() must be called before accessing them. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventPaths(EventPaths::Parser * const apEventPaths) const; + CHIP_ERROR GetMinIntervalFloorSeconds(uint16_t * const apMinIntervalFloorSeconds) const; /** - * @brief Get a parser for the AttributeDataVersionList. Next() must be called before accessing them. - * + * @brief Get MaxIntervalCeilingSeconds. Next() must be called before accessing them. * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const; + CHIP_ERROR GetMaxIntervalCeilingSeconds(uint16_t * const apMaxIntervalCeilingSeconds) const; /** - * @brief Get Event Number. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEventNumber(uint64_t * const apEventNumber) const; + CHIP_ERROR GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const; /** - * @brief Get MinIntervalSeconds. Next() must be called before accessing them. + * @brief Get a TLVReader for the EventPaths. Next() must be called before accessing them. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetMinIntervalSeconds(uint16_t * const apMinIntervalSeconds) const; + CHIP_ERROR GetEventRequests(EventPaths::Parser * const apEventRequests) const; /** - * @brief Get MaxIntervalSeconds. Next() must be called before accessing them. + * @brief Get a TLVReader for the EventFilters. Next() must be called before accessing them. + * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetMaxIntervalSeconds(uint16_t * const apMaxIntervalSeconds) const; + CHIP_ERROR GetEventFilters(EventFilters::Parser * const apEventFilters) const; /** - * @brief Check if subscription is kept. Next() must be called before accessing them. + * @brief Get GetIsProxy boolean . * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetKeepSubscriptions(bool * const apKeepExistingSubscription) const; + CHIP_ERROR GetIsProxy(bool * const apIsProxy) const; /** - * @brief Check if subscription is kept. Next() must be called before accessing them. + * @brief Get IsFabricFiltered boolean + * + * @param [in] apIsFabricFiltered A pointer to apIsFabricFiltered + * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetIsProxy(bool * const apIsProxy) const; + CHIP_ERROR GetIsFabricFiltered(bool * const apIsFabricFiltered) const; }; class Builder : public StructBuilder { public: - AttributePathIBs::Builder & CreateAttributePathListBuilder(); - - /** - * @brief Initialize a EventPaths::Builder for writing into the TLV stream - */ - EventPaths::Builder & CreateEventPathsBuilder(); - - /** - * @brief Initialize a AttributeDataVersionList::Builder for writing into the TLV stream - */ - AttributeDataVersionList::Builder & CreateAttributeDataVersionListBuilder(); - - /** - * @brief An initiator can optionally specify an EventNumber it has already to limit the - * set of retrieved events on the server for optimization purposes. - */ - SubscribeRequestMessage::Builder & EventNumber(const uint64_t aEventNumber); - - SubscribeRequestMessage::Builder & MinIntervalSeconds(const uint16_t aMinIntervalSeconds); - - SubscribeRequestMessage::Builder & MaxIntervalSeconds(const uint16_t aMinIntervalSeconds); - /** * @brief This is set to 'true' by the subscriber to indicate preservation of previous subscriptions. If omitted, it implies * 'false' as a value. */ SubscribeRequestMessage::Builder & KeepSubscriptions(const bool aKeepSubscriptions); + SubscribeRequestMessage::Builder & MinIntervalFloorSeconds(const uint16_t aMinIntervalFloorSeconds); + SubscribeRequestMessage::Builder & MaxIntervalCeilingSeconds(const uint16_t aMinIntervalFloorSeconds); + AttributePathIBs::Builder & CreateAttributeRequests(); + EventPaths::Builder & CreateEventRequests(); + EventFilters::Builder & CreateEventFilters(); /** * @brief This is set to true by the subscriber if it is a proxy-type device proxying for another client. This @@ -162,15 +149,21 @@ class Builder : public StructBuilder */ SubscribeRequestMessage::Builder & IsProxy(const bool aIsProxy); + /** + * @brief limits the data written within fabric-scoped lists to the accessing fabric + * @return A reference to *this + */ + SubscribeRequestMessage::Builder & IsFabricFiltered(const bool aIsFabricFiltered); + /** * @brief Mark the end of this SubscribeRequestMessage */ SubscribeRequestMessage::Builder & EndOfSubscribeRequestMessage(); private: - AttributePathIBs::Builder mAttributePathListBuilder; - EventPaths::Builder mEventPathsBuilder; - AttributeDataVersionList::Builder mAttributeDataVersionListBuilder; + AttributePathIBs::Builder mAttributeRequests; + EventPaths::Builder mEventRequests; + EventFilters::Builder mEventFilters; }; } // namespace SubscribeRequestMessage } // namespace app diff --git a/src/app/MessageDef/SubscribeResponseMessage.cpp b/src/app/MessageDef/SubscribeResponseMessage.cpp index 41684d5691edd2..6236e870388a97 100644 --- a/src/app/MessageDef/SubscribeResponseMessage.cpp +++ b/src/app/MessageDef/SubscribeResponseMessage.cpp @@ -88,6 +88,10 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE; + } } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); diff --git a/src/app/MessageDef/WriteRequestMessage.cpp b/src/app/MessageDef/WriteRequestMessage.cpp index e55db722cc9130..ace36b410f5538 100644 --- a/src/app/MessageDef/WriteRequestMessage.cpp +++ b/src/app/MessageDef/WriteRequestMessage.cpp @@ -28,19 +28,15 @@ #include -using namespace chip; -using namespace chip::TLV; - namespace chip { namespace app { #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - AttributeDataIBs::Parser AttributeDataIBs; - AttributeDataVersionList::Parser attributeDataVersionList; + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + PRETTY_PRINT("WriteRequestMessage ="); PRETTY_PRINT("{"); @@ -49,130 +45,126 @@ CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - case kCsTag_SuppressResponse: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_SuppressResponse)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_SuppressResponse); - VerifyOrExit(chip::TLV::kTLVType_Boolean == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + case to_underlying(Tag::kSuppressResponse): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse)); #if CHIP_DETAIL_LOGGING { - bool SuppressResponse; - err = reader.Get(SuppressResponse); - SuccessOrExit(err); - PRETTY_PRINT("\tSuppressResponse = %s, ", SuppressResponse ? "true" : "false"); + bool suppressResponse; + ReturnErrorOnFailure(reader.Get(suppressResponse)); + PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING break; - case kCsTag_AttributeDataIBs: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributeDataIBs)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributeDataIBs); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - AttributeDataIBs.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - err = AttributeDataIBs.CheckSchemaValidity(); - SuccessOrExit(err); - - PRETTY_PRINT_DECDEPTH(); + case to_underlying(Tag::kTimedRequest): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kTimedRequest))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kTimedRequest)); +#if CHIP_DETAIL_LOGGING + { + bool timedRequest; + ReturnErrorOnFailure(reader.Get(timedRequest)); + PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false"); + } +#endif // CHIP_DETAIL_LOGGING break; - case kCsTag_AttributeDataVersionList: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributeDataVersionList); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - attributeDataVersionList.Init(reader); - - PRETTY_PRINT_INCDEPTH(); - - err = attributeDataVersionList.CheckSchemaValidity(); - SuccessOrExit(err); + case to_underlying(Tag::kWriteRequests): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kWriteRequests))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kWriteRequests)); + { + AttributeDataIBs::Parser writeRequests; + ReturnErrorOnFailure(writeRequests.Init(reader)); - PRETTY_PRINT_DECDEPTH(); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(writeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } break; - case kCsTag_MoreChunkedMessages: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_MoreChunkedMessages)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_MoreChunkedMessages); - VerifyOrExit(chip::TLV::kTLVType_Boolean == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + case to_underlying(Tag::kMoreChunkedMessages): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kMoreChunkedMessages))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kMoreChunkedMessages)); #if CHIP_DETAIL_LOGGING { bool moreChunkedMessages; - err = reader.Get(moreChunkedMessages); - SuccessOrExit(err); - PRETTY_PRINT("\tMoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false"); + ReturnErrorOnFailure(reader.Get(moreChunkedMessages)); + PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "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); + TagPresenceMask |= (1 << to_underlying(Tag::kIsFabricFiltered)); +#if CHIP_DETAIL_LOGGING + { + bool isFabricFiltered; + ReturnErrorOnFailure(reader.Get(isFabricFiltered)); + PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING break; default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } - PRETTY_PRINT("}"); + + PRETTY_PRINT("},"); PRETTY_PRINT(""); - // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - err = CHIP_NO_ERROR; + const int RequiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)) | (1 << to_underlying(Tag::kTimedRequest)) | + (1 << to_underlying(Tag::kWriteRequests)); + + if ((TagPresenceMask & RequiredFields) == RequiredFields) + { + err = CHIP_NO_ERROR; + } + else + { + err = CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE; + } } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); -exit: - return err; + ReturnErrorOnFailure(err); + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR WriteRequestMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const { - return GetSimpleValue(kCsTag_SuppressResponse, chip::TLV::kTLVType_Boolean, apSuppressResponse); + return GetSimpleValue(to_underlying(Tag::kSuppressResponse), TLV::kTLVType_Boolean, apSuppressResponse); } -CHIP_ERROR WriteRequestMessage::Parser::GetAttributeReportIBs(AttributeDataIBs::Parser * const apAttributeDataIBs) const +CHIP_ERROR WriteRequestMessage::Parser::GetTimedRequest(bool * const apTimedRequest) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataIBs), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributeDataIBs->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + return GetSimpleValue(to_underlying(Tag::kTimedRequest), TLV::kTLVType_Boolean, apTimedRequest); } -CHIP_ERROR -WriteRequestMessage::Parser::GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const +CHIP_ERROR WriteRequestMessage::Parser::GetWriteRequests(AttributeDataIBs::Parser * const apAttributeDataIBs) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataVersionList), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributeDataVersionList->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kWriteRequests)), reader)); + return apAttributeDataIBs->Init(reader); } CHIP_ERROR WriteRequestMessage::Parser::GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const { - return GetSimpleValue(kCsTag_MoreChunkedMessages, chip::TLV::kTLVType_Boolean, apMoreChunkedMessages); + return GetSimpleValue(to_underlying(Tag::kMoreChunkedMessages), TLV::kTLVType_Boolean, apMoreChunkedMessages); +} + +CHIP_ERROR WriteRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const +{ + return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered); } WriteRequestMessage::Builder & WriteRequestMessage::Builder::SuppressResponse(const bool aSuppressResponse) @@ -180,38 +172,29 @@ WriteRequestMessage::Builder & WriteRequestMessage::Builder::SuppressResponse(co // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->PutBoolean(chip::TLV::ContextTag(kCsTag_SuppressResponse), aSuppressResponse); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kSuppressResponse)), aSuppressResponse); } return *this; } -AttributeDataIBs::Builder & WriteRequestMessage::Builder::CreateAttributeDataIBsBuilder() +WriteRequestMessage::Builder & WriteRequestMessage::Builder::TimedRequest(const bool aTimedRequest) { // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mAttributeDataIBsBuilder.Init(mpWriter, kCsTag_AttributeDataIBs); - } - else - { - mAttributeDataIBsBuilder.ResetError(mError); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kTimedRequest)), aTimedRequest); } - - return mAttributeDataIBsBuilder; + return *this; } -AttributeDataVersionList::Builder & WriteRequestMessage::Builder::CreateAttributeDataVersionListBuilder() +AttributeDataIBs::Builder & WriteRequestMessage::Builder::CreateWriteRequests() { // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mAttributeDataVersionListBuilder.Init(mpWriter, kCsTag_AttributeDataVersionList); - } - else - { - mAttributeDataVersionListBuilder.ResetError(mError); + mError = mWriteRequests.Init(mpWriter, to_underlying(Tag::kWriteRequests)); } - return mAttributeDataVersionListBuilder; + return mWriteRequests; } WriteRequestMessage::Builder & WriteRequestMessage::Builder::MoreChunkedMessages(const bool aMoreChunkedMessages) @@ -219,14 +202,19 @@ WriteRequestMessage::Builder & WriteRequestMessage::Builder::MoreChunkedMessages // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mpWriter->PutBoolean(chip::TLV::ContextTag(kCsTag_MoreChunkedMessages), aMoreChunkedMessages); + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kMoreChunkedMessages)), aMoreChunkedMessages); } return *this; } -AttributeDataIBs::Builder & WriteRequestMessage::Builder::GetAttributeReportIBsBuilder() +WriteRequestMessage::Builder & WriteRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered) { - return mAttributeDataIBsBuilder; + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kIsFabricFiltered)), aIsFabricFiltered); + } + return *this; } WriteRequestMessage::Builder & WriteRequestMessage::Builder::EndOfWriteRequestMessage() @@ -234,5 +222,5 @@ WriteRequestMessage::Builder & WriteRequestMessage::Builder::EndOfWriteRequestMe EndOfContainer(); return *this; } -}; // namespace app -}; // namespace chip +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/WriteRequestMessage.h b/src/app/MessageDef/WriteRequestMessage.h index 62abd141885352..53b4b2d63ad9f9 100644 --- a/src/app/MessageDef/WriteRequestMessage.h +++ b/src/app/MessageDef/WriteRequestMessage.h @@ -35,12 +35,13 @@ namespace chip { namespace app { namespace WriteRequestMessage { -enum +enum class Tag : uint8_t { - kCsTag_SuppressResponse = 0, - kCsTag_AttributeDataIBs = 1, - kCsTag_AttributeDataVersionList = 2, - kCsTag_MoreChunkedMessages = 3, + kSuppressResponse = 0, + kTimedRequest = 1, + kWriteRequests = 2, + kMoreChunkedMessages = 3, + kIsFabricFiltered = 4, }; class Parser : public StructParser @@ -60,7 +61,7 @@ class Parser : public StructParser CHIP_ERROR CheckSchemaValidity() const; /** - * @brief Get GetSuppressResponse Next() must be called before accessing them. + * @brief Get SuppressResponse boolean * * @param [in] apSuppressResponse A pointer to apSuppressResponse * @@ -70,27 +71,27 @@ class Parser : public StructParser CHIP_ERROR GetSuppressResponse(bool * const apSuppressResponse) const; /** - * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them. + * @brief Get TimedRequest boolean * - * @param [in] apAttributeDataIBs A pointer to apAttributeDataIBs + * @param [in] apTimedRequest A pointer to apTimedRequest * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributeReportIBs(AttributeDataIBs::Parser * const apAttributeDataIBs) const; + CHIP_ERROR GetTimedRequest(bool * const apTimedRequest) const; /** - * @brief Get a TLVReader for the AttributeDataVersionList. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them. * - * @param [in] apAttributeDataVersionList A pointer to apAttributeDataVersionList + * @param [in] apAttributeDataIBs A pointer to apAttributeDataIBs * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const; + CHIP_ERROR GetWriteRequests(AttributeDataIBs::Parser * const apAttributeDataIBs) const; /** - * @brief Get MoreChunkedMessages message. Next() must be called before accessing them. + * @brief Get MoreChunkedMessages boolean * * @param [in] apMoreChunkedMessages A pointer to apMoreChunkedMessages * @@ -98,6 +99,16 @@ class Parser : public StructParser * #CHIP_END_OF_TLV if there is no such element */ CHIP_ERROR GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const; + + /** + * @brief Get IsFabricFiltered boolean + * + * @param [in] apIsFabricFiltered A pointer to apIsFabricFiltered + * + * @return #CHIP_NO_ERROR on success + * #CHIP_END_OF_TLV if there is no such element + */ + CHIP_ERROR GetIsFabricFiltered(bool * const apIsFabricFiltered) const; }; class Builder : public StructBuilder @@ -111,18 +122,18 @@ class Builder : public StructBuilder WriteRequestMessage::Builder & SuppressResponse(const bool aSuppressResponse); /** - * @brief Initialize a AttributeDataIBs::Builder for writing into the TLV stream - * - * @return A reference to AttributeDataIBs::Builder + * @brief flag action as part of a timed write transaction + * @param [in] aSuppressResponse true if client need to signal suppress response + * @return A reference to *this */ - AttributeDataIBs::Builder & CreateAttributeDataIBsBuilder(); + WriteRequestMessage::Builder & TimedRequest(const bool aTimedRequest); /** - * @brief Initialize a AttributeDataVersionList::Builder for writing into the TLV stream + * @brief Initialize a AttributeDataIBs::Builder for writing into the TLV stream * - * @return A reference to EventPaths::Builder + * @return A reference to AttributeDataIBs::Builder */ - AttributeDataVersionList::Builder & CreateAttributeDataVersionListBuilder(); + AttributeDataIBs::Builder & CreateWriteRequests(); /** * @brief Set True if the set of AttributeDataIBs have to be sent across multiple packets in a single transaction @@ -131,7 +142,13 @@ class Builder : public StructBuilder */ WriteRequestMessage::Builder & MoreChunkedMessages(const bool aMoreChunkedMessages); - AttributeDataIBs::Builder & GetAttributeReportIBsBuilder(); + AttributeDataIBs::Builder & GetWriteRequests() { return mWriteRequests; }; + + /** + * @brief limits the data written within fabric-scoped lists to the accessing fabric + * @return A reference to *this + */ + WriteRequestMessage::Builder & IsFabricFiltered(const bool aIsFabricFiltered); /** * @brief Mark the end of this WriteRequestMessage @@ -141,9 +158,8 @@ class Builder : public StructBuilder WriteRequestMessage::Builder & EndOfWriteRequestMessage(); private: - AttributeDataIBs::Builder mAttributeDataIBsBuilder; - AttributeDataVersionList::Builder mAttributeDataVersionListBuilder; + AttributeDataIBs::Builder mWriteRequests; }; -}; // namespace WriteRequestMessage -}; // namespace app -}; // namespace chip +} // namespace WriteRequestMessage +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/WriteResponseMessage.cpp b/src/app/MessageDef/WriteResponseMessage.cpp index 00e51a3d3a8a64..a616783e761638 100644 --- a/src/app/MessageDef/WriteResponseMessage.cpp +++ b/src/app/MessageDef/WriteResponseMessage.cpp @@ -71,11 +71,14 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } + else + { + err = CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE; + } } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); - return CHIP_NO_ERROR; + return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -83,8 +86,7 @@ CHIP_ERROR WriteResponseMessage::Parser::GetWriteResponses(AttributeStatuses::Pa { TLV::TLVReader reader; ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kWriteResponses)), reader)); - ReturnErrorOnFailure(apWriteResponses->Init(reader)); - return CHIP_NO_ERROR; + return apWriteResponses->Init(reader); } AttributeStatuses::Builder & WriteResponseMessage::Builder::CreateWriteResponses() diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 46e90dcee8c554..39011bca46dc27 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -139,28 +139,34 @@ CHIP_ERROR ReadClient::SendReadRequest(ReadPrepareParams & aReadPrepareParams) if (aReadPrepareParams.mEventPathParamsListSize != 0 && aReadPrepareParams.mpEventPathParamsList != nullptr) { - EventPaths::Builder & eventPathListBuilder = request.CreateEventPathsBuilder(); + EventPaths::Builder & eventPathListBuilder = request.CreateEventRequests(); SuccessOrExit(err = eventPathListBuilder.GetError()); err = GenerateEventPaths(eventPathListBuilder, aReadPrepareParams.mpEventPathParamsList, aReadPrepareParams.mEventPathParamsListSize); SuccessOrExit(err); if (aReadPrepareParams.mEventNumber != 0) { - // EventNumber is optional - request.EventNumber(aReadPrepareParams.mEventNumber); + // EventFilter is optional + EventFilters::Builder eventFilters = request.CreateEventFilters(); + SuccessOrExit(err = request.GetError()); + EventFilterIB::Builder eventFilter = eventFilters.CreateEventFilter(); + eventFilter.EventMin(aReadPrepareParams.mEventNumber).EndOfEventFilterIB(); + SuccessOrExit(err = eventFilter.GetError()); + eventFilters.EndOfEventFilters(); + SuccessOrExit(err = eventFilters.GetError()); } } if (aReadPrepareParams.mAttributePathParamsListSize != 0 && aReadPrepareParams.mpAttributePathParamsList != nullptr) { - AttributePathIBs::Builder attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePathIBs::Builder attributePathListBuilder = request.CreateAttributeRequests(); SuccessOrExit(err = attributePathListBuilder.GetError()); err = GenerateAttributePathList(attributePathListBuilder, aReadPrepareParams.mpAttributePathParamsList, aReadPrepareParams.mAttributePathParamsListSize); SuccessOrExit(err); } - request.EndOfReadRequestMessage(); + request.IsFabricFiltered(false).EndOfReadRequestMessage(); SuccessOrExit(err = request.GetError()); err = writer.Finalize(&msgBuf); @@ -585,7 +591,7 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara if (aReadPrepareParams.mEventPathParamsListSize != 0 && aReadPrepareParams.mpEventPathParamsList != nullptr) { - EventPaths::Builder & eventPathListBuilder = request.CreateEventPathsBuilder(); + EventPaths::Builder & eventPathListBuilder = request.CreateEventRequests(); SuccessOrExit(err = eventPathListBuilder.GetError()); err = GenerateEventPaths(eventPathListBuilder, aReadPrepareParams.mpEventPathParamsList, aReadPrepareParams.mEventPathParamsListSize); @@ -594,13 +600,19 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara if (aReadPrepareParams.mEventNumber != 0) { // EventNumber is optional - request.EventNumber(aReadPrepareParams.mEventNumber); + EventFilters::Builder eventFilters = request.CreateEventFilters(); + SuccessOrExit(err = request.GetError()); + EventFilterIB::Builder eventFilter = eventFilters.CreateEventFilter(); + eventFilter.EventMin(aReadPrepareParams.mEventNumber).EndOfEventFilterIB(); + SuccessOrExit(err = eventFilter.GetError()); + eventFilters.EndOfEventFilters(); + SuccessOrExit(err = eventFilters.GetError()); } } if (aReadPrepareParams.mAttributePathParamsListSize != 0 && aReadPrepareParams.mpAttributePathParamsList != nullptr) { - AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributeRequests(); SuccessOrExit(err = attributePathListBuilder.GetError()); err = GenerateAttributePathList(attributePathListBuilder, aReadPrepareParams.mpAttributePathParamsList, aReadPrepareParams.mAttributePathParamsListSize); @@ -609,9 +621,10 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara VerifyOrExit(aReadPrepareParams.mMinIntervalFloorSeconds < aReadPrepareParams.mMaxIntervalCeilingSeconds, err = CHIP_ERROR_INVALID_ARGUMENT); - request.MinIntervalSeconds(aReadPrepareParams.mMinIntervalFloorSeconds) - .MaxIntervalSeconds(aReadPrepareParams.mMaxIntervalCeilingSeconds) + request.MinIntervalFloorSeconds(aReadPrepareParams.mMinIntervalFloorSeconds) + .MaxIntervalCeilingSeconds(aReadPrepareParams.mMaxIntervalCeilingSeconds) .KeepSubscriptions(aReadPrepareParams.mKeepSubscriptions) + .IsFabricFiltered(false) .EndOfSubscribeRequestMessage(); SuccessOrExit(err = request.GetError()); diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 48f6c1c80ccbe5..94e868dad6e1d7 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -274,7 +274,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa SuccessOrExit(err); #endif - err = readRequestParser.GetPathList(&attributePathListParser); + err = readRequestParser.GetAttributeRequests(&attributePathListParser); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; @@ -285,7 +285,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa err = ProcessAttributePathList(attributePathListParser); } SuccessOrExit(err); - err = readRequestParser.GetEventPaths(&eventPathListParser); + err = readRequestParser.GetEventRequests(&eventPathListParser); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; @@ -549,7 +549,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP #endif AttributePathIBs::Parser attributePathListParser; - CHIP_ERROR err = subscribeRequestParser.GetPathList(&attributePathListParser); + CHIP_ERROR err = subscribeRequestParser.GetAttributeRequests(&attributePathListParser); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; @@ -561,7 +561,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP ReturnErrorOnFailure(err); EventPaths::Parser eventPathListParser; - err = subscribeRequestParser.GetEventPaths(&eventPathListParser); + err = subscribeRequestParser.GetEventRequests(&eventPathListParser); if (err == CHIP_END_OF_TLV) { err = CHIP_NO_ERROR; @@ -572,9 +572,10 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP } ReturnErrorOnFailure(err); - ReturnErrorOnFailure(subscribeRequestParser.GetMinIntervalSeconds(&mMinIntervalFloorSeconds)); - ReturnErrorOnFailure(subscribeRequestParser.GetMaxIntervalSeconds(&mMaxIntervalCeilingSeconds)); + ReturnErrorOnFailure(subscribeRequestParser.GetMinIntervalFloorSeconds(&mMinIntervalFloorSeconds)); + ReturnErrorOnFailure(subscribeRequestParser.GetMaxIntervalCeilingSeconds(&mMaxIntervalCeilingSeconds)); VerifyOrReturnError(mMinIntervalFloorSeconds < mMaxIntervalCeilingSeconds, CHIP_ERROR_INVALID_ARGUMENT); + ReturnErrorOnFailure(subscribeRequestParser.GetIsFabricFiltered(&mIsFabricFiltered)); ReturnErrorOnFailure(Crypto::DRBG_get_bytes(reinterpret_cast(&mSubscriptionId), sizeof(mSubscriptionId))); MoveToState(HandlerState::GeneratingReports); diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 7f1e644832b0dc..fd1aa040ff54e5 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -208,6 +208,7 @@ class ReadHandler : public Messaging::ExchangeDelegate NodeId mInitiatorNodeId = kUndefinedNodeId; FabricIndex mFabricIndex = 0; AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr); + bool mIsFabricFiltered = false; }; } // namespace app } // namespace chip diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index 60d56a73551215..f540ac75116a8b 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -36,16 +36,17 @@ CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, Callbac VerifyOrReturnError(mpExchangeMgr == nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); - AttributeDataIBs::Builder AttributeDataIBsBuilder; + AttributeDataIBs::Builder attributeDataIBsBuilder; System::PacketBufferHandle packet = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes); VerifyOrReturnError(!packet.IsNull(), CHIP_ERROR_NO_MEMORY); mMessageWriter.Init(std::move(packet)); ReturnErrorOnFailure(mWriteRequestBuilder.Init(&mMessageWriter)); - - AttributeDataIBsBuilder = mWriteRequestBuilder.CreateAttributeDataIBsBuilder(); - ReturnErrorOnFailure(AttributeDataIBsBuilder.GetError()); + mWriteRequestBuilder.TimedRequest(false).IsFabricFiltered(false); + ReturnErrorOnFailure(mWriteRequestBuilder.GetError()); + attributeDataIBsBuilder = mWriteRequestBuilder.CreateWriteRequests(); + ReturnErrorOnFailure(attributeDataIBsBuilder.GetError()); ClearExistingExchangeContext(); mpExchangeMgr = apExchangeMgr; @@ -137,7 +138,7 @@ CHIP_ERROR WriteClient::PrepareAttribute(const AttributePathParams & attributePa { CHIP_ERROR err = CHIP_NO_ERROR; - AttributeDataIB::Builder AttributeDataIB = mWriteRequestBuilder.GetAttributeReportIBsBuilder().CreateAttributeDataIBBuilder(); + AttributeDataIB::Builder AttributeDataIB = mWriteRequestBuilder.GetWriteRequests().CreateAttributeDataIBBuilder(); SuccessOrExit(AttributeDataIB.GetError()); err = ConstructAttributePath(attributePathParams, AttributeDataIB); @@ -149,7 +150,7 @@ CHIP_ERROR WriteClient::FinishAttribute() { CHIP_ERROR err = CHIP_NO_ERROR; - AttributeDataIB::Builder AttributeDataIB = mWriteRequestBuilder.GetAttributeReportIBsBuilder().GetAttributeDataIBBuilder(); + AttributeDataIB::Builder AttributeDataIB = mWriteRequestBuilder.GetWriteRequests().GetAttributeDataIBBuilder(); // TODO: Add attribute version support AttributeDataIB.DataVersion(0); @@ -163,7 +164,7 @@ CHIP_ERROR WriteClient::FinishAttribute() TLV::TLVWriter * WriteClient::GetAttributeDataIBTLVWriter() { - return mWriteRequestBuilder.GetAttributeReportIBsBuilder().GetAttributeDataIBBuilder().GetWriter(); + return mWriteRequestBuilder.GetWriteRequests().GetAttributeDataIBBuilder().GetWriter(); } CHIP_ERROR WriteClient::ConstructAttributePath(const AttributePathParams & aAttributePathParams, @@ -180,7 +181,7 @@ CHIP_ERROR WriteClient::FinalizeMessage(System::PacketBufferHandle & aPacket) CHIP_ERROR err = CHIP_NO_ERROR; AttributeDataIBs::Builder AttributeDataIBsBuilder; VerifyOrExit(mState == State::AddAttribute, err = CHIP_ERROR_INCORRECT_STATE); - AttributeDataIBsBuilder = mWriteRequestBuilder.GetAttributeReportIBsBuilder().EndOfAttributeDataIBs(); + AttributeDataIBsBuilder = mWriteRequestBuilder.GetWriteRequests().EndOfAttributeDataIBs(); err = AttributeDataIBsBuilder.GetError(); SuccessOrExit(err); diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index c6533f28844969..ea3ac088abe026 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -202,7 +202,13 @@ CHIP_ERROR WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayl } SuccessOrExit(err); - err = writeRequestParser.GetAttributeReportIBs(&AttributeDataIBsParser); + err = writeRequestParser.GetTimedRequest(&mIsTimedRequest); + SuccessOrExit(err); + + err = writeRequestParser.GetIsFabricFiltered(&mIsFabricFiltered); + SuccessOrExit(err); + + err = writeRequestParser.GetWriteRequests(&AttributeDataIBsParser); SuccessOrExit(err); AttributeDataIBsParser.GetReader(&AttributeDataIBsReader); err = ProcessAttributeDataIBs(AttributeDataIBsReader); diff --git a/src/app/WriteHandler.h b/src/app/WriteHandler.h index 7d0edd139f085e..46ff424ebfbf5e 100644 --- a/src/app/WriteHandler.h +++ b/src/app/WriteHandler.h @@ -109,7 +109,9 @@ class WriteHandler Messaging::ExchangeContext * mpExchangeCtx = nullptr; WriteResponseMessage::Builder mWriteResponseBuilder; System::PacketBufferTLVWriter mMessageWriter; - State mState = State::Uninitialized; + State mState = State::Uninitialized; + bool mIsTimedRequest = false; + bool mIsFabricFiltered = false; }; } // namespace app } // namespace chip diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index 7c4d94e9c6b4b6..b83bf0739cc407 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -139,11 +139,9 @@ void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventFilters::Parser eventFiltersParser; - AttributePathIB::Parser attributePathParser; err = eventFiltersParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK err = eventFiltersParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1028,19 +1026,19 @@ void BuildReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrit err = readRequestBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder AttributePathIBs = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePathIBs::Builder AttributePathIBs = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePathList(apSuite, AttributePathIBs); - EventPaths::Builder eventPathList = readRequestBuilder.CreateEventPathsBuilder(); + EventPaths::Builder eventPathList = readRequestBuilder.CreateEventRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventPaths(apSuite, eventPathList); - AttributeDataVersionList::Builder attributeDataVersionList = readRequestBuilder.CreateAttributeDataVersionListBuilder(); + EventFilters::Builder eventFilters = readRequestBuilder.CreateEventFilters(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataVersionList(apSuite, attributeDataVersionList); + BuildEventFilters(apSuite, eventFilters); - readRequestBuilder.EventNumber(1); + readRequestBuilder.IsFabricFiltered(true); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); readRequestBuilder.EndOfReadRequestMessage(); @@ -1054,8 +1052,8 @@ void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead ReadRequestMessage::Parser readRequestParser; AttributePathIBs::Parser attributePathListParser; EventPaths::Parser eventPathListParser; - AttributeDataVersionList::Parser attributeDataVersionListParser; - uint64_t eventNumber; + EventFilters::Parser eventFiltersParser; + bool isFabricFiltered = false; err = readRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1063,17 +1061,17 @@ void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead err = readRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = readRequestParser.GetPathList(&attributePathListParser); + err = readRequestParser.GetAttributeRequests(&attributePathListParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = readRequestParser.GetEventPaths(&eventPathListParser); + err = readRequestParser.GetEventRequests(&eventPathListParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = readRequestParser.GetAttributeDataVersionList(&attributeDataVersionListParser); + err = readRequestParser.GetEventFilters(&eventFiltersParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = readRequestParser.GetEventNumber(&eventNumber); - NL_TEST_ASSERT(apSuite, eventNumber == 1 && err == CHIP_NO_ERROR); + err = readRequestParser.GetIsFabricFiltered(&isFabricFiltered); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isFabricFiltered); } void BuildWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) @@ -1087,17 +1085,19 @@ void BuildWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWri writeRequestBuilder.SuppressResponse(true); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributeDataIBs::Builder AttributeDataIBs = writeRequestBuilder.CreateAttributeDataIBsBuilder(); + writeRequestBuilder.TimedRequest(true); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIBs(apSuite, AttributeDataIBs); - AttributeDataVersionList::Builder attributeDataVersionList = writeRequestBuilder.CreateAttributeDataVersionListBuilder(); + AttributeDataIBs::Builder AttributeDataIBs = writeRequestBuilder.CreateWriteRequests(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataVersionList(apSuite, attributeDataVersionList); + BuildAttributeDataIBs(apSuite, AttributeDataIBs); writeRequestBuilder.MoreChunkedMessages(true); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + writeRequestBuilder.IsFabricFiltered(true); + NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + writeRequestBuilder.EndOfWriteRequestMessage(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); } @@ -1108,9 +1108,10 @@ void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea WriteRequestMessage::Parser writeRequestParser; bool suppressResponse = false; - AttributeDataIBs::Parser AttributeDataIBs; - AttributeDataVersionList::Parser attributeDataVersionList; + bool timeRequest = false; + AttributeDataIBs::Parser writeRequests; bool moreChunkedMessages = false; + bool isFabricFiltered = false; err = writeRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1121,14 +1122,17 @@ void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea err = writeRequestParser.GetSuppressResponse(&suppressResponse); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); - err = writeRequestParser.GetAttributeReportIBs(&AttributeDataIBs); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + err = writeRequestParser.GetTimedRequest(&timeRequest); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && timeRequest); - err = writeRequestParser.GetAttributeDataVersionList(&attributeDataVersionList); + err = writeRequestParser.GetWriteRequests(&writeRequests); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = writeRequestParser.GetMoreChunkedMessages(&moreChunkedMessages); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); + + err = writeRequestParser.GetIsFabricFiltered(&isFabricFiltered); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isFabricFiltered); } void BuildWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) @@ -1171,25 +1175,22 @@ void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & err = subscribeRequestBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder AttributePathIBs = subscribeRequestBuilder.CreateAttributePathListBuilder(); + AttributePathIBs::Builder attributePathIBs = subscribeRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, AttributePathIBs); + BuildAttributePathList(apSuite, attributePathIBs); - EventPaths::Builder eventPathList = subscribeRequestBuilder.CreateEventPathsBuilder(); + EventPaths::Builder eventPathList = subscribeRequestBuilder.CreateEventRequests(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventPaths(apSuite, eventPathList); - AttributeDataVersionList::Builder attributeDataVersionList = subscribeRequestBuilder.CreateAttributeDataVersionListBuilder(); + EventFilters::Builder eventFilters = subscribeRequestBuilder.CreateEventFilters(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataVersionList(apSuite, attributeDataVersionList); + BuildEventFilters(apSuite, eventFilters); - subscribeRequestBuilder.EventNumber(1); + subscribeRequestBuilder.MinIntervalFloorSeconds(2); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - subscribeRequestBuilder.MinIntervalSeconds(2); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - - subscribeRequestBuilder.MaxIntervalSeconds(3); + subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); subscribeRequestBuilder.KeepSubscriptions(true); @@ -1198,6 +1199,9 @@ void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & subscribeRequestBuilder.IsProxy(true); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + subscribeRequestBuilder.IsFabricFiltered(true); + NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + subscribeRequestBuilder.EndOfSubscribeRequestMessage(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); } @@ -1209,12 +1213,12 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & SubscribeRequestMessage::Parser subscribeRequestParser; AttributePathIBs::Parser attributePathListParser; EventPaths::Parser eventPathListParser; - AttributeDataVersionList::Parser attributeDataVersionListParser; - uint64_t eventNumber = 0; - uint16_t minIntervalSeconds = 0; - uint16_t maxIntervalSeconds = 0; - bool keepExistingSubscription = false; - bool isProxy = false; + EventFilters::Parser eventFiltersParser; + uint16_t MinIntervalFloorSeconds = 0; + uint16_t MaxIntervalCeilingSeconds = 0; + bool keepExistingSubscription = false; + bool isProxy = false; + bool isFabricFiltered = false; err = subscribeRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1222,29 +1226,29 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & err = subscribeRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = subscribeRequestParser.GetPathList(&attributePathListParser); + err = subscribeRequestParser.GetAttributeRequests(&attributePathListParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetEventPaths(&eventPathListParser); + err = subscribeRequestParser.GetEventRequests(&eventPathListParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetAttributeDataVersionList(&attributeDataVersionListParser); + err = subscribeRequestParser.GetEventFilters(&eventFiltersParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetEventNumber(&eventNumber); - NL_TEST_ASSERT(apSuite, eventNumber == 1 && err == CHIP_NO_ERROR); + err = subscribeRequestParser.GetMinIntervalFloorSeconds(&MinIntervalFloorSeconds); + NL_TEST_ASSERT(apSuite, MinIntervalFloorSeconds == 2 && err == CHIP_NO_ERROR); - err = subscribeRequestParser.GetMinIntervalSeconds(&minIntervalSeconds); - NL_TEST_ASSERT(apSuite, minIntervalSeconds == 2 && err == CHIP_NO_ERROR); - - err = subscribeRequestParser.GetMaxIntervalSeconds(&maxIntervalSeconds); - NL_TEST_ASSERT(apSuite, maxIntervalSeconds == 3 && err == CHIP_NO_ERROR); + err = subscribeRequestParser.GetMaxIntervalCeilingSeconds(&MaxIntervalCeilingSeconds); + NL_TEST_ASSERT(apSuite, MaxIntervalCeilingSeconds == 3 && err == CHIP_NO_ERROR); 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); } void BuildSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) @@ -1339,7 +1343,6 @@ void EventFilterTest(nlTestSuite * apSuite, void * apContext) reader.Init(std::move(buf)); err = reader.Next(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventFilterIB(apSuite, reader); } @@ -1349,7 +1352,7 @@ void EventFiltersTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; EventFilters::Builder eventFiltersBuilder; - + EventFilters::Parser eventFiltersParser; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = eventFiltersBuilder.Init(&writer); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 2e9fc4b4b2aa78..1650980bea9332 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -417,7 +417,7 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); @@ -432,7 +432,7 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - readRequestBuilder.EndOfReadRequestMessage(); + readRequestBuilder.IsFabricFiltered(false).EndOfReadRequestMessage(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); err = writer.Finalize(&readRequestbuf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -466,7 +466,7 @@ void TestReadInteraction::TestReadClientGenerateAttributePathList(nlTestSuite * attributePathParams[0].mAttributeId = 0; attributePathParams[1].mAttributeId = 0; attributePathParams[1].mListIndex = 0; - AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributeRequests(); err = readClient.GenerateAttributePathList(attributePathListBuilder, attributePathParams, 2 /*aAttributePathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } @@ -492,7 +492,7 @@ void TestReadInteraction::TestReadClientGenerateInvalidAttributePathList(nlTestS AttributePathParams attributePathParams[2]; attributePathParams[0].mAttributeId = 0; attributePathParams[1].mListIndex = 0; - AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributeRequests(); err = readClient.GenerateAttributePathList(attributePathListBuilder, attributePathParams, 2 /*aAttributePathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); } @@ -546,7 +546,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); @@ -556,8 +556,9 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - readRequestBuilder.EndOfReadRequestMessage(); + attributePathListBuilder.EndOfAttributePathIBs(); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + readRequestBuilder.IsFabricFiltered(false).EndOfReadRequestMessage(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); err = writer.Finalize(&readRequestbuf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -593,11 +594,11 @@ void TestReadInteraction::TestReadClientGenerateOneEventPaths(nlTestSuite * apSu eventPathParams[0].mClusterId = 3; eventPathParams[0].mEventId = 4; - EventPaths::Builder & eventPathListBuilder = request.CreateEventPathsBuilder(); + EventPaths::Builder & eventPathListBuilder = request.CreateEventRequests(); err = readClient.GenerateEventPaths(eventPathListBuilder, eventPathParams, 1 /*aEventPathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - request.EndOfReadRequestMessage(); + request.IsFabricFiltered(false).EndOfReadRequestMessage(); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == request.GetError()); err = writer.Finalize(&msgBuf); @@ -647,11 +648,11 @@ void TestReadInteraction::TestReadClientGenerateTwoEventPaths(nlTestSuite * apSu eventPathParams[1].mClusterId = 3; eventPathParams[1].mEventId = 5; - EventPaths::Builder & eventPathListBuilder = request.CreateEventPathsBuilder(); + EventPaths::Builder & eventPathListBuilder = request.CreateEventRequests(); err = readClient.GenerateEventPaths(eventPathListBuilder, eventPathParams, 2 /*aEventPathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - request.EndOfReadRequestMessage(); + request.IsFabricFiltered(false).EndOfReadRequestMessage(); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == request.GetError()); err = writer.Finalize(&msgBuf); @@ -948,7 +949,7 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi err = subscribeRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathListBuilder = subscribeRequestBuilder.CreateAttributePathListBuilder(); + AttributePathIBs::Builder attributePathListBuilder = subscribeRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); @@ -962,10 +963,10 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi err = attributePathListBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - subscribeRequestBuilder.MinIntervalSeconds(2); + subscribeRequestBuilder.MinIntervalFloorSeconds(2); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - subscribeRequestBuilder.MaxIntervalSeconds(3); + subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); subscribeRequestBuilder.KeepSubscriptions(true); @@ -974,7 +975,7 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi subscribeRequestBuilder.IsProxy(true); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - subscribeRequestBuilder.EndOfSubscribeRequestMessage(); + subscribeRequestBuilder.IsFabricFiltered(false).EndOfSubscribeRequestMessage(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index a3b935f386375f..c3776b596166e4 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -85,7 +85,7 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite writer.Init(std::move(readRequestbuf)); err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); + attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); @@ -107,7 +107,7 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite attributePathListBuilder.EndOfAttributePathIBs(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - readRequestBuilder.EndOfReadRequestMessage(); + readRequestBuilder.IsFabricFiltered(false).EndOfReadRequestMessage(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); err = writer.Finalize(&readRequestbuf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index fd83dd21491365..24c6ee82efb557 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -124,7 +124,7 @@ void TestWriteInteraction::GenerateWriteRequest(nlTestSuite * apSuite, void * ap WriteRequestMessage::Builder writeRequestBuilder; err = writeRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributeDataIBs::Builder attributeDataIBsBuilder = writeRequestBuilder.CreateAttributeDataIBsBuilder(); + AttributeDataIBs::Builder attributeDataIBsBuilder = writeRequestBuilder.CreateWriteRequests(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); AttributeDataIB::Builder attributeDataIBBuilder = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); @@ -155,7 +155,7 @@ void TestWriteInteraction::GenerateWriteRequest(nlTestSuite * apSuite, void * ap attributeDataIBsBuilder.EndOfAttributeDataIBs(); NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - writeRequestBuilder.EndOfWriteRequestMessage(); + writeRequestBuilder.TimedRequest(false).IsFabricFiltered(false).EndOfWriteRequestMessage(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); err = writer.Finalize(&aPayload); diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index edec0415c29220..9e41fa862f9e1f 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -663,10 +663,25 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) desc = "Malformed Interaction Model Invoke Response Message"; break; case CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_MESSAGE.AsInteger(): - desc = "Malformed Interaction Model Invoke Response MESSAGE"; + desc = "Malformed Interaction Model Invoke Response Message"; break; case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_MESSAGE.AsInteger(): - desc = "Malformed Interaction Model Attribute Report MESSAGE"; + desc = "Malformed Interaction Model Attribute Report Message"; + break; + 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"; + break; + case CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE.AsInteger(): + desc = "Malformed Interaction Model Read Request Message"; + break; + case CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE.AsInteger(): + desc = "Malformed Interaction Model Subscribe Request Message"; + break; + case CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE.AsInteger(): + desc = "Malformed Interaction Model Subscribe Response Message"; break; } #endif // !CHIP_CONFIG_SHORT_ERROR_STR diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index f101c2478b68bb..b2f7bc541f4224 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -2261,6 +2261,50 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_MESSAGE CHIP_CORE_ERROR(0xcf) +/** + * @def CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE + * + * @brief + * The WriteRequestMessage is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE CHIP_CORE_ERROR(0xd0) + +/** + * @def CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE + * + * @brief + * The WriteResponseMessage is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_WRITE_RESPONSE_MESSAGE CHIP_CORE_ERROR(0xd1) + +/** + * @def CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE + * + * @brief + * The ReadRequestMessage is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE CHIP_CORE_ERROR(0xd2) + +/** + * @def CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE + * + * @brief + * The SubscribeRequestMessage is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE CHIP_CORE_ERROR(0xd3) + +/** + * @def CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE + * + * @brief + * The SubscribeResponseMessage is malformed: it either does not contain + * the required elements + */ +#define CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE CHIP_CORE_ERROR(0xd4) /** * @} */