[dataset] GenerateRandom() to build network name using StringWriter (#10007)

This commit is contained in:
Abtin Keshavarzian
2024-04-09 17:05:04 -07:00
committed by GitHub
parent bf41332061
commit 51b94bb879
+2 -1
View File
@@ -56,6 +56,7 @@ Error Dataset::Info::GenerateRandom(Instance &aInstance)
Error error;
Mac::ChannelMask supportedChannels = aInstance.Get<Mac::Mac>().GetSupportedChannelMask();
Mac::ChannelMask preferredChannels(aInstance.Get<Radio>().GetPreferredChannelMask());
StringWriter nameWriter(mNetworkName.m8, sizeof(mNetworkName));
// If the preferred channel mask is not empty, select a random
// channel from it, otherwise choose one from the supported
@@ -83,7 +84,7 @@ Error Dataset::Info::GenerateRandom(Instance &aInstance)
SuccessOrExit(error = Random::Crypto::Fill(mExtendedPanId));
SuccessOrExit(error = AsCoreType(&mMeshLocalPrefix).GenerateRandomUla());
snprintf(mNetworkName.m8, sizeof(mNetworkName), "%s-%04x", NetworkName::kNetworkNameInit, mPanId);
nameWriter.Append("%s-%04x", NetworkName::kNetworkNameInit, mPanId);
mComponents.mIsActiveTimestampPresent = true;
mComponents.mIsNetworkKeyPresent = true;