mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 06:07:48 +00:00
[dataset] choose a preferred channel when forming new dataset (#3910)
This commit changes the `ActiveDataset::CreateNewNetwork()` to select a random channel from the preferred channel mask if it is not empty, otherwise a random channel from the supported mask is picked.
This commit is contained in:
committed by
Jonathan Hui
parent
d614d4a080
commit
dbc04a8a05
@@ -317,7 +317,9 @@ exit:
|
||||
|
||||
otError ActiveDataset::CreateNewNetwork(otOperationalDataset &aDataset)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otError error = OT_ERROR_NONE;
|
||||
Mac::ChannelMask supportedChannels = Get<Mac::Mac>().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<KeyManager>().GetSecurityPolicyFlags();
|
||||
aDataset.mChannelMask = Get<Mac::Mac>().GetSupportedChannelMask().GetMask();
|
||||
aDataset.mChannel = Get<Mac::Mac>().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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user