diff --git a/src/app/ClusterInfo.h b/src/app/ClusterInfo.h index f9179ab373db72..f8ff6823e5792a 100644 --- a/src/app/ClusterInfo.h +++ b/src/app/ClusterInfo.h @@ -18,103 +18,74 @@ #pragma once -#include #include #include #include namespace chip { namespace app { -static constexpr AttributeId kRootAttributeId = 0xFFFFFFFF; +/** + * ClusterInfo is the representation of an attribute path or an event path used by ReadHandler, ReadClient, WriteHandler, + * Report::Engine etc, it uses some invalid values for representing the wildcard values for its fields and contains a mpNext field + * so it can be used as a linked list. + */ +// TODO: The cluster info should be separated into AttributeInfo and EventInfo. +// Note: The change will happen after #11171 with a better linked list. struct ClusterInfo { - enum class Flags : uint8_t - { - kFieldIdValid = 0x01, - kListIndexValid = 0x02, - kEventIdValid = 0x03, - }; - +private: + // Endpoint Id is a uint16 number, and should between 0 and 0xFFFE + static constexpr EndpointId kInvalidEndpointId = 0xFFFF; + // The ClusterId, AttributeId and EventId are MEIs, + // 0xFFFF is not a valid manufacturer code, thus 0xFFFF'FFFF is not a valid MEI + static constexpr ClusterId kInvalidClusterId = 0xFFFF'FFFF; + static constexpr AttributeId kInvalidAttributeId = 0xFFFF'FFFF; + static constexpr EventId kInvalidEventId = 0xFFFF'FFFF; + // ListIndex is a uint16 number, thus 0xFFFF is not a valid list index. + static constexpr ListIndex kInvalidListIndex = 0xFFFF; + +public: bool IsAttributePathSupersetOf(const ClusterInfo & other) const { - if ((other.mEndpointId != mEndpointId) || (other.mClusterId != mClusterId)) - { - return false; - } - - Optional myFieldId = - mFlags.Has(Flags::kFieldIdValid) ? Optional::Value(mFieldId) : Optional::Missing(); - - Optional otherFieldId = other.mFlags.Has(Flags::kFieldIdValid) ? Optional::Value(other.mFieldId) - : Optional::Missing(); - - Optional myListIndex = - mFlags.Has(Flags::kListIndexValid) ? Optional::Value(mListIndex) : Optional::Missing(); + VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false); + VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false); + VerifyOrReturnError(HasWildcardAttributeId() || mFieldId == other.mFieldId, false); + VerifyOrReturnError(HasWildcardListIndex() || mListIndex == other.mListIndex, false); - Optional otherListIndex = other.mFlags.Has(Flags::kListIndexValid) ? Optional::Value(other.mListIndex) - : Optional::Missing(); - - // If list index exists, field index must exist - // Field 0xFFFFFFF (any) & listindex set is invalid - assert(!(myListIndex.HasValue() && !myFieldId.HasValue())); - assert(!(otherListIndex.HasValue() && !otherFieldId.HasValue())); - assert(!(myFieldId == Optional::Value(kRootAttributeId) && myListIndex.HasValue())); - assert(!(otherFieldId == Optional::Value(kRootAttributeId) && otherListIndex.HasValue())); - - if (myFieldId == Optional::Value(kRootAttributeId)) - { - return true; - } - - if (myFieldId != otherFieldId) - { - return false; - } + return true; + } - // We only support top layer for attribute representation, either FieldId or FieldId + ListIndex - // Combination: if myFieldId == otherFieldId, ListIndex cannot exist without FieldId - // 1. myListIndex and otherListIndex both missing or both exactly the same, then current is superset of other - // 2. myListIndex is missing, no matter if otherListIndex is missing or not, then current is superset of other - if (myListIndex == otherListIndex) - { - // either both missing or both exactly the same - return true; - } + bool HasWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); } - if (!myListIndex.HasValue()) - { - // difference is ok only if myListIndex is missing - return true; - } + /** + * Check that the path meets some basic constraints of an attribute path: If list index is not wildcard, then field id must not + * be wildcard. This does not verify that the attribute being targeted is actually of list type when the list index is not + * wildcard. + */ + bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); } - return false; - } + inline bool HasWildcardNodeId() const { return mNodeId == kUndefinedNodeId; } + inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; } + inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; } + inline bool HasWildcardAttributeId() const { return mFieldId == kInvalidAttributeId; } + inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; } + inline bool HasWildcardEventId() const { return mEventId == kInvalidEventId; } ClusterInfo() {} - NodeId mNodeId = 0; - ClusterId mClusterId = 0; - ListIndex mListIndex = 0; - AttributeId mFieldId = 0; - EndpointId mEndpointId = 0; - BitFlags mFlags; - ClusterInfo * mpNext = nullptr; - EventId mEventId = 0; - /* For better structure alignment - * Above ordering is by bit-size to ensure least amount of memory alignment padding. - * Changing order to something more natural (e.g. clusterid before nodeid) will result + /* + * For better structure alignment + * Below ordering is by bit-size to ensure least amount of memory alignment padding. + * Changing order to something more natural (e.g. endpoint id before cluster id) will result * in extra memory alignment padding. - * uint64 mNodeId - * uint16_t mClusterId - * uint16_t mListIndex - * uint8_t FieldId - * uint8_t EndpointId - * uint8_t mDirty - * uint8_t mType - * uint32_t mpNext - * uint16_t EventId - * padding 2 bytes */ + NodeId mNodeId = kUndefinedNodeId; // uint64 + ClusterInfo * mpNext = nullptr; // pointer width (32/64 bits) + ClusterId mClusterId = kInvalidClusterId; // uint32 + AttributeId mFieldId = kInvalidAttributeId; // uint32 + EventId mEventId = kInvalidEventId; // uint32 + ListIndex mListIndex = kInvalidListIndex; // uint16 + EndpointId mEndpointId = kInvalidEndpointId; // uint16 }; } // namespace app } // namespace chip diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index 201a1ac2398e21..67d82329c0eb02 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -663,6 +663,7 @@ static bool IsInterestedEventPaths(EventLoadOutContext * eventLoadOutContext, co } while (interestedEventPaths != nullptr) { + // TODO: Support wildcard event path if (interestedEventPaths->mNodeId == event.mNodeId && interestedEventPaths->mEndpointId == event.mEndpointId && interestedEventPaths->mClusterId == event.mClusterId && interestedEventPaths->mEventId == event.mEventId) { diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index b4135df49fa0df..50bc098cff135f 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -465,7 +465,6 @@ void InteractionModelEngine::ReleaseClusterInfoList(ClusterInfo *& aClusterInfo) { lastClusterInfo = lastClusterInfo->mpNext; } - lastClusterInfo->mFlags.ClearAll(); lastClusterInfo->mpNext = mpNextAvailableClusterInfo; mpNextAvailableClusterInfo = aClusterInfo; aClusterInfo = nullptr; @@ -502,7 +501,6 @@ bool InteractionModelEngine::MergeOverlappedAttributePath(ClusterInfo * apAttrib { runner->mListIndex = aAttributePath.mListIndex; runner->mFieldId = aAttributePath.mFieldId; - runner->mFlags = aAttributePath.mFlags; return true; } runner = runner->mpNext; diff --git a/src/app/MessageDef/AttributePath.h b/src/app/MessageDef/AttributePath.h index 790581dd74b178..a3d41b3e435f39 100644 --- a/src/app/MessageDef/AttributePath.h +++ b/src/app/MessageDef/AttributePath.h @@ -74,7 +74,8 @@ class Parser : public chip::app::Parser CHIP_ERROR CheckSchemaValidity() const; #endif /** - * @brief Get a TLVReader for the NodeId. Next() must be called before accessing them. + * @brief Get a TLVReader for the NodeId. Next() must be called before accessing them. If the node id field does not exist, the + * nodeid will not be touched. * * @param [in] apNodeId A pointer to apNodeId * @@ -85,7 +86,8 @@ class Parser : public chip::app::Parser CHIP_ERROR GetNodeId(chip::NodeId * const apNodeId) const; /** - * @brief Get a TLVReader for the EndpointId. Next() must be called before accessing them. + * @brief Get a TLVReader for the EndpointId. Next() must be called before accessing them. If the endpoint id field does not + * exist, the value will not be touched. * * @param [in] apEndpointId A pointer to apEndpointId * @@ -96,7 +98,8 @@ class Parser : public chip::app::Parser CHIP_ERROR GetEndpointId(chip::EndpointId * const apEndpointId) const; /** - * @brief Get a TLVReader for the ClusterId. Next() must be called before accessing them. + * @brief Get a TLVReader for the ClusterId. Next() must be called before accessing them. If the cluster id field does not + * exist, the value will not be touched. * * @param [in] apClusterId A pointer to apClusterId * @@ -107,7 +110,8 @@ class Parser : public chip::app::Parser CHIP_ERROR GetClusterId(chip::ClusterId * const apClusterId) const; /** - * @brief Get a TLVReader for the FieldId. Next() must be called before accessing them. + * @brief Get a TLVReader for the FieldId. Next() must be called before accessing them. If the field id field does not exist, + * the value will not be touched. * * @param [in] apFieldId A pointer to apFieldId * @@ -118,7 +122,8 @@ class Parser : public chip::app::Parser CHIP_ERROR GetFieldId(chip::AttributeId * const apFieldId) const; /** - * @brief Get a TLVReader for the ListIndex. Next() must be called before accessing them. + * @brief Get a TLVReader for the ListIndex. Next() must be called before accessing them. If the list index field does not + * exist, the value will not be touched. * * @param [in] apListIndex A pointer to apListIndex * diff --git a/src/app/MessageDef/Parser.h b/src/app/MessageDef/Parser.h index 446703bf417ccf..85fe3804cd463d 100644 --- a/src/app/MessageDef/Parser.h +++ b/src/app/MessageDef/Parser.h @@ -74,23 +74,37 @@ class Parser chip::TLV::TLVType mOuterContainerType; Parser(); + /** + * Gets a unsigned integer value with the given tag, the value is not touched when the tag is not found in the TLV. + * + * @return #CHIP_NO_ERROR on success + * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types + * #CHIP_END_OF_TLV if there is no such element + */ template CHIP_ERROR GetUnsignedInteger(const uint8_t aContextTag, T * const apLValue) const { return GetSimpleValue(aContextTag, chip::TLV::kTLVType_UnsignedInteger, apLValue); }; + /** + * Gets a scalar value with the given tag, the value is not touched when the tag is not found in the TLV. + * + * @return #CHIP_NO_ERROR on success + * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types + * #CHIP_END_OF_TLV if there is no such element + */ template CHIP_ERROR GetSimpleValue(const uint8_t aContextTag, const chip::TLV::TLVType aTLVType, T * const apLValue) const { CHIP_ERROR err = CHIP_NO_ERROR; chip::TLV::TLVReader reader; - *apLValue = 0; - err = mReader.FindElementWithTag(chip::TLV::ContextTag(aContextTag), reader); SuccessOrExit(err); + *apLValue = 0; + VerifyOrExit(aTLVType == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); err = reader.Get(*apLValue); diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index e72563973b65c5..4277d770db5d07 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -473,39 +473,37 @@ CHIP_ERROR ReadClient::ProcessAttributeDataList(TLV::TLVReader & aAttributeDataL SuccessOrExit(err); err = element.GetAttributePath(&attributePathParser); - SuccessOrExit(err); + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + + // We are using the feature that the parser won't touch the value if the field does not exist, since all fields in the + // cluster info will be invalid / wildcard, it is safe ignore CHIP_END_OF_TLV directly. err = attributePathParser.GetNodeId(&(clusterInfo.mNodeId)); - SuccessOrExit(err); + if (err == CHIP_END_OF_TLV) + { + err = CHIP_NO_ERROR; + } + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + + // The ReportData must contain a concrete attribute path err = attributePathParser.GetEndpointId(&(clusterInfo.mEndpointId)); - SuccessOrExit(err); + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); err = attributePathParser.GetClusterId(&(clusterInfo.mClusterId)); - SuccessOrExit(err); + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); err = attributePathParser.GetFieldId(&(clusterInfo.mFieldId)); - if (CHIP_NO_ERROR == err) - { - clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - } - else if (CHIP_END_OF_TLV == err) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); err = attributePathParser.GetListIndex(&(clusterInfo.mListIndex)); - if (CHIP_NO_ERROR == err) - { - VerifyOrExit(clusterInfo.mFlags.Has(ClusterInfo::Flags::kFieldIdValid), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); - clusterInfo.mFlags.Set(ClusterInfo::Flags::kListIndexValid); - } - else if (CHIP_END_OF_TLV == err) + if (CHIP_END_OF_TLV == err) { err = CHIP_NO_ERROR; } - SuccessOrExit(err); + VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + + VerifyOrExit(clusterInfo.IsValidAttributePath(), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); err = element.GetData(&dataReader); if (err == CHIP_END_OF_TLV) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index c2ec72d32f3924..d4479b60cad45f 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -335,28 +335,38 @@ CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathList::Parser & aAt AttributePath::Parser path; err = path.Init(reader); SuccessOrExit(err); - err = path.GetNodeId(&(clusterInfo.mNodeId)); - SuccessOrExit(err); + // TODO: Support wildcard paths here + // TODO: MEIs (ClusterId and AttributeId) have a invalid pattern instead of a single invalid value, need to add separate + // functions for checking if we have received valid values. err = path.GetEndpointId(&(clusterInfo.mEndpointId)); + if (err == CHIP_NO_ERROR) + { + VerifyOrExit(!clusterInfo.HasWildcardEndpointId(), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + } SuccessOrExit(err); err = path.GetClusterId(&(clusterInfo.mClusterId)); + if (err == CHIP_NO_ERROR) + { + VerifyOrExit(!clusterInfo.HasWildcardClusterId(), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + } + SuccessOrExit(err); err = path.GetFieldId(&(clusterInfo.mFieldId)); - if (CHIP_NO_ERROR == err) + if (CHIP_END_OF_TLV == err) { - clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); + err = CHIP_NO_ERROR; } - else if (CHIP_END_OF_TLV == err) + else if (err == CHIP_NO_ERROR) { - err = CHIP_NO_ERROR; + VerifyOrExit(!clusterInfo.HasWildcardAttributeId(), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); } SuccessOrExit(err); err = path.GetListIndex(&(clusterInfo.mListIndex)); if (CHIP_NO_ERROR == err) { - VerifyOrExit(clusterInfo.mFlags.Has(ClusterInfo::Flags::kFieldIdValid), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); - clusterInfo.mFlags.Set(ClusterInfo::Flags::kListIndexValid); + VerifyOrExit(!clusterInfo.HasWildcardAttributeId() && !clusterInfo.HasWildcardListIndex(), + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); } else if (CHIP_END_OF_TLV == err) { @@ -398,11 +408,7 @@ CHIP_ERROR ReadHandler::ProcessEventPaths(EventPaths::Parser & aEventPathsParser err = path.GetCluster(&(clusterInfo.mClusterId)); SuccessOrExit(err); err = path.GetEvent(&(clusterInfo.mEventId)); - if (CHIP_NO_ERROR == err) - { - clusterInfo.mFlags.Set(ClusterInfo::Flags::kEventIdValid); - } - else if (CHIP_END_OF_TLV == err) + if (CHIP_END_OF_TLV == err) { err = CHIP_NO_ERROR; } diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index 87d8a9eeb7c6c5..ee3959723da2ff 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -123,8 +123,14 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat err = element.GetAttributePath(&attributePath); SuccessOrExit(err); + // We are using the feature that the parser won't touch the value if the field does not exist, since all fields in the + // cluster info will be invalid / wildcard, it is safe ignore CHIP_END_OF_TLV directly. + err = attributePath.GetNodeId(&(clusterInfo.mNodeId)); - SuccessOrExit(err); + if (CHIP_END_OF_TLV == err) + { + err = CHIP_NO_ERROR; + } err = attributePath.GetEndpointId(&(clusterInfo.mEndpointId)); SuccessOrExit(err); @@ -133,23 +139,18 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat SuccessOrExit(err); err = attributePath.GetFieldId(&(clusterInfo.mFieldId)); - if (CHIP_NO_ERROR == err) - { - clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - } - else if (CHIP_END_OF_TLV == err) - { - err = CHIP_NO_ERROR; - } SuccessOrExit(err); err = attributePath.GetListIndex(&(clusterInfo.mListIndex)); - if (CHIP_NO_ERROR == err) + if (CHIP_END_OF_TLV == err) { - VerifyOrExit(clusterInfo.mFlags.Has(ClusterInfo::Flags::kFieldIdValid), err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); - clusterInfo.mFlags.Set(ClusterInfo::Flags::kListIndexValid); + err = CHIP_NO_ERROR; } + // We do not support Wildcard writes for now, reject all wildcard write requests. + VerifyOrExit(clusterInfo.IsValidAttributePath() && !clusterInfo.HasWildcard(), + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); + err = element.GetData(&dataReader); SuccessOrExit(err); diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 7c839dd5aa4d9c..6f83b7a13cae72 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -70,8 +70,7 @@ Engine::RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeDataList ConcreteAttributePath path(aClusterInfo.mEndpointId, aClusterInfo.mClusterId, aClusterInfo.mFieldId); AttributeDataElement::Builder attributeDataElementBuilder = aAttributeDataList.CreateAttributeDataElementBuilder(); AttributePath::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePathBuilder(); - attributePathBuilder.NodeId(aClusterInfo.mNodeId) - .EndpointId(aClusterInfo.mEndpointId) + attributePathBuilder.EndpointId(aClusterInfo.mEndpointId) .ClusterId(aClusterInfo.mClusterId) .FieldId(aClusterInfo.mFieldId) .EndOfAttributePath(); diff --git a/src/app/tests/TestClusterInfo.cpp b/src/app/tests/TestClusterInfo.cpp index 932fe062104e72..c3e49795d938ce 100644 --- a/src/app/tests/TestClusterInfo.cpp +++ b/src/app/tests/TestClusterInfo.cpp @@ -34,19 +34,15 @@ void TestAttributePathIncludedSameFieldId(nlTestSuite * apSuite, void * apContex ClusterInfo clusterInfo1; ClusterInfo clusterInfo2; ClusterInfo clusterInfo3; - clusterInfo1.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - clusterInfo2.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - clusterInfo3.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); clusterInfo1.mFieldId = 1; clusterInfo2.mFieldId = 1; clusterInfo3.mFieldId = 1; NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); - clusterInfo2.mFlags.Set(ClusterInfo::Flags::kListIndexValid); clusterInfo2.mListIndex = 1; NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); - clusterInfo1.mFlags.Set(ClusterInfo::Flags::kListIndexValid); + clusterInfo1.mListIndex = 0; NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo3)); - clusterInfo3.mFlags.Set(ClusterInfo::Flags::kListIndexValid); + clusterInfo3.mListIndex = 0; NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo3)); clusterInfo3.mListIndex = 1; NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo3)); @@ -54,22 +50,31 @@ void TestAttributePathIncludedSameFieldId(nlTestSuite * apSuite, void * apContex void TestAttributePathIncludedDifferentFieldId(nlTestSuite * apSuite, void * apContext) { - ClusterInfo clusterInfo1; - ClusterInfo clusterInfo2; - clusterInfo1.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - clusterInfo2.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); - clusterInfo1.mFieldId = 1; - clusterInfo2.mFieldId = 2; - NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); - clusterInfo1.mFieldId = 0xFFFFFFFF; - clusterInfo2.mFieldId = 2; - NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); - clusterInfo1.mFieldId = 0xFFFFFFFF; - clusterInfo2.mFieldId = 0xFFFFFFFF; - NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); - clusterInfo1.mFieldId = 1; - clusterInfo2.mFieldId = 0xFFFFFFFF; - NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); + { + ClusterInfo clusterInfo1; + ClusterInfo clusterInfo2; + clusterInfo1.mFieldId = 1; + clusterInfo2.mFieldId = 2; + NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); + } + { + ClusterInfo clusterInfo1; + ClusterInfo clusterInfo2; + clusterInfo2.mFieldId = 2; + NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); + } + { + ClusterInfo clusterInfo1; + ClusterInfo clusterInfo2; + NL_TEST_ASSERT(apSuite, clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); + } + { + ClusterInfo clusterInfo1; + ClusterInfo clusterInfo2; + + clusterInfo1.mFieldId = 1; + NL_TEST_ASSERT(apSuite, !clusterInfo1.IsAttributePathSupersetOf(clusterInfo2)); + } } void TestAttributePathIncludedDifferentEndpointId(nlTestSuite * apSuite, void * apContext) diff --git a/src/app/tests/TestInteractionModelEngine.cpp b/src/app/tests/TestInteractionModelEngine.cpp index b55200f7a901f7..3f0d6e66ab39e2 100644 --- a/src/app/tests/TestInteractionModelEngine.cpp +++ b/src/app/tests/TestInteractionModelEngine.cpp @@ -99,22 +99,27 @@ void TestInteractionModelEngine::TestMergeOverlappedAttributePath(nlTestSuite * NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ClusterInfo clusterInfoList[2]; - clusterInfoList[0].mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); clusterInfoList[0].mFieldId = 1; - clusterInfoList[1].mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); clusterInfoList[1].mFieldId = 2; - chip::app::ClusterInfo testClusterInfo; - testClusterInfo.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - testClusterInfo.mFieldId = 3; - - NL_TEST_ASSERT(apSuite, !InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); - testClusterInfo.mFieldId = 0xFFFFFFFF; - NL_TEST_ASSERT(apSuite, InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); - testClusterInfo.mFlags.Set(chip::app::ClusterInfo::Flags::kListIndexValid); - testClusterInfo.mFieldId = 1; - testClusterInfo.mListIndex = 2; - NL_TEST_ASSERT(apSuite, InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); + { + chip::app::ClusterInfo testClusterInfo; + testClusterInfo.mFieldId = 3; + NL_TEST_ASSERT(apSuite, + !InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); + } + { + chip::app::ClusterInfo testClusterInfo; + NL_TEST_ASSERT(apSuite, + InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); + } + { + chip::app::ClusterInfo testClusterInfo; + testClusterInfo.mFieldId = 1; + testClusterInfo.mListIndex = 2; + NL_TEST_ASSERT(apSuite, + InteractionModelEngine::GetInstance()->MergeOverlappedAttributePath(clusterInfoList, testClusterInfo)); + } } } // namespace app } // namespace chip diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index b1cae917314721..0fd394cf45c5c7 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -906,34 +906,28 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a chip::app::ClusterInfo dirtyPath1; dirtyPath1.mClusterId = kTestClusterId; dirtyPath1.mEndpointId = kTestEndpointId; - dirtyPath1.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - dirtyPath1.mFieldId = 1; + dirtyPath1.mFieldId = 1; chip::app::ClusterInfo dirtyPath2; dirtyPath2.mClusterId = kTestClusterId; dirtyPath2.mEndpointId = kTestEndpointId; - dirtyPath2.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - dirtyPath2.mFieldId = 2; + dirtyPath2.mFieldId = 2; chip::app::ClusterInfo dirtyPath3; - dirtyPath2.mClusterId = kTestClusterId; - dirtyPath2.mEndpointId = kTestEndpointId; - dirtyPath2.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - dirtyPath2.mFlags.Set(chip::app::ClusterInfo::Flags::kListIndexValid); - dirtyPath2.mFieldId = 2; - dirtyPath2.mListIndex = 1; + dirtyPath3.mClusterId = kTestClusterId; + dirtyPath3.mEndpointId = kTestEndpointId; + dirtyPath3.mFieldId = 2; + dirtyPath3.mListIndex = 1; chip::app::ClusterInfo dirtyPath4; dirtyPath4.mClusterId = kTestClusterId; dirtyPath4.mEndpointId = kTestEndpointId; - dirtyPath4.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - dirtyPath4.mFieldId = 3; + dirtyPath4.mFieldId = 3; chip::app::ClusterInfo dirtyPath5; dirtyPath5.mClusterId = kTestClusterId; dirtyPath5.mEndpointId = kTestEndpointId; - dirtyPath5.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); - dirtyPath5.mFieldId = 4; + dirtyPath5.mFieldId = 4; // Test report with 2 different path delegate.mpReadHandler->mHoldReport = false; diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index c805e15b9a41a4..9be9a077614cd0 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -171,7 +171,6 @@ void MutateClusterHandler(chip::System::Layer * systemLayer, void * appState) chip::app::ClusterInfo dirtyPath; dirtyPath.mClusterId = kTestClusterId; dirtyPath.mEndpointId = kTestEndpointId; - dirtyPath.mFlags.Set(chip::app::ClusterInfo::Flags::kFieldIdValid); printf("MutateClusterHandler is triggered..."); // send dirty change if (!testSyncReport) diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index e59527b436d89d..5e3dad6581d035 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -502,7 +502,6 @@ void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clust info.mClusterId = clusterId; info.mFieldId = attributeId; info.mEndpointId = endpoint; - info.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);