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