mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 23:57:47 +00:00
[dataset] add API to create new dataset for forming a network (#3825)
This commit is contained in:
committed by
Jonathan Hui
parent
73fea7a02c
commit
934efbdf69
@@ -1414,6 +1414,20 @@ otDatasetSetDelayTimerMinimal(
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
OTAPI
|
||||
otError
|
||||
OTCALL
|
||||
otDatasetCreateNewNetwork(
|
||||
_In_ otInstance *aInstance,
|
||||
_Out_ otOperationalDataset *aDataset
|
||||
)
|
||||
{
|
||||
if (aInstance == nullptr) return OT_ERROR_INVALID_ARGS;
|
||||
// TODO
|
||||
UNREFERENCED_PARAMETER(aDataset);
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
OTAPI
|
||||
uint32_t
|
||||
OTCALL
|
||||
|
||||
@@ -49,6 +49,18 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method creates a new Operational Dataset to use when forming a new network.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[out] aDataset The Operational Dataset.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully created a new Operational Dataset.
|
||||
* @retval OT_ERROR_FAILED Failed to generate random values for new parameters.
|
||||
*
|
||||
*/
|
||||
OTAPI otError OTCALL otDatasetCreateNewNetwork(otInstance *aInstance, otOperationalDataset *aDataset);
|
||||
|
||||
/**
|
||||
* Get minimal delay timer.
|
||||
*
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "utils/wrap_string.h"
|
||||
|
||||
#include <openthread/dataset.h>
|
||||
#include <openthread/dataset_ftd.h>
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "cli/cli_server.hpp"
|
||||
@@ -230,6 +231,12 @@ otError Dataset::ProcessInit(int argc, char *argv[])
|
||||
{
|
||||
SuccessOrExit(error = otDatasetGetPending(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
else if (strcmp(argv[0], "new") == 0)
|
||||
{
|
||||
SuccessOrExit(error = otDatasetCreateNewNetwork(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
|
||||
using namespace ot;
|
||||
|
||||
otError otDatasetCreateNewNetwork(otInstance *aInstance, otOperationalDataset *aDataset)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<MeshCoP::ActiveDataset>().CreateNewNetwork(*aDataset);
|
||||
}
|
||||
|
||||
uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
@@ -365,6 +365,17 @@ public:
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
|
||||
/**
|
||||
* This method creates a new Operational Dataset to use when forming a new network.
|
||||
*
|
||||
* @param[out] aDataset The Operational Dataset.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully created a new Operational Dataset.
|
||||
* @retval OT_ERROR_FAILED Failed to generate random values for new parameters.
|
||||
*
|
||||
*/
|
||||
otError CreateNewNetwork(otOperationalDataset &aDataset);
|
||||
|
||||
/**
|
||||
* This method starts the Leader functions for maintaining the Active Operational Dataset.
|
||||
*
|
||||
|
||||
@@ -317,6 +317,47 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
otError ActiveDataset::CreateNewNetwork(otOperationalDataset &aDataset)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
memset(&aDataset, 0, sizeof(aDataset));
|
||||
|
||||
aDataset.mActiveTimestamp = 1;
|
||||
|
||||
SuccessOrExit(error = otPlatRandomGetTrue(aDataset.mMasterKey.m8, sizeof(aDataset.mMasterKey)));
|
||||
SuccessOrExit(error = otPlatRandomGetTrue(aDataset.mPSKc.m8, sizeof(aDataset.mPSKc)));
|
||||
SuccessOrExit(error = otPlatRandomGetTrue(aDataset.mExtendedPanId.m8, sizeof(aDataset.mExtendedPanId)));
|
||||
|
||||
aDataset.mMeshLocalPrefix.m8[0] = 0xfd;
|
||||
SuccessOrExit(error = otPlatRandomGetTrue(&aDataset.mMeshLocalPrefix.m8[1], OT_MESH_LOCAL_PREFIX_SIZE - 1));
|
||||
|
||||
aDataset.mSecurityPolicy.mFlags = Get<KeyManager>().GetSecurityPolicyFlags();
|
||||
aDataset.mChannelMask = Get<Mac::Mac>().GetSupportedChannelMask().GetMask();
|
||||
aDataset.mChannel = Get<Mac::Mac>().GetSupportedChannelMask().ChooseRandomChannel();
|
||||
|
||||
do
|
||||
{
|
||||
aDataset.mPanId = Random::GetUint16();
|
||||
} while (aDataset.mPanId == Mac::kPanIdBroadcast);
|
||||
|
||||
snprintf(aDataset.mNetworkName.m8, sizeof(aDataset.mNetworkName), "OpenThread-%04x", aDataset.mPanId);
|
||||
|
||||
aDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
aDataset.mComponents.mIsMasterKeyPresent = true;
|
||||
aDataset.mComponents.mIsNetworkNamePresent = true;
|
||||
aDataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
aDataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
aDataset.mComponents.mIsPanIdPresent = true;
|
||||
aDataset.mComponents.mIsChannelPresent = true;
|
||||
aDataset.mComponents.mIsPSKcPresent = true;
|
||||
aDataset.mComponents.mIsSecurityPolicyPresent = true;
|
||||
aDataset.mComponents.mIsChannelMaskPresent = true;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
Reference in New Issue
Block a user