• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  *   This file includes definitions for MLE types and constants.
32  */
33 
34 #ifndef MLE_TYPES_HPP_
35 #define MLE_TYPES_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <limits.h>
40 #include <stdint.h>
41 #include <string.h>
42 
43 #include <openthread/thread.h>
44 
45 #include "common/as_core_type.hpp"
46 #include "common/clearable.hpp"
47 #include "common/code_utils.hpp"
48 #include "common/encoding.hpp"
49 #include "common/equatable.hpp"
50 #include "common/string.hpp"
51 #include "mac/mac_types.hpp"
52 #include "meshcop/extended_panid.hpp"
53 #include "net/ip6_address.hpp"
54 #include "thread/network_data_types.hpp"
55 
56 namespace ot {
57 namespace Mle {
58 
59 /**
60  * @addtogroup core-mle-core
61  *
62  * @brief
63  *   This module includes definition for MLE types and constants.
64  *
65  * @{
66  *
67  */
68 
69 constexpr uint16_t kMaxChildren               = OPENTHREAD_CONFIG_MLE_MAX_CHILDREN;
70 constexpr uint8_t  kMaxChildKeepAliveAttempts = 4; ///< Max keep alive attempts before reattach to a new Parent.
71 constexpr uint8_t  kFailedChildTransmissions  = OPENTHREAD_CONFIG_FAILED_CHILD_TRANSMISSIONS;
72 
73 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
74 // Extra one for core Backbone Router Service.
75 constexpr uint8_t kMaxServiceAlocs = OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_MAX_ALOCS + 1;
76 #else
77 constexpr uint8_t  kMaxServiceAlocs      = OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_MAX_ALOCS;
78 #endif
79 
80 constexpr uint8_t  kThreadVersion = OPENTHREAD_CONFIG_THREAD_VERSION; ///< Thread Version
81 constexpr uint16_t kUdpPort       = 19788;                            ///< MLE UDP Port
82 
83 /*
84  * MLE Protocol delays and timeouts.
85  *
86  */
87 constexpr uint32_t kParentRequestRouterTimeout     = 750;  ///< Router Parent Request timeout (in msec)
88 constexpr uint32_t kParentRequestDuplicateMargin   = 50;   ///< Margin for duplicate parent request
89 constexpr uint32_t kParentRequestReedTimeout       = 1250; ///< Router and REEDs Parent Request timeout (in msec)
90 constexpr uint32_t kAttachStartJitter              = 50;   ///< Max jitter time added to start of attach (in msec)
91 constexpr uint32_t kAnnounceProcessTimeout         = 250;  ///< Delay after Announce rx before channel/pan-id change
92 constexpr uint32_t kAnnounceTimeout                = 1400; ///< Total timeout for sending Announce messages (in msec)
93 constexpr uint32_t kMinAnnounceDelay               = 80;   ///< Min delay between Announcement messages (in msec)
94 constexpr uint32_t kParentResponseMaxDelayRouters  = 500;  ///< Max response delay for Parent Req to routers (in msec)
95 constexpr uint32_t kParentResponseMaxDelayAll      = 1000; ///< Max response delay for Parent Req to all (in msec)
96 constexpr uint32_t kUnicastRetransmissionDelay     = 1000; ///< Base delay before an MLE unicast retx (in msec)
97 constexpr uint32_t kChildUpdateRequestPendingDelay = 100;  ///< Delay for aggregating Child Update Req (in msec)
98 constexpr uint8_t  kMaxTransmissionCount           = 3;    ///< Max number of times an MLE message may be transmitted
99 constexpr uint32_t kMaxResponseDelay               = 1000; ///< Max response delay for a multicast request (in msec)
100 constexpr uint32_t kMaxChildIdRequestTimeout       = 5000; ///< Max delay to rx a Child ID Request (in msec)
101 constexpr uint32_t kMaxChildUpdateResponseTimeout  = 2000; ///< Max delay to rx a Child Update Response (in msec)
102 constexpr uint32_t kMaxLinkRequestTimeout          = 2000; ///< Max delay to rx a Link Accept
103 constexpr uint8_t  kMulticastLinkRequestDelay      = 5;    ///< Max delay for sending a mcast Link Request (in sec)
104 
105 constexpr uint32_t kMinTimeoutKeepAlive = (((kMaxChildKeepAliveAttempts + 1) * kUnicastRetransmissionDelay) / 1000);
106 constexpr uint32_t kMinPollPeriod       = OPENTHREAD_CONFIG_MAC_MINIMUM_POLL_PERIOD;
107 constexpr uint32_t kRetxPollPeriod      = OPENTHREAD_CONFIG_MAC_RETX_POLL_PERIOD;
108 constexpr uint32_t kMinTimeoutDataPoll  = (kMinPollPeriod + kFailedChildTransmissions * kRetxPollPeriod) / 1000;
109 constexpr uint32_t kMinTimeout          = OT_MAX(kMinTimeoutKeepAlive, kMinTimeoutDataPoll); ///< Min timeout (in sec)
110 
111 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
112 constexpr uint8_t kLinkAcceptMaxRouters = 3; ///< Max Route TLV entries in a Link Accept message
113 #else
114 constexpr uint8_t  kLinkAcceptMaxRouters = 20; ///< Max Route TLV entries in a Link Accept message
115 #endif
116 constexpr uint8_t kLinkAcceptSequenceRollback = 64; ///< Route Sequence value rollback in a Link Accept message.
117 
118 constexpr uint16_t kMinChildId = 1;   ///< Minimum Child ID
119 constexpr uint16_t kMaxChildId = 511; ///< Maximum Child ID
120 
121 constexpr uint8_t kRouterIdOffset   = 10; ///< Bit offset of Router ID in RLOC16
122 constexpr uint8_t kRlocPrefixLength = 14; ///< Prefix length of RLOC in bytes
123 
124 constexpr uint8_t kMinChallengeSize = 4; ///< Minimum Challenge size in bytes.
125 constexpr uint8_t kMaxChallengeSize = 8; ///< Maximum Challenge size in bytes.
126 
127 /*
128  * Routing Protocol Constants
129  *
130  */
131 constexpr uint32_t kAdvertiseIntervalMin = 1; ///< Min Advertise interval (in sec)
132 #if OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE
133 constexpr uint32_t kAdvertiseIntervalMax = 5; ///< Max Advertise interval (in sec)
134 #else
135 constexpr uint32_t kAdvertiseIntervalMax = 32; ///< Max Advertise interval (in sec)
136 #endif
137 
138 constexpr uint8_t kFailedRouterTransmissions = 4;
139 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
140 constexpr uint8_t kFailedCslDataPollTransmissions = 15;
141 #endif
142 
143 constexpr uint8_t  kRouterIdReuseDelay     = 100; ///< (in sec)
144 constexpr uint32_t kRouterIdSequencePeriod = 10;  ///< (in sec)
145 constexpr uint32_t kMaxNeighborAge         = 100; ///< (in sec)
146 
147 #if OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE
148 constexpr uint8_t kMaxRouteCost = 127;
149 #else
150 constexpr uint8_t  kMaxRouteCost         = 16;
151 #endif
152 
153 constexpr uint8_t kMaxRouterId           = OT_NETWORK_MAX_ROUTER_ID; ///< Max Router ID
154 constexpr uint8_t kInvalidRouterId       = kMaxRouterId + 1;         ///< Value indicating incorrect Router ID
155 constexpr uint8_t kMaxRouters            = OPENTHREAD_CONFIG_MLE_MAX_ROUTERS;
156 constexpr uint8_t kMinDowngradeNeighbors = 7;
157 
158 constexpr uint8_t kNetworkIdTimeout           = 120; ///< (in sec)
159 constexpr uint8_t kParentRouteToLeaderTimeout = 20;  ///< (in sec)
160 constexpr uint8_t kRouterSelectionJitter      = 120; ///< (in sec)
161 
162 constexpr uint8_t kRouterDowngradeThreshold = 23;
163 constexpr uint8_t kRouterUpgradeThreshold   = 16;
164 
165 /**
166  * Threshold to accept a router upgrade request with reason `kBorderRouterRequest` (number of BRs acting as router in
167  * Network Data).
168  *
169  */
170 constexpr uint8_t kRouterUpgradeBorderRouterRequestThreshold = 2;
171 
172 constexpr uint32_t kMaxLeaderToRouterTimeout = 90;  ///< (in sec)
173 constexpr uint32_t kReedAdvertiseInterval    = 570; ///< (in sec)
174 constexpr uint32_t kReedAdvertiseJitter      = 60;  ///< (in sec)
175 
176 constexpr uint8_t  kLeaderWeight             = 64;                                          ///< Default leader weight
177 constexpr uint32_t kMleEndDeviceTimeout      = OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT; ///< (in sec)
178 constexpr uint8_t  kMeshLocalPrefixContextId = 0; ///< 0 is reserved for Mesh Local Prefix
179 
180 constexpr int8_t kParentPriorityHigh        = 1;  ///< Parent Priority High
181 constexpr int8_t kParentPriorityMedium      = 0;  ///< Parent Priority Medium (default)
182 constexpr int8_t kParentPriorityLow         = -1; ///< Parent Priority Low
183 constexpr int8_t kParentPriorityUnspecified = -2; ///< Parent Priority Unspecified
184 
185 constexpr uint8_t kLinkQuality3LinkCost = 1;             ///< Link Cost for Link Quality 3
186 constexpr uint8_t kLinkQuality2LinkCost = 2;             ///< Link Cost for Link Quality 2
187 constexpr uint8_t kLinkQuality1LinkCost = 4;             ///< Link Cost for Link Quality 1
188 constexpr uint8_t kLinkQuality0LinkCost = kMaxRouteCost; ///< Link Cost for Link Quality 0
189 
190 constexpr uint8_t kMplChildDataMessageTimerExpirations  = 0; ///< Number of MPL retransmissions for Children.
191 constexpr uint8_t kMplRouterDataMessageTimerExpirations = 2; ///< Number of MPL retransmissions for Routers.
192 
193 /**
194  * This type represents a Thread device role.
195  *
196  */
197 enum DeviceRole : uint8_t
198 {
199     kRoleDisabled = OT_DEVICE_ROLE_DISABLED, ///< The Thread stack is disabled.
200     kRoleDetached = OT_DEVICE_ROLE_DETACHED, ///< Not currently participating in a Thread network/partition.
201     kRoleChild    = OT_DEVICE_ROLE_CHILD,    ///< The Thread Child role.
202     kRoleRouter   = OT_DEVICE_ROLE_ROUTER,   ///< The Thread Router role.
203     kRoleLeader   = OT_DEVICE_ROLE_LEADER,   ///< The Thread Leader role.
204 };
205 
206 constexpr uint16_t kAloc16Leader                      = 0xfc00;
207 constexpr uint16_t kAloc16DhcpAgentStart              = 0xfc01;
208 constexpr uint16_t kAloc16DhcpAgentEnd                = 0xfc0f;
209 constexpr uint16_t kAloc16ServiceStart                = 0xfc10;
210 constexpr uint16_t kAloc16ServiceEnd                  = 0xfc2f;
211 constexpr uint16_t kAloc16CommissionerStart           = 0xfc30;
212 constexpr uint16_t kAloc16CommissionerEnd             = 0xfc37;
213 constexpr uint16_t kAloc16BackboneRouterPrimary       = 0xfc38;
214 constexpr uint16_t kAloc16CommissionerMask            = 0x0007;
215 constexpr uint16_t kAloc16NeighborDiscoveryAgentStart = 0xfc40;
216 constexpr uint16_t kAloc16NeighborDiscoveryAgentEnd   = 0xfc4e;
217 
218 constexpr uint8_t kServiceMinId = 0x00; ///< Minimal Service ID.
219 constexpr uint8_t kServiceMaxId = 0x0f; ///< Maximal Service ID.
220 
221 /**
222  * This enumeration specifies the leader role start mode.
223  *
224  * The start mode indicates whether device is starting normally as leader or restoring its role after reset.
225  *
226  */
227 enum LeaderStartMode : uint8_t
228 {
229     kStartingAsLeader,              ///< Starting as leader normally.
230     kRestoringLeaderRoleAfterReset, ///< Restoring leader role after reset.
231 };
232 
233 #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
234 
235 /*
236  * Backbone Router / DUA / MLR constants
237  *
238  */
239 constexpr uint16_t kRegistrationDelayDefault         = 1200;              ///< In seconds.
240 constexpr uint32_t kMlrTimeoutDefault                = 3600;              ///< In seconds.
241 constexpr uint32_t kMlrTimeoutMin                    = 300;               ///< In seconds.
242 constexpr uint32_t kMlrTimeoutMax                    = 0x7fffffff / 1000; ///< In seconds (about 24 days).
243 constexpr uint8_t  kBackboneRouterRegistrationJitter = 5;                 ///< In seconds.
244 constexpr uint8_t  kParentAggregateDelay             = 5;                 ///< In seconds.
245 constexpr uint8_t  kNoBufDelay                       = 5;                 ///< In seconds.
246 constexpr uint8_t  kImmediateReRegisterDelay         = 1;                 ///< In seconds.
247 constexpr uint8_t  KResponseTimeoutDelay             = 30;                ///< In seconds.
248 
249 /**
250  * Time period after which the address becomes "Preferred" if no duplicate address error (in seconds).
251  *
252  */
253 constexpr uint32_t kDuaDadPeriod = 100;
254 
255 /**
256  * Maximum number of times the multicast DAD query and wait time DUA_DAD_QUERY_TIMEOUT are repeated by the BBR, as
257  * part of the DAD process.
258  *
259  */
260 constexpr uint8_t kDuaDadRepeats = 3;
261 
262 /**
263  * Time period (in seconds) during which a DUA registration is considered 'recent' at a BBR.
264  *
265  */
266 constexpr uint32_t kDuaRecentTime               = 20;
267 constexpr uint32_t kTimeSinceLastTransactionMax = 10 * 86400; ///< In seconds (10 days).
268 constexpr uint8_t  kDefaultBackboneHoplimit     = 1;          ///< default hoplimit for Backbone Link Protocol messages
269 
270 static_assert(kMlrTimeoutDefault >= kMlrTimeoutMin && kMlrTimeoutDefault <= kMlrTimeoutMax,
271               "kMlrTimeoutDefault must be larger than or equal to kMlrTimeoutMin");
272 
273 static_assert(Mle::kParentAggregateDelay > 1, "kParentAggregateDelay should be larger than 1 second");
274 static_assert(kMlrTimeoutMax * 1000 > kMlrTimeoutMax, "SecToMsec(kMlrTimeoutMax) will overflow");
275 
276 static_assert(kTimeSinceLastTransactionMax * 1000 > kTimeSinceLastTransactionMax,
277               "SecToMsec(kTimeSinceLastTransactionMax) will overflow");
278 
279 /**
280  * State change of Child's DUA
281  *
282  */
283 enum class ChildDuaState : uint8_t
284 {
285     kAdded,     ///< A new DUA registered by the Child via Address Registration.
286     kChanged,   ///< A different DUA registered by the Child via Address Registration.
287     kRemoved,   ///< DUA registered by the Child is removed and not in Address Registration.
288     kUnchanged, ///< The Child registers the same DUA again.
289 };
290 
291 #endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
292 
293 /**
294  * This type represents a MLE device mode.
295  *
296  */
297 class DeviceMode : public Equatable<DeviceMode>
298 {
299 public:
300     static constexpr uint8_t kModeRxOnWhenIdle     = 1 << 3; ///< If to keep receiver on when not transmitting.
301     static constexpr uint8_t kModeReserved         = 1 << 2; ///< Set on transmission, ignore on reception.
302     static constexpr uint8_t kModeFullThreadDevice = 1 << 1; ///< If the device is an FTD.
303     static constexpr uint8_t kModeFullNetworkData  = 1 << 0; ///< If the device requires the full Network Data.
304 
305     static constexpr uint16_t kInfoStringSize = 45; ///< String buffer size used for `ToString()`.
306 
307     /**
308      * This type defines the fixed-length `String` object returned from `ToString()`.
309      *
310      */
311     typedef String<kInfoStringSize> InfoString;
312 
313     /**
314      *  This structure represents an MLE Mode configuration.
315      *
316      */
317     typedef otLinkModeConfig ModeConfig;
318 
319     /**
320      * This is the default constructor for `DeviceMode` object.
321      *
322      */
323     DeviceMode(void) = default;
324 
325     /**
326      * This constructor initializes a `DeviceMode` object from a given mode TLV bitmask.
327      *
328      * @param[in] aMode   A mode TLV bitmask to initialize the `DeviceMode` object.
329      *
330      */
DeviceMode(uint8_t aMode)331     explicit DeviceMode(uint8_t aMode) { Set(aMode); }
332 
333     /**
334      * This constructor initializes a `DeviceMode` object from a given mode configuration structure.
335      *
336      * @param[in] aModeConfig   A mode configuration to initialize the `DeviceMode` object.
337      *
338      */
DeviceMode(ModeConfig aModeConfig)339     explicit DeviceMode(ModeConfig aModeConfig) { Set(aModeConfig); }
340 
341     /**
342      * This method gets the device mode as a mode TLV bitmask.
343      *
344      * @returns The device mode as a mode TLV bitmask.
345      *
346      */
Get(void) const347     uint8_t Get(void) const { return mMode; }
348 
349     /**
350      * This method sets the device mode from a given mode TLV bitmask.
351      *
352      * @param[in] aMode   A mode TLV bitmask.
353      *
354      */
Set(uint8_t aMode)355     void Set(uint8_t aMode) { mMode = aMode | kModeReserved; }
356 
357     /**
358      * This method gets the device mode as a mode configuration structure.
359      *
360      * @param[out] aModeConfig   A reference to a mode configuration structure to output the device mode.
361      *
362      */
363     void Get(ModeConfig &aModeConfig) const;
364 
365     /**
366      * this method sets the device mode from a given mode configuration structure.
367      *
368      * @param[in] aModeConfig   A mode configuration structure.
369      *
370      */
371     void Set(const ModeConfig &aModeConfig);
372 
373     /**
374      * This method indicates whether or not the device is rx-on-when-idle.
375      *
376      * @retval TRUE   If the device is rx-on-when-idle (non-sleepy).
377      * @retval FALSE  If the device is not rx-on-when-idle (sleepy).
378      *
379      */
IsRxOnWhenIdle(void) const380     bool IsRxOnWhenIdle(void) const { return (mMode & kModeRxOnWhenIdle) != 0; }
381 
382     /**
383      * This method indicates whether or not the device is a Full Thread Device.
384      *
385      * @retval TRUE   If the device is Full Thread Device.
386      * @retval FALSE  If the device if not Full Thread Device.
387      *
388      */
IsFullThreadDevice(void) const389     bool IsFullThreadDevice(void) const { return (mMode & kModeFullThreadDevice) != 0; }
390 
391     /**
392      * This method gets the Network Data type (full set or stable subset) that the device requests.
393      *
394      * @returns The Network Data type requested by this device.
395      *
396      */
GetNetworkDataType(void) const397     NetworkData::Type GetNetworkDataType(void) const
398     {
399         return (mMode & kModeFullNetworkData) ? NetworkData::kFullSet : NetworkData::kStableSubset;
400     }
401 
402     /**
403      * This method indicates whether or not the device is a Minimal End Device.
404      *
405      * @retval TRUE   If the device is a Minimal End Device.
406      * @retval FALSE  If the device is not a Minimal End Device.
407      *
408      */
IsMinimalEndDevice(void) const409     bool IsMinimalEndDevice(void) const
410     {
411         return (mMode & (kModeFullThreadDevice | kModeRxOnWhenIdle)) != (kModeFullThreadDevice | kModeRxOnWhenIdle);
412     }
413 
414     /**
415      * This method indicates whether or not the device mode flags are valid.
416      *
417      * An FTD which is not rx-on-when-idle (is sleepy) is considered invalid.
418      *
419      * @returns TRUE if , FALSE otherwise.
420      * @retval TRUE   If the device mode flags are valid.
421      * @retval FALSE  If the device mode flags are not valid.
422      *
423      */
IsValid(void) const424     bool IsValid(void) const { return !IsFullThreadDevice() || IsRxOnWhenIdle(); }
425 
426     /**
427      * This method converts the device mode into a human-readable string.
428      *
429      * @returns An `InfoString` object representing the device mode.
430      *
431      */
432     InfoString ToString(void) const;
433 
434 private:
435     uint8_t mMode;
436 };
437 
438 /**
439  * This class represents the Thread Leader Data.
440  *
441  */
442 class LeaderData : public otLeaderData, public Clearable<LeaderData>
443 {
444 public:
445     /**
446      * This method returns the Partition ID value.
447      *
448      * @returns The Partition ID value.
449      *
450      */
GetPartitionId(void) const451     uint32_t GetPartitionId(void) const { return mPartitionId; }
452 
453     /**
454      * This method sets the Partition ID value.
455      *
456      * @param[in]  aPartitionId  The Partition ID value.
457      *
458      */
SetPartitionId(uint32_t aPartitionId)459     void SetPartitionId(uint32_t aPartitionId) { mPartitionId = aPartitionId; }
460 
461     /**
462      * This method returns the Weighting value.
463      *
464      * @returns The Weighting value.
465      *
466      */
GetWeighting(void) const467     uint8_t GetWeighting(void) const { return mWeighting; }
468 
469     /**
470      * This method sets the Weighting value.
471      *
472      * @param[in]  aWeighting  The Weighting value.
473      *
474      */
SetWeighting(uint8_t aWeighting)475     void SetWeighting(uint8_t aWeighting) { mWeighting = aWeighting; }
476 
477     /**
478      * This method returns the Data Version value for a type (full set or stable subset).
479      *
480      * @param[in] aType   The Network Data type (full set or stable subset).
481      *
482      * @returns The Data Version value for @p aType.
483      *
484      */
GetDataVersion(NetworkData::Type aType) const485     uint8_t GetDataVersion(NetworkData::Type aType) const
486     {
487         return (aType == NetworkData::kFullSet) ? mDataVersion : mStableDataVersion;
488     }
489 
490     /**
491      * This method sets the Data Version value.
492      *
493      * @param[in]  aVersion  The Data Version value.
494      *
495      */
SetDataVersion(uint8_t aVersion)496     void SetDataVersion(uint8_t aVersion) { mDataVersion = aVersion; }
497 
498     /**
499      * This method sets the Stable Data Version value.
500      *
501      * @param[in]  aVersion  The Stable Data Version value.
502      *
503      */
SetStableDataVersion(uint8_t aVersion)504     void SetStableDataVersion(uint8_t aVersion) { mStableDataVersion = aVersion; }
505 
506     /**
507      * This method returns the Leader Router ID value.
508      *
509      * @returns The Leader Router ID value.
510      *
511      */
GetLeaderRouterId(void) const512     uint8_t GetLeaderRouterId(void) const { return mLeaderRouterId; }
513 
514     /**
515      * This method sets the Leader Router ID value.
516      *
517      * @param[in]  aRouterId  The Leader Router ID value.
518      *
519      */
SetLeaderRouterId(uint8_t aRouterId)520     void SetLeaderRouterId(uint8_t aRouterId) { mLeaderRouterId = aRouterId; }
521 };
522 
523 OT_TOOL_PACKED_BEGIN
524 class RouterIdSet : public Equatable<RouterIdSet>
525 {
526 public:
527     /**
528      * This method clears the Router Id Set.
529      *
530      */
Clear(void)531     void Clear(void) { memset(mRouterIdSet, 0, sizeof(mRouterIdSet)); }
532 
533     /**
534      * This method indicates whether or not a Router ID bit is set.
535      *
536      * @param[in]  aRouterId  The Router ID.
537      *
538      * @retval TRUE   If the Router ID bit is set.
539      * @retval FALSE  If the Router ID bit is not set.
540      *
541      */
Contains(uint8_t aRouterId) const542     bool Contains(uint8_t aRouterId) const { return (mRouterIdSet[aRouterId / 8] & (0x80 >> (aRouterId % 8))) != 0; }
543 
544     /**
545      * This method sets a given Router ID.
546      *
547      * @param[in]  aRouterId  The Router ID to set.
548      *
549      */
Add(uint8_t aRouterId)550     void Add(uint8_t aRouterId) { mRouterIdSet[aRouterId / 8] |= 0x80 >> (aRouterId % 8); }
551 
552     /**
553      * This method removes a given Router ID.
554      *
555      * @param[in]  aRouterId  The Router ID to remove.
556      *
557      */
Remove(uint8_t aRouterId)558     void Remove(uint8_t aRouterId) { mRouterIdSet[aRouterId / 8] &= ~(0x80 >> (aRouterId % 8)); }
559 
560 private:
561     uint8_t mRouterIdSet[BitVectorBytes(Mle::kMaxRouterId + 1)];
562 } OT_TOOL_PACKED_END;
563 
564 /**
565  * This class represents a MLE Key Material
566  *
567  */
568 typedef Mac::KeyMaterial KeyMaterial;
569 
570 /**
571  * This class represents a MLE Key.
572  *
573  */
574 typedef Mac::Key Key;
575 
576 /**
577  * @}
578  *
579  */
580 
581 } // namespace Mle
582 
583 DefineCoreType(otLeaderData, Mle::LeaderData);
584 DefineMapEnum(otDeviceRole, Mle::DeviceRole);
585 
586 } // namespace ot
587 
588 #endif // MLE_TYPES_HPP_
589