diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 9db0f6a0a..815293248 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -317,7 +317,9 @@ exit: otError ActiveDataset::CreateNewNetwork(otOperationalDataset &aDataset) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; + Mac::ChannelMask supportedChannels = Get().GetSupportedChannelMask(); + Mac::ChannelMask preferredChannels(otPlatRadioGetPreferredChannelMask(&GetInstance())); memset(&aDataset, 0, sizeof(aDataset)); @@ -331,8 +333,20 @@ otError ActiveDataset::CreateNewNetwork(otOperationalDataset &aDataset) SuccessOrExit(error = Random::Crypto::FillBuffer(&aDataset.mMeshLocalPrefix.m8[1], OT_MESH_LOCAL_PREFIX_SIZE - 1)); aDataset.mSecurityPolicy.mFlags = Get().GetSecurityPolicyFlags(); - aDataset.mChannelMask = Get().GetSupportedChannelMask().GetMask(); - aDataset.mChannel = Get().GetSupportedChannelMask().ChooseRandomChannel(); + + // If the preferred channel mask is not empty, select a random + // channel from it, otherwise choose one from the supported + // channel mask. + + preferredChannels.Intersect(supportedChannels); + + if (preferredChannels.IsEmpty()) + { + preferredChannels = supportedChannels; + } + + aDataset.mChannel = preferredChannels.ChooseRandomChannel(); + aDataset.mChannelMask = supportedChannels.GetMask(); do {