diff --git a/src/lib/support/ThreadOperationalDataset.cpp b/src/lib/support/ThreadOperationalDataset.cpp index b6a88f2aea7332..35dedc8878a8e6 100644 --- a/src/lib/support/ThreadOperationalDataset.cpp +++ b/src/lib/support/ThreadOperationalDataset.cpp @@ -288,6 +288,19 @@ CHIP_ERROR OperationalDataset::GetExtendedPanId(uint8_t (&aExtendedPanId)[kSizeE return CHIP_ERROR_TLV_TAG_NOT_FOUND; } +CHIP_ERROR OperationalDataset::GetExtendedPanIdAsByteSpan(ByteSpan & span) const +{ + const ThreadTLV * tlv = Locate(ThreadTLV::kExtendedPanId); + + if (tlv != nullptr) + { + span = ByteSpan(reinterpret_cast(tlv->GetValue()), tlv->GetLength()); + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_TLV_TAG_NOT_FOUND; +} + CHIP_ERROR OperationalDataset::SetExtendedPanId(const uint8_t (&aExtendedPanId)[kSizeExtendedPanId]) { ThreadTLV * tlv = MakeRoom(ThreadTLV::kExtendedPanId, sizeof(*tlv) + sizeof(aExtendedPanId)); diff --git a/src/lib/support/ThreadOperationalDataset.h b/src/lib/support/ThreadOperationalDataset.h index e91ad5b6361174..3a2d58cf2675d6 100644 --- a/src/lib/support/ThreadOperationalDataset.h +++ b/src/lib/support/ThreadOperationalDataset.h @@ -113,6 +113,18 @@ class OperationalDataset */ CHIP_ERROR GetExtendedPanId(uint8_t (&aExtendedPanId)[kSizeExtendedPanId]) const; + /** + * This method returns a const ByteSpan to the extended PAN ID in the dataset. + * This can be used to pass the extended PAN ID to a cluster command without the use of external memory. + * + * @param[out] span A reference to receive the location of the extended PAN ID. + * + * @retval CHIP_NO_ERROR Successfully retrieved the extended PAN ID. + * @retval CHIP_ERROR_TLV_TAG_NOT_FOUND Thread extended PAN ID is not present in the dataset. + * + */ + CHIP_ERROR GetExtendedPanIdAsByteSpan(ByteSpan & span) const; + /** * This method sets Thread extended PAN ID to the dataset. * diff --git a/src/lib/support/tests/TestThreadOperationalDataset.cpp b/src/lib/support/tests/TestThreadOperationalDataset.cpp index 7d9552f55f4956..47eb062cf04a23 100644 --- a/src/lib/support/tests/TestThreadOperationalDataset.cpp +++ b/src/lib/support/tests/TestThreadOperationalDataset.cpp @@ -80,6 +80,11 @@ void TestExtendedPanId(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, dataset.SetExtendedPanId(kExtendedPanId) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, dataset.GetExtendedPanId(extendedPanId) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, memcmp(extendedPanId, kExtendedPanId, sizeof(kExtendedPanId)) == 0); + + ByteSpan span; + NL_TEST_ASSERT(inSuite, dataset.GetExtendedPanIdAsByteSpan(span) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, span.size() == sizeof(kExtendedPanId)); + NL_TEST_ASSERT(inSuite, memcmp(extendedPanId, span.data(), sizeof(kExtendedPanId)) == 0); } void TestMasterKey(nlTestSuite * inSuite, void * inContext)