From 692983ed56896b7465ba34aedf9a09f03a1cb4d5 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 24 Oct 2024 14:49:12 -0400 Subject: [PATCH 1/7] Use custom ember-buffer decode on codegen data model Read as well. (#36229) * Use EmberAttributeDataBuffer for codegen provider _Read * Fix comments * Restyled by clang-format --------- Co-authored-by: Andrei Litvin Co-authored-by: Restyled.io --- .../CodegenDataModelProvider_Read.cpp | 175 +----- .../EmberAttributeDataBuffer.cpp | 250 +++++++- .../EmberAttributeDataBuffer.h | 31 +- .../tests/TestEmberAttributeDataBuffer.cpp | 542 +++++++++++++++++- 4 files changed, 822 insertions(+), 176 deletions(-) diff --git a/src/app/codegen-data-model-provider/CodegenDataModelProvider_Read.cpp b/src/app/codegen-data-model-provider/CodegenDataModelProvider_Read.cpp index 6ce5d282f89d30..ea35356391d63d 100644 --- a/src/app/codegen-data-model-provider/CodegenDataModelProvider_Read.cpp +++ b/src/app/codegen-data-model-provider/CodegenDataModelProvider_Read.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include @@ -85,173 +87,6 @@ std::optional TryReadViaAccessInterface(const ConcreteAttributePath return encoder.TriedEncode() ? std::make_optional(CHIP_NO_ERROR) : std::nullopt; } -/// Metadata of what a ember/pascal short string means (prepended by a u8 length) -struct ShortPascalString -{ - using LengthType = uint8_t; - static constexpr LengthType kNullLength = 0xFF; - - static size_t GetLength(ByteSpan buffer) - { - VerifyOrDie(buffer.size() >= 1); - // NOTE: we do NOT use emberAfStringLength from ember-strings.h because that will result in 0 - // length for null sizes (i.e. 0xFF is translated to 0 and we do not want that here) - return buffer[0]; - } -}; - -/// Metadata of what a ember/pascal LONG string means (prepended by a u16 length) -struct LongPascalString -{ - using LengthType = uint16_t; - static constexpr LengthType kNullLength = 0xFFFF; - - static size_t GetLength(ByteSpan buffer) - { - // NOTE: we do NOT use emberAfLongStringLength from ember-strings.h because that will result in 0 - // length for null sizes (i.e. 0xFFFF is translated to 0 and we do not want that here) - VerifyOrDie(buffer.size() >= 2); - const uint8_t * data = buffer.data(); - return Encoding::LittleEndian::Read16(data); - } -}; - -// ember assumptions ... should just work -static_assert(sizeof(ShortPascalString::LengthType) == 1); -static_assert(sizeof(LongPascalString::LengthType) == 2); - -/// Given a ByteSpan containing data from ember, interpret it -/// as a span of type OUT (i.e. ByteSpan or CharSpan) given a ENCODING -/// where ENCODING is Short or Long pascal strings. -template -std::optional ExtractEmberString(ByteSpan data) -{ - constexpr size_t kLengthTypeSize = sizeof(typename ENCODING::LengthType); - VerifyOrDie(kLengthTypeSize <= data.size()); - auto len = ENCODING::GetLength(data); - - if (len == ENCODING::kNullLength) - { - return std::nullopt; - } - - VerifyOrDie(len + sizeof(len) <= data.size()); - return std::make_optional(reinterpret_cast(data.data() + kLengthTypeSize), len); -} - -/// Encode a value inside `encoder` -/// -/// The value encoded will be of type T (e.g. CharSpan or ByteSpan) and it will be decoded -/// via the given ENCODING (i.e. ShortPascalString or LongPascalString) -/// -/// isNullable defines if the value of NULL is allowed to be encoded. -template -CHIP_ERROR EncodeStringLike(ByteSpan data, bool isNullable, AttributeValueEncoder & encoder) -{ - std::optional value = ExtractEmberString(data); - if (!value.has_value()) - { - if (isNullable) - { - return encoder.EncodeNull(); - } - return CHIP_ERROR_INCORRECT_STATE; - } - - // encode value as-is - return encoder.Encode(*value); -} - -/// Encodes a numeric data value of type T from the given ember-encoded buffer `data`. -/// -/// isNullable defines if the value of NULL is allowed to be encoded. -template -CHIP_ERROR EncodeFromSpan(ByteSpan data, bool isNullable, AttributeValueEncoder & encoder) -{ - typename NumericAttributeTraits::StorageType value; - - VerifyOrReturnError(data.size() >= sizeof(value), CHIP_ERROR_INVALID_ARGUMENT); - memcpy(&value, data.data(), sizeof(value)); - - if (isNullable && NumericAttributeTraits::IsNullValue(value)) - { - return encoder.EncodeNull(); - } - - if (!NumericAttributeTraits::CanRepresentValue(isNullable, value)) - { - return CHIP_ERROR_INCORRECT_STATE; - } - - return encoder.Encode(NumericAttributeTraits::StorageToWorking(value)); -} - -/// Converts raw ember data from `data` into the encoder -/// -/// Uses the attribute `metadata` to determine how the data is encoded into `data` and -/// write a suitable value into `encoder`. -CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * metadata, AttributeValueEncoder & encoder) -{ - VerifyOrReturnError(metadata != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - const bool isNullable = metadata->IsNullable(); - - switch (AttributeBaseType(metadata->attributeType)) - { - case ZCL_NO_DATA_ATTRIBUTE_TYPE: // No data - return encoder.EncodeNull(); - case ZCL_BOOLEAN_ATTRIBUTE_TYPE: // Boolean - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT8U_ATTRIBUTE_TYPE: // Unsigned 8-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT16U_ATTRIBUTE_TYPE: // Unsigned 16-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT24U_ATTRIBUTE_TYPE: // Unsigned 24-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT32U_ATTRIBUTE_TYPE: // Unsigned 32-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT40U_ATTRIBUTE_TYPE: // Unsigned 40-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT48U_ATTRIBUTE_TYPE: // Unsigned 48-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT56U_ATTRIBUTE_TYPE: // Unsigned 56-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT64U_ATTRIBUTE_TYPE: // Unsigned 64-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT8S_ATTRIBUTE_TYPE: // Signed 8-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT16S_ATTRIBUTE_TYPE: // Signed 16-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT24S_ATTRIBUTE_TYPE: // Signed 24-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT32S_ATTRIBUTE_TYPE: // Signed 32-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_INT40S_ATTRIBUTE_TYPE: // Signed 40-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT48S_ATTRIBUTE_TYPE: // Signed 48-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT56S_ATTRIBUTE_TYPE: // Signed 56-bit integer - return EncodeFromSpan>(data, isNullable, encoder); - case ZCL_INT64S_ATTRIBUTE_TYPE: // Signed 64-bit integer - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_SINGLE_ATTRIBUTE_TYPE: // 32-bit float - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_DOUBLE_ATTRIBUTE_TYPE: // 64-bit float - return EncodeFromSpan(data, isNullable, encoder); - case ZCL_CHAR_STRING_ATTRIBUTE_TYPE: // Char string - return EncodeStringLike(data, isNullable, encoder); - case ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE: - return EncodeStringLike(data, isNullable, encoder); - case ZCL_OCTET_STRING_ATTRIBUTE_TYPE: // Octet string - return EncodeStringLike(data, isNullable, encoder); - case ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE: - return EncodeStringLike(data, isNullable, encoder); - default: - ChipLogError(DataManagement, "Attribute type 0x%x not handled", static_cast(metadata->attributeType)); - return CHIP_IM_GLOBAL_STATUS(Failure); - } -} - } // namespace /// separated-out ReadAttribute implementation (given existing complexity) @@ -343,7 +178,11 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::ReadAttribute(const Data return CHIP_ERROR_IM_GLOBAL_STATUS_VALUE(status); } - return EncodeEmberValue(gEmberAttributeIOBufferSpan, attributeMetadata, encoder); + VerifyOrReturnError(attributeMetadata != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + + MutableByteSpan data = gEmberAttributeIOBufferSpan; + Ember::EmberAttributeDataBuffer emberData(attributeMetadata, data); + return encoder.Encode(emberData); } } // namespace app diff --git a/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.cpp b/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.cpp index ab8891657fde50..2c764241ebf3d8 100644 --- a/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.cpp +++ b/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.cpp @@ -17,14 +17,18 @@ #include #include +#include #include #include #include +#include #include +#include #include #include #include +#include #include namespace chip { @@ -43,7 +47,7 @@ constexpr uint32_t MaxLength(EmberAttributeDataBuffer::PascalStringType s) { return std::numeric_limits::max() - 1; } - // EmberAttributeBuffer::PascalStringType::kLong: + // EmberAttributeDataBuffer::PascalStringType::kLong: return std::numeric_limits::max() - 1; } @@ -116,6 +120,55 @@ constexpr SignedDecodeInfo GetSignedDecodeInfo(EmberAfAttributeType type) chipDie(); } +/// Encodes the string of type stringType pointed to by `reader` into the TLV `writer`. +/// Then encoded string will be at tag `tag` and of type `tlvType` +CHIP_ERROR EncodeString(EmberAttributeDataBuffer::PascalStringType stringType, TLV::TLVType tlvType, TLV::TLVWriter & writer, + TLV::Tag tag, EmberAttributeDataBuffer::EndianReader & reader, bool nullable) +{ + unsigned stringLen; + if (stringType == EmberAttributeDataBuffer::PascalStringType::kShort) + { + uint8_t len; + if (!reader.Read8(&len).IsSuccess()) + { + return reader.StatusCode(); + } + if (len == NumericAttributeTraits::kNullValue) + { + VerifyOrReturnError(nullable, CHIP_ERROR_INVALID_ARGUMENT); + return writer.PutNull(tag); + } + stringLen = len; + } + else + { + uint16_t len; + if (!reader.Read16(&len).IsSuccess()) + { + return reader.StatusCode(); + } + if (len == NumericAttributeTraits::kNullValue) + { + VerifyOrReturnError(nullable, CHIP_ERROR_INVALID_ARGUMENT); + return writer.PutNull(tag); + } + stringLen = len; + } + + const uint8_t * data; + if (!reader.ZeroCopyProcessBytes(stringLen, &data).IsSuccess()) + { + return reader.StatusCode(); + } + + if (tlvType == TLV::kTLVType_UTF8String) + { + return writer.PutString(tag, reinterpret_cast(data), stringLen); + } + + return writer.PutBytes(tag, data, stringLen); +} + } // namespace CHIP_ERROR EmberAttributeDataBuffer::DecodeUnsignedInteger(chip::TLV::TLVReader & reader, EndianWriter & writer) @@ -191,6 +244,7 @@ CHIP_ERROR EmberAttributeDataBuffer::DecodeAsString(chip::TLV::TLVReader & reade writer.Put16(NumericAttributeTraits::kNullValue); break; } + return CHIP_NO_ERROR; } @@ -321,6 +375,200 @@ CHIP_ERROR EmberAttributeDataBuffer::Decode(chip::TLV::TLVReader & reader) return CHIP_NO_ERROR; } +CHIP_ERROR EmberAttributeDataBuffer::EncodeInteger(chip::TLV::TLVWriter & writer, TLV::Tag tag, EndianReader & reader) const +{ + // Encodes an integer by first reading as raw bytes and then + // bitshift-convert + // + // This optimizes code size rather than readability at this point. + + uint8_t raw_bytes[8]; + + bool isSigned = (mAttributeType == ZCL_INT8S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT16S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT24S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT32S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT40S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT48S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT56S_ATTRIBUTE_TYPE) // + || (mAttributeType == ZCL_INT64S_ATTRIBUTE_TYPE); + + unsigned byteCount; + uint64_t nullValue; + + if (isSigned) + { + const SignedDecodeInfo info = GetSignedDecodeInfo(mAttributeType); + byteCount = info.byteCount; + nullValue = static_cast(info.minValue); // just a bit cast for easy compare + } + else + { + const UnsignedDecodeInfo info = GetUnsignedDecodeInfo(mAttributeType); + byteCount = info.byteCount; + nullValue = info.maxValue; + } + + VerifyOrDie(sizeof(raw_bytes) >= byteCount); + if (!reader.ReadBytes(raw_bytes, byteCount).IsSuccess()) + { + return reader.StatusCode(); + } + + // At this point, RAW_VALUE contains the actual value, need to make it "real" + union + { + int64_t int_value; + uint64_t uint_value; + } value; + + value.uint_value = 0; + +#if CHIP_CONFIG_BIG_ENDIAN_TARGET + bool isNegative = isSigned && (raw_bytes[0] >= 0x80); + if (isNegative) + { + value.int_value = -1; + } + for (int i = 0; i < static_cast(byteCount); i++) + { +#else + bool isNegative = isSigned && (raw_bytes[byteCount - 1] >= 0x80); + if (isNegative) + { + value.int_value = -1; + } + for (int i = static_cast(byteCount) - 1; i >= 0; i--) + { +#endif + value.uint_value <<= 8; + value.uint_value = (value.uint_value & ~0xFFULL) | raw_bytes[i]; + } + + if (mIsNullable && (value.uint_value == nullValue)) + { + // MaxValue is used for NULL setting + return writer.PutNull(tag); + } + + switch (mAttributeType) + { + case ZCL_INT8U_ATTRIBUTE_TYPE: // Unsigned 8-bit integer + return writer.Put(tag, static_cast(value.uint_value)); + case ZCL_INT16U_ATTRIBUTE_TYPE: // Unsigned 16-bit integer + return writer.Put(tag, static_cast(value.uint_value)); + case ZCL_INT24U_ATTRIBUTE_TYPE: // Unsigned 24-bit integer + case ZCL_INT32U_ATTRIBUTE_TYPE: // Unsigned 32-bit integer + return writer.Put(tag, static_cast(value.uint_value)); + case ZCL_INT40U_ATTRIBUTE_TYPE: // Unsigned 40-bit integer + case ZCL_INT48U_ATTRIBUTE_TYPE: // Unsigned 48-bit integer + case ZCL_INT56U_ATTRIBUTE_TYPE: // Signed 56-bit integer + case ZCL_INT64U_ATTRIBUTE_TYPE: // Signed 64-bit integer + return writer.Put(tag, static_cast(value.uint_value)); + case ZCL_INT8S_ATTRIBUTE_TYPE: // Signed 8-bit integer + return writer.Put(tag, static_cast(value.int_value)); + case ZCL_INT16S_ATTRIBUTE_TYPE: // Signed 16-bit integer + return writer.Put(tag, static_cast(value.int_value)); + case ZCL_INT24S_ATTRIBUTE_TYPE: // Signed 24-bit integer + case ZCL_INT32S_ATTRIBUTE_TYPE: // Signed 32-bit integer + return writer.Put(tag, static_cast(value.int_value)); + default: + return writer.Put(tag, static_cast(value.int_value)); + } +} + +CHIP_ERROR EmberAttributeDataBuffer::Encode(chip::TLV::TLVWriter & writer, TLV::Tag tag) const +{ + EndianReader endianReader(mDataBuffer.data(), mDataBuffer.size()); + + switch (mAttributeType) + { + case ZCL_NO_DATA_ATTRIBUTE_TYPE: // No data + return writer.PutNull(tag); + case ZCL_BOOLEAN_ATTRIBUTE_TYPE: { // Boolean + uint8_t value; + if (!endianReader.Read8(&value).IsSuccess()) + { + return endianReader.StatusCode(); + } + switch (value) + { + case 0: + case 1: + return writer.PutBoolean(tag, value != 0); + case 0xFF: + return writer.PutNull(tag); + default: + // Unknown types + return CHIP_ERROR_INCORRECT_STATE; + } + } + case ZCL_INT8U_ATTRIBUTE_TYPE: // Unsigned 8-bit integer + case ZCL_INT16U_ATTRIBUTE_TYPE: // Unsigned 16-bit integer + case ZCL_INT24U_ATTRIBUTE_TYPE: // Unsigned 24-bit integer + case ZCL_INT32U_ATTRIBUTE_TYPE: // Unsigned 32-bit integer + case ZCL_INT40U_ATTRIBUTE_TYPE: // Unsigned 40-bit integer + case ZCL_INT48U_ATTRIBUTE_TYPE: // Unsigned 48-bit integer + case ZCL_INT56U_ATTRIBUTE_TYPE: // Unsigned 56-bit integer + case ZCL_INT64U_ATTRIBUTE_TYPE: // Unsigned 64-bit integer + case ZCL_INT8S_ATTRIBUTE_TYPE: // Signed 8-bit integer + case ZCL_INT16S_ATTRIBUTE_TYPE: // Signed 16-bit integer + case ZCL_INT24S_ATTRIBUTE_TYPE: // Signed 24-bit integer + case ZCL_INT32S_ATTRIBUTE_TYPE: // Signed 32-bit integer + case ZCL_INT40S_ATTRIBUTE_TYPE: // Signed 40-bit integer + case ZCL_INT48S_ATTRIBUTE_TYPE: // Signed 48-bit integer + case ZCL_INT56S_ATTRIBUTE_TYPE: // Signed 56-bit integer + case ZCL_INT64S_ATTRIBUTE_TYPE: // Signed 64-bit integer + return EncodeInteger(writer, tag, endianReader); + case ZCL_SINGLE_ATTRIBUTE_TYPE: { // 32-bit float + union + { + uint8_t raw[sizeof(float)]; + float value; + } value; + + if (!endianReader.ReadBytes(value.raw, sizeof(value)).IsSuccess()) + { + return endianReader.StatusCode(); + } + if (NumericAttributeTraits::IsNullValue(value.value)) + { + return writer.PutNull(tag); + } + return writer.Put(tag, value.value); + } + case ZCL_DOUBLE_ATTRIBUTE_TYPE: { // 64-bit float + union + { + uint8_t raw[sizeof(double)]; + double value; + } value; + + if (!endianReader.ReadBytes(value.raw, sizeof(value)).IsSuccess()) + { + return endianReader.StatusCode(); + } + if (NumericAttributeTraits::IsNullValue(value.value)) + { + return writer.PutNull(tag); + } + return writer.Put(tag, value.value); + } + + case ZCL_CHAR_STRING_ATTRIBUTE_TYPE: // Char string + return EncodeString(PascalStringType::kShort, TLV::kTLVType_UTF8String, writer, tag, endianReader, mIsNullable); + case ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE: + return EncodeString(PascalStringType::kLong, TLV::kTLVType_UTF8String, writer, tag, endianReader, mIsNullable); + case ZCL_OCTET_STRING_ATTRIBUTE_TYPE: // Octet string + return EncodeString(PascalStringType::kShort, TLV::kTLVType_ByteString, writer, tag, endianReader, mIsNullable); + case ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE: + return EncodeString(PascalStringType::kLong, TLV::kTLVType_ByteString, writer, tag, endianReader, mIsNullable); + default: + ChipLogError(DataManagement, "Attribute type 0x%x not handled", static_cast(mAttributeType)); + return CHIP_IM_GLOBAL_STATUS(Failure); + } +} + } // namespace Ember } // namespace app } // namespace chip diff --git a/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.h b/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.h index a4f24c78c0476b..c3d7acfcafb72b 100644 --- a/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.h +++ b/src/app/codegen-data-model-provider/EmberAttributeDataBuffer.h @@ -16,10 +16,12 @@ */ #pragma once +#include "lib/core/TLVWriter.h" #include #include #include #include +#include #include #include @@ -39,6 +41,14 @@ namespace Ember { class EmberAttributeDataBuffer { public: +#if CHIP_CONFIG_BIG_ENDIAN_TARGET + using EndianWriter = Encoding::BigEndian::BufferWriter; + using EndianReader = Encoding::BigEndian::Reader; +#else + using EndianWriter = Encoding::LittleEndian::BufferWriter; + using EndianReader = Encoding::LittleEndian::Reader; +#endif + enum class PascalStringType { kShort, @@ -59,12 +69,14 @@ class EmberAttributeDataBuffer /// modified by this call. CHIP_ERROR Decode(chip::TLV::TLVReader & reader); + /// Writes the data encoded in the underlying buffer into the given `writer` + /// + /// The data in the internal data buffer is assumed to be already formatted correctly + /// HOWEVER the size inside it will not be fully considered (i.e. encoding will use + /// the data encoding line integer or string sizes and NOT the databuffer max size) + CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, TLV::Tag tag) const; + private: -#if CHIP_CONFIG_BIG_ENDIAN_TARGET - using EndianWriter = Encoding::BigEndian::BufferWriter; -#else - using EndianWriter = Encoding::LittleEndian::BufferWriter; -#endif /// Decodes the UNSIGNED integer stored in `reader` and places its content into `writer` /// Takes into account internal mIsNullable. CHIP_ERROR DecodeUnsignedInteger(chip::TLV::TLVReader & reader, EndianWriter & writer); @@ -73,6 +85,10 @@ class EmberAttributeDataBuffer /// Takes into account internal mIsNullable. CHIP_ERROR DecodeSignedInteger(chip::TLV::TLVReader & reader, EndianWriter & writer); + /// Encodes the UNSIGNED integer into `writer`. + /// Takes into account internal mIsNullable. + CHIP_ERROR EncodeInteger(chip::TLV::TLVWriter & writer, TLV::Tag tag, EndianReader & reader) const; + /// Decodes the string/byte string contained in `reader` and stores it into `writer`. /// String is encoded using a pascal-prefix of size `stringType`. /// Takes into account internal mIsNullable. @@ -96,6 +112,11 @@ inline CHIP_ERROR Decode(TLV::TLVReader & reader, Ember::EmberAttributeDataBuffe return buffer.Decode(reader); } +inline CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, Ember::EmberAttributeDataBuffer & buffer) +{ + return buffer.Encode(writer, tag); +} + } // namespace DataModel } // namespace app } // namespace chip diff --git a/src/app/codegen-data-model-provider/tests/TestEmberAttributeDataBuffer.cpp b/src/app/codegen-data-model-provider/tests/TestEmberAttributeDataBuffer.cpp index 7d46360029c529..dc83773454d1ff 100644 --- a/src/app/codegen-data-model-provider/tests/TestEmberAttributeDataBuffer.cpp +++ b/src/app/codegen-data-model-provider/tests/TestEmberAttributeDataBuffer.cpp @@ -101,6 +101,56 @@ class EncodeResult std::optional mResult; }; +template +bool IsEqual(const T & a, const T & b) +{ + return a == b; +} + +template <> +bool IsEqual(const ByteSpan & a, const ByteSpan & b) +{ + return a.data_equal(b); +} + +template <> +bool IsEqual(const CharSpan & a, const CharSpan & b) +{ + return a.data_equal(b); +} + +template +bool IsEqual(const std::optional & a, const std::optional & b) +{ + if (a.has_value() != b.has_value()) + { + return false; + } + + if (!a.has_value()) + { + return true; + } + + return IsEqual(*a, *b); +} + +template +bool IsEqual(const DataModel::Nullable & a, const DataModel::Nullable & b) +{ + if (a.IsNull() != b.IsNull()) + { + return false; + } + + if (a.IsNull()) + { + return true; + } + + return IsEqual(a.Value(), b.Value()); +} + /// Validates that an encoded value in ember takes a specific format template class EncodeTester @@ -122,7 +172,6 @@ class EncodeTester CHIP_ERROR err = buffer.Decode(reader); if (err != CHIP_NO_ERROR) { - ChipLogError(Test, "Decoding failed: %" CHIP_ERROR_FORMAT, err.Format()); return err; } @@ -142,6 +191,42 @@ class EncodeTester return EncodeResult::Ok(); } + template + EncodeResult TryDecode(const T & value, const uint8_t (&arr)[N]) + { + // Write data to TLV + { + uint8_t mutableBuffer[N]; + memcpy(mutableBuffer, arr, N); + + MutableByteSpan data_span(mutableBuffer); + Ember::EmberAttributeDataBuffer buffer(mMetaData, data_span); + + TLV::TLVWriter writer; + writer.Init(mEmberAttributeDataBuffer, sizeof(mEmberAttributeDataBuffer)); + ReturnErrorOnFailure(buffer.Encode(writer, TLV::AnonymousTag())); + ReturnErrorOnFailure(writer.Finalize()); + } + + // Data was written in TLV. Take it back out + + TLV::TLVReader reader; + reader.Init(mEmberAttributeDataBuffer, sizeof(mEmberAttributeDataBuffer)); + + ReturnErrorOnFailure(reader.Next()); + + T encodedValue; + ReturnErrorOnFailure(DataModel::Decode(reader, encodedValue)); + + if (!IsEqual(encodedValue, value)) + { + ChipLogError(Test, "Encode mismatch: different data"); + return CHIP_ERROR_INTERNAL; + } + + return EncodeResult::Ok(); + } + private: const EmberAfAttributeMetadata * mMetaData; uint8_t mEmberAttributeDataBuffer[kMaxSize]; @@ -570,7 +655,7 @@ TEST(TestEmberAttributeBuffer, TestEncodeStrings) } } -TEST(TestEmberAttributeBuffer, TestFailures) +TEST(TestEmberAttributeBuffer, TestEncodeFailures) { { // attribute type that is not handled @@ -581,11 +666,38 @@ TEST(TestEmberAttributeBuffer, TestFailures) { // Insufficient space EncodeTester<3> tester(CreateFakeMeta(ZCL_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + + // Empty is ok EXPECT_TRUE(tester.TryEncode(""_span, { 0 }).IsSuccess()); + + // Short strings (with and without count) is wrong. EXPECT_EQ(tester.TryEncode("test"_span, { 0 }), CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(tester.TryEncode("foo"_span, { 3, 'f', 'o' }), CHIP_ERROR_NO_MEMORY); + EXPECT_TRUE(tester.TryEncode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); } + { + // Insufficient space + EncodeTester<3> tester(CreateFakeMeta(ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + + // Empty is ok + EXPECT_TRUE(tester.TryEncode(""_span, { 0, 0 }).IsSuccess()); + + // Short strings (with and without count) is wrong. + EXPECT_EQ(tester.TryEncode("test"_span, { 0 }), CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(tester.TryEncode("foo"_span, { 0, 3, 'f', 'o' }), CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(tester.TryEncode("test"_span, { 0xFF }), CHIP_ERROR_NO_MEMORY); + + EXPECT_TRUE(tester.TryEncode>(DataModel::NullNullable, { 0xFF, 0xFF }).IsSuccess()); + } + + { + // Insufficient space even for length + EncodeTester<1> tester(CreateFakeMeta(ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_EQ(tester.TryEncode(""_span, { 0 }), CHIP_ERROR_NO_MEMORY); + } + // bad type casts { EncodeTester tester(CreateFakeMeta(ZCL_CHAR_STRING_ATTRIBUTE_TYPE, false /* nullable */)); @@ -596,3 +708,429 @@ TEST(TestEmberAttributeBuffer, TestFailures) EXPECT_EQ(tester.TryEncode(true, { 0 }), CHIP_ERROR_WRONG_TLV_TYPE); } } + +TEST(TestEmberAttributeBuffer, TestNoData) +{ + EncodeTester tester(CreateFakeMeta(ZCL_NO_DATA_ATTRIBUTE_TYPE, true /* nullable */)); + + // support a always-null type + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0 }).IsSuccess()); +} + +TEST(TestEmberAttributeBuffer, TestDecodeFailures) +{ + { + // attribute type that is not handled + EncodeTester tester(CreateFakeMeta(ZCL_UNKNOWN_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_EQ(tester.TryDecode>(DataModel::NullNullable, { 0 }), CHIP_IM_GLOBAL_STATUS(Failure)); + } + + { + // Insufficient input + EncodeTester<3> tester(CreateFakeMeta(ZCL_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_EQ(tester.TryDecode("test"_span, { 10 }), CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(tester.TryDecode("foo"_span, { 3, 'f', 'o' }), CHIP_ERROR_BUFFER_TOO_SMALL); + } + + { + // Insufficient data buffer - should never happen, but test that we will error out + EncodeTester tester(CreateFakeMeta(ZCL_INT32U_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_EQ(tester.TryDecode(123, { 1, 2, 3 }), CHIP_ERROR_BUFFER_TOO_SMALL); + } + + { + // Insufficient data buffer - should never happen, but test that we will error out + EncodeTester tester(CreateFakeMeta(ZCL_SINGLE_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_EQ(tester.TryDecode(1.5f, { 1, 2, 3 }), CHIP_ERROR_BUFFER_TOO_SMALL); + } + + { + // Insufficient data buffer - should never happen, but test that we will error out + EncodeTester tester(CreateFakeMeta(ZCL_DOUBLE_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_EQ(tester.TryDecode(1.5, { 1, 2, 3 }), CHIP_ERROR_BUFFER_TOO_SMALL); + } + + { + // Bad boolean data + EncodeTester tester(CreateFakeMeta(ZCL_BOOLEAN_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_EQ(tester.TryDecode(true, { 123 }), CHIP_ERROR_INCORRECT_STATE); + } +} + +TEST(TestEmberAttributeBuffer, TestDecodeSignedTypes) +{ + { + EncodeTester tester(CreateFakeMeta(ZCL_INT8S_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(127, { 127 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-128, { 0x80 }).IsSuccess()); + + // longer data is ok + EXPECT_TRUE(tester.TryDecode(-128, { 0x80, 1, 2, 3, 4 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT8S_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(127, { 127 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-127, { 0x81 }).IsSuccess()); + + // NULL can be decoded + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0x80 }).IsSuccess()); + + // decoding as nullable proceeds as normal + EXPECT_TRUE(tester.TryDecode>(-127, { 0x81 }).IsSuccess()); + } + + { + + EncodeTester tester(CreateFakeMeta(ZCL_INT16S_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(127, { 127, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-128, { 0x80, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(std::numeric_limits::min(), { 0x0, 0x80 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT16S_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(127, { 127, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6, 0xFF }).IsSuccess()); + + // NULL decoding + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0x00, 0x80 }).IsSuccess()); + } + + // Odd size integers + { + EncodeTester tester(CreateFakeMeta(ZCL_INT24S_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1, { 0xFF, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT24S_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1, { 0xFF, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-10, { 0xF6, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF }).IsSuccess()); + + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0x00, 0x00, 0x80 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT40S_ATTRIBUTE_TYPE, true /* nullable */)); + + // NOTE: to generate encoded values, you an use commands like: + // + // python -c 'import struct; print(", ".join(["0x%X" % v for v in struct.pack("(0, { 0, 0, 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-123456789, { 0xeb, 0x32, 0xa4, 0xf8, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(-12345678910, { 0xc2, 0xe3, 0x23, 0x20, 0xfd }).IsSuccess()); + + EXPECT_TRUE( + tester.TryDecode>(DataModel::NullNullable, { 0x00, 0x00, 0x00, 0x00, 0x80 }).IsSuccess()); + } + + // Double-check tests, not as exhaustive, to cover all other unsigned values and get + // more test line coverage + { + EncodeTester tester(CreateFakeMeta(ZCL_INT32S_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT48S_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT56S_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT64S_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }).IsSuccess()); + + // min/max ranges too + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::min() + 1, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }) + .IsSuccess()); + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::max(), { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }) + .IsSuccess()); + + EXPECT_TRUE(tester + .TryDecode>(DataModel::NullNullable, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }) + .IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT64S_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(-1234, { 0x2E, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }).IsSuccess()); + + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::min(), { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }) + .IsSuccess()); + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::min() + 1, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }) + .IsSuccess()); + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::max(), { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }) + .IsSuccess()); + } +} + +TEST(TestEmberAttributeBuffer, TestDecodeUnsignedTypes) +{ + { + EncodeTester tester(CreateFakeMeta(ZCL_INT8U_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFD, { 0xFD }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(255, { 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT8U_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFD, { 0xFD }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); + + // NULL decoding should work + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT16U_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFD, { 0xFD, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(255, { 0xFF, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xABCD, { 0xCD, 0xAB }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFFFF, { 0xFF, 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT16U_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(123, { 123, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFD, { 0xFD, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(255, { 0xFF, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xABCD, { 0xCD, 0xAB }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF }).IsSuccess()); + + // NULL SUPPORT + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT64U_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0, 0, 0, 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x1234567, { 0x67, 0x45, 0x23, 0x01, 0, 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xAABBCCDDEEFF1122, { 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA }).IsSuccess()); + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::max() - 1, { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }) + .IsSuccess()); + + EXPECT_TRUE(tester + .TryDecode>(DataModel::NullNullable, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }) + .IsSuccess()); + + EXPECT_TRUE(tester + .TryDecode>(DataModel::NullNullable, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }) + .IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT64U_ATTRIBUTE_TYPE, false /* nullable */)); + + // we should be able to encode the maximum value + EXPECT_TRUE( + tester.TryDecode(std::numeric_limits::max(), { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }) + .IsSuccess()); + } + + /// Odd sized integers + { + EncodeTester tester(CreateFakeMeta(ZCL_INT24U_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0xFFFFFF, { 0xFF, 0xFF, 0xFF }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT24U_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF, 0xFF }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(0x1234, { 0x34, 0x12, 0x00 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_INT40U_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0, { 0, 0, 0, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456, { 0x56, 0x34, 0x12, 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(0x123456FFFF, { 0xFF, 0xFF, 0x56, 0x34, 0x12 }).IsSuccess()); + EXPECT_TRUE( + tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }).IsSuccess()); + } + + // Double-check tests, not as exhaustive, to cover all other unsigned values and get + // more test line coverage + { + EncodeTester tester(CreateFakeMeta(ZCL_INT32U_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0x1234, { 0x34, 0x12, 0, 0 }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT48U_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0x1234, { 0x34, 0x12, 0, 0, 0, 0 }).IsSuccess()); + } + { + EncodeTester tester(CreateFakeMeta(ZCL_INT56U_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(0x1234, { 0x34, 0x12, 0, 0, 0, 0, 0 }).IsSuccess()); + } +} + +TEST(TestEmberAttributeBuffer, TestDecodeStrings) +{ + { + EncodeTester tester(CreateFakeMeta(ZCL_CHAR_STRING_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(""_span, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode("test"_span, { 4, 't', 'e', 's', 't' }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode("foo"_span, { 3, 'f', 'o', 'o' }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(""_span, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode("test"_span, { 4, 't', 'e', 's', 't' }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(""_span, { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode("test"_span, { 4, 0, 't', 'e', 's', 't' }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode("foo"_span, { 3, 0, 'f', 'o', 'o' }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode("test"_span, { 4, 0, 't', 'e', 's', 't' }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF }).IsSuccess()); + } + + const uint8_t kOctetData[] = { 1, 2, 3 }; + + // Binary data + { + EncodeTester tester(CreateFakeMeta(ZCL_OCTET_STRING_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(ByteSpan({}), { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(ByteSpan(kOctetData), { 3, 1, 2, 3 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_OCTET_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(ByteSpan({}), { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(ByteSpan(kOctetData), { 3, 1, 2, 3 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(ByteSpan({}), { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(ByteSpan(kOctetData), { 3, 0, 1, 2, 3 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(ByteSpan({}), { 0, 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(ByteSpan(kOctetData), { 3, 0, 1, 2, 3 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF, 0xFF }).IsSuccess()); + } +} + +TEST(TestEmberAttributeBuffer, TestDecodeBool) +{ + { + EncodeTester tester(CreateFakeMeta(ZCL_BOOLEAN_ATTRIBUTE_TYPE, false /* nullable */)); + + EXPECT_TRUE(tester.TryDecode(true, { 1 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode(false, { 0 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_BOOLEAN_ATTRIBUTE_TYPE, true /* nullable */)); + + EXPECT_TRUE(tester.TryDecode>(true, { 1 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(false, { 0 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0xFF }).IsSuccess()); + } +} + +TEST(TestEmberAttributeBuffer, TestDecodeFloatingPoint) +{ + // NOTE: to generate encoded values, you an use commands like: + // + // python -c 'import struct; print(", ".join(["0x%X" % v for v in struct.pack("(123.55f, { 0x9A, 0x19, 0xF7, 0x42 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_SINGLE_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(123.55f, { 0x9A, 0x19, 0xF7, 0x42 }).IsSuccess()); + EXPECT_TRUE(tester.TryDecode>(DataModel::NullNullable, { 0, 0, 0xC0, 0x7F }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_DOUBLE_ATTRIBUTE_TYPE, false /* nullable */)); + EXPECT_TRUE(tester.TryDecode(123.55, { 0x33, 0x33, 0x33, 0x33, 0x33, 0xE3, 0x5E, 0x40 }).IsSuccess()); + } + + { + EncodeTester tester(CreateFakeMeta(ZCL_DOUBLE_ATTRIBUTE_TYPE, true /* nullable */)); + EXPECT_TRUE(tester.TryDecode(123.55, { 0x33, 0x33, 0x33, 0x33, 0x33, 0xE3, 0x5E, 0x40 }).IsSuccess()); + EXPECT_TRUE( + tester.TryDecode>(123.55, { 0x33, 0x33, 0x33, 0x33, 0x33, 0xE3, 0x5E, 0x40 }).IsSuccess()); + EXPECT_TRUE( + tester.TryDecode>(DataModel::NullNullable, { 0, 0, 0, 0, 0, 0, 0xF8, 0x7F }).IsSuccess()); + } +} From d814ce7073014aff5c812542a8500b6a34ad5a66 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 24 Oct 2024 21:12:57 +0200 Subject: [PATCH 2/7] [chip-tool[darwin-framework-tool] Using ComplexArgument leaks on syntax failure and even on success (#36227) * [chip-tool[darwin-framework-tool] Using a malformed ComplexArgument may result into a leak * [chip-tool[darwin-framework-tool] Even on success the ComplexArgument may not be cleared properly --------- Co-authored-by: Andrei Litvin --- .../commands/clusters/ComplexArgument.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ComplexArgument.h b/examples/chip-tool/commands/clusters/ComplexArgument.h index 6f92256ff735e4..695af2f764a9c1 100644 --- a/examples/chip-tool/commands/clusters/ComplexArgument.h +++ b/examples/chip-tool/commands/clusters/ComplexArgument.h @@ -181,7 +181,12 @@ class ComplexArgumentParser // - 11 is the maximum length of a %d (-2147483648, 2147483647) // - 2 is the length for the "[" and "]" characters. snprintf(labelWithIndex, sizeof(labelWithIndex), "%.241s[%d]", label, i); - ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithIndex, content[i], value[i])); + auto error = ComplexArgumentParser::Setup(labelWithIndex, content[i], value[i]); + if (CHIP_NO_ERROR != error) + { + chip::Platform::MemoryFree(content); + return error; + } } request = chip::app::DataModel::List(content, value.size()); @@ -415,7 +420,14 @@ class TypedComplexArgument : public ComplexArgument return ComplexArgumentParser::Setup(label, *mRequest, value); } - void Reset() { *mRequest = T(); } + void Reset() + { + if (mRequest != nullptr) + { + ComplexArgumentParser::Finalize(*mRequest); + *mRequest = T(); + } + } private: T * mRequest; From 4224d70393200ecf027c067788007cb63010a9ea Mon Sep 17 00:00:00 2001 From: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:16:27 -0400 Subject: [PATCH 3/7] delete unnecessary files from the docker image (#36237) --- integrations/docker/images/base/chip-build/version | 2 +- .../images/stage-2/chip-build-efr32/Dockerfile | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/integrations/docker/images/base/chip-build/version b/integrations/docker/images/base/chip-build/version index f44401475bad25..081a6389d0be23 100644 --- a/integrations/docker/images/base/chip-build/version +++ b/integrations/docker/images/base/chip-build/version @@ -1 +1 @@ -86 : [Tizen] Pass runner's path as QEMU argument \ No newline at end of file +87 : [Silabs] Delete SDK files to reduce the amount of flash consummed diff --git a/integrations/docker/images/stage-2/chip-build-efr32/Dockerfile b/integrations/docker/images/stage-2/chip-build-efr32/Dockerfile index 3d65e2c52fa606..a202e835a78256 100644 --- a/integrations/docker/images/stage-2/chip-build-efr32/Dockerfile +++ b/integrations/docker/images/stage-2/chip-build-efr32/Dockerfile @@ -18,21 +18,28 @@ RUN wget https://github.com/SiliconLabs/simplicity_sdk/releases/download/v2024.6 && unzip /tmp/simplicity_sdk.zip -d /tmp/simplicity_sdk \ && rm -rf /tmp/simplicity_sdk.zip \ # Deleting files that are not needed to save space - && rm -rf /tmp/simplicity_sdk/protocol/flex /tmp/simplicity_sdk/protocol/z-wave /tmp/simplicity_sdk/protocol/zigbee /tmp/simplicity_sdk/protocol/wisun \ + && rm -rf /tmp/simplicity_sdk/protocol/flex /tmp/simplicity_sdk/protocol/z-wave /tmp/simplicity_sdk/protocol/zigbee /tmp/simplicity_sdk/protocol/wisun /tmp/simplicity_sdk/util/third_party/tensorflow_extra \ + /tmp/simplicity_sdk/util/third_party/sqlite /tmp/simplicity_sdk/util/third_party/ot-br-posix /tmp/simplicity_sdk/util/third_party/tflite-micro /tmp/simplicity_sdk/util/third_party/tflite-fatfs /tmp/simplicity_sdk/util/third_party/unity_test_framework \ + /tmp/simplicity_sdk/platform/radio/efr32_multiphy_configurator \ && find /tmp/simplicity_sdk/protocol/bluetooth /tmp/simplicity_sdk/platform -name "*.a" -type f -delete \ && find /tmp/simplicity_sdk/protocol/openthread -name "*efr32mg21*" -delete \ + && find /tmp/simplicity_sdk \( -name "libsl_platform_ftd_efr32mg2*" -o -name "libsl_ot_stack_mtd_efr32mg2*" \) -type f -delete \ + && find /tmp/simplicity_sdk/hardware/board/config -mindepth 1 -maxdepth 1 -type d ! \( -name '*brd4186c*' -o -name '*brd4187c*' -o -name '*brd4186a*' -o -name '*brd4187a*' -o -name '*brd2601b*' -o -name '*brd2703a*' -o -name '*brd2704a*' \ + -o -name '*brd4316a*' -o -name '*brd4317a*' -o -name '*brd4318a*' -o -name '*brd4319a*' -o -name '*brd4116a*' -o -name '*brd4117a*' -o -name '*brd4118a*' -o -name '*brd2608a*' \) -exec rm -rf {} + \ + && find /tmp/simplicity_sdk/platform/Device/SiliconLabs -mindepth 1 -maxdepth 1 -type d ! \( -name 'EFR32MG24' -o -name 'EFR32MG26' -o -name 'MGM24' \) -exec rm -rf {} + \ + && find /tmp/simplicity_sdk -name "*.slc*" -type f -delete \ && : # last line # Clone WiSeConnect Wi-Fi and Bluetooth Software 2.10.3 (b6d6cb5) RUN git clone --depth=1 --single-branch --branch=2.10.3 https://github.com/SiliconLabs/wiseconnect-wifi-bt-sdk.git /tmp/wiseconnect-wifi-bt-sdk && \ cd /tmp/wiseconnect-wifi-bt-sdk && \ - rm -rf .git \ + rm -rf .git examples \ && : # last line # Clone WiSeConnect SDK v3.3.3 (a6390dd) RUN git clone --depth=1 --single-branch --branch=v3.3.3 https://github.com/SiliconLabs/wiseconnect.git /tmp/wifi_sdk && \ cd /tmp/wifi_sdk && \ - rm -rf .git \ + rm -rf .git examples components/device/stm32 \ && : # last line # SLC-cli install From 8852bbeb47a83b384d251d90a8f59c2649f8f73c Mon Sep 17 00:00:00 2001 From: Raul Marquez <130402456+raul-marquez-csa@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:37:56 -0700 Subject: [PATCH 4/7] Removes yaml script (#36212) --- .../certification/Test_TC_OPCREDS_3_2.yaml | 437 ------------------ src/app/tests/suites/manualTests.json | 1 - 2 files changed, 438 deletions(-) delete mode 100644 src/app/tests/suites/certification/Test_TC_OPCREDS_3_2.yaml diff --git a/src/app/tests/suites/certification/Test_TC_OPCREDS_3_2.yaml b/src/app/tests/suites/certification/Test_TC_OPCREDS_3_2.yaml deleted file mode 100644 index a4974d02df7e3d..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_OPCREDS_3_2.yaml +++ /dev/null @@ -1,437 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: - 15.2.2. [TC-OPCREDS-3.2] Attribute-CurrentFabricIndex validation - [DUT-Server] - -PICS: - - OPCREDS.S - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Precondition" - verification: | - This test case assumes that during Commissioning AddNOC will be sent with ICACValue - disabled: true - - - label: "Step 1: Factory Reset DUT" - verification: | - On both DUT and TH side use the below command - sudo rm -rf /tmp/chip_* - disabled: true - - - label: - "Step 2: Commission DUT to TH1s Fabric When DUT sends NOC response - save FabricIndex as FabricIndex_TH1" - verification: | - DUT side: - sudo ./chip-all-clusters-app --wifi - - TH side: - ./chip-tool pairing ble-wifi 1 zigbeehome matter123 20202021 3841 --trace_decode 1 - - [1650455358.501816][4366:4371] CHIP:TOO: Device commissioning completed with success" - - - After commissioning DUT to TH1's fabric read nocs - - Save the FabricIndex and NOC value during commissioning in TH Log - - [1673248033.951950][1706:1708] CHIP:CTL: OperationalSessionSetup[1:0000000000000001]: State change 2 --> 3 - [1673248033.952156][1706:1708] CHIP:IN: SecureSession[0xffffa803fa40]: Allocated Type:2 LSID:14065 - [1673248033.952247][1706:1708] CHIP:SC: Initiating session on local FabricIndex 1 from 0x000000000001B669 -> 0x0000000000000001 - [1673248033.954558][1706:1708] CHIP:EM: <<< [E:44273i M:220413667] (U) Msg TX to 0:0000000000000000 [0000] --- Type 0000:30 (SecureChannel:CASE_Sigma1) - [1673248033.954856][1706:1708] CHIP:IN: (U) Sending msg 220413667 to IP address 'UDP:[fe80::e65f:1ff:fe0e:be36%eth0]:5540' - [1673248033.955496][1706:1708] CHIP:DMG: >> to UDP:[fe80::e65f:1ff:fe0e:be36%eth0]:5540 | 220413667 | [Secure Channel (0) / Certificate Authenticated Session Establishment Sigma '1' (0x30) / Session = 0 / Exchange = 44273] - [1679562607.575771][126855:126857] CHIP:DMG: } - [1679562607.575776][126855:126857] CHIP:DMG: - [1679562607.575833][126855:126857] CHIP:DMG: NOCValue (241) = - [1679562607.575852][126855:126857] CHIP:DMG: { - FTABAQEkAgE3AyQTAhgmBIAigScmBYAlTTo3BiQVASQRARgkBwEkCAEwCUEECq7oyCv/0OLZ4DyFaO6+SuXasHNJcvBFGJcsjh7K/OU92vFP6+dVfa72+vn0Bj2zE2yEB/xGY6firv0ccIYCaDcKNQEoARgkAgE2AwQCBAEYMAQUyGYyV+0qHvlilDYdFF5//OTDeCcwBRSTcEvTAX3+cztsuvoZoqtHd61F3BgwC0BOygoI269loXpAssEaxpMPqplxS9GHmVhY04u/WVsNODFSFnzgBMd4Bd4yl75UoEIYkQ9SNMbuE6wMidFO1b8OGA== - [1679562607.575866][126855:126857] CHIP:DMG: } - [1679562607.575872][126855:126857] CHIP:DMG: - [1679562607.575878][126855:126857] CHIP:DMG: ICACValue (231) = - [1679562607.575893][126855:126857] CHIP:DMG: { - FTABAQEkAgE3AyQUARgmBIAigScmBYAlTTo3BiQTAhgkBwEkCAEwCUEE9/MhX0otpexJN0+X1TLOLaojJWg4sd+DU6GaVBPRmauhGVxJSCocNTl86dugdU9BNSyZ4YKvzTFNi9ahXKwboDcKNQEpARgkAmAwBBSTcEvTAX3+cztsuvoZoqtHd61F3DAFFOA5rOqBb2KMCwcU5FTt/zF2IvMBGDALQEUmrbTN1Y4du9eHicbE5iKphxlrBRyscULxD/ZfaWyN38XuXZKOGdkGhfLL1tYLjhc7wVd9mLLl3RtNJEUDBtgY - [1679562607.575908][126855:126857] CHIP:DMG: } - [1679562607.575914][126855:126857] CHIP:DMG: - [1679562607.575930][126855:126857] CHIP:DMG: InvokeRequestMessage = - [1679562607.575937][126855:126857] CHIP:DMG: { - [1679562607.575944][126855:126857] CHIP:DMG: suppressResponse = false, - [1679562607.575952][126855:126857] CHIP:DMG: timedRequest = false, - [1679562607.575958][126855:126857] CHIP:DMG: InvokeRequests = - [1679562607.575971][126855:126857] CHIP:DMG: [ - [1679562607.575978][126855:126857] CHIP:DMG: CommandDataIB = - [1679562607.575987][126855:126857] CHIP:DMG: { - [1679562607.575993][126855:126857] CHIP:DMG: CommandPathIB = - [1679562607.576002][126855:126857] CHIP:DMG: { - [1679562607.576011][126855:126857] CHIP:DMG: EndpointId = 0x0, - [1679562607.576020][126855:126857] CHIP:DMG: ClusterId = 0x3e, - [1679562607.576028][126855:126857] CHIP:DMG: CommandId = 0x6, - [1679562607.576039][126855:126857] CHIP:DMG: }, - [1679562607.576048][126855:126857] CHIP:DMG: - [1679562607.576055][126855:126857] CHIP:DMG: CommandFields = - [1679562607.576065][126855:126857] CHIP:DMG: { - [1679562607.576074][126855:126857] CHIP:DMG: 0x0 = [ - [1679562607.576127][126855:126857] CHIP:DMG: 0x15, 0x30, 0x1, 0x1, 0x1, 0x24, 0x2, 0x1, 0x37, 0x3, 0x24, 0x13, 0x1, 0x18, 0x26, 0x4, 0x80, 0x22, 0x81, 0x27, 0x26, 0x5, 0x80, 0x25, 0x4d, 0x3a, 0x37, 0x6, 0x24, 0x15, 0x1, 0x24, 0x11, 0x1, 0x18, 0x24, 0x7, 0x1, 0x24, 0x8, 0x1, 0x30, 0x9, 0x41, 0x4, 0x94, 0x5b, 0xb6, 0xd3, 0x14, 0x0, 0x45, 0x35, 0xf0, 0x64, 0x25, 0x7d, 0xb7, 0x8a, 0x56, 0x9d, 0x5, 0x0, 0x56, 0xec, 0xbc, 0xa9, 0xb5, 0xdc, 0xfa, 0xa4, 0x93, 0x28, 0x14, 0x1d, 0x7, 0x3a, 0xc9, 0x7d, 0x1c, 0x9d, 0x21, 0x56, 0xf4, 0xec, 0xc8, 0x7d, 0x3c, 0x87, 0x6f, 0x51, 0xa3, 0x65, 0x89, 0x92, 0x4d, 0xcf, 0xd9, 0x11, 0x71, 0xab, 0x4e, 0x99, 0xcb, 0x90, 0x72, 0xb5, 0x45, 0xa9, 0x37, 0xa, 0x35, 0x1, 0x28, 0x1, 0x18, 0x24, 0x2, 0x1, 0x36, 0x3, 0x4, 0x2, 0x4, 0x1, 0x18, 0x30, 0x4, 0x14, 0xf2, 0x2d, 0x91, 0xb, 0xf2, 0xb1, 0xce, 0xdb, 0x60, 0x10, 0x23, 0x97, 0x31, 0xfd, 0x43, 0xc4, 0x40, 0x46, 0x5a, 0x99, 0x30, 0x5, 0x14, 0xf9, 0x94, 0xad, 0x9e, 0x2b, 0x0, 0x6b, 0xa9, 0xc1, 0x27, 0x6d, 0x20, 0xcb, 0x27, 0xa4, 0xf1, 0x21, 0x2b, 0xc9, 0x8b, 0x18, 0x30, 0xb, 0x40, 0xa1, 0xd2, 0x49, 0x5c, 0xa, 0xc1, 0x58, 0x12, 0x71, 0xd, 0x1a, 0x37, 0xe4, 0x7b, 0x3d, 0xbd, 0x19, 0xe, 0xe8, 0x86, 0xa8, 0x49, 0x4, 0x8, 0x7b, 0x20, 0x94, 0xfa, 0x21, 0xe8, 0x5b, 0xbf, 0x58, 0xc, 0x7d, 0x93, 0x4b, 0x89, 0x88, 0x78, 0xeb, 0xf2, 0x9, 0xf9, 0x3e, 0x6, 0xf7, 0x85, 0xbe, 0xa2, 0xa1, 0xf, 0xc8, 0x40, 0x64, 0xd5, 0xdf, 0x97, 0x6f, 0xef, 0x2c, 0xad, 0xbc, 0xcc, 0x18, - [1679562607.576155][126855:126857] CHIP:DMG: ] (241 bytes) - disabled: true - - - label: "Step 3: Save TH1s Fabric ID as FabricID1" - verification: | - Refer the above step - disabled: true - - - label: - "Step 4: Commission DUT to TH2s Fabric When DUT sends NOC response - save FabricIndex as FabricIndex_TH2" - verification: | - To commission DUT to TH2 follow below procedure - - ./chip-tool pairing open-commissioning-window 1 1 400 2000 3841 - - Verify in TH1 Log: - - CHIP:IN: Sending encrypted msg 0xaaaad3464d10 with MessageCounter:0 to 0x0000000000000001 at monotonic time: 5805157 msec - [1635691999.946536][3822:3827] CHIP:DMG: ICR moving to [CommandSen] - [1635691999.946586][3822:3827] CHIP:CTL: Manual pairing code: [35407541839] - [1635691999.946650][3822:3827] CHIP:CTL: SetupQRCode: [MT:00000CQM00G6V851H10] - [1635691999.946802][3822:3827] CHIP:EM: Sending Standalone Ack for MessageCounter:3234931243 on exchange 35324i - [1635691999.946850][3822:3827] CHIP:IN: Prepared plaintext message 0xffffaa58a960 to 0x0000000000000000 of type 0x10 and protocolId (0, 0) on exchange 35324i with MessageCounter:1726016118. - [1635691999.946895][3822:3827] CHIP:IN: Sending plaintext msg 0xffffaa58a960 with MessageCounter:1726016118 to 0x0000000000000000 at monotonic time: 5805158 msec - [1635691999.946983][3822:3827] CHIP:EM: Flushed pending ack for MessageCounter:3234931243 on exchange 35324i - - 2. On 2nd controller, using chip-tool connect using manual code. - Below is the example when using chip tool as controller (considering 35998938564 as the manual code generated by 1st controller) - - - ./chip-tool pairing code 2 35407541839 --commissioner-name beta --trace_decode 1 - Verify whether you got below message in the log of TH - Device commissioning completed with success - - After commissioning DUT to TH2's fabric read nocs - - Save the the FabricIndex and NOC value during commissioning in TH2 Log - - - [1673249259.166158][1742:1744] CHIP:DIS: Keeping DNSSD lookup active - [1673249259.362947][1742:1744] CHIP:DIS: Checking node lookup status after 200 ms - [1673249259.363205][1742:1744] CHIP:DIS: OperationalSessionSetup[2:0000000000000002]: Updating device address to UDP:[fe80::e65f:1ff:fe0e:be37%eth0]:5540 while in state 2 - [1673249259.363267][1742:1744] CHIP:CTL: OperationalSessionSetup[2:0000000000000002]: State change 2 --> 3 - [1673249259.363467][1742:1744] CHIP:IN: SecureSession[0xffff98011400]: Allocated Type:2 LSID:60039 - [1673249259.363558][1742:1744] CHIP:SC: Initiating session on local FabricIndex 2 from 0x000000000001B669 -> 0x0000000000000002 - [1673249259.365555][1742:1744] CHIP:EM: <<< [E:13995i M:219921998] (U) Msg TX to 0:0000000000000000 [0000] --- Type 0000:30 (SecureChannel:CASE_Sigma1) - [1681213277.146543][2983:2985] CHIP:DMG: - [1681213277.146631][2983:2985] CHIP:DMG: NOCValue (241) = - [1681213277.146662][2983:2985] CHIP:DMG: { - FTABAQEkAgE3AyQTAhgmBIAigScmBYAlTTo3BiQVAiQRAhgkBwEkCAEwCUEEooiu0bizmyLUR9k8phgWrcsaLfWIrjF3MmJuMrM2rGsjl/k8nxqkNtfiVCPUbMfo+Z2vMByAa74UKVnvxz4a2DcKNQEoARgkAgE2AwQCBAEYMAQUmZjxv4X5S8T6+5BRACiWMwvb2hIwBRTzEAaDTxWHp9yNRa21A/LaQylK9BgwC0DyL4TkYg6tVc5DCXnE+ZXq6wRE1oCi72icy+9rcsptmfXdgWjew2uiEfQiJIQJdzM1mZN8OKLlJx8aY4CVsC/AGA== - [1681213277.146693][2983:2985] CHIP:DMG: } - [1681213277.146708][2983:2985] CHIP:DMG: - [1681213277.146725][2983:2985] CHIP:DMG: ICACValue (231) = - [1681213277.146748][2983:2985] CHIP:DMG: { - FTABAQEkAgE3AyQUARgmBIAigScmBYAlTTo3BiQTAhgkBwEkCAEwCUEEjjgt8C2SvzhTjCUn3polJfTxEfZhJ5Dg7B24NEfypWrVKu3MsEmx4eHexmohFV9+Najv+bp7ns53w6vakJqo7TcKNQEpARgkAmAwBBTzEAaDTxWHp9yNRa21A/LaQylK9DAFFJg1jJGztPg2TbeXsehGcGT67Ry2GDALQEZnfw7LkGjbDUPw8p0OReBz4hQAuVmQ7myxWcX0LPxsKm4lV0TC9bXnwmrQ8rMz0uY/gxdXfbWdd87SPbp2698Y - [1681213277.146780][2983:2985] CHIP:DMG: } - [1681213277.146795][2983:2985] CHIP:DMG: - [1681213277.146826][2983:2985] CHIP:DMG: InvokeRequestMessage = - [1681213277.146844][2983:2985] CHIP:DMG: { - [1681213277.146862][2983:2985] CHIP:DMG: suppressResponse = false, - [1681213277.146883][2983:2985] CHIP:DMG: timedRequest = false, - [1681213277.146902][2983:2985] CHIP:DMG: InvokeRequests = - [1681213277.146928][2983:2985] CHIP:DMG: [ - [1681213277.146947][2983:2985] CHIP:DMG: CommandDataIB = - [1681213277.146970][2983:2985] CHIP:DMG: { - [1681213277.146990][2983:2985] CHIP:DMG: CommandPathIB = - [1681213277.147013][2983:2985] CHIP:DMG: { - [1681213277.147037][2983:2985] CHIP:DMG: EndpointId = 0x0, - [1681213277.147063][2983:2985] CHIP:DMG: ClusterId = 0x3e, - [1681213277.147088][2983:2985] CHIP:DMG: CommandId = 0x6, - [1681213277.147111][2983:2985] CHIP:DMG: }, - [1681213277.147136][2983:2985] CHIP:DMG: - [1681213277.147156][2983:2985] CHIP:DMG: CommandFields = - [1681213277.147179][2983:2985] CHIP:DMG: { - [1681213277.147204][2983:2985] CHIP:DMG: 0x0 = [ - [1681213277.147296][2983:2985] CHIP:DMG: 0x15, 0x30, 0x01, 0x01, 0x01, 0x24, 0x02, 0x01, 0x37, 0x03, 0x24, 0x13, 0x02, 0x18, 0x26, 0x04, 0x80, 0x22, 0x81, 0x27, 0x26, 0x05, 0x80, 0x25, 0x4d, 0x3a, 0x37, 0x06, 0x24, 0x15, 0x02, 0x24, 0x11, 0x02, 0x18, 0x24, 0x07, 0x01, 0x24, 0x08, 0x01, 0x30, 0x09, 0x41, 0x04, 0xa2, 0x88, 0xae, 0xd1, 0xb8, 0xb3, 0x9b, 0x22, 0xd4, 0x47, 0xd9, 0x3c, 0xa6, 0x18, 0x16, 0xad, 0xcb, 0x1a, 0x2d, 0xf5, 0x88, 0xae, 0x31, 0x77, 0x32, 0x62, 0x6e, 0x32, 0xb3, 0x36, 0xac, 0x6b, 0x23, 0x97, 0xf9, 0x3c, 0x9f, 0x1a, 0xa4, 0x36, 0xd7, 0xe2, 0x54, 0x23, 0xd4, 0x6c, 0xc7, 0xe8, 0xf9, 0x9d, 0xaf, 0x30, 0x1c, 0x80, 0x6b, 0xbe, 0x14, 0x29, 0x59, 0xef, 0xc7, 0x3e, 0x1a, 0xd8, 0x37, 0x0a, 0x35, 0x01, 0x28, 0x01, 0x18, 0x24, 0x02, 0x01, 0x36, 0x03, 0x04, 0x02, 0x04, 0x01, 0x18, 0x30, 0x04, 0x14, 0x99, 0x98, 0xf1, 0xbf, 0x85, 0xf9, 0x4b, 0xc4, 0xfa, 0xfb, 0x90, 0x51, 0x00, 0x28, 0x96, 0x33, 0x0b, 0xdb, 0xda, 0x12, 0x30, 0x05, 0x14, 0xf3, 0x10, 0x06, 0x83, 0x4f, 0x15, 0x87, 0xa7, 0xdc, 0x8d, 0x45, 0xad, 0xb5, 0x03, 0xf2, 0xda, 0x43, 0x29, 0x4a, 0xf4, 0x18, 0x30, 0x0b, 0x40, 0xf2, 0x2f, 0x84, 0xe4, 0x62, 0x0e, 0xad, 0x55, 0xce, 0x43, 0x09, 0x79, 0xc4, 0xf9, 0x95, 0xea, 0xeb, 0x04, 0x44, 0xd6, 0x80, 0xa2, 0xef, 0x68, 0x9c, 0xcb, 0xef, 0x6b, 0x72, 0xca, 0x6d, 0x99, 0xf5, 0xdd, 0x81, 0x68, 0xde, 0xc3, 0x6b, 0xa2, 0x11, 0xf4, 0x22, 0x24, 0x84, 0x09, 0x77, 0x33, 0x35, 0x99, 0x93, 0x7c, 0x38, 0xa2, 0xe5, 0x27, 0x1f, 0x1a, 0x63, 0x80, 0x95, 0xb0, 0x2f, 0xc0, 0x18, - [1681213277.147347][2983:2985] CHIP:DMG: ] (241 bytes) - disabled: true - - - label: "Step 5: Save TH2s Fabric ID as FabricID2" - verification: | - Refer the above step - disabled: true - - - label: "Step 6: From TH1 read the CurrentFabricIndex" - verification: | - ./chip-tool operationalcredentials read current-fabric-index 1 0 - - Verify the current fabric index in TH1 Log - - CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0005 DataVersion: 2445178920 - CHIP:TOO: CurrentFabricIndex: 1 - CHIP:EM: Sending Standalone Ack for MessageCounter:7141893 on exchange 26909i - disabled: true - - - label: "Step 7: Verify that CurrentFabricIndex = FabricIndex_TH1" - verification: | - Verify that CurrentFabricIndex = FabricIndex_TH1 - disabled: true - - - label: - "Step 8: From TH1 read the entire NOCs List attribute with a - non-fabric-filtered read" - verification: | - ./chip-tool operationalcredentials read nocs 1 0 - - Verify the NOCs List in TH1 Log - - [1658819541.245848][8318:8323] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819541.245960][8318:8323] CHIP:TOO: NOCs: 1 entries - [1658819541.246062][8318:8323] CHIP:TOO: [1]: { - [1658819541.246104][8318:8323] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - [1658819541.246163][8318:8323] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A370624130118240701240801300941045C9D561F53AAB6D9473DF2EE5170B03332BC38EF461842C37954CE99ADC4D55B272B3E545BB9FB2440CB712BA70BDDE27A318BEE1348D5F8C2D2C98CDBAD63C9370A3501290118240260300414F994AD9E2B006BA9C1276D20CB27A4F1212BC98B3005149040FBAF6F57D4E32188CD360DD4959272745D7618300B40C5EFCC41A18A4FAD6B1DAE6B12675D0C3FF1690728C31D1E95629511F23A4336DB5392E1FEF05EF1BA1DA46080A29BAB60EC613DEF031E2ED9850BB2E3B48B1118 - [1658819541.246198][8318:8323] CHIP:TOO: FabricIndex: 1 - [1658819541.246224][8318:8323] CHIP:TOO: } - disabled: true - - - label: - "Step 9: Verify that there is only data for the entry whose - FabricIndex field is equal to FabricIndex_TH1" - verification: | - Verify that Noc"s list has only data for FabricIndex_TH1 - - [1658819541.245848][8318:8323] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819541.245960][8318:8323] CHIP:TOO: NOCs: 1 entries - [1658819541.246062][8318:8323] CHIP:TOO: [1]: { - [1658819541.246104][8318:8323] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - [1658819541.246163][8318:8323] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A370624130118240701240801300941045C9D561F53AAB6D9473DF2EE5170B03332BC38EF461842C37954CE99ADC4D55B272B3E545BB9FB2440CB712BA70BDDE27A318BEE1348D5F8C2D2C98CDBAD63C9370A3501290118240260300414F994AD9E2B006BA9C1276D20CB27A4F1212BC98B3005149040FBAF6F57D4E32188CD360DD4959272745D7618300B40C5EFCC41A18A4FAD6B1DAE6B12675D0C3FF1690728C31D1E95629511F23A4336DB5392E1FEF05EF1BA1DA46080A29BAB60EC613DEF031E2ED9850BB2E3B48B1118 - [1658819541.246198][8318:8323] CHIP:TOO: FabricIndex: 1 - [1658819541.246224][8318:8323] CHIP:TOO: } - disabled: true - - - label: - "Step 10: From TH1 read the entire NOCs List attribute with a - fabric-filtered read" - verification: | - ./chip-tool operationalcredentials read nocs 1 0 --fabric-filtered 1 - - Verify the NOCs List in TH1 Log - - [1658819590.504973][8327:8332] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819590.505058][8327:8332] CHIP:TOO: NOCs: 1 entries - [1658819590.505131][8327:8332] CHIP:TOO: [1]: { - [1658819590.505173][8327:8332] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - [1658819590.505232][8327:8332] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A370624130118240701240801300941045C9D561F53AAB6D9473DF2EE5170B03332BC38EF461842C37954CE99ADC4D55B272B3E545BB9FB2440CB712BA70BDDE27A318BEE1348D5F8C2D2C98CDBAD63C9370A3501290118240260300414F994AD9E2B006BA9C1276D20CB27A4F1212BC98B3005149040FBAF6F57D4E32188CD360DD4959272745D7618300B40C5EFCC41A18A4FAD6B1DAE6B12675D0C3FF1690728C31D1E95629511F23A4336DB5392E1FEF05EF1BA1DA46080A29BAB60EC613DEF031E2ED9850BB2E3B48B1118 - [1658819590.505266][8327:8332] CHIP:TOO: FabricIndex: 1 - [1658819590.505292][8327:8332] CHIP:TOO: } - disabled: true - - - label: - "Step 11: Verify that there is only data for the entry whose - FabricIndex field is equal to FabricIndex_TH1" - verification: | - Verify that Noc"s list has only data for FabricIndex_TH1 - - [1658819590.504973][8327:8332] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819590.505058][8327:8332] CHIP:TOO: NOCs: 1 entries - [1658819590.505131][8327:8332] CHIP:TOO: [1]: { - [1658819590.505173][8327:8332] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - [1658819590.505232][8327:8332] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A370624130118240701240801300941045C9D561F53AAB6D9473DF2EE5170B03332BC38EF461842C37954CE99ADC4D55B272B3E545BB9FB2440CB712BA70BDDE27A318BEE1348D5F8C2D2C98CDBAD63C9370A3501290118240260300414F994AD9E2B006BA9C1276D20CB27A4F1212BC98B3005149040FBAF6F57D4E32188CD360DD4959272745D7618300B40C5EFCC41A18A4FAD6B1DAE6B12675D0C3FF1690728C31D1E95629511F23A4336DB5392E1FEF05EF1BA1DA46080A29BAB60EC613DEF031E2ED9850BB2E3B48B1118 - [1658819590.505266][8327:8332] CHIP:TOO: FabricIndex: 1 - [1658819590.505292][8327:8332] CHIP:TOO: } - disabled: true - - - label: "Step 12: Read NOCStruct values from entry at index 0" - verification: | - ./chip-tool operationalcredentials read nocs 1 0 --fabric-filtered 1 - - Verify FabricIndex field equal to FabricIndex_TH1 in TH1 Log - - [1658819590.504973][8327:8332] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819590.505058][8327:8332] CHIP:TOO: NOCs: 1 entries - [1658819590.505131][8327:8332] CHIP:TOO: [1]: { - [1658819590.505173][8327:8332] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - [1658819590.505232][8327:8332] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A370624130118240701240801300941045C9D561F53AAB6D9473DF2EE5170B03332BC38EF461842C37954CE99ADC4D55B272B3E545BB9FB2440CB712BA70BDDE27A318BEE1348D5F8C2D2C98CDBAD63C9370A3501290118240260300414F994AD9E2B006BA9C1276D20CB27A4F1212BC98B3005149040FBAF6F57D4E32188CD360DD4959272745D7618300B40C5EFCC41A18A4FAD6B1DAE6B12675D0C3FF1690728C31D1E95629511F23A4336DB5392E1FEF05EF1BA1DA46080A29BAB60EC613DEF031E2ED9850BB2E3B48B1118 - [1658819590.505266][8327:8332] CHIP:TOO: FabricIndex: 1 - [1658819590.505292][8327:8332] CHIP:TOO: } - disabled: true - - - label: - "Step 13: From the NOCStruct values verify the following: NOC matches - the NOC sent to the DUT during commissioning process ICAC matches the - ICAC sent to the DUT during commissioning process from AddNOC in - pre-condition" - verification: | - Verify NOC and ICAC value in step 12 and 2 matches - - NOC value of step 12 - Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411011824070124080130094104945BB6D314004535F064257DB78A569D050056ECBCA9B5DCFAA49328141D073AC97D1C9D2156F4ECC87D3C876F51A36589924DCFD91171AB4E99CB9072B545A9370A350128011824020136030402040118300414F22D910BF2B1CEDB6010239731FD43C440465A99300514F994AD9E2B006BA9C1276D20CB27A4F1212BC98B18300B40A1D2495C0AC15812710D1A37E47B3DBD190EE886A84904087B2094FA21E85BBF580C7D934B898878EBF209F93E06F785BEA2A10FC84064D5DF976FEF2CADBCCC18 - - NOC value of Step 2 - - 0x15, 0x30, 0x1, 0x1, 0x1, 0x24, 0x2, 0x1, 0x37, 0x3, 0x24, 0x13, 0x1, 0x18, 0x26, 0x4, 0x80, 0x22, 0x81, 0x27, 0x26, 0x5, 0x80, 0x25, 0x4d, 0x3a, 0x37, 0x6, 0x24, 0x15, 0x1, 0x24, 0x11, 0x1, 0x18, 0x24, 0x7, 0x1, 0x24, 0x8, 0x1, 0x30, 0x9, 0x41, 0x4, 0x94, 0x5b, 0xb6, 0xd3, 0x14, 0x0, 0x45, 0x35, 0xf0, 0x64, 0x25, 0x7d, 0xb7, 0x8a, 0x56, 0x9d, 0x5, 0x0, 0x56, 0xec, 0xbc, 0xa9, 0xb5, 0xdc, 0xfa, 0xa4, 0x93, 0x28, 0x14, 0x1d, 0x7, 0x3a, 0xc9, 0x7d, 0x1c, 0x9d, 0x21, 0x56, 0xf4, 0xec, 0xc8, 0x7d, 0x3c, 0x87, 0x6f, 0x51, 0xa3, 0x65, 0x89, 0x92, 0x4d, 0xcf, 0xd9, 0x11, 0x71, 0xab, 0x4e, 0x99, 0xcb, 0x90, 0x72, 0xb5, 0x45, 0xa9, 0x37, 0xa, 0x35, 0x1, 0x28, 0x1, 0x18, 0x24, 0x2, 0x1, 0x36, 0x3, 0x4, 0x2, 0x4, 0x1, 0x18, 0x30, 0x4, 0x14, 0xf2, 0x2d, 0x91, 0xb, 0xf2, 0xb1, 0xce, 0xdb, 0x60, 0x10, 0x23, 0x97, 0x31, 0xfd, 0x43, 0xc4, 0x40, 0x46, 0x5a, 0x99, 0x30, 0x5, 0x14, 0xf9, 0x94, 0xad, 0x9e, 0x2b, 0x0, 0x6b, 0xa9, 0xc1, 0x27, 0x6d, 0x20, 0xcb, 0x27, 0xa4, 0xf1, 0x21, 0x2b, 0xc9, 0x8b, 0x18, 0x30, 0xb, 0x40, 0xa1, 0xd2, 0x49, 0x5c, 0xa, 0xc1, 0x58, 0x12, 0x71, 0xd, 0x1a, 0x37, 0xe4, 0x7b, 0x3d, 0xbd, 0x19, 0xe, 0xe8, 0x86, 0xa8, 0x49, 0x4, 0x8, 0x7b, 0x20, 0x94, 0xfa, 0x21, 0xe8, 0x5b, 0xbf, 0x58, 0xc, 0x7d, 0x93, 0x4b, 0x89, 0x88, 0x78, 0xeb, 0xf2, 0x9, 0xf9, 0x3e, 0x6, 0xf7, 0x85, 0xbe, 0xa2, 0xa1, 0xf, 0xc8, 0x40, 0x64, 0xd5, 0xdf, 0x97, 0x6f, 0xef, 0x2c, 0xad, 0xbc, 0xcc, 0x18, - disabled: true - - - label: - "Step 14: Read the Fabrics List and get the FabricDescriptorStruct for - the entry where FabricIndex = FabricIndex_TH1 from DUT" - verification: | - ./chip-tool operationalcredentials read fabrics 1 0 - - Verify FabricIndex = FabricIndex_TH1 in TH1 Log - - [1657693240.722099][15129:15134] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0001 DataVersion: 908345149 - [1657693240.722200][15129:15134] CHIP:TOO: Fabrics: 1 entries - [1657693240.722273][15129:15134] CHIP:TOO: [1]: { - [1657693240.722316][15129:15134] CHIP:TOO: RootPublicKey: 04038A93AE14428E9179C2ACC3BA1522D4D19BC20A3203BE97FEC0BE47EBC6CCCD4AD5F7B1CE0A02F85FF1B14216FAFCA034B3B312C16B0517267804D5B03582EF - [1657693240.722368][15129:15134] CHIP:TOO: VendorId: 65521 - [1657693240.722401][15129:15134] CHIP:TOO: FabricId: 1 - [1657693240.722431][15129:15134] CHIP:TOO: NodeId: 1 - [1657693240.722462][15129:15134] CHIP:TOO: Label: - [1657693240.722492][15129:15134] CHIP:TOO: FabricIndex: 1 - [1657693240.722522][15129:15134] CHIP:TOO: } - disabled: true - - - label: - "Step 15: Verify that TH1 is able to read the FabricDescriptorStruct - values Verify that Fabrics list does not have any entry as FabricID = - FabricID2" - verification: | - Verify the FabricDescriptorStruct values has no entry log FabricID2 on TH1 - - [1657693240.722099][15129:15134] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0001 DataVersion: 908345149 - [1657693240.722200][15129:15134] CHIP:TOO: Fabrics: 1 entries - [1657693240.722273][15129:15134] CHIP:TOO: [1]: { - [1657693240.722316][15129:15134] CHIP:TOO: RootPublicKey: 04038A93AE14428E9179C2ACC3BA1522D4D19BC20A3203BE97FEC0BE47EBC6CCCD4AD5F7B1CE0A02F85FF1B14216FAFCA034B3B312C16B0517267804D5B03582EF - [1657693240.722368][15129:15134] CHIP:TOO: VendorId: 65521 - [1657693240.722401][15129:15134] CHIP:TOO: FabricId: 1 - [1657693240.722431][15129:15134] CHIP:TOO: NodeId: 1 - [1657693240.722462][15129:15134] CHIP:TOO: Label: - [1657693240.722492][15129:15134] CHIP:TOO: FabricIndex: 1 - [1657693240.722522][15129:15134] CHIP:TOO: } - disabled: true - - - label: "Step 16: From TH2 read the CurrentFabricIndex" - verification: | - ./chip-tool operationalcredentials read current-fabric-index 2 0 --commissioner-name beta - - Verify current fabric index in TH2 Log - - CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0005 DataVersion: 2445178920 - CHIP:TOO: CurrentFabricIndex: 2 - CHIP:EM: Sending Standalone Ack for MessageCounter:8900122 on exchange 26519i - disabled: true - - - label: "Step 17: Verify that CurrentFabricIndex = FabricIndex_TH2" - verification: | - Verify that CurrentFabricIndex = FabricIndex_TH2 - disabled: true - - - label: - "Step 18: From TH2 read the entire NOCs List attribute with a - non-fabric-filtered read" - verification: | - ./chip-tool operationalcredentials read nocs 2 0 --commissioner-name beta - - - Verify the NOCs List in TH2 Log - - [1658819643.546022][8397:8402] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819643.546148][8397:8402] CHIP:TOO: NOCs: 1 entries - [1658819643.546258][8397:8402] CHIP:TOO: [1]: { - [1658819643.546307][8397:8402] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411021824070124080130094104FF8D28DB36902F674F4BF312985CDEA52231E0B3C4795E54E3EFC0D6DE9AED140DEF653EDE9160B10BF446D6E2FAC5DBD38BF85597E095136A209F0990E54394370A3501280118240201360304020401183004144F0F08EA1F5414C324914019EB74CA31C9819AC6300514FF5D080583B5B132C45F800B8D2E184E7D599F5118300B40D434A0D9DA1C7D61784D8BCBEE3E7179A4818499442DD23919A81933C0170673FF33D0E8654312388EE717161DF5E1B6E14402380602B873D551174B2BA0D8E718 - [1658819643.546407][8397:8402] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A37062413011824070124080130094104A58C57E9D8919152DE03DAC991155D750A5D8C93093D75E166E1C5CF86381EA926E108BFE78DAD9FFFB4363A706DA88B9F3B8EF5D80F428F44EAE26472C81B47370A3501290118240260300414FF5D080583B5B132C45F800B8D2E184E7D599F513005143036AAD3B8EDBF6075364A85A96F9A0583EEC49718300B4014BEAF33C7B547857AC36A17AD1CDD4D90D7045889C5B576CA644C78F021B6C21498EDDC43730AFEAD6AF5A945728D1C4F7DF7EE37C313D5AE27E78F0509DB9918 - [1658819643.546447][8397:8402] CHIP:TOO: FabricIndex: 2 - [1658819643.546478][8397:8402] CHIP:TOO: } - disabled: true - - - label: - "Step 19: Verify that there is only data for the entry whose - FabricIndex field is equal to FabricIndex_TH2" - verification: | - ./chip-tool operationalcredentials read current-fabric-index 2 0 --commissioner-name beta - - Verify current fabric index in TH2 Log - - CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0005 DataVersion: 2445178920 - CHIP:TOO: CurrentFabricIndex: 2 - CHIP:EM: Sending Standalone Ack for MessageCounter:8900122 on exchange 26519i - disabled: true - - - label: - "Step 20: From TH2 read the entire NOCs List attribute with a - fabric-filtered read" - verification: | - ./chip-tool operationalcredentials read nocs 2 0 --fabric-filtered 1 --commissioner-name beta - - - Verify the NOCs List in TH2 Log - - [1658819643.546022][8397:8402] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819643.546148][8397:8402] CHIP:TOO: NOCs: 1 entries - [1658819643.546258][8397:8402] CHIP:TOO: [1]: { - [1658819643.546307][8397:8402] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411021824070124080130094104FF8D28DB36902F674F4BF312985CDEA52231E0B3C4795E54E3EFC0D6DE9AED140DEF653EDE9160B10BF446D6E2FAC5DBD38BF85597E095136A209F0990E54394370A3501280118240201360304020401183004144F0F08EA1F5414C324914019EB74CA31C9819AC6300514FF5D080583B5B132C45F800B8D2E184E7D599F5118300B40D434A0D9DA1C7D61784D8BCBEE3E7179A4818499442DD23919A81933C0170673FF33D0E8654312388EE717161DF5E1B6E14402380602B873D551174B2BA0D8E718 - [1658819643.546407][8397:8402] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A37062413011824070124080130094104A58C57E9D8919152DE03DAC991155D750A5D8C93093D75E166E1C5CF86381EA926E108BFE78DAD9FFFB4363A706DA88B9F3B8EF5D80F428F44EAE26472C81B47370A3501290118240260300414FF5D080583B5B132C45F800B8D2E184E7D599F513005143036AAD3B8EDBF6075364A85A96F9A0583EEC49718300B4014BEAF33C7B547857AC36A17AD1CDD4D90D7045889C5B576CA644C78F021B6C21498EDDC43730AFEAD6AF5A945728D1C4F7DF7EE37C313D5AE27E78F0509DB9918 - [1658819643.546447][8397:8402] CHIP:TOO: FabricIndex: 2 - [1658819643.546478][8397:8402] CHIP:TOO: } - disabled: true - - - label: - "Step 21: Verify that there is only data for the entry whose - FabricIndex field is equal to FabricIndex_TH2" - verification: | - Verify that Noc"s list has only data for FabricIndex_TH2 - - [1658819643.546022][8397:8402] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819643.546148][8397:8402] CHIP:TOO: NOCs: 1 entries - [1658819643.546258][8397:8402] CHIP:TOO: [1]: { - [1658819643.546307][8397:8402] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411021824070124080130094104FF8D28DB36902F674F4BF312985CDEA52231E0B3C4795E54E3EFC0D6DE9AED140DEF653EDE9160B10BF446D6E2FAC5DBD38BF85597E095136A209F0990E54394370A3501280118240201360304020401183004144F0F08EA1F5414C324914019EB74CA31C9819AC6300514FF5D080583B5B132C45F800B8D2E184E7D599F5118300B40D434A0D9DA1C7D61784D8BCBEE3E7179A4818499442DD23919A81933C0170673FF33D0E8654312388EE717161DF5E1B6E14402380602B873D551174B2BA0D8E718 - [1658819643.546407][8397:8402] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A37062413011824070124080130094104A58C57E9D8919152DE03DAC991155D750A5D8C93093D75E166E1C5CF86381EA926E108BFE78DAD9FFFB4363A706DA88B9F3B8EF5D80F428F44EAE26472C81B47370A3501290118240260300414FF5D080583B5B132C45F800B8D2E184E7D599F513005143036AAD3B8EDBF6075364A85A96F9A0583EEC49718300B4014BEAF33C7B547857AC36A17AD1CDD4D90D7045889C5B576CA644C78F021B6C21498EDDC43730AFEAD6AF5A945728D1C4F7DF7EE37C313D5AE27E78F0509DB9918 - [1658819643.546447][8397:8402] CHIP:TOO: FabricIndex: 2 - [1658819643.546478][8397:8402] CHIP:TOO: } - disabled: true - - - label: "Step 22: Read NOCStruct values from entry at index 1" - verification: | - ./chip-tool operationalcredentials read nocs 2 0 --commissioner-name beta - - Verify FabricIndex = FabricIndex_TH2 in TH2 Log - - [1658819643.546022][8397:8402] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Attribute 0x0000_0000 DataVersion: 2645922631 - [1658819643.546148][8397:8402] CHIP:TOO: NOCs: 1 entries - [1658819643.546258][8397:8402] CHIP:TOO: [1]: { - [1658819643.546307][8397:8402] CHIP:TOO: Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411021824070124080130094104FF8D28DB36902F674F4BF312985CDEA52231E0B3C4795E54E3EFC0D6DE9AED140DEF653EDE9160B10BF446D6E2FAC5DBD38BF85597E095136A209F0990E54394370A3501280118240201360304020401183004144F0F08EA1F5414C324914019EB74CA31C9819AC6300514FF5D080583B5B132C45F800B8D2E184E7D599F5118300B40D434A0D9DA1C7D61784D8BCBEE3E7179A4818499442DD23919A81933C0170673FF33D0E8654312388EE717161DF5E1B6E14402380602B873D551174B2BA0D8E718 - [1658819643.546407][8397:8402] CHIP:TOO: Icac: 1530010100240201370324140018260480228127260580254D3A37062413011824070124080130094104A58C57E9D8919152DE03DAC991155D750A5D8C93093D75E166E1C5CF86381EA926E108BFE78DAD9FFFB4363A706DA88B9F3B8EF5D80F428F44EAE26472C81B47370A3501290118240260300414FF5D080583B5B132C45F800B8D2E184E7D599F513005143036AAD3B8EDBF6075364A85A96F9A0583EEC49718300B4014BEAF33C7B547857AC36A17AD1CDD4D90D7045889C5B576CA644C78F021B6C21498EDDC43730AFEAD6AF5A945728D1C4F7DF7EE37C313D5AE27E78F0509DB9918 - [1658819643.546447][8397:8402] CHIP:TOO: FabricIndex: 2 - [1658819643.546478][8397:8402] CHIP:TOO: } - disabled: true - - - label: - "Step 23: From the NOCStruct values verify the following: NOC matches - the NOC sent to the DUT during commissioning process ICAC matches the - ICAC sent to the DUT during commissioning process from AddNOC in - pre-condition" - verification: | - Verify the value of NOC and ICAC are same in step 22 and 4 are same - - Step 22 Log: - Noc: 1530010101240201370324130118260480228127260580254D3A37062415012411021824070124080130094104FF8D28DB36902F674F4BF312985CDEA52231E0B3C4795E54E3EFC0D6DE9AED140DEF653EDE9160B10BF446D6E2FAC5DBD38BF85597E095136A209F0990E54394370A3501280118240201360304020401183004144F0F08EA1F5414C324914019EB74CA31C9819AC6300514FF5D080583B5B132C45F800B8D2E184E7D599F5118300B40D434A0D9DA1C7D61784D8BCBEE3E7179A4818499442DD23919A81933C0170673FF33D0E8654312388EE717161DF5E1B6E14402380602B873D551174B2BA0D8E718 - - Step 4 Log - 0x15, 0x30, 0x1, 0x1, 0x1, 0x24, 0x2, 0x1, 0x37, 0x3, 0x24, 0x13, 0x1, 0x18, 0x26, 0x4, 0x80, 0x22, 0x81, 0x27, 0x26, 0x5, 0x80, 0x25, 0x4d, 0x3a, 0x37, 0x6, 0x24, 0x15, 0x1, 0x24, 0x11, 0x2, 0x18, 0x24, 0x7, 0x1, 0x24, 0x8, 0x1, 0x30, 0x9, 0x41, 0x4, 0xff, 0x8d, 0x28, 0xdb, 0x36, 0x90, 0x2f, 0x67, 0x4f, 0x4b, 0xf3, 0x12, 0x98, 0x5c, 0xde, 0xa5, 0x22, 0x31, 0xe0, 0xb3, 0xc4, 0x79, 0x5e, 0x54, 0xe3, 0xef, 0xc0, 0xd6, 0xde, 0x9a, 0xed, 0x14, 0xd, 0xef, 0x65, 0x3e, 0xde, 0x91, 0x60, 0xb1, 0xb, 0xf4, 0x46, 0xd6, 0xe2, 0xfa, 0xc5, 0xdb, 0xd3, 0x8b, 0xf8, 0x55, 0x97, 0xe0, 0x95, 0x13, 0x6a, 0x20, 0x9f, 0x9, 0x90, 0xe5, 0x43, 0x94, 0x37, 0xa, 0x35, 0x1, 0x28, 0x1, 0x18, 0x24, 0x2, 0x1, 0x36, 0x3, 0x4, 0x2, 0x4, 0x1, 0x18, 0x30, 0x4, 0x14, 0x4f, 0xf, 0x8, 0xea, 0x1f, 0x54, 0x14, 0xc3, 0x24, 0x91, 0x40, 0x19, 0xeb, 0x74, 0xca, 0x31, 0xc9, 0x81, 0x9a, 0xc6, 0x30, 0x5, 0x14, 0xff, 0x5d, 0x8, 0x5, 0x83, 0xb5, 0xb1, 0x32, 0xc4, 0x5f, 0x80, 0xb, 0x8d, 0x2e, 0x18, 0x4e, 0x7d, 0x59, 0x9f, 0x51, 0x18, 0x30, 0xb, 0x40, 0xd4, 0x34, 0xa0, 0xd9, 0xda, 0x1c, 0x7d, 0x61, 0x78, 0x4d, 0x8b, 0xcb, 0xee, 0x3e, 0x71, 0x79, 0xa4, 0x81, 0x84, 0x99, 0x44, 0x2d, 0xd2, 0x39, 0x19, 0xa8, 0x19, 0x33, 0xc0, 0x17, 0x6, 0x73, 0xff, 0x33, 0xd0, 0xe8, 0x65, 0x43, 0x12, 0x38, 0x8e, 0xe7, 0x17, 0x16, 0x1d, 0xf5, 0xe1, 0xb6, 0xe1, 0x44, 0x2, 0x38, 0x6, 0x2, 0xb8, 0x73, 0xd5, 0x51, 0x17, 0x4b, 0x2b, 0xa0, 0xd8, 0xe7, 0x18, - disabled: true diff --git a/src/app/tests/suites/manualTests.json b/src/app/tests/suites/manualTests.json index 01d98213b3e279..5f7aa99f9b2952 100644 --- a/src/app/tests/suites/manualTests.json +++ b/src/app/tests/suites/manualTests.json @@ -82,7 +82,6 @@ "DeviceManagement": [ "Test_TC_BINFO_3_1", "Test_TC_OPCREDS_3_1", - "Test_TC_OPCREDS_3_2", "Test_TC_OPCREDS_3_3", "Test_TC_OPCREDS_3_4", "Test_TC_OPCREDS_3_5", From 6ee19136455da56d1f37f6ce4827f74e9cdcd273 Mon Sep 17 00:00:00 2001 From: arun-silabs <141724790+arun-silabs@users.noreply.github.com> Date: Fri, 25 Oct 2024 01:11:56 +0530 Subject: [PATCH 5/7] [Silabs] Fix for thermostat app hang issue on 917SoC (#35721) * Add ScheduleWork by removing LockChipStack and UnlockChipStack in SensorTimerEventHandler. * Restyled by clang-format * Modified the API name as suggested. * Posting SensorTimerEventHandler as an event to AppTask. --------- Co-authored-by: Restyled.io --- examples/thermostat/silabs/include/SensorManager.h | 3 ++- examples/thermostat/silabs/src/SensorManager.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/thermostat/silabs/include/SensorManager.h b/examples/thermostat/silabs/include/SensorManager.h index 03b916de699d2b..8a88d775207fa1 100644 --- a/examples/thermostat/silabs/include/SensorManager.h +++ b/examples/thermostat/silabs/include/SensorManager.h @@ -37,8 +37,9 @@ class SensorManager osTimerId_t mSensorTimer; - // Reads new generated sensor value, stores it, and updates local temperature attribute static void SensorTimerEventHandler(void * arg); + // Reads new generated sensor value, stores it, and updates local temperature attribute + static void TemperatureUpdateEventHandler(AppEvent * aEvent); static SensorManager sSensorManager; }; diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp index 3522e9f5a30d1d..e4186664c6f36e 100644 --- a/examples/thermostat/silabs/src/SensorManager.cpp +++ b/examples/thermostat/silabs/src/SensorManager.cpp @@ -78,6 +78,15 @@ CHIP_ERROR SensorManager::Init() } void SensorManager::SensorTimerEventHandler(void * arg) +{ + AppEvent event; + event.Type = AppEvent::kEventType_Timer; + event.Handler = TemperatureUpdateEventHandler; + + AppTask::GetAppTask().PostEvent(&event); +} + +void SensorManager::TemperatureUpdateEventHandler(AppEvent * aEvent) { int16_t temperature = 0; static int16_t lastTemperature = 0; From 019dcc7b8f21e952de99a0bbc3ef6e61537018be Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:29:48 -0400 Subject: [PATCH 6/7] Removed un-necessary check (#36234) --- .../dishwasher-app/silabs/src/ElectricalSensorManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/dishwasher-app/silabs/src/ElectricalSensorManager.cpp b/examples/dishwasher-app/silabs/src/ElectricalSensorManager.cpp index c751c71c268255..cf7e4806a7828a 100644 --- a/examples/dishwasher-app/silabs/src/ElectricalSensorManager.cpp +++ b/examples/dishwasher-app/silabs/src/ElectricalSensorManager.cpp @@ -196,12 +196,12 @@ void ElectricalSensorManager::UpdateEPMAttributes(OperationalStateEnum state) { if (gEPMDelegate) { - uint16_t updateState = to_underlying(state); - uint16_t ERROR_STATE_INDEX = ArraySize(kAttributes) - 1; + uint8_t updateState = to_underlying(state); + // Check state range - if ((updateState < 0) || (updateState > ERROR_STATE_INDEX)) + if (updateState >= ArraySize(kAttributes)) { - updateState = ERROR_STATE_INDEX; + updateState = ArraySize(kAttributes) - 1; } ChipLogDetail(AppServer, "UpdateAllAttributes to Operational State : %d", updateState); From 41b6830bced81976ecc8cd52c2889f448551055d Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:11:23 -0400 Subject: [PATCH 7/7] Fix missed discrepancy in TC_S_2_2 (#36235) --- src/app/tests/suites/certification/Test_TC_S_2_2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/tests/suites/certification/Test_TC_S_2_2.yaml b/src/app/tests/suites/certification/Test_TC_S_2_2.yaml index 0d78bccbe64e05..abbc71a32afccc 100644 --- a/src/app/tests/suites/certification/Test_TC_S_2_2.yaml +++ b/src/app/tests/suites/certification/Test_TC_S_2_2.yaml @@ -874,7 +874,7 @@ tests: to 60 000 000 (60 000s) and a set of extension fields appropriate to AC1." verification: | - ./chip-tool scenesmanagement add-scene 0x0001 0x01 60000000 "scene name" '[{"clusterID": "0x0300", "attributeValueList":[{"attributeID": "0x4001", "ValueUnsigned8": "0x01"}]}]' 1 1 + ./chip-tool scenesmanagement add-scene 0x0001 0x01 60000000 "scene name" '[{"clusterID": "0x0300", "attributeValueList":[{"attributeID": "0x4000", "valueUnsigned16": "0x01"}]}]' 1 1 Verify DUT sends a AddSceneResponse command to TH with the Status field set to 0x00 (SUCCESS), the GroupID field set to G1 and the SceneID field set to 0x01 on the TH(Chip-tool) Log and below is the sample log provided for the raspi platform: