Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OperationalDataset: Add ByteSpan extendedPanID #12304

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/support/ThreadOperationalDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint8_t *>(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));
Expand Down
12 changes: 12 additions & 0 deletions src/lib/support/ThreadOperationalDataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions src/lib/support/tests/TestThreadOperationalDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down