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 NETWORK_DIAGNOSTIC_TLVS_HPP_ 35 #define NETWORK_DIAGNOSTIC_TLVS_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include <openthread/netdiag.h> 40 #include <openthread/thread.h> 41 42 #include "common/clearable.hpp" 43 #include "common/encoding.hpp" 44 #include "common/message.hpp" 45 #include "common/tlvs.hpp" 46 #include "net/ip6_address.hpp" 47 #include "radio/radio.hpp" 48 #include "thread/link_quality.hpp" 49 #include "thread/mle_tlvs.hpp" 50 #include "thread/mle_types.hpp" 51 52 namespace ot { 53 namespace NetworkDiagnostic { 54 55 using ot::Encoding::BigEndian::HostSwap16; 56 using ot::Encoding::BigEndian::HostSwap32; 57 58 /** 59 * This class implements Network Diagnostic TLV generation and parsing. 60 * 61 */ 62 OT_TOOL_PACKED_BEGIN 63 class Tlv : public ot::Tlv 64 { 65 public: 66 /** 67 * Network Diagnostic TLV Types. 68 * 69 */ 70 enum Type : uint8_t 71 { 72 kExtMacAddress = OT_NETWORK_DIAGNOSTIC_TLV_EXT_ADDRESS, 73 kAddress16 = OT_NETWORK_DIAGNOSTIC_TLV_SHORT_ADDRESS, 74 kMode = OT_NETWORK_DIAGNOSTIC_TLV_MODE, 75 kTimeout = OT_NETWORK_DIAGNOSTIC_TLV_TIMEOUT, 76 kConnectivity = OT_NETWORK_DIAGNOSTIC_TLV_CONNECTIVITY, 77 kRoute = OT_NETWORK_DIAGNOSTIC_TLV_ROUTE, 78 kLeaderData = OT_NETWORK_DIAGNOSTIC_TLV_LEADER_DATA, 79 kNetworkData = OT_NETWORK_DIAGNOSTIC_TLV_NETWORK_DATA, 80 kIp6AddressList = OT_NETWORK_DIAGNOSTIC_TLV_IP6_ADDR_LIST, 81 kMacCounters = OT_NETWORK_DIAGNOSTIC_TLV_MAC_COUNTERS, 82 kBatteryLevel = OT_NETWORK_DIAGNOSTIC_TLV_BATTERY_LEVEL, 83 kSupplyVoltage = OT_NETWORK_DIAGNOSTIC_TLV_SUPPLY_VOLTAGE, 84 kChildTable = OT_NETWORK_DIAGNOSTIC_TLV_CHILD_TABLE, 85 kChannelPages = OT_NETWORK_DIAGNOSTIC_TLV_CHANNEL_PAGES, 86 kTypeList = OT_NETWORK_DIAGNOSTIC_TLV_TYPE_LIST, 87 kMaxChildTimeout = OT_NETWORK_DIAGNOSTIC_TLV_MAX_CHILD_TIMEOUT, 88 kVersion = OT_NETWORK_DIAGNOSTIC_TLV_VERSION, 89 kVendorName = OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_NAME, 90 kVendorModel = OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_MODEL, 91 kVendorSwVersion = OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_SW_VERSION, 92 kThreadStackVersion = OT_NETWORK_DIAGNOSTIC_TLV_THREAD_STACK_VERSION, 93 }; 94 95 /** 96 * Maximum length of Vendor Name TLV. 97 * 98 */ 99 static constexpr uint8_t kMaxVendorNameLength = OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_NAME_TLV_LENGTH; 100 101 /** 102 * Maximum length of Vendor Model TLV. 103 * 104 */ 105 static constexpr uint8_t kMaxVendorModelLength = OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_MODEL_TLV_LENGTH; 106 107 /** 108 * Maximum length of Vendor SW Version TLV. 109 * 110 */ 111 static constexpr uint8_t kMaxVendorSwVersionLength = OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_SW_VERSION_TLV_LENGTH; 112 113 /** 114 * Maximum length of Vendor SW Version TLV. 115 * 116 */ 117 static constexpr uint8_t kMaxThreadStackVersionLength = OT_NETWORK_DIAGNOSTIC_MAX_THREAD_STACK_VERSION_TLV_LENGTH; 118 119 /** 120 * This method returns the Type value. 121 * 122 * @returns The Type value. 123 * 124 */ GetType(void) const125 Type GetType(void) const { return static_cast<Type>(ot::Tlv::GetType()); } 126 127 /** 128 * This method sets the Type value. 129 * 130 * @param[in] aType The Type value. 131 * 132 */ SetType(Type aType)133 void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); } 134 135 } OT_TOOL_PACKED_END; 136 137 /** 138 * This class defines Extended MAC Address TLV constants and types. 139 * 140 */ 141 typedef SimpleTlvInfo<Tlv::kExtMacAddress, Mac::ExtAddress> ExtMacAddressTlv; 142 143 /** 144 * This class defines Address16 TLV constants and types. 145 * 146 */ 147 typedef UintTlvInfo<Tlv::kAddress16, uint16_t> Address16Tlv; 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 Network Data TLV constants and types. 163 * 164 */ 165 typedef TlvInfo<Tlv::kNetworkData> NetworkDataTlv; 166 167 /** 168 * This class defines IPv6 Address List TLV constants and types. 169 * 170 */ 171 typedef TlvInfo<Tlv::kIp6AddressList> Ip6AddressListTlv; 172 173 /** 174 * This class defines Battery Level TLV constants and types. 175 * 176 */ 177 typedef UintTlvInfo<Tlv::kBatteryLevel, uint8_t> BatteryLevelTlv; 178 179 /** 180 * This class defines Supply Voltage TLV constants and types. 181 * 182 */ 183 typedef UintTlvInfo<Tlv::kSupplyVoltage, uint16_t> SupplyVoltageTlv; 184 185 /** 186 * This class defines Child Table TLV constants and types. 187 * 188 */ 189 typedef TlvInfo<Tlv::kChildTable> ChildTableTlv; 190 191 /** 192 * This class defines Max Child Timeout TLV constants and types. 193 * 194 */ 195 typedef UintTlvInfo<Tlv::kMaxChildTimeout, uint32_t> MaxChildTimeoutTlv; 196 197 /** 198 * This class defines Version TLV constants and types. 199 * 200 */ 201 typedef UintTlvInfo<Tlv::kVersion, uint16_t> VersionTlv; 202 203 /** 204 * This class defines Vendor Name TLV constants and types. 205 * 206 */ 207 typedef StringTlvInfo<Tlv::kVendorName, Tlv::kMaxVendorNameLength> VendorNameTlv; 208 209 /** 210 * This class defines Vendor Model TLV constants and types. 211 * 212 */ 213 typedef StringTlvInfo<Tlv::kVendorModel, Tlv::kMaxVendorModelLength> VendorModelTlv; 214 215 /** 216 * This class defines Vendor SW Version TLV constants and types. 217 * 218 */ 219 typedef StringTlvInfo<Tlv::kVendorSwVersion, Tlv::kMaxVendorSwVersionLength> VendorSwVersionTlv; 220 221 /** 222 * This class defines Thread Stack Version TLV constants and types. 223 * 224 */ 225 typedef StringTlvInfo<Tlv::kThreadStackVersion, Tlv::kMaxThreadStackVersionLength> ThreadStackVersionTlv; 226 227 typedef otNetworkDiagConnectivity Connectivity; ///< Network Diagnostic Connectivity value. 228 229 /** 230 * This class implements Connectivity TLV generation and parsing. 231 * 232 */ 233 OT_TOOL_PACKED_BEGIN 234 class ConnectivityTlv : public Mle::ConnectivityTlv 235 { 236 public: 237 static constexpr uint8_t kType = ot::NetworkDiagnostic::Tlv::kConnectivity; ///< The TLV Type value. 238 239 /** 240 * This method initializes the TLV. 241 * 242 */ Init(void)243 void Init(void) 244 { 245 Mle::ConnectivityTlv::Init(); 246 ot::Tlv::SetType(kType); 247 } 248 249 /** 250 * This method retrieves the `Connectivity` value. 251 * 252 * @param[out] aConnectivity A reference to `Connectivity` to populate. 253 * 254 */ GetConnectivity(Connectivity & aConnectivity) const255 void GetConnectivity(Connectivity &aConnectivity) const 256 { 257 aConnectivity.mParentPriority = GetParentPriority(); 258 aConnectivity.mLinkQuality3 = GetLinkQuality3(); 259 aConnectivity.mLinkQuality2 = GetLinkQuality2(); 260 aConnectivity.mLinkQuality1 = GetLinkQuality1(); 261 aConnectivity.mLeaderCost = GetLeaderCost(); 262 aConnectivity.mIdSequence = GetIdSequence(); 263 aConnectivity.mActiveRouters = GetActiveRouters(); 264 aConnectivity.mSedBufferSize = GetSedBufferSize(); 265 aConnectivity.mSedDatagramCount = GetSedDatagramCount(); 266 } 267 268 } OT_TOOL_PACKED_END; 269 270 /** 271 * This class implements Route TLV generation and parsing. 272 * 273 */ 274 OT_TOOL_PACKED_BEGIN 275 class RouteTlv : public Mle::RouteTlv 276 { 277 public: 278 static constexpr uint8_t kType = ot::NetworkDiagnostic::Tlv::kRoute; ///< The TLV Type value. 279 280 /** 281 * This method initializes the TLV. 282 * 283 */ Init(void)284 void Init(void) 285 { 286 Mle::RouteTlv::Init(); 287 ot::Tlv::SetType(kType); 288 } 289 } OT_TOOL_PACKED_END; 290 291 /** 292 * This class implements Leader Data TLV generation and parsing. 293 * 294 */ 295 OT_TOOL_PACKED_BEGIN 296 class LeaderDataTlv : public Mle::LeaderDataTlv 297 { 298 public: 299 static constexpr uint8_t kType = ot::NetworkDiagnostic::Tlv::kLeaderData; ///< The TLV Type value. 300 301 /** 302 * This method initializes the TLV. 303 * 304 */ Init(void)305 void Init(void) 306 { 307 Mle::LeaderDataTlv::Init(); 308 ot::Tlv::SetType(kType); 309 } 310 } OT_TOOL_PACKED_END; 311 312 /** 313 * This class implements Mac Counters TLV generation and parsing. 314 * 315 */ 316 OT_TOOL_PACKED_BEGIN 317 class MacCountersTlv : public Tlv, public TlvInfo<Tlv::kMacCounters> 318 { 319 public: 320 /** 321 * This method initializes the TLV. 322 * 323 */ Init(void)324 void Init(void) 325 { 326 SetType(kMacCounters); 327 SetLength(sizeof(*this) - sizeof(Tlv)); 328 } 329 330 /** 331 * This method indicates whether or not the TLV appears to be well-formed. 332 * 333 * @retval TRUE If the TLV appears to be well-formed. 334 * @retval FALSE If the TLV does not appear to be well-formed. 335 * 336 */ IsValid(void) const337 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 338 339 /** 340 * This method returns the IfInUnknownProtos counter. 341 * 342 * @returns The IfInUnknownProtos counter 343 * 344 */ GetIfInUnknownProtos(void) const345 uint32_t GetIfInUnknownProtos(void) const { return HostSwap32(mIfInUnknownProtos); } 346 347 /** 348 * This method sets the IfInUnknownProtos counter. 349 * 350 * @param[in] aIfInUnknownProtos The IfInUnknownProtos counter 351 * 352 */ SetIfInUnknownProtos(const uint32_t aIfInUnknownProtos)353 void SetIfInUnknownProtos(const uint32_t aIfInUnknownProtos) 354 { 355 mIfInUnknownProtos = HostSwap32(aIfInUnknownProtos); 356 } 357 358 /** 359 * This method returns the IfInErrors counter. 360 * 361 * @returns The IfInErrors counter 362 * 363 */ GetIfInErrors(void) const364 uint32_t GetIfInErrors(void) const { return HostSwap32(mIfInErrors); } 365 366 /** 367 * This method sets the IfInErrors counter. 368 * 369 * @param[in] aIfInErrors The IfInErrors counter 370 * 371 */ SetIfInErrors(const uint32_t aIfInErrors)372 void SetIfInErrors(const uint32_t aIfInErrors) { mIfInErrors = HostSwap32(aIfInErrors); } 373 374 /** 375 * This method returns the IfOutErrors counter. 376 * 377 * @returns The IfOutErrors counter 378 * 379 */ GetIfOutErrors(void) const380 uint32_t GetIfOutErrors(void) const { return HostSwap32(mIfOutErrors); } 381 382 /** 383 * This method sets the IfOutErrors counter. 384 * 385 * @param[in] aIfOutErrors The IfOutErrors counter. 386 * 387 */ SetIfOutErrors(const uint32_t aIfOutErrors)388 void SetIfOutErrors(const uint32_t aIfOutErrors) { mIfOutErrors = HostSwap32(aIfOutErrors); } 389 390 /** 391 * This method returns the IfInUcastPkts counter. 392 * 393 * @returns The IfInUcastPkts counter 394 * 395 */ GetIfInUcastPkts(void) const396 uint32_t GetIfInUcastPkts(void) const { return HostSwap32(mIfInUcastPkts); } 397 398 /** 399 * This method sets the IfInUcastPkts counter. 400 * 401 * @param[in] aIfInUcastPkts The IfInUcastPkts counter. 402 * 403 */ SetIfInUcastPkts(const uint32_t aIfInUcastPkts)404 void SetIfInUcastPkts(const uint32_t aIfInUcastPkts) { mIfInUcastPkts = HostSwap32(aIfInUcastPkts); } 405 /** 406 * This method returns the IfInBroadcastPkts counter. 407 * 408 * @returns The IfInBroadcastPkts counter 409 * 410 */ GetIfInBroadcastPkts(void) const411 uint32_t GetIfInBroadcastPkts(void) const { return HostSwap32(mIfInBroadcastPkts); } 412 413 /** 414 * This method sets the IfInBroadcastPkts counter. 415 * 416 * @param[in] aIfInBroadcastPkts The IfInBroadcastPkts counter. 417 * 418 */ SetIfInBroadcastPkts(const uint32_t aIfInBroadcastPkts)419 void SetIfInBroadcastPkts(const uint32_t aIfInBroadcastPkts) 420 { 421 mIfInBroadcastPkts = HostSwap32(aIfInBroadcastPkts); 422 } 423 424 /** 425 * This method returns the IfInDiscards counter. 426 * 427 * @returns The IfInDiscards counter 428 * 429 */ GetIfInDiscards(void) const430 uint32_t GetIfInDiscards(void) const { return HostSwap32(mIfInDiscards); } 431 432 /** 433 * This method sets the IfInDiscards counter. 434 * 435 * @param[in] aIfInDiscards The IfInDiscards counter. 436 * 437 */ SetIfInDiscards(const uint32_t aIfInDiscards)438 void SetIfInDiscards(const uint32_t aIfInDiscards) { mIfInDiscards = HostSwap32(aIfInDiscards); } 439 440 /** 441 * This method returns the IfOutUcastPkts counter. 442 * 443 * @returns The IfOutUcastPkts counter 444 * 445 */ GetIfOutUcastPkts(void) const446 uint32_t GetIfOutUcastPkts(void) const { return HostSwap32(mIfOutUcastPkts); } 447 448 /** 449 * This method sets the IfOutUcastPkts counter. 450 * 451 * @param[in] aIfOutUcastPkts The IfOutUcastPkts counter. 452 * 453 */ SetIfOutUcastPkts(const uint32_t aIfOutUcastPkts)454 void SetIfOutUcastPkts(const uint32_t aIfOutUcastPkts) { mIfOutUcastPkts = HostSwap32(aIfOutUcastPkts); } 455 456 /** 457 * This method returns the IfOutBroadcastPkts counter. 458 * 459 * @returns The IfOutBroadcastPkts counter 460 * 461 */ GetIfOutBroadcastPkts(void) const462 uint32_t GetIfOutBroadcastPkts(void) const { return HostSwap32(mIfOutBroadcastPkts); } 463 464 /** 465 * This method sets the IfOutBroadcastPkts counter. 466 * 467 * @param[in] aIfOutBroadcastPkts The IfOutBroadcastPkts counter. 468 * 469 */ SetIfOutBroadcastPkts(const uint32_t aIfOutBroadcastPkts)470 void SetIfOutBroadcastPkts(const uint32_t aIfOutBroadcastPkts) 471 { 472 mIfOutBroadcastPkts = HostSwap32(aIfOutBroadcastPkts); 473 } 474 475 /** 476 * This method returns the IfOutDiscards counter. 477 * 478 * @returns The IfOutDiscards counter 479 * 480 */ GetIfOutDiscards(void) const481 uint32_t GetIfOutDiscards(void) const { return HostSwap32(mIfOutDiscards); } 482 483 /** 484 * This method sets the IfOutDiscards counter. 485 * 486 * @param[in] aIfOutDiscards The IfOutDiscards counter. 487 * 488 */ SetIfOutDiscards(const uint32_t aIfOutDiscards)489 void SetIfOutDiscards(const uint32_t aIfOutDiscards) { mIfOutDiscards = HostSwap32(aIfOutDiscards); } 490 491 private: 492 uint32_t mIfInUnknownProtos; 493 uint32_t mIfInErrors; 494 uint32_t mIfOutErrors; 495 uint32_t mIfInUcastPkts; 496 uint32_t mIfInBroadcastPkts; 497 uint32_t mIfInDiscards; 498 uint32_t mIfOutUcastPkts; 499 uint32_t mIfOutBroadcastPkts; 500 uint32_t mIfOutDiscards; 501 } OT_TOOL_PACKED_END; 502 503 /** 504 * This class implements Child Table Entry generation and parsing. 505 * 506 */ 507 OT_TOOL_PACKED_BEGIN 508 class ChildTableEntry : public Clearable<ChildTableEntry> 509 { 510 public: 511 /** 512 * This method returns the Timeout value. 513 * 514 * @returns The Timeout value. 515 * 516 */ GetTimeout(void) const517 uint8_t GetTimeout(void) const { return (GetTimeoutChildId() & kTimeoutMask) >> kTimeoutOffset; } 518 519 /** 520 * This method sets the Timeout value. 521 * 522 * @param[in] aTimeout The Timeout value. 523 * 524 */ SetTimeout(uint8_t aTimeout)525 void SetTimeout(uint8_t aTimeout) 526 { 527 SetTimeoutChildId((GetTimeoutChildId() & ~kTimeoutMask) | ((aTimeout << kTimeoutOffset) & kTimeoutMask)); 528 } 529 530 /** 531 * This method the Link Quality value. 532 * 533 * @returns The Link Quality value. 534 * 535 */ GetLinkQuality(void) const536 LinkQuality GetLinkQuality(void) const 537 { 538 return static_cast<LinkQuality>((GetTimeoutChildId() & kLqiMask) >> kLqiOffset); 539 } 540 541 /** 542 * This method set the Link Quality value. 543 * 544 * @param[in] aLinkQuality The Link Quality value. 545 * 546 */ SetLinkQuality(LinkQuality aLinkQuality)547 void SetLinkQuality(LinkQuality aLinkQuality) 548 { 549 SetTimeoutChildId((GetTimeoutChildId() & ~kLqiMask) | ((aLinkQuality << kLqiOffset) & kLqiMask)); 550 } 551 552 /** 553 * This method returns the Child ID value. 554 * 555 * @returns The Child ID value. 556 * 557 */ GetChildId(void) const558 uint16_t GetChildId(void) const { return (GetTimeoutChildId() & kChildIdMask) >> kChildIdOffset; } 559 560 /** 561 * This method sets the Child ID value. 562 * 563 * @param[in] aChildId The Child ID value. 564 * 565 */ SetChildId(uint16_t aChildId)566 void SetChildId(uint16_t aChildId) 567 { 568 SetTimeoutChildId((GetTimeoutChildId() & ~kChildIdMask) | ((aChildId << kChildIdOffset) & kChildIdMask)); 569 } 570 571 /** 572 * This method returns the Device Mode 573 * 574 * @returns The Device Mode 575 * 576 */ GetMode(void) const577 Mle::DeviceMode GetMode(void) const { return Mle::DeviceMode(mMode); } 578 579 /** 580 * This method sets the Device Mode. 581 * 582 * @param[in] aMode The Device Mode. 583 * 584 */ SetMode(Mle::DeviceMode aMode)585 void SetMode(Mle::DeviceMode aMode) { mMode = aMode.Get(); } 586 587 private: 588 // 1 0 589 // 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 590 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 591 // | Timeout |LQI| Child ID | 592 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 593 594 static constexpr uint8_t kTimeoutOffset = 11; 595 static constexpr uint8_t kLqiOffset = 9; 596 static constexpr uint8_t kChildIdOffset = 0; 597 static constexpr uint16_t kTimeoutMask = 0x1f << kTimeoutOffset; 598 static constexpr uint16_t kLqiMask = 0x3 << kLqiOffset; 599 static constexpr uint16_t kChildIdMask = 0x1ff << kChildIdOffset; 600 GetTimeoutChildId(void) const601 uint16_t GetTimeoutChildId(void) const { return HostSwap16(mTimeoutChildId); } SetTimeoutChildId(uint16_t aTimeoutChildIf)602 void SetTimeoutChildId(uint16_t aTimeoutChildIf) { mTimeoutChildId = HostSwap16(aTimeoutChildIf); } 603 604 uint16_t mTimeoutChildId; 605 uint8_t mMode; 606 } OT_TOOL_PACKED_END; 607 608 /** 609 * This class implements Channel Pages TLV generation and parsing. 610 * 611 */ 612 OT_TOOL_PACKED_BEGIN 613 class ChannelPagesTlv : public Tlv, public TlvInfo<Tlv::kChannelPages> 614 { 615 public: 616 /** 617 * This method initializes the TLV. 618 * 619 */ Init(void)620 void Init(void) 621 { 622 SetType(kChannelPages); 623 SetLength(sizeof(*this) - sizeof(Tlv)); 624 } 625 626 /** 627 * This method indicates whether or not the TLV appears to be well-formed. 628 * 629 * @retval TRUE If the TLV appears to be well-formed. 630 * @retval FALSE If the TLV does not appear to be well-formed. 631 * 632 */ IsValid(void) const633 bool IsValid(void) const 634 { 635 // At least one channel page must be included. 636 return GetLength() >= 1; 637 } 638 639 /** 640 * This method returns a pointer to the list of Channel Pages. 641 * 642 * @returns A pointer to the list of Channel Pages. 643 * 644 */ GetChannelPages(void)645 uint8_t *GetChannelPages(void) { return mChannelPages; } 646 647 private: 648 uint8_t mChannelPages[Radio::kNumChannelPages]; 649 } OT_TOOL_PACKED_END; 650 651 /** 652 * This class implements IPv6 Address List TLV generation and parsing. 653 * 654 */ 655 OT_TOOL_PACKED_BEGIN 656 class TypeListTlv : public Tlv, public TlvInfo<Tlv::kTypeList> 657 { 658 public: 659 /** 660 * This method initializes the TLV. 661 * 662 */ Init(void)663 void Init(void) 664 { 665 SetType(kTypeList); 666 SetLength(sizeof(*this) - sizeof(Tlv)); 667 } 668 } OT_TOOL_PACKED_END; 669 670 } // namespace NetworkDiagnostic 671 } // namespace ot 672 673 #endif // NETWORK_DIAGNOSTIC_TLVS_HPP_ 674