diff --git a/src/app/MessageDef/CommandDataIB.h b/src/app/MessageDef/CommandDataIB.h index b3bd2f4181d2c9..9872f5e43584dc 100644 --- a/src/app/MessageDef/CommandDataIB.h +++ b/src/app/MessageDef/CommandDataIB.h @@ -71,7 +71,7 @@ class Parser : public StructParser /** * @brief Get the provided command reference associated with the CommandData * - * @param [in] apRef A pointer to apRef + * @param [out] apRef A pointer to apRef * * @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 diff --git a/src/app/MessageDef/CommandStatusIB.cpp b/src/app/MessageDef/CommandStatusIB.cpp index 4f38bb292e657e..566ea0a7d83058 100644 --- a/src/app/MessageDef/CommandStatusIB.cpp +++ b/src/app/MessageDef/CommandStatusIB.cpp @@ -75,6 +75,14 @@ CHIP_ERROR CommandStatusIB::Parser::PrettyPrint() const PRETTY_PRINT_DECDEPTH(); } break; + case to_underlying(Tag::kRef): + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + { + uint16_t reference; + ReturnErrorOnFailure(reader.Get(reference)); + PRETTY_PRINT("\tRef = 0x%x,", reference); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -108,6 +116,11 @@ CHIP_ERROR CommandStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apEr return apErrorStatus->Init(reader); } +CHIP_ERROR CommandStatusIB::Parser::GetRef(uint16_t * const apRef) const +{ + return GetUnsignedInteger(to_underlying(Tag::kRef), apRef); +} + CommandPathIB::Builder & CommandStatusIB::Builder::CreatePath() { if (mError == CHIP_NO_ERROR) @@ -126,6 +139,11 @@ StatusIB::Builder & CommandStatusIB::Builder::CreateErrorStatus() return mErrorStatus; } +CHIP_ERROR CommandStatusIB::Builder::Ref(const uint16_t aRef) +{ + return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef); +} + CHIP_ERROR CommandStatusIB::Builder::EndOfCommandStatusIB() { EndOfContainer(); diff --git a/src/app/MessageDef/CommandStatusIB.h b/src/app/MessageDef/CommandStatusIB.h index 8614df28cab4b5..a780e02683eec0 100644 --- a/src/app/MessageDef/CommandStatusIB.h +++ b/src/app/MessageDef/CommandStatusIB.h @@ -37,6 +37,7 @@ enum class Tag : uint8_t { kPath = 0, kErrorStatus = 1, + kRef = 2, }; class Parser : public StructParser @@ -67,6 +68,17 @@ class Parser : public StructParser * #CHIP_END_OF_TLV if there is no such element */ CHIP_ERROR GetErrorStatus(StatusIB::Parser * const apErrorStatus) const; + + /** + * @brief Get the provided command reference associated with the CommandStatus + * + * @param [out] apRef A pointer to apRef + * + * @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 + */ + CHIP_ERROR GetRef(uint16_t * const apRef) const; }; class Builder : public StructBuilder @@ -86,6 +98,15 @@ class Builder : public StructBuilder */ StatusIB::Builder & CreateErrorStatus(); + /** + * @brief Inject Command Ref into the TLV stream. + * + * @param [in] aRef refer to the CommandRef to set in CommandStatusIB. + * + * @return #CHIP_NO_ERROR on success + */ + CHIP_ERROR Ref(const uint16_t aRef); + /** * @brief Mark the end of this CommandStatusIB *