1 /* 2 * Copyright (c) 2019, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes definitions for MAC radio links. 32 */ 33 34 #ifndef MAC_LINKS_HPP_ 35 #define MAC_LINKS_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include "common/debug.hpp" 40 #include "common/locator.hpp" 41 #include "mac/mac_frame.hpp" 42 #include "mac/mac_types.hpp" 43 #include "mac/sub_mac.hpp" 44 #include "radio/radio.hpp" 45 #include "radio/trel_link.hpp" 46 47 namespace ot { 48 namespace Mac { 49 50 /** 51 * @addtogroup core-mac 52 * 53 * @brief 54 * This module includes definitions for MAC radio links (multi radio). 55 * 56 * @{ 57 * 58 */ 59 60 /** 61 * Represents tx frames for different radio link types. 62 * 63 */ 64 class TxFrames : InstanceLocator 65 { 66 friend class Links; 67 68 public: 69 #if OPENTHREAD_CONFIG_MULTI_RADIO 70 /** 71 * Gets the `TxFrame` for a given radio link type. 72 * 73 * Also updates the selected radio types (from `GetSelectedRadioTypes()`) to include the @p aRadioType. 74 * 75 * @param[in] aRadioType A radio link type. 76 * 77 * @returns A reference to the `TxFrame` for the given radio link type. 78 * 79 */ 80 TxFrame &GetTxFrame(RadioType aRadioType); 81 82 /** 83 * Gets the `TxFrame` with the smallest MTU size among a given set of radio types. 84 * 85 * Also updates the selected radio types (from `GetSelectedRadioTypes()`) to include the set 86 * @p aRadioTypes. 87 * 88 * @param[in] aRadioTypes A set of radio link types. 89 * 90 * @returns A reference to the `TxFrame` with the smallest MTU size among the set of @p aRadioTypes. 91 * 92 */ 93 TxFrame &GetTxFrame(RadioTypes aRadioTypes); 94 95 /** 96 * Gets the `TxFrame` for sending a broadcast frame. 97 * 98 * Also updates the selected radio type (from `GetSelectedRadioTypes()`) to include all radio types 99 * (supported by device). 100 * 101 * The broadcast frame is the `TxFrame` with the smallest MTU size among all radio types. 102 * 103 * @returns A reference to a `TxFrame` for broadcast. 104 * 105 */ 106 TxFrame &GetBroadcastTxFrame(void); 107 108 /** 109 * Gets the selected radio types. 110 * 111 * This set specifies the radio links the frame should be sent over (in parallel). The set starts a empty after 112 * method `Clear()` is called. It gets updated through calls to methods `GetTxFrame(aType)`, 113 * `GetTxFrame(aRadioTypes)`, or `GetBroadcastTxFrame()`. 114 * 115 * @returns The selected radio types. 116 * 117 */ GetSelectedRadioTypes(void) const118 RadioTypes GetSelectedRadioTypes(void) const { return mSelectedRadioTypes; } 119 120 /** 121 * Gets the required radio types. 122 * 123 * This set specifies the radio links for which we expect the frame tx to be successful to consider the overall tx 124 * successful. If the set is empty, successful tx over any radio link is sufficient for overall tx to be considered 125 * successful. The required radio type set is expected to be a subset of selected radio types. 126 * 127 * The set starts as empty after `Clear()` call. It can be updated through `SetRequiredRadioTypes()` method 128 * 129 * @returns The required radio types. 130 * 131 */ GetRequiredRadioTypes(void) const132 RadioTypes GetRequiredRadioTypes(void) const { return mRequiredRadioTypes; } 133 134 /** 135 * Sets the required types. 136 * 137 * Please see `GetRequiredRadioTypes()` for more details on how this set is used during tx. 138 * 139 * @param[in] aRadioTypes A set of radio link types. 140 * 141 */ SetRequiredRadioTypes(RadioTypes aRadioTypes)142 void SetRequiredRadioTypes(RadioTypes aRadioTypes) { mRequiredRadioTypes = aRadioTypes; } 143 144 #else // #if OPENTHREAD_CONFIG_MULTI_RADIO 145 146 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 147 /** 148 * Gets the tx frame. 149 * 150 * @returns A reference to `TxFrame`. 151 * 152 */ 153 TxFrame &GetTxFrame(void) { return mTxFrame802154; } 154 #elif OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 155 /** 156 * Gets the tx frame. 157 * 158 * @returns A reference to `TxFrame`. 159 * 160 */ 161 TxFrame &GetTxFrame(void) { return mTxFrameTrel; } 162 #endif 163 /** 164 * Gets a tx frame for sending a broadcast frame. 165 * 166 * @returns A reference to a `TxFrame` for broadcast. 167 * 168 */ 169 TxFrame &GetBroadcastTxFrame(void) { return GetTxFrame(); } 170 171 #endif // #if OPENTHREAD_CONFIG_MULTI_RADIO 172 173 /** 174 * Clears all supported radio tx frames (sets the PSDU length to zero and clears flags). 175 * 176 */ Clear(void)177 void Clear(void) 178 { 179 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 180 mTxFrame802154.SetLength(0); 181 mTxFrame802154.SetIsARetransmission(false); 182 mTxFrame802154.SetIsSecurityProcessed(false); 183 mTxFrame802154.SetCsmaCaEnabled(true); // Set to true by default, only set to `false` for CSL transmission 184 mTxFrame802154.SetIsHeaderUpdated(false); 185 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 186 mTxFrame802154.SetTxDelay(0); 187 mTxFrame802154.SetTxDelayBaseTime(0); 188 #endif 189 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 190 mTxFrame802154.SetCslIePresent(false); 191 #endif 192 #endif 193 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 194 mTxFrameTrel.SetLength(0); 195 mTxFrameTrel.SetIsARetransmission(false); 196 mTxFrameTrel.SetIsSecurityProcessed(false); 197 mTxFrameTrel.SetCsmaCaEnabled(true); 198 mTxFrameTrel.SetIsHeaderUpdated(false); 199 #endif 200 201 #if OPENTHREAD_CONFIG_MULTI_RADIO 202 mSelectedRadioTypes.Clear(); 203 mRequiredRadioTypes.Clear(); 204 #endif 205 } 206 207 /** 208 * Sets the channel on all supported radio tx frames. 209 * 210 * @param[in] aChannel A channel. 211 * 212 */ SetChannel(uint8_t aChannel)213 void SetChannel(uint8_t aChannel) 214 { 215 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 216 mTxFrame802154.SetChannel(aChannel); 217 #endif 218 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 219 mTxFrameTrel.SetChannel(aChannel); 220 #endif 221 } 222 223 /** 224 * Sets the Sequence Number value on all supported radio tx frames. 225 * 226 * @param[in] aSequence The Sequence Number value. 227 * 228 */ SetSequence(uint8_t aSequence)229 void SetSequence(uint8_t aSequence) 230 { 231 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 232 mTxFrame802154.SetSequence(aSequence); 233 #endif 234 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 235 mTxFrameTrel.SetSequence(aSequence); 236 #endif 237 } 238 239 /** 240 * Sets the maximum number of the CSMA-CA backoffs on all supported radio tx 241 * frames. 242 * 243 * @param[in] aMaxCsmaBackoffs The maximum number of CSMA-CA backoffs. 244 * 245 */ SetMaxCsmaBackoffs(uint8_t aMaxCsmaBackoffs)246 void SetMaxCsmaBackoffs(uint8_t aMaxCsmaBackoffs) 247 { 248 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 249 mTxFrame802154.SetMaxCsmaBackoffs(aMaxCsmaBackoffs); 250 #endif 251 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 252 mTxFrameTrel.SetMaxCsmaBackoffs(aMaxCsmaBackoffs); 253 #endif 254 } 255 256 /** 257 * Sets the maximum number of retries allowed after a transmission failure on all supported radio tx 258 * frames. 259 * 260 * @param[in] aMaxFrameRetries The maximum number of retries allowed after a transmission failure. 261 * 262 */ SetMaxFrameRetries(uint8_t aMaxFrameRetries)263 void SetMaxFrameRetries(uint8_t aMaxFrameRetries) 264 { 265 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 266 mTxFrame802154.SetMaxFrameRetries(aMaxFrameRetries); 267 #endif 268 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 269 mTxFrameTrel.SetMaxFrameRetries(aMaxFrameRetries); 270 #endif 271 } 272 273 private: 274 explicit TxFrames(Instance &aInstance); 275 276 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 277 TxFrame &mTxFrame802154; 278 #endif 279 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 280 TxFrame &mTxFrameTrel; 281 #endif 282 283 #if OPENTHREAD_CONFIG_MULTI_RADIO 284 RadioTypes mSelectedRadioTypes; 285 RadioTypes mRequiredRadioTypes; 286 #endif 287 }; 288 289 /** 290 * Represents MAC radio links (multi radio). 291 * 292 */ 293 class Links : public InstanceLocator 294 { 295 friend class ot::Instance; 296 297 public: 298 /** 299 * Initializes the `Links` object. 300 * 301 * @param[in] aInstance A reference to the OpenThread instance. 302 * 303 */ 304 explicit Links(Instance &aInstance); 305 306 /** 307 * Sets the PAN ID. 308 * 309 * @param[in] aPanId The PAN ID. 310 * 311 */ SetPanId(PanId aPanId)312 void SetPanId(PanId aPanId) 313 { 314 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 315 mSubMac.SetPanId(aPanId); 316 #endif 317 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 318 mTrel.SetPanId(aPanId); 319 #endif 320 } 321 322 /** 323 * Gets the MAC Short Address. 324 * 325 * @returns The MAC Short Address. 326 * 327 */ GetShortAddress(void) const328 ShortAddress GetShortAddress(void) const 329 { 330 return 331 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 332 mSubMac.GetShortAddress(); 333 #else 334 mShortAddress; 335 #endif 336 } 337 338 /** 339 * Sets the MAC Short Address. 340 * 341 * @param[in] aShortAddress A MAC Short Address. 342 * 343 */ SetShortAddress(ShortAddress aShortAddress)344 void SetShortAddress(ShortAddress aShortAddress) 345 { 346 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 347 mSubMac.SetShortAddress(aShortAddress); 348 #else 349 mShortAddress = aShortAddress; 350 #endif 351 } 352 353 /** 354 * Gets the MAC Extended Address. 355 * 356 * @returns The MAC Extended Address. 357 * 358 */ GetExtAddress(void) const359 const ExtAddress &GetExtAddress(void) const 360 { 361 return 362 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 363 mSubMac.GetExtAddress(); 364 #else 365 mExtAddress; 366 #endif 367 } 368 369 /** 370 * Sets the MAC Extended Address. 371 * 372 * @param[in] aExtAddress A MAC Extended Address. 373 * 374 */ SetExtAddress(const ExtAddress & aExtAddress)375 void SetExtAddress(const ExtAddress &aExtAddress) 376 { 377 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 378 mSubMac.SetExtAddress(aExtAddress); 379 #else 380 mExtAddress = aExtAddress; 381 #endif 382 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 383 mTrel.HandleExtAddressChange(); 384 #endif 385 } 386 387 /** 388 * Registers a callback to provide received packet capture for IEEE 802.15.4 frames. 389 * 390 * @param[in] aPcapCallback A pointer to a function that is called when receiving an IEEE 802.15.4 link frame 391 * or nullptr to disable the callback. 392 * @param[in] aCallbackContext A pointer to application-specific context. 393 * 394 */ SetPcapCallback(otLinkPcapCallback aPcapCallback,void * aCallbackContext)395 void SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackContext) 396 { 397 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 398 mSubMac.SetPcapCallback(aPcapCallback, aCallbackContext); 399 #endif 400 OT_UNUSED_VARIABLE(aPcapCallback); 401 OT_UNUSED_VARIABLE(aCallbackContext); 402 } 403 404 /** 405 * Indicates whether radio should stay in Receive or Sleep during idle periods. 406 * 407 * @param[in] aRxOnWhenIdle TRUE to keep radio in Receive, FALSE to put to Sleep during idle periods. 408 * 409 */ SetRxOnWhenIdle(bool aRxOnWhenIdle)410 void SetRxOnWhenIdle(bool aRxOnWhenIdle) 411 { 412 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 413 mSubMac.SetRxOnWhenIdle(aRxOnWhenIdle); 414 #endif 415 OT_UNUSED_VARIABLE(aRxOnWhenIdle); 416 } 417 418 /** 419 * Enables all radio links. 420 * 421 */ Enable(void)422 void Enable(void) 423 { 424 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 425 IgnoreError(mSubMac.Enable()); 426 #endif 427 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 428 mTrel.Enable(); 429 #endif 430 } 431 432 /** 433 * Disables all radio links. 434 * 435 */ Disable(void)436 void Disable(void) 437 { 438 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 439 IgnoreError(mSubMac.Disable()); 440 #endif 441 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 442 mTrel.Disable(); 443 #endif 444 } 445 446 /** 447 * Transitions all radio links to Sleep. 448 * 449 */ Sleep(void)450 void Sleep(void) 451 { 452 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 453 IgnoreError(mSubMac.Sleep()); 454 #endif 455 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 456 mTrel.Sleep(); 457 #endif 458 } 459 460 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 461 /** 462 * Configures CSL parameters in all radios. 463 * 464 * @param[in] aPeriod The CSL period. 465 * @param[in] aChannel The CSL channel. 466 * @param[in] aShortAddr The short source address of CSL receiver's peer. 467 * @param[in] aExtAddr The extended source address of CSL receiver's peer. 468 * 469 * @retval TRUE if CSL Period or CSL Channel changed. 470 * @retval FALSE if CSL Period and CSL Channel did not change. 471 * 472 */ UpdateCsl(uint16_t aPeriod,uint8_t aChannel,otShortAddress aShortAddr,const otExtAddress * aExtAddr)473 bool UpdateCsl(uint16_t aPeriod, uint8_t aChannel, otShortAddress aShortAddr, const otExtAddress *aExtAddr) 474 { 475 bool retval = false; 476 477 OT_UNUSED_VARIABLE(aPeriod); 478 OT_UNUSED_VARIABLE(aChannel); 479 OT_UNUSED_VARIABLE(aShortAddr); 480 OT_UNUSED_VARIABLE(aExtAddr); 481 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 482 retval = mSubMac.UpdateCsl(aPeriod, aChannel, aShortAddr, aExtAddr); 483 #endif 484 return retval; 485 } 486 487 /** 488 * Transitions all radios link to CSL sample state, given that a non-zero CSL period is configured. 489 * 490 * CSL sample state is only applicable and used for 15.4 radio link. Other link are transitioned to sleep state 491 * when CSL period is non-zero. 492 * 493 */ CslSample(void)494 void CslSample(void) 495 { 496 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 497 mSubMac.CslSample(); 498 #endif 499 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 500 mTrel.Sleep(); 501 #endif 502 } 503 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 504 505 /** 506 * Transitions all radio links to Receive. 507 * 508 * @param[in] aChannel The channel to use for receiving. 509 * 510 */ Receive(uint8_t aChannel)511 void Receive(uint8_t aChannel) 512 { 513 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 514 IgnoreError(mSubMac.Receive(aChannel)); 515 #endif 516 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 517 mTrel.Receive(aChannel); 518 #endif 519 } 520 521 /** 522 * Gets the radio transmit frames. 523 * 524 * @returns The transmit frames. 525 * 526 */ GetTxFrames(void)527 TxFrames &GetTxFrames(void) { return mTxFrames; } 528 529 #if !OPENTHREAD_CONFIG_MULTI_RADIO 530 531 /** 532 * Sends a prepared frame. 533 * 534 * The prepared frame is from `GetTxFrames()`. This method is available only in single radio link mode. 535 * 536 */ Send(void)537 void Send(void) 538 { 539 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 540 SuccessOrAssert(mSubMac.Send()); 541 #endif 542 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 543 mTrel.Send(); 544 #endif 545 } 546 547 #else // #if !OPENTHREAD_CONFIG_MULTI_RADIO 548 549 /** 550 * Sends prepared frames over a given set of radio links. 551 * 552 * The prepared frame must be from `GetTxFrames()`. This method is available only in multi radio link mode. 553 * 554 * @param[in] aFrame A reference to a prepared frame. 555 * @param[in] aRadioTypes A set of radio types to send on. 556 * 557 */ 558 void Send(TxFrame &aFrame, RadioTypes aRadioTypes); 559 560 #endif // !OPENTHREAD_CONFIG_MULTI_RADIO 561 562 /** 563 * Gets the number of transmit retries for the last transmitted frame. 564 * 565 * @returns Number of transmit retries. 566 * 567 */ GetTransmitRetries(void) const568 uint8_t GetTransmitRetries(void) const 569 { 570 return 571 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 572 mSubMac.GetTransmitRetries(); 573 #else 574 0; 575 #endif 576 } 577 578 /** 579 * Gets the most recent RSSI measurement from radio link. 580 * 581 * @returns The RSSI in dBm when it is valid. `Radio::kInvalidRssi` when RSSI is invalid. 582 * 583 */ GetRssi(void) const584 int8_t GetRssi(void) const 585 { 586 return 587 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 588 mSubMac.GetRssi(); 589 #else 590 Radio::kInvalidRssi; 591 #endif 592 } 593 594 /** 595 * Begins energy scan. 596 * 597 * @param[in] aScanChannel The channel to perform the energy scan on. 598 * @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned. 599 * 600 * @retval kErrorNone Successfully started scanning the channel. 601 * @retval kErrorBusy The radio is performing energy scanning. 602 * @retval kErrorInvalidState The radio was disabled or transmitting. 603 * @retval kErrorNotImplemented Energy scan is not supported by radio link. 604 * 605 */ EnergyScan(uint8_t aScanChannel,uint16_t aScanDuration)606 Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration) 607 { 608 OT_UNUSED_VARIABLE(aScanChannel); 609 OT_UNUSED_VARIABLE(aScanDuration); 610 611 return 612 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 613 mSubMac.EnergyScan(aScanChannel, aScanDuration); 614 #else 615 kErrorNotImplemented; 616 #endif 617 } 618 619 /** 620 * Returns the noise floor value (currently use the radio receive sensitivity value). 621 * 622 * @returns The noise floor value in dBm. 623 * 624 */ GetNoiseFloor(void) const625 int8_t GetNoiseFloor(void) const 626 { 627 return 628 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 629 mSubMac.GetNoiseFloor(); 630 #else 631 kDefaultNoiseFloor; 632 #endif 633 } 634 635 /** 636 * Gets a reference to the `SubMac` instance. 637 * 638 * @returns A reference to the `SubMac` instance. 639 * 640 */ GetSubMac(void)641 SubMac &GetSubMac(void) { return mSubMac; } 642 643 /** 644 * Gets a reference to the `SubMac` instance. 645 * 646 * @returns A reference to the `SubMac` instance. 647 * 648 */ GetSubMac(void) const649 const SubMac &GetSubMac(void) const { return mSubMac; } 650 651 /** 652 * Returns a reference to the current MAC key (for Key Mode 1) for a given Frame. 653 * 654 * @param[in] aFrame The frame for which to get the MAC key. 655 * 656 * @returns A reference to the current MAC key. 657 * 658 */ 659 const KeyMaterial *GetCurrentMacKey(const Frame &aFrame) const; 660 661 /** 662 * Returns a reference to the temporary MAC key (for Key Mode 1) for a given Frame based on a given 663 * Key Sequence. 664 * 665 * @param[in] aFrame The frame for which to get the MAC key. 666 * @param[in] aKeySequence The Key Sequence number (MUST be one off (+1 or -1) from current key sequence number). 667 * 668 * @returns A reference to the temporary MAC key. 669 * 670 */ 671 const KeyMaterial *GetTemporaryMacKey(const Frame &aFrame, uint32_t aKeySequence) const; 672 673 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 674 /** 675 * Sets the current MAC frame counter value from the value from a `TxFrame`. 676 * 677 * @param[in] TxFrame The `TxFrame` from which to get the counter value. 678 * 679 * @retval kErrorNone If successful. 680 * @retval kErrorInvalidState If the raw link-layer isn't enabled. 681 * 682 */ 683 void SetMacFrameCounter(TxFrame &aFrame); 684 #endif 685 686 private: 687 static constexpr int8_t kDefaultNoiseFloor = Radio::kDefaultReceiveSensitivity; 688 689 SubMac mSubMac; 690 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 691 Trel::Link mTrel; 692 #endif 693 694 // `TxFrames` member definition should be after `mSubMac`, `mTrel` 695 // definitions to allow it to use their methods from its 696 // constructor. 697 TxFrames mTxFrames; 698 699 #if !OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE 700 ShortAddress mShortAddress; 701 ExtAddress mExtAddress; 702 #endif 703 }; 704 705 /** 706 * @} 707 * 708 */ 709 710 } // namespace Mac 711 } // namespace ot 712 713 #endif // MAC_LINKS_HPP_ 714