From c870536c5b7d9991f222a38a4d430a070c8ceb18 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Thu, 23 Jul 2020 03:47:16 +0800 Subject: [PATCH] [OpenThread] Add missing SetThreadProvision implementation on RTOS (#1679) --- ...nericThreadStackManagerImpl_OpenThread.ipp | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp index 272dbafa378f44..eaad08c5bb726e 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,57 @@ exit: return MapOpenThreadError(otErr); } +template +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadProvision(const DeviceNetworkInfo & netInfo) +{ + otError otErr = OT_ERROR_FAILED; + otOperationalDataset newDataset; + + // Form a Thread operational dataset from the given network parameters. + memset(&newDataset, 0, sizeof(newDataset)); + newDataset.mComponents.mIsActiveTimestampPresent = true; + newDataset.mComponents.mIsPendingTimestampPresent = true; + if (netInfo.ThreadNetworkName[0] != 0) + { + strncpy((char *) newDataset.mNetworkName.m8, netInfo.ThreadNetworkName, sizeof(newDataset.mNetworkName.m8)); + newDataset.mComponents.mIsNetworkNamePresent = true; + } + if (netInfo.FieldPresent.ThreadExtendedPANId) + { + memcpy(newDataset.mExtendedPanId.m8, netInfo.ThreadExtendedPANId, sizeof(newDataset.mExtendedPanId.m8)); + newDataset.mComponents.mIsExtendedPanIdPresent = true; + } + if (netInfo.FieldPresent.ThreadMeshPrefix) + { + memcpy(newDataset.mMeshLocalPrefix.m8, netInfo.ThreadMeshPrefix, sizeof(newDataset.mMeshLocalPrefix.m8)); + newDataset.mComponents.mIsMeshLocalPrefixPresent = true; + } + memcpy(newDataset.mMasterKey.m8, netInfo.ThreadNetworkKey, sizeof(newDataset.mMasterKey.m8)); + newDataset.mComponents.mIsMasterKeyPresent = true; + if (netInfo.FieldPresent.ThreadPSKc) + { + memcpy(newDataset.mPskc.m8, netInfo.ThreadPSKc, sizeof(newDataset.mPskc.m8)); + newDataset.mComponents.mIsPskcPresent = true; + } + if (netInfo.ThreadPANId != kThreadPANId_NotSpecified) + { + newDataset.mPanId = netInfo.ThreadPANId; + newDataset.mComponents.mIsPanIdPresent = true; + } + if (netInfo.ThreadChannel != kThreadChannel_NotSpecified) + { + newDataset.mChannel = netInfo.ThreadChannel; + newDataset.mComponents.mIsChannelPresent = true; + } + + // Set the dataset as the active dataset for the node. + Impl()->LockThreadStack(); + otErr = otDatasetSetActive(mOTInst, &newDataset); + Impl()->UnlockThreadStack(); + + return MapOpenThreadError(otErr); +} + template bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned(void) {