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 MeshCoP TLVs. 32 * 33 */ 34 35 #ifndef MESHCOP_TLVS_HPP_ 36 #define MESHCOP_TLVS_HPP_ 37 38 #include "openthread-core-config.h" 39 40 #include <openthread/commissioner.h> 41 #include <openthread/dataset.h> 42 #include <openthread/platform/radio.h> 43 44 #include "common/const_cast.hpp" 45 #include "common/encoding.hpp" 46 #include "common/message.hpp" 47 #include "common/num_utils.hpp" 48 #include "common/string.hpp" 49 #include "common/tlvs.hpp" 50 #include "mac/mac_types.hpp" 51 #include "meshcop/extended_panid.hpp" 52 #include "meshcop/network_name.hpp" 53 #include "meshcop/timestamp.hpp" 54 #include "net/ip6_address.hpp" 55 #include "radio/radio.hpp" 56 #include "thread/key_manager.hpp" 57 #include "thread/mle_tlvs.hpp" 58 #include "thread/mle_types.hpp" 59 60 namespace ot { 61 namespace MeshCoP { 62 63 /** 64 * Implements MeshCoP TLV generation and parsing. 65 * 66 */ 67 OT_TOOL_PACKED_BEGIN 68 class Tlv : public ot::Tlv 69 { 70 public: 71 /** 72 * MeshCoP TLV Types. 73 * 74 */ 75 enum Type : uint8_t 76 { 77 kChannel = OT_MESHCOP_TLV_CHANNEL, ///< Channel TLV 78 kPanId = OT_MESHCOP_TLV_PANID, ///< PAN ID TLV 79 kExtendedPanId = OT_MESHCOP_TLV_EXTPANID, ///< Extended PAN ID TLV 80 kNetworkName = OT_MESHCOP_TLV_NETWORKNAME, ///< Network Name TLV 81 kPskc = OT_MESHCOP_TLV_PSKC, ///< PSKc TLV 82 kNetworkKey = OT_MESHCOP_TLV_NETWORKKEY, ///< Network Network Key TLV 83 kNetworkKeySequence = OT_MESHCOP_TLV_NETWORK_KEY_SEQUENCE, ///< Network Key Sequence TLV 84 kMeshLocalPrefix = OT_MESHCOP_TLV_MESHLOCALPREFIX, ///< Mesh Local Prefix TLV 85 kSteeringData = OT_MESHCOP_TLV_STEERING_DATA, ///< Steering Data TLV 86 kBorderAgentLocator = OT_MESHCOP_TLV_BORDER_AGENT_RLOC, ///< Border Agent Locator TLV 87 kCommissionerId = OT_MESHCOP_TLV_COMMISSIONER_ID, ///< Commissioner ID TLV 88 kCommissionerSessionId = OT_MESHCOP_TLV_COMM_SESSION_ID, ///< Commissioner Session ID TLV 89 kSecurityPolicy = OT_MESHCOP_TLV_SECURITYPOLICY, ///< Security Policy TLV 90 kGet = OT_MESHCOP_TLV_GET, ///< Get TLV 91 kActiveTimestamp = OT_MESHCOP_TLV_ACTIVETIMESTAMP, ///< Active Timestamp TLV 92 kCommissionerUdpPort = OT_MESHCOP_TLV_COMMISSIONER_UDP_PORT, ///< Commissioner UDP Port TLV 93 kState = OT_MESHCOP_TLV_STATE, ///< State TLV 94 kJoinerDtlsEncapsulation = OT_MESHCOP_TLV_JOINER_DTLS, ///< Joiner DTLS Encapsulation TLV 95 kJoinerUdpPort = OT_MESHCOP_TLV_JOINER_UDP_PORT, ///< Joiner UDP Port TLV 96 kJoinerIid = OT_MESHCOP_TLV_JOINER_IID, ///< Joiner IID TLV 97 kJoinerRouterLocator = OT_MESHCOP_TLV_JOINER_RLOC, ///< Joiner Router Locator TLV 98 kJoinerRouterKek = OT_MESHCOP_TLV_JOINER_ROUTER_KEK, ///< Joiner Router KEK TLV 99 kProvisioningUrl = OT_MESHCOP_TLV_PROVISIONING_URL, ///< Provisioning URL TLV 100 kVendorName = OT_MESHCOP_TLV_VENDOR_NAME_TLV, ///< meshcop Vendor Name TLV 101 kVendorModel = OT_MESHCOP_TLV_VENDOR_MODEL_TLV, ///< meshcop Vendor Model TLV 102 kVendorSwVersion = OT_MESHCOP_TLV_VENDOR_SW_VERSION_TLV, ///< meshcop Vendor SW Version TLV 103 kVendorData = OT_MESHCOP_TLV_VENDOR_DATA_TLV, ///< meshcop Vendor Data TLV 104 kVendorStackVersion = OT_MESHCOP_TLV_VENDOR_STACK_VERSION_TLV, ///< meshcop Vendor Stack Version TLV 105 kUdpEncapsulation = OT_MESHCOP_TLV_UDP_ENCAPSULATION_TLV, ///< meshcop UDP encapsulation TLV 106 kIp6Address = OT_MESHCOP_TLV_IPV6_ADDRESS_TLV, ///< meshcop IPv6 address TLV 107 kPendingTimestamp = OT_MESHCOP_TLV_PENDINGTIMESTAMP, ///< Pending Timestamp TLV 108 kDelayTimer = OT_MESHCOP_TLV_DELAYTIMER, ///< Delay Timer TLV 109 kChannelMask = OT_MESHCOP_TLV_CHANNELMASK, ///< Channel Mask TLV 110 kCount = OT_MESHCOP_TLV_COUNT, ///< Count TLV 111 kPeriod = OT_MESHCOP_TLV_PERIOD, ///< Period TLV 112 kScanDuration = OT_MESHCOP_TLV_SCAN_DURATION, ///< Scan Duration TLV 113 kEnergyList = OT_MESHCOP_TLV_ENERGY_LIST, ///< Energy List TLV 114 kDiscoveryRequest = OT_MESHCOP_TLV_DISCOVERYREQUEST, ///< Discovery Request TLV 115 kDiscoveryResponse = OT_MESHCOP_TLV_DISCOVERYRESPONSE, ///< Discovery Response TLV 116 kJoinerAdvertisement = OT_MESHCOP_TLV_JOINERADVERTISEMENT, ///< Joiner Advertisement TLV 117 }; 118 119 /** 120 * Max length of Provisioning URL TLV. 121 * 122 */ 123 static constexpr uint8_t kMaxProvisioningUrlLength = OT_PROVISIONING_URL_MAX_SIZE; 124 125 static constexpr uint8_t kMaxCommissionerIdLength = 64; ///< Max length of Commissioner ID TLV. 126 static constexpr uint8_t kMaxVendorNameLength = 32; ///< Max length of Vendor Name TLV. 127 static constexpr uint8_t kMaxVendorModelLength = 32; ///< Max length of Vendor Model TLV. 128 static constexpr uint8_t kMaxVendorSwVersionLength = 16; ///< Max length of Vendor SW Version TLV. 129 static constexpr uint8_t kMaxVendorDataLength = 64; ///< Max length of Vendor Data TLV. 130 131 /** 132 * Returns the Type value. 133 * 134 * @returns The Type value. 135 * 136 */ GetType(void) const137 Type GetType(void) const { return static_cast<Type>(ot::Tlv::GetType()); } 138 139 /** 140 * Sets the Type value. 141 * 142 * @param[in] aType The Type value. 143 * 144 */ SetType(Type aType)145 void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); } 146 147 /** 148 * Returns a pointer to the next TLV. 149 * 150 * @returns A pointer to the next TLV. 151 * 152 */ GetNext(void)153 Tlv *GetNext(void) { return As<Tlv>(ot::Tlv::GetNext()); } 154 155 /** 156 * Returns a pointer to the next TLV. 157 * 158 * @returns A pointer to the next TLV. 159 * 160 */ GetNext(void) const161 const Tlv *GetNext(void) const { return As<Tlv>(ot::Tlv::GetNext()); } 162 163 } OT_TOOL_PACKED_END; 164 165 /** 166 * Implements extended MeshCoP TLV generation and parsing. 167 * 168 */ 169 OT_TOOL_PACKED_BEGIN 170 class ExtendedTlv : public ot::ExtendedTlv 171 { 172 public: 173 /** 174 * Returns the Type value. 175 * 176 * @returns The Type value. 177 * 178 */ GetType(void) const179 MeshCoP::Tlv::Type GetType(void) const { return static_cast<MeshCoP::Tlv::Type>(ot::ExtendedTlv::GetType()); } 180 181 /** 182 * Sets the Type value. 183 * 184 * @param[in] aType The Type value. 185 * 186 */ SetType(MeshCoP::Tlv::Type aType)187 void SetType(MeshCoP::Tlv::Type aType) { ot::ExtendedTlv::SetType(static_cast<uint8_t>(aType)); } 188 } OT_TOOL_PACKED_END; 189 190 /** 191 * Defines Commissioner UDP Port TLV constants and types. 192 * 193 */ 194 typedef UintTlvInfo<Tlv::kCommissionerUdpPort, uint16_t> CommissionerUdpPortTlv; 195 196 /** 197 * Defines IPv6 Address TLV constants and types. 198 * 199 */ 200 typedef SimpleTlvInfo<Tlv::kIp6Address, Ip6::Address> Ip6AddressTlv; 201 202 /** 203 * Defines Joiner IID TLV constants and types. 204 * 205 */ 206 typedef SimpleTlvInfo<Tlv::kJoinerIid, Ip6::InterfaceIdentifier> JoinerIidTlv; 207 208 /** 209 * Defines Joiner Router Locator TLV constants and types. 210 * 211 */ 212 typedef UintTlvInfo<Tlv::kJoinerRouterLocator, uint16_t> JoinerRouterLocatorTlv; 213 214 /** 215 * Defines Joiner Router KEK TLV constants and types. 216 * 217 */ 218 typedef SimpleTlvInfo<Tlv::kJoinerRouterKek, Kek> JoinerRouterKekTlv; 219 220 /** 221 * Defines Count TLV constants and types. 222 * 223 */ 224 typedef UintTlvInfo<Tlv::kCount, uint8_t> CountTlv; 225 226 /** 227 * Defines Period TLV constants and types. 228 * 229 */ 230 typedef UintTlvInfo<Tlv::kPeriod, uint16_t> PeriodTlv; 231 232 /** 233 * Defines Scan Duration TLV constants and types. 234 * 235 */ 236 typedef UintTlvInfo<Tlv::kScanDuration, uint16_t> ScanDurationTlv; 237 238 /** 239 * Defines Commissioner ID TLV constants and types. 240 * 241 */ 242 typedef StringTlvInfo<Tlv::kCommissionerId, Tlv::kMaxCommissionerIdLength> CommissionerIdTlv; 243 244 /** 245 * Implements Channel TLV value format. 246 * 247 */ 248 typedef Mle::ChannelTlvValue ChannelTlvValue; 249 250 /** 251 * Defines Channel TLV constants and types. 252 * 253 */ 254 typedef SimpleTlvInfo<Tlv::kChannel, ChannelTlvValue> ChannelTlv; 255 256 /** 257 * Defines PAN ID TLV constants and types. 258 * 259 */ 260 typedef UintTlvInfo<Tlv::kPanId, uint16_t> PanIdTlv; 261 262 /** 263 * Defines Extended PAN ID TLV constants and types. 264 * 265 */ 266 typedef SimpleTlvInfo<Tlv::kExtendedPanId, ExtendedPanId> ExtendedPanIdTlv; 267 268 /** 269 * Implements Network Name TLV generation and parsing. 270 * 271 */ 272 OT_TOOL_PACKED_BEGIN 273 class NetworkNameTlv : public Tlv, public StringTlvInfo<Tlv::kNetworkName, NetworkName::kMaxSize> 274 { 275 public: 276 /** 277 * Initializes the TLV. 278 * 279 */ Init(void)280 void Init(void) 281 { 282 SetType(kNetworkName); 283 SetLength(sizeof(*this) - sizeof(Tlv)); 284 } 285 286 /** 287 * Indicates whether or not the TLV appears to be well-formed. 288 * 289 * @retval TRUE If the TLV appears to be well-formed. 290 * @retval FALSE If the TLV does not appear to be well-formed. 291 * 292 */ 293 bool IsValid(void) const; 294 295 /** 296 * Gets the Network Name value. 297 * 298 * @returns The Network Name value (as `NameData`). 299 * 300 */ 301 NameData GetNetworkName(void) const; 302 303 /** 304 * Sets the Network Name value. 305 * 306 * @param[in] aNameData A Network Name value (as `NameData`). 307 * 308 */ 309 void SetNetworkName(const NameData &aNameData); 310 311 private: 312 char mNetworkName[NetworkName::kMaxSize]; 313 } OT_TOOL_PACKED_END; 314 315 /** 316 * Defines PSKc TLV constants and types. 317 * 318 */ 319 typedef SimpleTlvInfo<Tlv::kPskc, Pskc> PskcTlv; 320 321 /** 322 * Defines Network Key TLV constants and types. 323 * 324 */ 325 typedef SimpleTlvInfo<Tlv::kNetworkKey, NetworkKey> NetworkKeyTlv; 326 327 /** 328 * Defines Network Key Sequence TLV constants and types. 329 * 330 */ 331 typedef UintTlvInfo<Tlv::kNetworkKeySequence, uint32_t> NetworkKeySequenceTlv; 332 333 /** 334 * Defines Mesh Local Prefix TLV constants and types. 335 * 336 */ 337 typedef SimpleTlvInfo<Tlv::kMeshLocalPrefix, Ip6::NetworkPrefix> MeshLocalPrefixTlv; 338 339 class SteeringData; 340 341 /** 342 * Implements Steering Data TLV generation and parsing. 343 * 344 */ 345 OT_TOOL_PACKED_BEGIN 346 class SteeringDataTlv : public Tlv, public TlvInfo<Tlv::kSteeringData> 347 { 348 public: 349 /** 350 * Initializes the TLV. 351 * 352 */ Init(void)353 void Init(void) 354 { 355 SetType(kSteeringData); 356 SetLength(sizeof(*this) - sizeof(Tlv)); 357 Clear(); 358 } 359 360 /** 361 * Indicates whether or not the TLV appears to be well-formed. 362 * 363 * @retval TRUE If the TLV appears to be well-formed. 364 * @retval FALSE If the TLV does not appear to be well-formed. 365 * 366 */ IsValid(void) const367 bool IsValid(void) const { return GetLength() > 0; } 368 369 /** 370 * Returns the Steering Data length. 371 * 372 * @returns The Steering Data length. 373 * 374 */ GetSteeringDataLength(void) const375 uint8_t GetSteeringDataLength(void) const 376 { 377 return GetLength() <= sizeof(mSteeringData) ? GetLength() : sizeof(mSteeringData); 378 } 379 380 /** 381 * Sets all bits in the Bloom Filter to zero. 382 * 383 */ Clear(void)384 void Clear(void) { memset(mSteeringData, 0, GetSteeringDataLength()); } 385 386 /** 387 * Copies the Steering Data from the TLV into a given `SteeringData` variable. 388 * 389 * @param[out] aSteeringData A reference to a `SteeringData` to copy into. 390 * 391 */ 392 void CopyTo(SteeringData &aSteeringData) const; 393 394 private: 395 uint8_t mSteeringData[OT_STEERING_DATA_MAX_LENGTH]; 396 } OT_TOOL_PACKED_END; 397 398 /** 399 * Implements Border Agent Locator TLV generation and parsing. 400 * 401 */ 402 OT_TOOL_PACKED_BEGIN 403 class BorderAgentLocatorTlv : public Tlv, public UintTlvInfo<Tlv::kBorderAgentLocator, uint16_t> 404 { 405 public: 406 /** 407 * Initializes the TLV. 408 * 409 */ Init(void)410 void Init(void) 411 { 412 SetType(kBorderAgentLocator); 413 SetLength(sizeof(*this) - sizeof(Tlv)); 414 } 415 416 /** 417 * Indicates whether or not the TLV appears to be well-formed. 418 * 419 * @retval TRUE If the TLV appears to be well-formed. 420 * @retval FALSE If the TLV does not appear to be well-formed. 421 * 422 */ IsValid(void) const423 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 424 425 /** 426 * Returns the Border Agent Locator value. 427 * 428 * @returns The Border Agent Locator value. 429 * 430 */ GetBorderAgentLocator(void) const431 uint16_t GetBorderAgentLocator(void) const { return BigEndian::HostSwap16(mLocator); } 432 433 /** 434 * Sets the Border Agent Locator value. 435 * 436 * @param[in] aLocator The Border Agent Locator value. 437 * 438 */ SetBorderAgentLocator(uint16_t aLocator)439 void SetBorderAgentLocator(uint16_t aLocator) { mLocator = BigEndian::HostSwap16(aLocator); } 440 441 private: 442 uint16_t mLocator; 443 } OT_TOOL_PACKED_END; 444 445 /** 446 * Implements Commissioner Session ID TLV generation and parsing. 447 * 448 */ 449 OT_TOOL_PACKED_BEGIN 450 class CommissionerSessionIdTlv : public Tlv, public UintTlvInfo<Tlv::kCommissionerSessionId, uint16_t> 451 { 452 public: 453 /** 454 * Initializes the TLV. 455 * 456 */ Init(void)457 void Init(void) 458 { 459 SetType(kCommissionerSessionId); 460 SetLength(sizeof(*this) - sizeof(Tlv)); 461 } 462 463 /** 464 * Indicates whether or not the TLV appears to be well-formed. 465 * 466 * @retval TRUE If the TLV appears to be well-formed. 467 * @retval FALSE If the TLV does not appear to be well-formed. 468 * 469 */ IsValid(void) const470 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 471 472 /** 473 * Returns the Commissioner Session ID value. 474 * 475 * @returns The Commissioner Session ID value. 476 * 477 */ GetCommissionerSessionId(void) const478 uint16_t GetCommissionerSessionId(void) const { return BigEndian::HostSwap16(mSessionId); } 479 480 /** 481 * Sets the Commissioner Session ID value. 482 * 483 * @param[in] aSessionId The Commissioner Session ID value. 484 * 485 */ SetCommissionerSessionId(uint16_t aSessionId)486 void SetCommissionerSessionId(uint16_t aSessionId) { mSessionId = BigEndian::HostSwap16(aSessionId); } 487 488 private: 489 uint16_t mSessionId; 490 } OT_TOOL_PACKED_END; 491 492 /** 493 * Implements Security Policy TLV generation and parsing. 494 * 495 */ 496 OT_TOOL_PACKED_BEGIN 497 class SecurityPolicyTlv : public Tlv, public TlvInfo<Tlv::kSecurityPolicy> 498 { 499 public: 500 /** 501 * Initializes the TLV. 502 * 503 */ Init(void)504 void Init(void) 505 { 506 SetType(kSecurityPolicy); 507 SetLength(sizeof(*this) - sizeof(Tlv)); 508 } 509 510 /** 511 * Indicates whether or not the TLV appears to be well-formed. 512 * 513 * @retval TRUE If the TLV appears to be well-formed. 514 * @retval FALSE If the TLV does not appear to be well-formed. 515 * 516 */ 517 bool IsValid(void) const; 518 519 /** 520 * Returns the Security Policy. 521 * 522 * @returns The Security Policy. 523 * 524 */ 525 SecurityPolicy GetSecurityPolicy(void) const; 526 527 /** 528 * Sets the Security Policy. 529 * 530 * @param[in] aSecurityPolicy The Security Policy which will be set. 531 * 532 */ 533 void SetSecurityPolicy(const SecurityPolicy &aSecurityPolicy); 534 535 private: 536 static constexpr uint8_t kThread11FlagsLength = 1; // The Thread 1.1 Security Policy Flags length. 537 static constexpr uint8_t kThread12FlagsLength = 2; // The Thread 1.2 Security Policy Flags length. 538 SetRotationTime(uint16_t aRotationTime)539 void SetRotationTime(uint16_t aRotationTime) { mRotationTime = BigEndian::HostSwap16(aRotationTime); } GetRotationTime(void) const540 uint16_t GetRotationTime(void) const { return BigEndian::HostSwap16(mRotationTime); } GetFlagsLength(void) const541 uint8_t GetFlagsLength(void) const { return GetLength() - sizeof(mRotationTime); } 542 543 uint16_t mRotationTime; 544 #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 545 uint8_t mFlags[kThread12FlagsLength]; 546 #else 547 uint8_t mFlags[kThread11FlagsLength]; 548 #endif 549 } OT_TOOL_PACKED_END; 550 551 /** 552 * Defines Active Timestamp TLV constants and types. 553 * 554 */ 555 typedef SimpleTlvInfo<Tlv::kActiveTimestamp, Timestamp> ActiveTimestampTlv; 556 557 /** 558 * Implements State TLV generation and parsing. 559 * 560 */ 561 class StateTlv : public UintTlvInfo<Tlv::kState, uint8_t> 562 { 563 public: 564 StateTlv(void) = delete; 565 566 /** 567 * State values. 568 * 569 */ 570 enum State : uint8_t 571 { 572 kReject = 0xff, ///< Reject (-1) 573 kPending = 0, ///< Pending 574 kAccept = 1, ///< Accept 575 }; 576 577 /** 578 * Converts a `State` to a string. 579 * 580 * @param[in] aState An item state. 581 * 582 * @returns A string representation of @p aState. 583 * 584 */ 585 static const char *StateToString(State aState); 586 }; 587 588 /** 589 * Defines Joiner UDP Port TLV constants and types. 590 * 591 */ 592 typedef UintTlvInfo<Tlv::kJoinerUdpPort, uint16_t> JoinerUdpPortTlv; 593 594 /** 595 * Defines Pending Timestamp TLV constants and types. 596 * 597 */ 598 typedef SimpleTlvInfo<Tlv::kPendingTimestamp, Timestamp> PendingTimestampTlv; 599 600 /** 601 * Defines Delay Timer TLV constants and types. 602 * 603 */ 604 class DelayTimerTlv : public UintTlvInfo<Tlv::kDelayTimer, uint32_t> 605 { 606 public: 607 /** 608 * Minimum Delay Timer value (in msec). 609 * 610 */ 611 static constexpr uint32_t kMinDelay = OPENTHREAD_CONFIG_TMF_PENDING_DATASET_MINIMUM_DELAY; 612 613 /** 614 * Maximum Delay Timer value (in msec). 615 * 616 */ 617 static constexpr uint32_t kMaxDelay = (72 * Time::kOneHourInMsec); 618 619 /** 620 * Default Delay Timer value (in msec). 621 * 622 */ 623 static constexpr uint32_t kDefaultDelay = OPENTHREAD_CONFIG_TMF_PENDING_DATASET_DEFAULT_DELAY; 624 625 /** 626 * Calculates the remaining delay in milliseconds, based on the value read from a Delay Timer TLV and the specified 627 * update time. 628 * 629 * Ensures that the calculated delay does not exceed `kMaxDelay`. Also accounts for time already elapsed since 630 * @p aUpdateTime. 631 * 632 * Caller MUST ensure that @p aDelayTimerTlv is a Delay Timer TLV, otherwise behavior is undefined. 633 * 634 * @param[in] aDelayTimerTlv The delay timer TLV to read delay from. 635 * @param[in] aUpdateTimer The update time of the Dataset. 636 * 637 * @return The remaining delay (in msec). 638 * 639 */ 640 static uint32_t CalculateRemainingDelay(const Tlv &aDelayTimerTlv, TimeMilli aUpdateTime); 641 642 static_assert(kMinDelay <= kMaxDelay, "TMF_PENDING_DATASET_MINIMUM_DELAY is larger than max allowed"); 643 static_assert(kDefaultDelay <= kMaxDelay, "TMF_PENDING_DATASET_DEFAULT_DELAY is larger than max allowed"); 644 static_assert(kDefaultDelay >= kMinDelay, "TMF_PENDING_DATASET_DEFAULT_DELAY is smaller than min allowed"); 645 }; 646 647 /** 648 * Implements Channel Mask TLV generation and parsing. 649 * 650 */ 651 OT_TOOL_PACKED_BEGIN 652 class ChannelMaskTlv : public Tlv, public TlvInfo<Tlv::kChannelMask> 653 { 654 static constexpr uint8_t kEntryHeaderSize = 2; // Two bytes: mChannelPage and mMaskLength 655 static constexpr uint8_t kEntrySize = kEntryHeaderSize + sizeof(uint32_t); 656 657 public: 658 /** 659 * Represents Channel Mask TLV value to append. 660 * 661 */ 662 struct Value 663 { 664 static constexpr uint16_t kMaxLength = (kEntrySize * Radio::kNumChannelPages); ///< Max value length. 665 666 uint8_t mData[kMaxLength]; ///< Array to store TLV value (encoded as one or more Channel Mask TLV Entry) 667 uint8_t mLength; ///< Value length in bytes. 668 }; 669 670 ChannelMaskTlv(void) = delete; 671 672 /** 673 * Parses the Channel Mask TLV value and validates that all the included entries are well-formed. 674 * 675 * @returns TRUE if the TLV is well-formed, FALSE otherwise. 676 * 677 */ 678 bool IsValid(void) const; 679 680 /** 681 * Parses and retrieves the combined channel mask for all supported channel pages from entries in the TLV. 682 * 683 * @param[out] aChannelMask A reference to return the channel mask. 684 * 685 * @retval kErrorNone Successfully parsed the TLV value, @p aChannelMask is updated. 686 * @retval kErrorParse TLV value is not well-formed. 687 * 688 */ 689 Error ReadChannelMask(uint32_t &aChannelMask) const; 690 691 /** 692 * Searches within a given message for Channel Mask TLV, parses and validates the TLV value and returns the 693 * combined channel mask for all supported channel pages included in the TLV. 694 * 695 * @param[in] aMessage The message to search in. 696 * @param[out] aChannelMask A reference to return the channel mask. 697 * 698 * @retval kErrorNone Found the TLV, successfully parsed its value, @p aChannelMask is updated. 699 * @retval kErrorNotFound No Channel Mask TLV found in the @p aMessage. 700 * @retval kErrorParse Found the TLV, but failed to parse it. 701 * 702 */ 703 static Error FindIn(const Message &aMessage, uint32_t &aChannelMask); 704 705 /** 706 * Prepares Channel Mask TLV value for appending/writing. 707 * 708 * @param[out] aValue A reference to `Value` structure to populate. 709 * @param[in] aChannelMask The combined channel mask for all supported channel pages. 710 * 711 */ 712 static void PrepareValue(Value &aValue, uint32_t aChannelMask); 713 714 /** 715 * Prepares a Channel Mask TLV value and appends the TLV to a given message. 716 * 717 * @param[in] aMessage The message to append to. 718 * @param[in] aChannelMask The combined channel mask for all supported channel pages. 719 * 720 * @retval kErrorNone Successfully prepared the Channel Mask TLV and appended it to @p aMessage. 721 * @retval kErrorNoBufs Insufficient available buffers to grow the message. 722 * 723 */ 724 static Error AppendTo(Message &aMessage, uint32_t aChannelMask); 725 726 private: 727 static constexpr uint8_t kMaskLength = sizeof(uint32_t); 728 729 OT_TOOL_PACKED_BEGIN 730 class Entry 731 { 732 public: GetChannelPage(void) const733 uint8_t GetChannelPage(void) const { return mChannelPage; } SetChannelPage(uint8_t aChannelPage)734 void SetChannelPage(uint8_t aChannelPage) { mChannelPage = aChannelPage; } GetMaskLength(void) const735 uint8_t GetMaskLength(void) const { return mMaskLength; } SetMaskLength(uint8_t aMaskLength)736 void SetMaskLength(uint8_t aMaskLength) { mMaskLength = aMaskLength; } GetMask(void) const737 uint32_t GetMask(void) const { return Reverse32(BigEndian::HostSwap32(mMask)); } SetMask(uint32_t aMask)738 void SetMask(uint32_t aMask) { mMask = BigEndian::HostSwap32(Reverse32(aMask)); } 739 740 private: 741 uint8_t mChannelPage; 742 uint8_t mMaskLength; 743 uint32_t mMask; 744 } OT_TOOL_PACKED_END; 745 746 struct EntriesData : public Clearable<EntriesData> 747 { 748 // Represents received Channel Mask TLV Entries data which 749 // is either contained in `mData` buffer, or in `mMessage` 750 // at `mOffset`. 751 752 Error Parse(uint32_t &aChannelMask); 753 754 const uint8_t *mData; 755 const Message *mMessage; 756 OffsetRange mOffsetRange; 757 }; 758 759 uint8_t mEntriesStart; 760 } OT_TOOL_PACKED_BEGIN; 761 762 /** 763 * Implements Energy List TLV generation and parsing. 764 * 765 */ 766 OT_TOOL_PACKED_BEGIN 767 class EnergyListTlv : public Tlv, public TlvInfo<Tlv::kEnergyList> 768 { 769 public: 770 /** 771 * Initializes the TLV. 772 * 773 */ Init(void)774 void Init(void) 775 { 776 SetType(kEnergyList); 777 SetLength(sizeof(*this) - sizeof(Tlv)); 778 } 779 780 /** 781 * Indicates whether or not the TLV appears to be well-formed. 782 * 783 * @retval TRUE If the TLV appears to be well-formed. 784 * @retval FALSE If the TLV does not appear to be well-formed. 785 * 786 */ IsValid(void) const787 bool IsValid(void) const { return true; } 788 789 /** 790 * Returns a pointer to the start of energy measurement list. 791 * 792 * @returns A pointer to the start start of energy energy measurement list. 793 * 794 */ GetEnergyList(void) const795 const uint8_t *GetEnergyList(void) const { return mEnergyList; } 796 797 /** 798 * Returns the length of energy measurement list. 799 * 800 * @returns The length of energy measurement list. 801 * 802 */ GetEnergyListLength(void) const803 uint8_t GetEnergyListLength(void) const { return Min(kMaxListLength, GetLength()); } 804 805 private: 806 static constexpr uint8_t kMaxListLength = OPENTHREAD_CONFIG_TMF_ENERGY_SCAN_MAX_RESULTS; 807 808 uint8_t mEnergyList[kMaxListLength]; 809 } OT_TOOL_PACKED_END; 810 811 /** 812 * Defines Provisioning TLV constants and types. 813 * 814 */ 815 typedef StringTlvInfo<Tlv::kProvisioningUrl, Tlv::kMaxProvisioningUrlLength> ProvisioningUrlTlv; 816 817 /** 818 * Defines Vendor Name TLV constants and types. 819 * 820 */ 821 typedef StringTlvInfo<Tlv::kVendorName, Tlv::kMaxVendorNameLength> VendorNameTlv; 822 823 /** 824 * Defines Vendor Model TLV constants and types. 825 * 826 */ 827 typedef StringTlvInfo<Tlv::kVendorModel, Tlv::kMaxVendorModelLength> VendorModelTlv; 828 829 /** 830 * Defines Vendor SW Version TLV constants and types. 831 * 832 */ 833 typedef StringTlvInfo<Tlv::kVendorSwVersion, Tlv::kMaxVendorSwVersionLength> VendorSwVersionTlv; 834 835 /** 836 * Defines Vendor Data TLV constants and types. 837 * 838 */ 839 typedef StringTlvInfo<Tlv::kVendorData, Tlv::kMaxVendorDataLength> VendorDataTlv; 840 841 /** 842 * Implements Vendor Stack Version TLV generation and parsing. 843 * 844 */ 845 OT_TOOL_PACKED_BEGIN 846 class VendorStackVersionTlv : public Tlv, public TlvInfo<Tlv::kVendorStackVersion> 847 { 848 public: 849 /** 850 * Default constructor. 851 * 852 */ VendorStackVersionTlv(void)853 VendorStackVersionTlv(void) 854 : mBuildRevision(0) 855 , mMinorMajor(0) 856 { 857 } 858 859 /** 860 * Initializes the TLV. 861 * 862 */ Init(void)863 void Init(void) 864 { 865 SetType(kVendorStackVersion); 866 SetLength(sizeof(*this) - sizeof(Tlv)); 867 } 868 869 /** 870 * Indicates whether or not the TLV appears to be well-formed. 871 * 872 * @retval TRUE If the TLV appears to be well-formed. 873 * @retval FALSE If the TLV does not appear to be well-formed. 874 * 875 */ IsValid(void) const876 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 877 878 /** 879 * Returns the Stack Vendor OUI value. 880 * 881 * @returns The Vendor Stack Vendor OUI value. 882 * 883 */ GetOui(void) const884 uint32_t GetOui(void) const { return BigEndian::ReadUint24(mOui); } 885 886 /** 887 * Returns the Stack Vendor OUI value. 888 * 889 * @param[in] aOui The Vendor Stack Vendor OUI value. 890 * 891 */ SetOui(uint32_t aOui)892 void SetOui(uint32_t aOui) { BigEndian::WriteUint24(aOui, mOui); } 893 894 /** 895 * Returns the Build value. 896 * 897 * @returns The Build value. 898 * 899 */ GetBuild(void) const900 uint16_t GetBuild(void) const { return (BigEndian::HostSwap16(mBuildRevision) & kBuildMask) >> kBuildOffset; } 901 902 /** 903 * Sets the Build value. 904 * 905 * @param[in] aBuild The Build value. 906 * 907 */ SetBuild(uint16_t aBuild)908 void SetBuild(uint16_t aBuild) 909 { 910 mBuildRevision = BigEndian::HostSwap16((BigEndian::HostSwap16(mBuildRevision) & ~kBuildMask) | 911 ((aBuild << kBuildOffset) & kBuildMask)); 912 } 913 914 /** 915 * Returns the Revision value. 916 * 917 * @returns The Revision value. 918 * 919 */ GetRevision(void) const920 uint8_t GetRevision(void) const { return (BigEndian::HostSwap16(mBuildRevision) & kRevMask) >> kRevOffset; } 921 922 /** 923 * Sets the Revision value. 924 * 925 * @param[in] aRevision The Revision value. 926 * 927 */ SetRevision(uint8_t aRevision)928 void SetRevision(uint8_t aRevision) 929 { 930 mBuildRevision = BigEndian::HostSwap16((BigEndian::HostSwap16(mBuildRevision) & ~kRevMask) | 931 ((aRevision << kRevOffset) & kRevMask)); 932 } 933 934 /** 935 * Returns the Minor value. 936 * 937 * @returns The Minor value. 938 * 939 */ GetMinor(void) const940 uint8_t GetMinor(void) const { return (mMinorMajor & kMinorMask) >> kMinorOffset; } 941 942 /** 943 * Sets the Minor value. 944 * 945 * @param[in] aMinor The Minor value. 946 * 947 */ SetMinor(uint8_t aMinor)948 void SetMinor(uint8_t aMinor) 949 { 950 mMinorMajor = (mMinorMajor & ~kMinorMask) | ((aMinor << kMinorOffset) & kMinorMask); 951 } 952 953 /** 954 * Returns the Major value. 955 * 956 * @returns The Major value. 957 * 958 */ GetMajor(void) const959 uint8_t GetMajor(void) const { return (mMinorMajor & kMajorMask) >> kMajorOffset; } 960 961 /** 962 * Sets the Major value. 963 * 964 * @param[in] aMajor The Major value. 965 * 966 */ SetMajor(uint8_t aMajor)967 void SetMajor(uint8_t aMajor) 968 { 969 mMinorMajor = (mMinorMajor & ~kMajorMask) | ((aMajor << kMajorOffset) & kMajorMask); 970 } 971 972 private: 973 // For `mBuildRevision` 974 static constexpr uint8_t kBuildOffset = 4; 975 static constexpr uint16_t kBuildMask = 0xfff << kBuildOffset; 976 static constexpr uint8_t kRevOffset = 0; 977 static constexpr uint16_t kRevMask = 0xf << kBuildOffset; 978 979 // For `mMinorMajor` 980 static constexpr uint8_t kMinorOffset = 4; 981 static constexpr uint8_t kMinorMask = 0xf << kMinorOffset; 982 static constexpr uint8_t kMajorOffset = 0; 983 static constexpr uint8_t kMajorMask = 0xf << kMajorOffset; 984 985 uint8_t mOui[3]; 986 uint16_t mBuildRevision; 987 uint8_t mMinorMajor; 988 } OT_TOOL_PACKED_END; 989 990 /** 991 * Defines UDP Encapsulation TLV types and constants. 992 * 993 */ 994 typedef TlvInfo<MeshCoP::Tlv::kUdpEncapsulation> UdpEncapsulationTlv; 995 996 /** 997 * Represents UDP Encapsulation TLV value header (source and destination ports). 998 * 999 */ 1000 OT_TOOL_PACKED_BEGIN 1001 class UdpEncapsulationTlvHeader 1002 { 1003 public: 1004 /** 1005 * Returns the source port. 1006 * 1007 * @returns The source port. 1008 * 1009 */ GetSourcePort(void) const1010 uint16_t GetSourcePort(void) const { return BigEndian::HostSwap16(mSourcePort); } 1011 1012 /** 1013 * Updates the source port. 1014 * 1015 * @param[in] aSourcePort The source port. 1016 * 1017 */ SetSourcePort(uint16_t aSourcePort)1018 void SetSourcePort(uint16_t aSourcePort) { mSourcePort = BigEndian::HostSwap16(aSourcePort); } 1019 1020 /** 1021 * Returns the destination port. 1022 * 1023 * @returns The destination port. 1024 * 1025 */ GetDestinationPort(void) const1026 uint16_t GetDestinationPort(void) const { return BigEndian::HostSwap16(mDestinationPort); } 1027 1028 /** 1029 * Updates the destination port. 1030 * 1031 * @param[in] aDestinationPort The destination port. 1032 * 1033 */ SetDestinationPort(uint16_t aDestinationPort)1034 void SetDestinationPort(uint16_t aDestinationPort) { mDestinationPort = BigEndian::HostSwap16(aDestinationPort); } 1035 1036 private: 1037 uint16_t mSourcePort; 1038 uint16_t mDestinationPort; 1039 // Followed by the UDP Payload. 1040 } OT_TOOL_PACKED_END; 1041 1042 /** 1043 * Implements Discovery Request TLV generation and parsing. 1044 * 1045 */ 1046 OT_TOOL_PACKED_BEGIN 1047 class DiscoveryRequestTlv : public Tlv, public TlvInfo<Tlv::kDiscoveryRequest> 1048 { 1049 public: 1050 /** 1051 * Initializes the TLV. 1052 * 1053 */ Init(void)1054 void Init(void) 1055 { 1056 SetType(kDiscoveryRequest); 1057 SetLength(sizeof(*this) - sizeof(Tlv)); 1058 mFlags = 0; 1059 mReserved = 0; 1060 } 1061 1062 /** 1063 * Indicates whether or not the TLV appears to be well-formed. 1064 * 1065 * @retval TRUE If the TLV appears to be well-formed. 1066 * @retval FALSE If the TLV does not appear to be well-formed. 1067 * 1068 */ IsValid(void) const1069 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 1070 1071 /** 1072 * Returns the Version value. 1073 * 1074 * @returns The Version value. 1075 * 1076 */ GetVersion(void) const1077 uint8_t GetVersion(void) const { return mFlags >> kVersionOffset; } 1078 1079 /** 1080 * Sets the Version value. 1081 * 1082 * @param[in] aVersion The Version value. 1083 * 1084 */ SetVersion(uint8_t aVersion)1085 void SetVersion(uint8_t aVersion) 1086 { 1087 mFlags = (mFlags & ~kVersionMask) | ((aVersion << kVersionOffset) & kVersionMask); 1088 } 1089 1090 /** 1091 * Indicates whether or not the Joiner flag is set. 1092 * 1093 * @retval TRUE If the Joiner flag is set. 1094 * @retval FALSE If the Joiner flag is not set. 1095 * 1096 */ IsJoiner(void) const1097 bool IsJoiner(void) const { return (mFlags & kJoinerMask) != 0; } 1098 1099 /** 1100 * Sets the Joiner flag. 1101 * 1102 * @param[in] aJoiner TRUE if set, FALSE otherwise. 1103 * 1104 */ SetJoiner(bool aJoiner)1105 void SetJoiner(bool aJoiner) 1106 { 1107 if (aJoiner) 1108 { 1109 mFlags |= kJoinerMask; 1110 } 1111 else 1112 { 1113 mFlags &= ~kJoinerMask; 1114 } 1115 } 1116 1117 private: 1118 static constexpr uint8_t kVersionOffset = 4; 1119 static constexpr uint8_t kVersionMask = 0xf << kVersionOffset; 1120 static constexpr uint8_t kJoinerOffset = 3; 1121 static constexpr uint8_t kJoinerMask = 1 << kJoinerOffset; 1122 1123 uint8_t mFlags; 1124 uint8_t mReserved; 1125 } OT_TOOL_PACKED_END; 1126 1127 /** 1128 * Implements Discovery Response TLV generation and parsing. 1129 * 1130 */ 1131 OT_TOOL_PACKED_BEGIN 1132 class DiscoveryResponseTlv : public Tlv, public TlvInfo<Tlv::kDiscoveryResponse> 1133 { 1134 public: 1135 /** 1136 * Initializes the TLV. 1137 * 1138 */ Init(void)1139 void Init(void) 1140 { 1141 SetType(kDiscoveryResponse); 1142 SetLength(sizeof(*this) - sizeof(Tlv)); 1143 mFlags = 0; 1144 mReserved = 0; 1145 } 1146 1147 /** 1148 * Indicates whether or not the TLV appears to be well-formed. 1149 * 1150 * @retval TRUE If the TLV appears to be well-formed. 1151 * @retval FALSE If the TLV does not appear to be well-formed. 1152 * 1153 */ IsValid(void) const1154 bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } 1155 1156 /** 1157 * Returns the Version value. 1158 * 1159 * @returns The Version value. 1160 * 1161 */ GetVersion(void) const1162 uint8_t GetVersion(void) const { return mFlags >> kVersionOffset; } 1163 1164 /** 1165 * Sets the Version value. 1166 * 1167 * @param[in] aVersion The Version value. 1168 * 1169 */ SetVersion(uint8_t aVersion)1170 void SetVersion(uint8_t aVersion) 1171 { 1172 mFlags = (mFlags & ~kVersionMask) | ((aVersion << kVersionOffset) & kVersionMask); 1173 } 1174 1175 /** 1176 * Indicates whether or not the Native Commissioner flag is set. 1177 * 1178 * @retval TRUE If the Native Commissioner flag is set. 1179 * @retval FALSE If the Native Commissioner flag is not set. 1180 * 1181 */ IsNativeCommissioner(void) const1182 bool IsNativeCommissioner(void) const { return (mFlags & kNativeMask) != 0; } 1183 1184 /** 1185 * Sets the Native Commissioner flag. 1186 * 1187 * @param[in] aNativeCommissioner TRUE if set, FALSE otherwise. 1188 * 1189 */ SetNativeCommissioner(bool aNativeCommissioner)1190 void SetNativeCommissioner(bool aNativeCommissioner) 1191 { 1192 if (aNativeCommissioner) 1193 { 1194 mFlags |= kNativeMask; 1195 } 1196 else 1197 { 1198 mFlags &= ~kNativeMask; 1199 } 1200 } 1201 1202 /** 1203 * Indicates whether or not the Commercial Commissioning Mode flag is set. 1204 * 1205 * @retval TRUE If the Commercial Commissioning Mode flag is set. 1206 * @retval FALSE If the Commercial Commissioning Mode flag is not set. 1207 * 1208 */ IsCommercialCommissioningMode(void) const1209 bool IsCommercialCommissioningMode(void) const { return (mFlags & kCcmMask) != 0; } 1210 1211 /** 1212 * Sets the Commercial Commissioning Mode flag. 1213 * 1214 * @param[in] aCcm TRUE if set, FALSE otherwise. 1215 * 1216 */ SetCommercialCommissioningMode(bool aCcm)1217 void SetCommercialCommissioningMode(bool aCcm) 1218 { 1219 if (aCcm) 1220 { 1221 mFlags |= kCcmMask; 1222 } 1223 else 1224 { 1225 mFlags &= ~kCcmMask; 1226 } 1227 } 1228 1229 private: 1230 static constexpr uint8_t kVersionOffset = 4; 1231 static constexpr uint8_t kVersionMask = 0xf << kVersionOffset; 1232 static constexpr uint8_t kNativeOffset = 3; 1233 static constexpr uint8_t kNativeMask = 1 << kNativeOffset; 1234 static constexpr uint8_t kCcmOffset = 2; 1235 static constexpr uint8_t kCcmMask = 1 << kCcmOffset; 1236 1237 uint8_t mFlags; 1238 uint8_t mReserved; 1239 } OT_TOOL_PACKED_END; 1240 1241 /** 1242 * Implements Joiner Advertisement TLV generation and parsing. 1243 * 1244 */ 1245 OT_TOOL_PACKED_BEGIN 1246 class JoinerAdvertisementTlv : public Tlv, public TlvInfo<Tlv::kJoinerAdvertisement> 1247 { 1248 public: 1249 static constexpr uint8_t kAdvDataMaxLength = OT_JOINER_ADVDATA_MAX_LENGTH; ///< The Max Length of AdvData 1250 1251 /** 1252 * Initializes the TLV. 1253 * 1254 */ Init(void)1255 void Init(void) 1256 { 1257 SetType(kJoinerAdvertisement); 1258 SetLength(sizeof(*this) - sizeof(Tlv)); 1259 } 1260 1261 /** 1262 * Indicates whether or not the TLV appears to be well-formed. 1263 * 1264 * @retval TRUE If the TLV appears to be well-formed. 1265 * @retval FALSE If the TLV does not appear to be well-formed. 1266 * 1267 */ IsValid(void) const1268 bool IsValid(void) const { return GetLength() >= sizeof(mOui) && GetLength() <= sizeof(mOui) + sizeof(mAdvData); } 1269 1270 /** 1271 * Returns the Vendor OUI value. 1272 * 1273 * @returns The Vendor OUI value. 1274 * 1275 */ GetOui(void) const1276 uint32_t GetOui(void) const { return BigEndian::ReadUint24(mOui); } 1277 1278 /** 1279 * Sets the Vendor OUI value. 1280 * 1281 * @param[in] aOui The Vendor OUI value. 1282 * 1283 */ SetOui(uint32_t aOui)1284 void SetOui(uint32_t aOui) { return BigEndian::WriteUint24(aOui, mOui); } 1285 1286 /** 1287 * Returns the Adv Data length. 1288 * 1289 * @returns The AdvData length. 1290 * 1291 */ GetAdvDataLength(void) const1292 uint8_t GetAdvDataLength(void) const { return GetLength() - sizeof(mOui); } 1293 1294 /** 1295 * Returns the Adv Data value. 1296 * 1297 * @returns A pointer to the Adv Data value. 1298 * 1299 */ GetAdvData(void) const1300 const uint8_t *GetAdvData(void) const { return mAdvData; } 1301 1302 /** 1303 * Sets the Adv Data value. 1304 * 1305 * @param[in] aAdvData A pointer to the AdvData value. 1306 * @param[in] aAdvDataLength The length of AdvData in bytes. 1307 * 1308 */ SetAdvData(const uint8_t * aAdvData,uint8_t aAdvDataLength)1309 void SetAdvData(const uint8_t *aAdvData, uint8_t aAdvDataLength) 1310 { 1311 OT_ASSERT((aAdvData != nullptr) && (aAdvDataLength > 0) && (aAdvDataLength <= kAdvDataMaxLength)); 1312 1313 SetLength(aAdvDataLength + sizeof(mOui)); 1314 memcpy(mAdvData, aAdvData, aAdvDataLength); 1315 } 1316 1317 private: 1318 uint8_t mOui[3]; 1319 uint8_t mAdvData[kAdvDataMaxLength]; 1320 } OT_TOOL_PACKED_END; 1321 1322 } // namespace MeshCoP 1323 1324 } // namespace ot 1325 1326 #endif // MESHCOP_TLVS_HPP_ 1327