Skip to content

Commit 3243bc3

Browse files
authored
[dataset] introduce AffectsConnectivity() and public API (openthread#13134)
This commit introduces helper methods to `MeshCoP::Dataset` to determine if a given Dataset affects network connectivity or the Network Key. It also adds a corresponding public API `otDatasetAffectsConnectivity()`. A Dataset is considered to affect connectivity if it contains a different Channel, PAN ID, Mesh Local Prefix, or Network Key than the current values in use.
1 parent 597ca44 commit 3243bc3

6 files changed

Lines changed: 116 additions & 40 deletions

File tree

include/openthread/dataset.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ void otDatasetConvertToTlvs(const otOperationalDataset *aDataset, otOperationalD
633633
*/
634634
otError otDatasetUpdateTlvs(const otOperationalDataset *aDataset, otOperationalDatasetTlvs *aDatasetTlvs);
635635

636+
/**
637+
* Indicates whether or not a given Operational Dataset (in TLVs format) affects connectivity.
638+
*
639+
* A Dataset affects connectivity if it contains a different Channel, PAN ID, Mesh Local Prefix, Network Key, or
640+
* Security Policy than the current values in use.
641+
*
642+
* The following security policy changes are considered to affect connectivity:
643+
* - Disabling routers (R bit: 1 to 0).
644+
* - Enabling non-CCM routers (NCR bit: 0 to 1).
645+
* - Increasing the version threshold for routing (VR field).
646+
*
647+
* @param[in] aInstance A pointer to an OpenThread instance.
648+
* @param[in] aDatasetTlvs A pointer to Operational Dataset TLVs.
649+
*
650+
* @returns TRUE if @p aDatasetTlvs affects connectivity, FALSE otherwise.
651+
*/
652+
bool otDatasetAffectsConnectivity(otInstance *aInstance, const otOperationalDatasetTlvs *aDatasetTlvs);
653+
636654
/**
637655
* @}
638656
*/

include/openthread/instance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C" {
5252
*
5353
* @note This number versions both OpenThread platform and user APIs.
5454
*/
55-
#define OPENTHREAD_API_VERSION (598)
55+
#define OPENTHREAD_API_VERSION (599)
5656

5757
/**
5858
* @addtogroup api-instance

src/core/api/dataset_api.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,17 @@ otError otDatasetUpdateTlvs(const otOperationalDataset *aDataset, otOperationalD
228228
exit:
229229
return error;
230230
}
231+
232+
bool otDatasetAffectsConnectivity(otInstance *aInstance, const otOperationalDatasetTlvs *aDatasetTlvs)
233+
{
234+
bool affects = false;
235+
MeshCoP::Dataset dataset;
236+
237+
AssertPointerIsNotNull(aDatasetTlvs);
238+
239+
SuccessOrExit(dataset.SetFrom(*aDatasetTlvs));
240+
affects = dataset.AffectsConnectivity(AsCoreType(aInstance));
241+
242+
exit:
243+
return affects;
244+
}

src/core/meshcop/dataset.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,51 @@ bool Dataset::IsSubsetOf(const Dataset &aOther) const
611611
return isSubset;
612612
}
613613

614+
bool Dataset::AffectsConnectivity(Instance &aInstance) const
615+
{
616+
bool affects = true;
617+
ChannelTlvValue channelValue;
618+
Mac::PanId panId;
619+
Ip6::NetworkPrefix meshLocalPrefix;
620+
621+
if (Read<ChannelTlv>(channelValue) == kErrorNone)
622+
{
623+
VerifyOrExit(channelValue.GetChannel() == aInstance.Get<Mac::Mac>().GetPanChannel());
624+
}
625+
626+
if (Read<PanIdTlv>(panId) == kErrorNone)
627+
{
628+
VerifyOrExit(panId == aInstance.Get<Mac::Mac>().GetPanId());
629+
}
630+
631+
if (Read<MeshLocalPrefixTlv>(meshLocalPrefix) == kErrorNone)
632+
{
633+
VerifyOrExit(meshLocalPrefix == aInstance.Get<Mle::Mle>().GetMeshLocalPrefix());
634+
}
635+
636+
VerifyOrExit(!AffectsNetworkKey(aInstance));
637+
638+
affects = false;
639+
640+
exit:
641+
return affects;
642+
}
643+
644+
bool Dataset::AffectsNetworkKey(Instance &aInstance) const
645+
{
646+
bool affects = false;
647+
NetworkKey networkKey;
648+
NetworkKey localNetworkKey;
649+
650+
SuccessOrExit(Read<NetworkKeyTlv>(networkKey));
651+
652+
aInstance.Get<KeyManager>().GetNetworkKey(localNetworkKey);
653+
affects = (networkKey != localNetworkKey);
654+
655+
exit:
656+
return affects;
657+
}
658+
614659
const char *Dataset::TypeToString(Type aType) { return (aType == kActive) ? "Active" : "Pending"; }
615660

616661
} // namespace MeshCoP

src/core/meshcop/dataset.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,36 @@ class Dataset
655655
*/
656656
bool IsSubsetOf(const Dataset &aOther) const;
657657

658+
/**
659+
* Indicates whether or not the Dataset affects connectivity.
660+
*
661+
* A Dataset affects connectivity if it contains a different Channel, PAN ID, Mesh Local Prefix, Network Key, or
662+
* Security Policy than the current values in use.
663+
*
664+
* The following security policy changes are considered to affect connectivity:
665+
* - Disabling routers (R bit: 1 to 0).
666+
* - Enabling non-CCM routers (NCR bit: 0 to 1).
667+
* - Increasing the version threshold for routing (VR field).
668+
*
669+
* @param[in] aInstance The OpenThread instance.
670+
*
671+
* @retval TRUE The Dataset affects connectivity.
672+
* @retval FALSE The Dataset does not affect connectivity.
673+
*/
674+
bool AffectsConnectivity(Instance &aInstance) const;
675+
676+
/**
677+
* Indicates whether or not the Dataset affects the Network Key.
678+
*
679+
* A Dataset affects the Network Key if it contains a different Network Key than the current value in use.
680+
*
681+
* @param[in] aInstance The OpenThread instance.
682+
*
683+
* @retval TRUE The Dataset affects the Network Key.
684+
* @retval FALSE The Dataset does not affect the Network Key.
685+
*/
686+
bool AffectsNetworkKey(Instance &aInstance) const;
687+
658688
/**
659689
* Converts a Dataset Type to a string.
660690
*

src/core/meshcop/dataset_manager_ftd.cpp

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ Error DatasetManager::ProcessSetOrReplaceRequest(MgmtCommand aCommand,
4949
const Coap::Message &aMessage,
5050
RequestInfo &aInfo) const
5151
{
52-
Error error = kErrorParse;
53-
Dataset dataset;
54-
OffsetRange offsetRange;
55-
Timestamp activeTimestamp;
56-
ChannelTlvValue channelValue;
57-
uint16_t sessionId;
58-
Ip6::NetworkPrefix meshLocalPrefix;
59-
NetworkKey networkKey;
60-
uint16_t panId;
61-
uint32_t delayTimer;
52+
Error error = kErrorParse;
53+
Dataset dataset;
54+
OffsetRange offsetRange;
55+
Timestamp activeTimestamp;
56+
uint16_t sessionId;
57+
uint32_t delayTimer;
6258

6359
aInfo.Clear();
6460

@@ -86,35 +82,8 @@ Error DatasetManager::ProcessSetOrReplaceRequest(MgmtCommand aCommand,
8682
// Determine whether the new Dataset affects connectivity
8783
// or network key.
8884

89-
if ((dataset.Read<ChannelTlv>(channelValue) == kErrorNone) &&
90-
(channelValue.GetChannel() != Get<Mac::Mac>().GetPanChannel()))
91-
{
92-
aInfo.mAffectsConnectivity = true;
93-
}
94-
95-
if ((dataset.Read<PanIdTlv>(panId) == kErrorNone) && (panId != Get<Mac::Mac>().GetPanId()))
96-
{
97-
aInfo.mAffectsConnectivity = true;
98-
}
99-
100-
if ((dataset.Read<MeshLocalPrefixTlv>(meshLocalPrefix) == kErrorNone) &&
101-
(meshLocalPrefix != Get<Mle::Mle>().GetMeshLocalPrefix()))
102-
{
103-
aInfo.mAffectsConnectivity = true;
104-
}
105-
106-
if (dataset.Read<NetworkKeyTlv>(networkKey) == kErrorNone)
107-
{
108-
NetworkKey localNetworkKey;
109-
110-
Get<KeyManager>().GetNetworkKey(localNetworkKey);
111-
112-
if (networkKey != localNetworkKey)
113-
{
114-
aInfo.mAffectsConnectivity = true;
115-
aInfo.mAffectsNetworkKey = true;
116-
}
117-
}
85+
aInfo.mAffectsConnectivity = dataset.AffectsConnectivity(GetInstance());
86+
aInfo.mAffectsNetworkKey = dataset.AffectsNetworkKey(GetInstance());
11887

11988
// Check active timestamp rollback. If there is no change to
12089
// network key, active timestamp must be ahead of local value.

0 commit comments

Comments
 (0)