1 /* 2 * Copyright (c) 2016, 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 generating and processing MLE TLVs. 32 */ 33 34 #ifndef MLE_TLVS_HPP_ 35 #define MLE_TLVS_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include "common/encoding.hpp" 40 #include "common/message.hpp" 41 #include "common/tlvs.hpp" 42 #include "meshcop/timestamp.hpp" 43 #include "net/ip6_address.hpp" 44 #include "thread/link_metrics_tlvs.hpp" 45 #include "thread/mle_types.hpp" 46 47 namespace ot { 48 49 namespace Mle { 50 51 using ot::Encoding::BigEndian::HostSwap16; 52 using ot::Encoding::BigEndian::HostSwap32; 53 54 /** 55 * @addtogroup core-mle-tlvs 56 * 57 * @brief 58 * This module includes definitions for generating and processing MLE TLVs. 59 * 60 * @{ 61 * 62 */ 63 64 /** 65 * This class implements MLE TLV generation and parsing. 66 * 67 */ 68 OT_TOOL_PACKED_BEGIN 69 class Tlv : public ot::Tlv 70 { 71 public: 72 /** 73 * MLE TLV Types. 74 * 75 */ 76 enum Type : uint8_t 77 { 78 kSourceAddress = 0, ///< Source Address TLV 79 kMode = 1, ///< Mode TLV 80 kTimeout = 2, ///< Timeout TLV 81 kChallenge = 3, ///< Challenge TLV 82 kResponse = 4, ///< Response TLV 83 kLinkFrameCounter = 5, ///< Link-Layer Frame Counter TLV 84 kLinkQuality = 6, ///< Link Quality TLV 85 kNetworkParameter = 7, ///< Network Parameter TLV 86 kMleFrameCounter = 8, ///< MLE Frame Counter TLV 87 kRoute = 9, ///< Route64 TLV 88 kAddress16 = 10, ///< Address16 TLV 89 kLeaderData = 11, ///< Leader Data TLV 90 kNetworkData = 12, ///< Network Data TLV 91 kTlvRequest = 13, ///< TLV Request TLV 92 kScanMask = 14, ///< Scan Mask TLV 93 kConnectivity = 15, ///< Connectivity TLV 94 kLinkMargin = 16, ///< Link Margin TLV 95 kStatus = 17, ///< Status TLV 96 kVersion = 18, ///< Version TLV 97 kAddressRegistration = 19, ///< Address Registration TLV 98 kChannel = 20, ///< Channel TLV 99 kPanId = 21, ///< PAN ID TLV 100 kActiveTimestamp = 22, ///< Active Timestamp TLV 101 kPendingTimestamp = 23, ///< Pending Timestamp TLV 102 kActiveDataset = 24, ///< Active Operational Dataset TLV 103 kPendingDataset = 25, ///< Pending Operational Dataset TLV 104 kDiscovery = 26, ///< Thread Discovery TLV 105 kCslChannel = 80, ///< CSL Channel TLV 106 kCslTimeout = 85, ///< CSL Timeout TLV 107 kCslClockAccuracy = 86, ///< CSL Clock Accuracy TLV 108 kLinkMetricsQuery = 87, ///< Link Metrics Query TLV 109 kLinkMetricsManagement = 88, ///< Link Metrics Management TLV 110 kLinkMetricsReport = 89, ///< Link Metrics Report TLV 111 kLinkProbe = 90, ///< Link Probe TLV 112 113 /** 114 * Applicable/Required only when time synchronization service 115 * (`OPENTHREAD_CONFIG_TIME_SYNC_ENABLE`) is enabled. 116 * 117 */ 118 kTimeRequest = 252, ///< Time Request TLV 119 kTimeParameter = 253, ///< Time Parameter TLV 120 kXtalAccuracy = 254, ///< XTAL Accuracy TLV 121 122 kInvalid = 255, 123 }; 124 125 /** 126 * This method returns the Type value. 127 * 128 * @returns The Type value. 129 * 130 */ GetType(void) const131 Type GetType(void) const { return static_cast<Type>(ot::Tlv::GetType()); } 132 133 /** 134 * This method sets the Type value. 135 * 136 * @param[in] aType The Type value. 137 * 138 */ SetType(Type aType)139 void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); } 140 141 } OT_TOOL_PACKED_END; 142 143 /** 144 * This class defines Source Address TLV constants and types. 145 * 146 */ 147 typedef UintTlvInfo<Tlv::kSourceAddress, uint16_t> SourceAddressTlv; 148 149 /** 150 * This class defines Mode TLV constants and types. 151 * 152 */ 153 typedef UintTlvInfo<Tlv::kMode, uint8_t> ModeTlv; 154 155 /** 156 * This class defines Timeout TLV constants and types. 157 * 158 */ 159 typedef UintTlvInfo<Tlv::kTimeout, uint32_t> TimeoutTlv; 160 161 /** 162 * This class defines Challenge TLV constants and types. 163 * 164 */ 165 typedef TlvInfo<Tlv::kChallenge> ChallengeTlv; 166 167 /** 168 * This class defines Response TLV constants and types. 169 * 170 */ 171 typedef TlvInfo<Tlv::kResponse> ResponseTlv; 172 173 /** 174 * This class defines Link Frame Counter TLV constants and types. 175 * 176 */ 177 typedef UintTlvInfo<Tlv::kLinkFrameCounter, uint32_t> LinkFrameCounterTlv; 178 179 /** 180 * This class defines MLE Frame Counter TLV constants and types. 181 * 182 */ 183 typedef UintTlvInfo<Tlv::kMleFrameCounter, uint32_t> MleFrameCounterTlv; 184 185 /** 186 * This class defines Address16 TLV constants and types. 187 * 188 */ 189 typedef UintTlvInfo<Tlv::kAddress16, uint16_t> Address16Tlv; 190 191 /** 192 * This class defines Network Data TLV constants and types. 193 * 194 */ 195 typedef TlvInfo<Tlv::kNetworkData> NetworkDataTlv; 196 197 /** 198 * This class defines TLV Request TLV constants and types. 199 * 200 */ 201 typedef TlvInfo<Tlv::kTlvRequest> TlvRequestTlv; 202 203 /** 204 * This class defines Link Margin TLV constants and types. 205 * 206 */ 207 typedef UintTlvInfo<Tlv::kLinkMargin, uint8_t> LinkMarginTlv; 208 209 /** 210 * This class defines Version TLV constants and types. 211 * 212 */ 213 typedef UintTlvInfo<Tlv::kVersion, uint16_t> VersionTlv; 214 215 /** 216 * This class defines PAN ID TLV constants and types. 217 * 218 */ 219 typedef UintTlvInfo<Tlv::kPanId, uint16_t> PanIdTlv; 220 221 /** 222 * This class defines Active Timestamp TLV constants and types. 223 * 224 */ 225 typedef SimpleTlvInfo<Tlv::kActiveTimestamp, MeshCoP::Timestamp> ActiveTimestampTlv; 226 227 /** 228 * This class defines Pending Timestamp TLV constants and types. 229 * 230 */ 231 typedef SimpleTlvInfo<Tlv::kPendingTimestamp, MeshCoP::Timestamp> PendingTimestampTlv; 232 233 /** 234 * This class defines CSL Timeout TLV constants and types. 235 * 236 */ 237 typedef UintTlvInfo<Tlv::kCslTimeout, uint32_t> CslTimeoutTlv; 238 239 /** 240 * This class defines XTAL Accuracy TLV constants and types. 241 * 242 */ 243 typedef UintTlvInfo<Tlv::kXtalAccuracy, uint16_t> XtalAccuracyTlv; 244 245 #if !OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE 246 247 /** 248 * This class implements Route TLV generation and parsing. 249 * 250 */ 251 OT_TOOL_PACKED_BEGIN 252 class RouteTlv : public Tlv, public TlvInfo<Tlv::kRoute> 253 { 254 public: 255 /** 256 * This method initializes the TLV. 257 * 258 */ Init(void)259 void Init(void) 260 { 261 SetType(kRoute); 262 SetLength(sizeof(*this) - sizeof(Tlv)); 263 mRouterIdMask.Clear(); 264 memset(mRouteData, 0, sizeof(mRouteData)); 265 } 266 267 /** 268 * This method indicates whether or not the TLV appears to be well-formed. 269 * 270 * @retval TRUE If the TLV appears to be well-formed. 271 * @retval FALSE If the TLV does not appear to be well-formed. 272 * 273 */ IsValid(void) const274 bool IsValid(void) const { return GetLength() >= sizeof(mRouterIdSequence) + sizeof(mRouterIdMask); } 275 276 /** 277 * This method returns the Router ID Sequence value. 278 * 279 * @returns The Router ID Sequence value. 280 * 281 */ GetRouterIdSequence(void) const282 uint8_t GetRouterIdSequence(void) const { return mRouterIdSequence; } 283 284 /** 285 * This method sets the Router ID Sequence value. 286 * 287 * @param[in] aSequence The Router ID Sequence value. 288 * 289 */ SetRouterIdSequence(uint8_t aSequence)290 void SetRouterIdSequence(uint8_t aSequence) { mRouterIdSequence = aSequence; } 291 292 /** 293 * This method gets the Router ID Mask. 294 * 295 */ GetRouterIdMask(void) const296 const RouterIdSet &GetRouterIdMask(void) const { return mRouterIdMask; } 297 298 /** 299 * This method sets the Router ID Mask. 300 * 301 * @param[in] aRouterIdSet The Router ID Mask to set. 302 * 303 */ SetRouterIdMask(const RouterIdSet & aRouterIdSet)304 void SetRouterIdMask(const RouterIdSet &aRouterIdSet) { mRouterIdMask = aRouterIdSet; } 305 306 /** 307 * This method indicates whether or not a Router ID bit is set. 308 * 309 * @param[in] aRouterId The Router ID bit. 310 * 311 * @retval TRUE If the Router ID bit is set. 312 * @retval FALSE If the Router ID bit is not set. 313 * 314 */ IsRouterIdSet(uint8_t aRouterId) const315 bool IsRouterIdSet(uint8_t aRouterId) const { return mRouterIdMask.Contains(aRouterId); } 316 317 /** 318 * This method returns the Route Data Length value. 319 * 320 * @returns The Route Data Length value. 321 * 322 */ GetRouteDataLength(void) const323 uint8_t GetRouteDataLength(void) const { return GetLength() - sizeof(mRouterIdSequence) - sizeof(mRouterIdMask); } 324 325 /** 326 * This method sets the Route Data Length value. 327 * 328 * @param[in] aLength The Route Data Length value. 329 * 330 */ SetRouteDataLength(uint8_t aLength)331 void SetRouteDataLength(uint8_t aLength) { SetLength(sizeof(mRouterIdSequence) + sizeof(mRouterIdMask) + aLength); } 332 333 /** 334 * This method returns the Route Cost value for a given Router index. 335 * 336 * @param[in] aRouterIndex The Router index. 337 * 338 * @returns The Route Cost value for a given Router index. 339 * 340 */ GetRouteCost(uint8_t aRouterIndex) const341 uint8_t GetRouteCost(uint8_t aRouterIndex) const { return mRouteData[aRouterIndex] & kRouteCostMask; } 342 343 /** 344 * This method sets the Route Cost value for a given Router index. 345 * 346 * @param[in] aRouterIndex The Router index. 347 * @param[in] aRouteCost The Route Cost value. 348 * 349 */ SetRouteCost(uint8_t aRouterIndex,uint8_t aRouteCost)350 void SetRouteCost(uint8_t aRouterIndex, uint8_t aRouteCost) 351 { 352 mRouteData[aRouterIndex] = (mRouteData[aRouterIndex] & ~kRouteCostMask) | aRouteCost; 353 } 354 355 /** 356 * This method returns the Link Quality In value for a given Router index. 357 * 358 * @param[in] aRouterIndex The Router index. 359 * 360 * @returns The Link Quality In value for a given Router index. 361 * 362 */ GetLinkQualityIn(uint8_t aRouterIndex) const363 LinkQuality GetLinkQualityIn(uint8_t aRouterIndex) const 364 { 365 return static_cast<LinkQuality>((mRouteData[aRouterIndex] & kLinkQualityInMask) >> kLinkQualityInOffset); 366 } 367 368 /** 369 * This method sets the Link Quality In value for a given Router index. 370 * 371 * @param[in] aRouterIndex The Router index. 372 * @param[in] aLinkQuality The Link Quality In value for a given Router index. 373 * 374 */ SetLinkQualityIn(uint8_t aRouterIndex,LinkQuality aLinkQuality)375 void SetLinkQualityIn(uint8_t aRouterIndex, LinkQuality aLinkQuality) 376 { 377 mRouteData[aRouterIndex] = (mRouteData[aRouterIndex] & ~kLinkQualityInMask) | 378 ((aLinkQuality << kLinkQualityInOffset) & kLinkQualityInMask); 379 } 380 381 /** 382 * This method returns the Link Quality Out value for a given Router index. 383 * 384 * @param[in] aRouterIndex The Router index. 385 * 386 * @returns The Link Quality Out value for a given Router index. 387 * 388 */ GetLinkQualityOut(uint8_t aRouterIndex) const389 LinkQuality GetLinkQualityOut(uint8_t aRouterIndex) const 390 { 391 return static_cast<LinkQuality>((mRouteData[aRouterIndex] & kLinkQualityOutMask) >> kLinkQualityOutOffset); 392 } 393 394 /** 395 * This method sets the Link Quality Out value for a given Router index. 396 * 397 * @param[in] aRouterIndex The Router index. 398 * @param[in] aLinkQuality The Link Quality Out value for a given Router index. 399 * 400 */ SetLinkQualityOut(uint8_t aRouterIndex,LinkQuality aLinkQuality)401 void SetLinkQualityOut(uint8_t aRouterIndex, LinkQuality aLinkQuality) 402 { 403 mRouteData[aRouterIndex] = (mRouteData[aRouterIndex] & ~kLinkQualityOutMask) | 404 ((aLinkQuality << kLinkQualityOutOffset) & kLinkQualityOutMask); 405 } 406 407 private: 408 static constexpr uint8_t kLinkQualityOutOffset = 6; 409 static constexpr uint8_t kLinkQualityOutMask = 3 << kLinkQualityOutOffset; 410 static constexpr uint8_t kLinkQualityInOffset = 4; 411 static constexpr uint8_t kLinkQualityInMask = 3 << kLinkQualityInOffset; 412 static constexpr uint8_t kRouteCostOffset = 0; 413 static constexpr uint8_t kRouteCostMask = 0xf << kRouteCostOffset; 414 415 uint8_t mRouterIdSequence; 416 RouterIdSet mRouterIdMask; 417 uint8_t mRouteData[kMaxRouterId + 1]; 418 } OT_TOOL_PACKED_END; 419 420 #else // OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE 421 422 /** 423 * This class implements Route TLV generation and parsing. 424 * 425 */ 426 OT_TOOL_PACKED_BEGIN 427 class RouteTlv : public Tlv, public TlvInfo<Tlv::kRoute> 428 { 429 public: 430 /** 431 * This method initializes the TLV. 432 * 433 */ Init(void)434 void Init(void) 435 { 436 SetType(kRoute); 437 SetLength(sizeof(*this) - sizeof(Tlv)); 438 } 439 440 /** 441 * This method indicates whether or not the TLV appears to be well-formed. 442 * 443 * @retval TRUE If the TLV appears to be well-formed. 444 * @retval FALSE If the TLV does not appear to be well-formed. 445 * 446 */ IsValid(void) const447 bool IsValid(void) const { return GetLength() >= sizeof(mRouterIdSequence) + sizeof(mRouterIdMask); } 448 449 /** 450 * This method returns the Router ID Sequence value. 451 * 452 * @returns The Router ID Sequence value. 453 * 454 */ GetRouterIdSequence(void) const455 uint8_t GetRouterIdSequence(void) const { return mRouterIdSequence; } 456 457 /** 458 * This method sets the Router ID Sequence value. 459 * 460 * @param[in] aSequence The Router ID Sequence value. 461 * 462 */ SetRouterIdSequence(uint8_t aSequence)463 void SetRouterIdSequence(uint8_t aSequence) { mRouterIdSequence = aSequence; } 464 465 /** 466 * This method gets the Router ID Mask. 467 * 468 */ GetRouterIdMask(void) const469 const RouterIdSet &GetRouterIdMask(void) const { return mRouterIdMask; } 470 471 /** 472 * This method sets the Router ID Mask. 473 * 474 * @param[in] aRouterIdSet The Router ID Mask to set. 475 * 476 */ SetRouterIdMask(const RouterIdSet & aRouterIdSet)477 void SetRouterIdMask(const RouterIdSet &aRouterIdSet) { mRouterIdMask = aRouterIdSet; } 478 479 /** 480 * This method indicates whether or not a Router ID bit is set. 481 * 482 * @param[in] aRouterId The Router ID. 483 * 484 * @retval TRUE If the Router ID bit is set. 485 * @retval FALSE If the Router ID bit is not set. 486 * 487 */ IsRouterIdSet(uint8_t aRouterId) const488 bool IsRouterIdSet(uint8_t aRouterId) const { return mRouterIdMask.Contains(aRouterId); } 489 490 /** 491 * This method sets the Router ID bit. 492 * 493 * @param[in] aRouterId The Router ID bit to set. 494 * 495 */ SetRouterId(uint8_t aRouterId)496 void SetRouterId(uint8_t aRouterId) { mRouterIdMask.Add(aRouterId); } 497 498 /** 499 * This method returns the Route Data Length value. 500 * 501 * @returns The Route Data Length value in bytes 502 * 503 */ GetRouteDataLength(void) const504 uint8_t GetRouteDataLength(void) const { return GetLength() - sizeof(mRouterIdSequence) - sizeof(mRouterIdMask); } 505 506 /** 507 * This method sets the Route Data Length value. 508 * 509 * @param[in] aLength The Route Data Length value in number of router entries 510 * 511 */ SetRouteDataLength(uint8_t aLength)512 void SetRouteDataLength(uint8_t aLength) 513 { 514 SetLength(sizeof(mRouterIdSequence) + sizeof(mRouterIdMask) + aLength + (aLength + 1) / 2); 515 } 516 517 /** 518 * This method returns the Route Cost value for a given Router index. 519 * 520 * @param[in] aRouterIndex The Router index. 521 * 522 * @returns The Route Cost value for a given Router index. 523 * 524 */ GetRouteCost(uint8_t aRouterIndex) const525 uint8_t GetRouteCost(uint8_t aRouterIndex) const 526 { 527 if (aRouterIndex & 1) 528 { 529 return mRouteData[aRouterIndex + aRouterIndex / 2 + 1]; 530 } 531 else 532 { 533 return static_cast<uint8_t>((mRouteData[aRouterIndex + aRouterIndex / 2] & kRouteCostMask) 534 << kOddEntryOffset) | 535 ((mRouteData[aRouterIndex + aRouterIndex / 2 + 1] & 536 static_cast<uint8_t>(kRouteCostMask << kOddEntryOffset)) >> 537 kOddEntryOffset); 538 } 539 } 540 541 /** 542 * This method sets the Route Cost value for a given Router index. 543 * 544 * @param[in] aRouterIndex The Router index. 545 * @param[in] aRouteCost The Route Cost value. 546 * 547 */ SetRouteCost(uint8_t aRouterIndex,uint8_t aRouteCost)548 void SetRouteCost(uint8_t aRouterIndex, uint8_t aRouteCost) 549 { 550 if (aRouterIndex & 1) 551 { 552 mRouteData[aRouterIndex + aRouterIndex / 2 + 1] = aRouteCost; 553 } 554 else 555 { 556 mRouteData[aRouterIndex + aRouterIndex / 2] = 557 (mRouteData[aRouterIndex + aRouterIndex / 2] & ~kRouteCostMask) | 558 ((aRouteCost >> kOddEntryOffset) & kRouteCostMask); 559 mRouteData[aRouterIndex + aRouterIndex / 2 + 1] = static_cast<uint8_t>( 560 (mRouteData[aRouterIndex + aRouterIndex / 2 + 1] & ~(kRouteCostMask << kOddEntryOffset)) | 561 ((aRouteCost & kRouteCostMask) << kOddEntryOffset)); 562 } 563 } 564 565 /** 566 * This method returns the Link Quality In value for a given Router index. 567 * 568 * @param[in] aRouterIndex The Router index. 569 * 570 * @returns The Link Quality In value for a given Router index. 571 * 572 */ GetLinkQualityIn(uint8_t aRouterIndex) const573 uint8_t GetLinkQualityIn(uint8_t aRouterIndex) const 574 { 575 int offset = ((aRouterIndex & 1) ? kOddEntryOffset : 0); 576 return (mRouteData[aRouterIndex + aRouterIndex / 2] & (kLinkQualityInMask >> offset)) >> 577 (kLinkQualityInOffset - offset); 578 } 579 580 /** 581 * This method sets the Link Quality In value for a given Router index. 582 * 583 * @param[in] aRouterIndex The Router index. 584 * @param[in] aLinkQuality The Link Quality In value for a given Router index. 585 * 586 */ SetLinkQualityIn(uint8_t aRouterIndex,uint8_t aLinkQuality)587 void SetLinkQualityIn(uint8_t aRouterIndex, uint8_t aLinkQuality) 588 { 589 int offset = ((aRouterIndex & 1) ? kOddEntryOffset : 0); 590 mRouteData[aRouterIndex + aRouterIndex / 2] = 591 (mRouteData[aRouterIndex + aRouterIndex / 2] & ~(kLinkQualityInMask >> offset)) | 592 ((aLinkQuality << (kLinkQualityInOffset - offset)) & (kLinkQualityInMask >> offset)); 593 } 594 595 /** 596 * This method returns the Link Quality Out value for a given Router index. 597 * 598 * @param[in] aRouterIndex The Router index. 599 * 600 * @returns The Link Quality Out value for a given Router index. 601 * 602 */ GetLinkQualityOut(uint8_t aRouterIndex) const603 LinkQuality GetLinkQualityOut(uint8_t aRouterIndex) const 604 { 605 int offset = ((aRouterIndex & 1) ? kOddEntryOffset : 0); 606 return static_cast<LinkQuality>( 607 (mRouteData[aRouterIndex + aRouterIndex / 2] & (kLinkQualityOutMask >> offset)) >> 608 (kLinkQualityOutOffset - offset)); 609 } 610 611 /** 612 * This method sets the Link Quality Out value for a given Router index. 613 * 614 * @param[in] aRouterIndex The Router index. 615 * @param[in] aLinkQuality The Link Quality Out value for a given Router index. 616 * 617 */ SetLinkQualityOut(uint8_t aRouterIndex,LinkQuality aLinkQuality)618 void SetLinkQualityOut(uint8_t aRouterIndex, LinkQuality aLinkQuality) 619 { 620 int offset = ((aRouterIndex & 1) ? kOddEntryOffset : 0); 621 mRouteData[aRouterIndex + aRouterIndex / 2] = 622 (mRouteData[aRouterIndex + aRouterIndex / 2] & ~(kLinkQualityOutMask >> offset)) | 623 ((aLinkQuality << (kLinkQualityOutOffset - offset)) & (kLinkQualityOutMask >> offset)); 624 } 625 626 private: 627 static constexpr uint8_t kLinkQualityOutOffset = 6; 628 static constexpr uint8_t kLinkQualityOutMask = 3 << kLinkQualityOutOffset; 629 static constexpr uint8_t kLinkQualityInOffset = 4; 630 static constexpr uint8_t kLinkQualityInMask = 3 << kLinkQualityInOffset; 631 static constexpr uint8_t kRouteCostOffset = 0; 632 static constexpr uint8_t kRouteCostMask = 0xf << kRouteCostOffset; 633 static constexpr uint8_t kOddEntryOffset = 4; 634 635 uint8_t mRouterIdSequence; 636 RouterIdSet mRouterIdMask; 637 // Since we do hold 12 (compressible to 11) bits of data per router, each entry occupies 1.5 bytes, 638 // consecutively. First 4 bits are link qualities, remaining 8 bits are route cost. 639 uint8_t mRouteData[kMaxRouterId + 1 + kMaxRouterId / 2 + 1]; 640 } OT_TOOL_PACKED_END; 641 642 #endif // OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE 643 644 /** 645 * This class implements Leader Data TLV generation and parsing. 646 * 647 */ 648 OT_TOOL_PACKED_BEGIN 649 class LeaderDataTlv : public Tlv, public TlvInfo<Tlv::kLeaderData> 650 { 651 public: 652 /** 653 * This method initializes the TLV. 654 * 655 */ Init(void)656 void Init(void) 657 { 658 SetType(kLeaderData); 659 SetLength(sizeof(*this) - sizeof(Tlv)); 660 } 661 662 /** 663 * This method indicates whether or not the TLV appears to be well-formed. 664 * 665 * @retval TRUE If the TLV appears to be well-formed. 666 * @retval FALSE If the TLV does not appear to be well-formed. 667 * 668 */ IsValid(void) const669 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 670 671 /** 672 * This method gets the Leader Data info from TLV. 673 * 674 * @param[out] aLeaderData A reference to output Leader Data info. 675 * 676 */ Get(LeaderData & aLeaderData) const677 void Get(LeaderData &aLeaderData) const 678 { 679 aLeaderData.SetPartitionId(HostSwap32(mPartitionId)); 680 aLeaderData.SetWeighting(mWeighting); 681 aLeaderData.SetDataVersion(mDataVersion); 682 aLeaderData.SetStableDataVersion(mStableDataVersion); 683 aLeaderData.SetLeaderRouterId(mLeaderRouterId); 684 } 685 686 /** 687 * This method sets the Leader Data. 688 * 689 * @param[in] aLeaderData A Leader Data. 690 * 691 */ Set(const LeaderData & aLeaderData)692 void Set(const LeaderData &aLeaderData) 693 { 694 mPartitionId = HostSwap32(aLeaderData.GetPartitionId()); 695 mWeighting = aLeaderData.GetWeighting(); 696 mDataVersion = aLeaderData.GetDataVersion(NetworkData::kFullSet); 697 mStableDataVersion = aLeaderData.GetDataVersion(NetworkData::kStableSubset); 698 mLeaderRouterId = aLeaderData.GetLeaderRouterId(); 699 } 700 701 private: 702 uint32_t mPartitionId; 703 uint8_t mWeighting; 704 uint8_t mDataVersion; 705 uint8_t mStableDataVersion; 706 uint8_t mLeaderRouterId; 707 } OT_TOOL_PACKED_END; 708 709 /** 710 * This class implements Scan Mask TLV generation and parsing. 711 * 712 */ 713 class ScanMaskTlv : public UintTlvInfo<Tlv::kScanMask, uint8_t> 714 { 715 public: 716 static constexpr uint8_t kRouterFlag = 1 << 7; ///< Scan Mask Router Flag. 717 static constexpr uint8_t kEndDeviceFlag = 1 << 6; ///< Scan Mask End Device Flag. 718 719 /** 720 * This method indicates whether or not the Router flag is set. 721 * 722 * @param[in] aMask A scan mask value. 723 * 724 * @retval TRUE If the Router flag is set. 725 * @retval FALSE If the Router flag is not set. 726 */ IsRouterFlagSet(uint8_t aMask)727 static bool IsRouterFlagSet(uint8_t aMask) { return (aMask & kRouterFlag) != 0; } 728 729 /** 730 * This method indicates whether or not the End Device flag is set. 731 * 732 * @param[in] aMask A scan mask value. 733 * 734 * @retval TRUE If the End Device flag is set. 735 * @retval FALSE If the End Device flag is not set. 736 */ IsEndDeviceFlagSet(uint8_t aMask)737 static bool IsEndDeviceFlagSet(uint8_t aMask) { return (aMask & kEndDeviceFlag) != 0; } 738 }; 739 740 /** 741 * This class implements Connectivity TLV generation and parsing. 742 * 743 */ 744 OT_TOOL_PACKED_BEGIN 745 class ConnectivityTlv : public Tlv, public TlvInfo<Tlv::kConnectivity> 746 { 747 public: 748 /** 749 * This method initializes the TLV. 750 * 751 */ Init(void)752 void Init(void) 753 { 754 SetType(kConnectivity); 755 SetLength(sizeof(*this) - sizeof(Tlv)); 756 } 757 758 /** 759 * This method indicates whether or not the TLV appears to be well-formed. 760 * 761 * @retval TRUE If the TLV appears to be well-formed. 762 * @retval FALSE If the TLV does not appear to be well-formed. 763 * 764 */ IsValid(void) const765 bool IsValid(void) const 766 { 767 return IsSedBufferingIncluded() || 768 (GetLength() == sizeof(*this) - sizeof(Tlv) - sizeof(mSedBufferSize) - sizeof(mSedDatagramCount)); 769 } 770 771 /** 772 * This method indicates whether or not the sed buffer size and datagram count are included. 773 * 774 * @retval TRUE If the sed buffer size and datagram count are included. 775 * @retval FALSE If the sed buffer size and datagram count are not included. 776 * 777 */ IsSedBufferingIncluded(void) const778 bool IsSedBufferingIncluded(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 779 780 /** 781 * This method returns the Parent Priority value. 782 * 783 * @returns The Parent Priority value. 784 * 785 */ GetParentPriority(void) const786 int8_t GetParentPriority(void) const 787 { 788 return (static_cast<int8_t>(mParentPriority & kParentPriorityMask)) >> kParentPriorityOffset; 789 } 790 791 /** 792 * This method sets the Parent Priority value. 793 * 794 * @param[in] aParentPriority The Parent Priority value. 795 * 796 */ SetParentPriority(int8_t aParentPriority)797 void SetParentPriority(int8_t aParentPriority) 798 { 799 mParentPriority = (static_cast<uint8_t>(aParentPriority) << kParentPriorityOffset) & kParentPriorityMask; 800 } 801 802 /** 803 * This method returns the Link Quality 3 value. 804 * 805 * @returns The Link Quality 3 value. 806 * 807 */ GetLinkQuality3(void) const808 uint8_t GetLinkQuality3(void) const { return mLinkQuality3; } 809 810 /** 811 * This method sets the Link Quality 3 value. 812 * 813 * @param[in] aLinkQuality The Link Quality 3 value. 814 * 815 */ SetLinkQuality3(uint8_t aLinkQuality)816 void SetLinkQuality3(uint8_t aLinkQuality) { mLinkQuality3 = aLinkQuality; } 817 818 /** 819 * This method returns the Link Quality 2 value. 820 * 821 * @returns The Link Quality 2 value. 822 * 823 */ GetLinkQuality2(void) const824 uint8_t GetLinkQuality2(void) const { return mLinkQuality2; } 825 826 /** 827 * This method sets the Link Quality 2 value. 828 * 829 * @param[in] aLinkQuality The Link Quality 2 value. 830 * 831 */ SetLinkQuality2(uint8_t aLinkQuality)832 void SetLinkQuality2(uint8_t aLinkQuality) { mLinkQuality2 = aLinkQuality; } 833 834 /** 835 * This method sets the Link Quality 1 value. 836 * 837 * @returns The Link Quality 1 value. 838 * 839 */ GetLinkQuality1(void) const840 uint8_t GetLinkQuality1(void) const { return mLinkQuality1; } 841 842 /** 843 * This method sets the Link Quality 1 value. 844 * 845 * @param[in] aLinkQuality The Link Quality 1 value. 846 * 847 */ SetLinkQuality1(uint8_t aLinkQuality)848 void SetLinkQuality1(uint8_t aLinkQuality) { mLinkQuality1 = aLinkQuality; } 849 850 /** 851 * This method sets the Active Routers value. 852 * 853 * @returns The Active Routers value. 854 * 855 */ GetActiveRouters(void) const856 uint8_t GetActiveRouters(void) const { return mActiveRouters; } 857 858 /** 859 * This method sets the Active Routers value. 860 * 861 * @param[in] aActiveRouters The Active Routers value. 862 * 863 */ SetActiveRouters(uint8_t aActiveRouters)864 void SetActiveRouters(uint8_t aActiveRouters) { mActiveRouters = aActiveRouters; } 865 866 /** 867 * This method returns the Leader Cost value. 868 * 869 * @returns The Leader Cost value. 870 * 871 */ GetLeaderCost(void) const872 uint8_t GetLeaderCost(void) const { return mLeaderCost; } 873 874 /** 875 * This method sets the Leader Cost value. 876 * 877 * @param[in] aCost The Leader Cost value. 878 * 879 */ SetLeaderCost(uint8_t aCost)880 void SetLeaderCost(uint8_t aCost) { mLeaderCost = aCost; } 881 882 /** 883 * This method returns the ID Sequence value. 884 * 885 * @returns The ID Sequence value. 886 * 887 */ GetIdSequence(void) const888 uint8_t GetIdSequence(void) const { return mIdSequence; } 889 890 /** 891 * This method sets the ID Sequence value. 892 * 893 * @param[in] aSequence The ID Sequence value. 894 * 895 */ SetIdSequence(uint8_t aSequence)896 void SetIdSequence(uint8_t aSequence) { mIdSequence = aSequence; } 897 898 /** 899 * This method returns the SED Buffer Size value. 900 * 901 * @returns The SED Buffer Size value. 902 * 903 */ GetSedBufferSize(void) const904 uint16_t GetSedBufferSize(void) const 905 { 906 uint16_t buffersize = OPENTHREAD_CONFIG_DEFAULT_SED_BUFFER_SIZE; 907 908 if (IsSedBufferingIncluded()) 909 { 910 buffersize = HostSwap16(mSedBufferSize); 911 } 912 return buffersize; 913 } 914 915 /** 916 * This method sets the SED Buffer Size value. 917 * 918 * @param[in] aSedBufferSize The SED Buffer Size value. 919 * 920 */ SetSedBufferSize(uint16_t aSedBufferSize)921 void SetSedBufferSize(uint16_t aSedBufferSize) { mSedBufferSize = HostSwap16(aSedBufferSize); } 922 923 /** 924 * This method returns the SED Datagram Count value. 925 * 926 * @returns The SED Datagram Count value. 927 * 928 */ GetSedDatagramCount(void) const929 uint8_t GetSedDatagramCount(void) const 930 { 931 uint8_t count = OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT; 932 933 if (IsSedBufferingIncluded()) 934 { 935 count = mSedDatagramCount; 936 } 937 return count; 938 } 939 940 /** 941 * This method sets the SED Datagram Count value. 942 * 943 * @param[in] aSedDatagramCount The SED Datagram Count value. 944 * 945 */ SetSedDatagramCount(uint8_t aSedDatagramCount)946 void SetSedDatagramCount(uint8_t aSedDatagramCount) { mSedDatagramCount = aSedDatagramCount; } 947 948 private: 949 static constexpr uint8_t kParentPriorityOffset = 6; 950 static constexpr uint8_t kParentPriorityMask = 3 << kParentPriorityOffset; 951 952 uint8_t mParentPriority; 953 uint8_t mLinkQuality3; 954 uint8_t mLinkQuality2; 955 uint8_t mLinkQuality1; 956 uint8_t mLeaderCost; 957 uint8_t mIdSequence; 958 uint8_t mActiveRouters; 959 uint16_t mSedBufferSize; 960 uint8_t mSedDatagramCount; 961 } OT_TOOL_PACKED_END; 962 963 /** 964 * This class specifies Status TLV status values. 965 * 966 */ 967 struct StatusTlv : public UintTlvInfo<Tlv::kStatus, uint8_t> 968 { 969 /** 970 * Status values. 971 */ 972 enum Status : uint8_t 973 { 974 kError = 1, ///< Error. 975 }; 976 }; 977 978 /** 979 * This class implements Source Address TLV generation and parsing. 980 * 981 */ 982 OT_TOOL_PACKED_BEGIN 983 class AddressRegistrationEntry 984 { 985 public: 986 /** 987 * This method returns the IPv6 address or IID length. 988 * 989 * @returns The IPv6 address length if the Compressed bit is clear, or the IID length if the Compressed bit is 990 * set. 991 * 992 */ GetLength(void) const993 uint8_t GetLength(void) const { return sizeof(mControl) + (IsCompressed() ? sizeof(mIid) : sizeof(mIp6Address)); } 994 995 /** 996 * This method indicates whether or not the Compressed flag is set. 997 * 998 * @retval TRUE If the Compressed flag is set. 999 * @retval FALSE If the Compressed flag is not set. 1000 * 1001 */ IsCompressed(void) const1002 bool IsCompressed(void) const { return (mControl & kCompressed) != 0; } 1003 1004 /** 1005 * This method sets the Uncompressed flag. 1006 * 1007 */ SetUncompressed(void)1008 void SetUncompressed(void) { mControl = 0; } 1009 1010 /** 1011 * This method returns the Context ID for the compressed form. 1012 * 1013 * @returns The Context ID value. 1014 * 1015 */ GetContextId(void) const1016 uint8_t GetContextId(void) const { return mControl & kCidMask; } 1017 1018 /** 1019 * This method sets the Context ID value. 1020 * 1021 * @param[in] aContextId The Context ID value. 1022 * 1023 */ SetContextId(uint8_t aContextId)1024 void SetContextId(uint8_t aContextId) { mControl = kCompressed | aContextId; } 1025 1026 /** 1027 * This method returns the IID value. 1028 * 1029 * @returns The IID value. 1030 * 1031 */ GetIid(void) const1032 const Ip6::InterfaceIdentifier &GetIid(void) const { return mIid; } 1033 1034 /** 1035 * This method sets the IID value. 1036 * 1037 * @param[in] aIid The IID value. 1038 * 1039 */ SetIid(const Ip6::InterfaceIdentifier & aIid)1040 void SetIid(const Ip6::InterfaceIdentifier &aIid) { mIid = aIid; } 1041 1042 /** 1043 * This method returns the IPv6 Address value. 1044 * 1045 * @returns The IPv6 Address value. 1046 * 1047 */ GetIp6Address(void) const1048 const Ip6::Address &GetIp6Address(void) const { return mIp6Address; } 1049 1050 /** 1051 * This method sets the IPv6 Address value. 1052 * 1053 * @param[in] aAddress A reference to the IPv6 Address value. 1054 * 1055 */ SetIp6Address(const Ip6::Address & aAddress)1056 void SetIp6Address(const Ip6::Address &aAddress) { mIp6Address = aAddress; } 1057 1058 private: 1059 static constexpr uint8_t kCompressed = 1 << 7; 1060 static constexpr uint8_t kCidMask = 0xf; 1061 1062 uint8_t mControl; 1063 union 1064 { 1065 Ip6::InterfaceIdentifier mIid; 1066 Ip6::Address mIp6Address; 1067 } OT_TOOL_PACKED_FIELD; 1068 } OT_TOOL_PACKED_END; 1069 1070 /** 1071 * This class implements Channel TLV generation and parsing. 1072 * 1073 */ 1074 OT_TOOL_PACKED_BEGIN 1075 class ChannelTlv : public Tlv, public TlvInfo<Tlv::kChannel> 1076 { 1077 public: 1078 /** 1079 * This method initializes the TLV. 1080 * 1081 */ Init(void)1082 void Init(void) 1083 { 1084 SetType(kChannel); 1085 SetLength(sizeof(*this) - sizeof(Tlv)); 1086 } 1087 1088 /** 1089 * This method indicates whether or not the TLV appears to be well-formed. 1090 * 1091 * @retval TRUE If the TLV appears to be well-formed. 1092 * @retval FALSE If the TLV does not appear to be well-formed. 1093 * 1094 */ IsValid(void) const1095 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 1096 1097 /** 1098 * This method returns the Channel Page value. 1099 * 1100 * @returns The Channel Page value. 1101 * 1102 */ GetChannelPage(void) const1103 uint8_t GetChannelPage(void) const { return mChannelPage; } 1104 1105 /** 1106 * This method sets the Channel Page value. 1107 * 1108 * @param[in] aChannelPage The Channel Page value. 1109 * 1110 */ SetChannelPage(uint8_t aChannelPage)1111 void SetChannelPage(uint8_t aChannelPage) { mChannelPage = aChannelPage; } 1112 1113 /** 1114 * This method returns the Channel value. 1115 * 1116 * @returns The Channel value. 1117 * 1118 */ GetChannel(void) const1119 uint16_t GetChannel(void) const { return HostSwap16(mChannel); } 1120 1121 /** 1122 * This method sets the Channel value. 1123 * 1124 * @param[in] aChannel The Channel value. 1125 * 1126 */ SetChannel(uint16_t aChannel)1127 void SetChannel(uint16_t aChannel) { mChannel = HostSwap16(aChannel); } 1128 1129 private: 1130 uint8_t mChannelPage; 1131 uint16_t mChannel; 1132 } OT_TOOL_PACKED_END; 1133 1134 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 1135 /** 1136 * This class defines Time Request TLV constants and types. 1137 * 1138 */ 1139 typedef TlvInfo<Tlv::kTimeRequest> TimeRequestTlv; 1140 1141 /** 1142 * This class implements Time Parameter TLV generation and parsing. 1143 * 1144 */ 1145 OT_TOOL_PACKED_BEGIN 1146 class TimeParameterTlv : public Tlv, public TlvInfo<Tlv::kTimeParameter> 1147 { 1148 public: 1149 /** 1150 * This method initializes the TLV. 1151 * 1152 */ Init(void)1153 void Init(void) 1154 { 1155 SetType(kTimeParameter); 1156 SetLength(sizeof(*this) - sizeof(Tlv)); 1157 } 1158 1159 /** 1160 * This method indicates whether or not the TLV appears to be well-formed. 1161 * 1162 * @retval TRUE If the TLV appears to be well-formed. 1163 * @retval FALSE If the TLV does not appear to be well-formed. 1164 * 1165 */ IsValid(void) const1166 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 1167 1168 /** 1169 * This method returns the time sync period. 1170 * 1171 * @returns The time sync period. 1172 * 1173 */ GetTimeSyncPeriod(void) const1174 uint16_t GetTimeSyncPeriod(void) const { return HostSwap16(mTimeSyncPeriod); } 1175 1176 /** 1177 * This method sets the time sync period. 1178 * 1179 * @param[in] aTimeSyncPeriod The time sync period. 1180 * 1181 */ SetTimeSyncPeriod(uint16_t aTimeSyncPeriod)1182 void SetTimeSyncPeriod(uint16_t aTimeSyncPeriod) { mTimeSyncPeriod = HostSwap16(aTimeSyncPeriod); } 1183 1184 /** 1185 * This method returns the XTAL accuracy threshold. 1186 * 1187 * @returns The XTAL accuracy threshold. 1188 * 1189 */ GetXtalThreshold(void) const1190 uint16_t GetXtalThreshold(void) const { return HostSwap16(mXtalThreshold); } 1191 1192 /** 1193 * This method sets the XTAL accuracy threshold. 1194 * 1195 * @param[in] aXTALThreshold The XTAL accuracy threshold. 1196 * 1197 */ SetXtalThreshold(uint16_t aXtalThreshold)1198 void SetXtalThreshold(uint16_t aXtalThreshold) { mXtalThreshold = HostSwap16(aXtalThreshold); } 1199 1200 private: 1201 uint16_t mTimeSyncPeriod; 1202 uint16_t mXtalThreshold; 1203 } OT_TOOL_PACKED_END; 1204 1205 #endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 1206 1207 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE) 1208 /** 1209 * This class implements CSL Channel TLV generation and parsing. 1210 * 1211 */ 1212 OT_TOOL_PACKED_BEGIN 1213 class CslChannelTlv : public Tlv, public TlvInfo<Tlv::kCslChannel> 1214 { 1215 public: 1216 /** 1217 * This method initializes the TLV. 1218 * 1219 */ Init(void)1220 void Init(void) 1221 { 1222 SetType(kCslChannel); 1223 SetLength(sizeof(*this) - sizeof(Tlv)); 1224 } 1225 1226 /** 1227 * This method indicates whether or not the TLV appears to be well-formed. 1228 * 1229 * @retval TRUE If the TLV appears to be well-formed. 1230 * @retval FALSE If the TLV does not appear to be well-formed. 1231 * 1232 */ IsValid(void) const1233 bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv); } 1234 1235 /** 1236 * This method returns the Channel Page value. 1237 * 1238 * @returns The Channel Page value. 1239 * 1240 */ GetChannelPage(void) const1241 uint8_t GetChannelPage(void) const { return mChannelPage; } 1242 1243 /** 1244 * This method sets the Channel Page value. 1245 * 1246 * @param[in] aChannelPage The Channel Page value. 1247 * 1248 */ SetChannelPage(uint8_t aChannelPage)1249 void SetChannelPage(uint8_t aChannelPage) { mChannelPage = aChannelPage; } 1250 1251 /** 1252 * This method returns the Channel value. 1253 * 1254 * @returns The Channel value. 1255 * 1256 */ GetChannel(void) const1257 uint16_t GetChannel(void) const { return HostSwap16(mChannel); } 1258 1259 /** 1260 * This method sets the Channel value. 1261 * 1262 * @param[in] aChannel The Channel value. 1263 * 1264 */ SetChannel(uint16_t aChannel)1265 void SetChannel(uint16_t aChannel) { mChannel = HostSwap16(aChannel); } 1266 1267 private: 1268 uint8_t mChannelPage; 1269 uint16_t mChannel; 1270 } OT_TOOL_PACKED_END; 1271 1272 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE) 1273 1274 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 1275 /** 1276 * This class implements CSL Clock Accuracy TLV generation and parsing. 1277 * 1278 */ 1279 OT_TOOL_PACKED_BEGIN 1280 class CslClockAccuracyTlv : public Tlv, public TlvInfo<Tlv::kCslClockAccuracy> 1281 { 1282 public: 1283 /** 1284 * This method initializes the TLV. 1285 * 1286 */ Init(void)1287 void Init(void) 1288 { 1289 SetType(kCslClockAccuracy); 1290 SetLength(sizeof(*this) - sizeof(Tlv)); 1291 } 1292 1293 /** 1294 * This method returns the CSL Clock Accuracy value. 1295 * 1296 * @returns The CSL Clock Accuracy value. 1297 * 1298 */ GetCslClockAccuracy(void)1299 uint8_t GetCslClockAccuracy(void) { return mCslClockAccuracy; } 1300 1301 /** 1302 * This method sets the CSL Clock Accuracy value. 1303 * 1304 * @param[in] aCslClockAccuracy The CSL Clock Accuracy value. 1305 * 1306 */ SetCslClockAccuracy(uint8_t aCslClockAccuracy)1307 void SetCslClockAccuracy(uint8_t aCslClockAccuracy) { mCslClockAccuracy = aCslClockAccuracy; } 1308 1309 /** 1310 * This method returns the Clock Accuracy value. 1311 * 1312 * @returns The Clock Accuracy value. 1313 * 1314 */ GetCslUncertainty(void)1315 uint8_t GetCslUncertainty(void) { return mCslUncertainty; } 1316 1317 /** 1318 * This method sets the CSL Uncertainty value. 1319 * 1320 * @param[in] aCslUncertainty The CSL Uncertainty value. 1321 * 1322 */ SetCslUncertainty(uint8_t aCslUncertainty)1323 void SetCslUncertainty(uint8_t aCslUncertainty) { mCslUncertainty = aCslUncertainty; } 1324 1325 private: 1326 uint8_t mCslClockAccuracy; 1327 uint8_t mCslUncertainty; 1328 } OT_TOOL_PACKED_END; 1329 1330 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 1331 /** 1332 * @} 1333 * 1334 */ 1335 1336 } // namespace Mle 1337 1338 } // namespace ot 1339 1340 #endif // MLE_TLVS_HPP_ 1341