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         mTxFrame802154.SetTxPower(kRadioPowerInvalid);
190 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
191         mTxFrame802154.SetCslIePresent(false);
192 #endif
193 #endif
194 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
195         mTxFrameTrel.SetLength(0);
196         mTxFrameTrel.SetIsARetransmission(false);
197         mTxFrameTrel.SetIsSecurityProcessed(false);
198         mTxFrameTrel.SetCsmaCaEnabled(true);
199         mTxFrameTrel.SetIsHeaderUpdated(false);
200 #endif
201 
202 #if OPENTHREAD_CONFIG_MULTI_RADIO
203         mSelectedRadioTypes.Clear();
204         mRequiredRadioTypes.Clear();
205 #endif
206     }
207 
208     /**
209      * Sets the channel on all supported radio tx frames.
210      *
211      * @param[in] aChannel  A channel.
212      *
213      */
SetChannel(uint8_t aChannel)214     void SetChannel(uint8_t aChannel)
215     {
216 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
217         mTxFrame802154.SetChannel(aChannel);
218 #endif
219 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
220         mTxFrameTrel.SetChannel(aChannel);
221 #endif
222     }
223 
224     /**
225      * Sets the Sequence Number value on all supported radio tx frames.
226      *
227      * @param[in]  aSequence  The Sequence Number value.
228      *
229      */
SetSequence(uint8_t aSequence)230     void SetSequence(uint8_t aSequence)
231     {
232 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
233         mTxFrame802154.SetSequence(aSequence);
234 #endif
235 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
236         mTxFrameTrel.SetSequence(aSequence);
237 #endif
238     }
239 
240     /**
241      * Sets the maximum number of the CSMA-CA backoffs on all supported radio tx
242      * frames.
243      *
244      * @param[in]  aMaxCsmaBackoffs  The maximum number of CSMA-CA backoffs.
245      *
246      */
SetMaxCsmaBackoffs(uint8_t aMaxCsmaBackoffs)247     void SetMaxCsmaBackoffs(uint8_t aMaxCsmaBackoffs)
248     {
249 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
250         mTxFrame802154.SetMaxCsmaBackoffs(aMaxCsmaBackoffs);
251 #endif
252 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
253         mTxFrameTrel.SetMaxCsmaBackoffs(aMaxCsmaBackoffs);
254 #endif
255     }
256 
257     /**
258      * Sets the maximum number of retries allowed after a transmission failure on all supported radio tx
259      * frames.
260      *
261      * @param[in]  aMaxFrameRetries  The maximum number of retries allowed after a transmission failure.
262      *
263      */
SetMaxFrameRetries(uint8_t aMaxFrameRetries)264     void SetMaxFrameRetries(uint8_t aMaxFrameRetries)
265     {
266 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
267         mTxFrame802154.SetMaxFrameRetries(aMaxFrameRetries);
268 #endif
269 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
270         mTxFrameTrel.SetMaxFrameRetries(aMaxFrameRetries);
271 #endif
272     }
273 
274 private:
275     explicit TxFrames(Instance &aInstance);
276 
277 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
278     TxFrame &mTxFrame802154;
279 #endif
280 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
281     TxFrame &mTxFrameTrel;
282 #endif
283 
284 #if OPENTHREAD_CONFIG_MULTI_RADIO
285     RadioTypes mSelectedRadioTypes;
286     RadioTypes mRequiredRadioTypes;
287 #endif
288 };
289 
290 /**
291  * Represents MAC radio links (multi radio).
292  *
293  */
294 class Links : public InstanceLocator
295 {
296     friend class ot::Instance;
297 
298 public:
299     /**
300      * Initializes the `Links` object.
301      *
302      * @param[in]  aInstance  A reference to the OpenThread instance.
303      *
304      */
305     explicit Links(Instance &aInstance);
306 
307     /**
308      * Sets the PAN ID.
309      *
310      * @param[in] aPanId  The PAN ID.
311      *
312      */
SetPanId(PanId aPanId)313     void SetPanId(PanId aPanId)
314     {
315 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
316         mSubMac.SetPanId(aPanId);
317 #endif
318 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
319         mTrel.SetPanId(aPanId);
320 #endif
321     }
322 
323     /**
324      * Gets the MAC Short Address.
325      *
326      * @returns The MAC Short Address.
327      *
328      */
GetShortAddress(void) const329     ShortAddress GetShortAddress(void) const
330     {
331         return
332 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
333             mSubMac.GetShortAddress();
334 #else
335             mShortAddress;
336 #endif
337     }
338 
339     /**
340      * Sets the MAC Short Address.
341      *
342      * @param[in] aShortAddress   A MAC Short Address.
343      *
344      */
SetShortAddress(ShortAddress aShortAddress)345     void SetShortAddress(ShortAddress aShortAddress)
346     {
347 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
348         mSubMac.SetShortAddress(aShortAddress);
349 #else
350         mShortAddress = aShortAddress;
351 #endif
352     }
353 
354     /**
355      * Gets the MAC Extended Address.
356      *
357      * @returns The MAC Extended Address.
358      *
359      */
GetExtAddress(void) const360     const ExtAddress &GetExtAddress(void) const
361     {
362         return
363 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
364             mSubMac.GetExtAddress();
365 #else
366             mExtAddress;
367 #endif
368     }
369 
370     /**
371      * Sets the MAC Extended Address.
372      *
373      * @param[in] aExtAddress  A MAC Extended Address.
374      *
375      */
SetExtAddress(const ExtAddress & aExtAddress)376     void SetExtAddress(const ExtAddress &aExtAddress)
377     {
378 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
379         mSubMac.SetExtAddress(aExtAddress);
380 #else
381         mExtAddress = aExtAddress;
382 #endif
383 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
384         mTrel.HandleExtAddressChange();
385 #endif
386     }
387 
388     /**
389      * Registers a callback to provide received packet capture for IEEE 802.15.4 frames.
390      *
391      * @param[in]  aPcapCallback     A pointer to a function that is called when receiving an IEEE 802.15.4 link frame
392      *                               or nullptr to disable the callback.
393      * @param[in]  aCallbackContext  A pointer to application-specific context.
394      *
395      */
SetPcapCallback(otLinkPcapCallback aPcapCallback,void * aCallbackContext)396     void SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackContext)
397     {
398 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
399         mSubMac.SetPcapCallback(aPcapCallback, aCallbackContext);
400 #endif
401         OT_UNUSED_VARIABLE(aPcapCallback);
402         OT_UNUSED_VARIABLE(aCallbackContext);
403     }
404 
405     /**
406      * Indicates whether radio should stay in Receive or Sleep during idle periods.
407      *
408      * @param[in]  aRxOnWhenIdle  TRUE to keep radio in Receive, FALSE to put to Sleep during idle periods.
409      *
410      */
SetRxOnWhenIdle(bool aRxOnWhenIdle)411     void SetRxOnWhenIdle(bool aRxOnWhenIdle)
412     {
413 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
414         mSubMac.SetRxOnWhenIdle(aRxOnWhenIdle);
415 #endif
416         OT_UNUSED_VARIABLE(aRxOnWhenIdle);
417     }
418 
419     /**
420      * Enables all radio links.
421      *
422      */
Enable(void)423     void Enable(void)
424     {
425 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
426         IgnoreError(mSubMac.Enable());
427 #endif
428 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
429         mTrel.Enable();
430 #endif
431     }
432 
433     /**
434      * Disables all radio links.
435      *
436      */
Disable(void)437     void Disable(void)
438     {
439 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
440         IgnoreError(mSubMac.Disable());
441 #endif
442 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
443         mTrel.Disable();
444 #endif
445     }
446 
447     /**
448      * Transitions all radio links to Sleep.
449      *
450      */
Sleep(void)451     void Sleep(void)
452     {
453 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
454         IgnoreError(mSubMac.Sleep());
455 #endif
456 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
457         mTrel.Sleep();
458 #endif
459     }
460 
461 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
462     /**
463      * Configures CSL parameters in all radios.
464      *
465      * @param[in]  aPeriod    The CSL period.
466      * @param[in]  aChannel   The CSL channel.
467      * @param[in]  aShortAddr The short source address of CSL receiver's peer.
468      * @param[in]  aExtAddr   The extended source address of CSL receiver's peer.
469      *
470      * @retval  TRUE if CSL Period or CSL Channel changed.
471      * @retval  FALSE if CSL Period and CSL Channel did not change.
472      *
473      */
UpdateCsl(uint16_t aPeriod,uint8_t aChannel,otShortAddress aShortAddr,const otExtAddress * aExtAddr)474     bool UpdateCsl(uint16_t aPeriod, uint8_t aChannel, otShortAddress aShortAddr, const otExtAddress *aExtAddr)
475     {
476         bool retval = false;
477 
478         OT_UNUSED_VARIABLE(aPeriod);
479         OT_UNUSED_VARIABLE(aChannel);
480         OT_UNUSED_VARIABLE(aShortAddr);
481         OT_UNUSED_VARIABLE(aExtAddr);
482 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
483         retval = mSubMac.UpdateCsl(aPeriod, aChannel, aShortAddr, aExtAddr);
484 #endif
485         return retval;
486     }
487 
488     /**
489      * Transitions all radios link to CSL sample state, given that a non-zero CSL period is configured.
490      *
491      * CSL sample state is only applicable and used for 15.4 radio link. Other link are transitioned to sleep state
492      * when CSL period is non-zero.
493      *
494      */
CslSample(void)495     void CslSample(void)
496     {
497 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
498         mSubMac.CslSample();
499 #endif
500 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
501         mTrel.Sleep();
502 #endif
503     }
504 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
505 
506     /**
507      * Transitions all radio links to Receive.
508      *
509      * @param[in]  aChannel   The channel to use for receiving.
510      *
511      */
Receive(uint8_t aChannel)512     void Receive(uint8_t aChannel)
513     {
514 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
515         IgnoreError(mSubMac.Receive(aChannel));
516 #endif
517 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
518         mTrel.Receive(aChannel);
519 #endif
520     }
521 
522     /**
523      * Gets the radio transmit frames.
524      *
525      * @returns The transmit frames.
526      *
527      */
GetTxFrames(void)528     TxFrames &GetTxFrames(void) { return mTxFrames; }
529 
530 #if !OPENTHREAD_CONFIG_MULTI_RADIO
531 
532     /**
533      * Sends a prepared frame.
534      *
535      * The prepared frame is from `GetTxFrames()`. This method is available only in single radio link mode.
536      *
537      */
Send(void)538     void Send(void)
539     {
540 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
541         SuccessOrAssert(mSubMac.Send());
542 #endif
543 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
544         mTrel.Send();
545 #endif
546     }
547 
548 #else // #if !OPENTHREAD_CONFIG_MULTI_RADIO
549 
550     /**
551      * Sends prepared frames over a given set of radio links.
552      *
553      * The prepared frame must be from `GetTxFrames()`. This method is available only in multi radio link mode.
554      *
555      * @param[in] aFrame       A reference to a prepared frame.
556      * @param[in] aRadioTypes  A set of radio types to send on.
557      *
558      */
559     void Send(TxFrame &aFrame, RadioTypes aRadioTypes);
560 
561 #endif // !OPENTHREAD_CONFIG_MULTI_RADIO
562 
563     /**
564      * Gets the number of transmit retries for the last transmitted frame.
565      *
566      * @returns Number of transmit retries.
567      *
568      */
GetTransmitRetries(void) const569     uint8_t GetTransmitRetries(void) const
570     {
571         return
572 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
573             mSubMac.GetTransmitRetries();
574 #else
575             0;
576 #endif
577     }
578 
579     /**
580      * Gets the most recent RSSI measurement from radio link.
581      *
582      * @returns The RSSI in dBm when it is valid. `Radio::kInvalidRssi` when RSSI is invalid.
583      *
584      */
GetRssi(void) const585     int8_t GetRssi(void) const
586     {
587         return
588 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
589             mSubMac.GetRssi();
590 #else
591             Radio::kInvalidRssi;
592 #endif
593     }
594 
595     /**
596      * Begins energy scan.
597      *
598      * @param[in] aScanChannel   The channel to perform the energy scan on.
599      * @param[in] aScanDuration  The duration, in milliseconds, for the channel to be scanned.
600      *
601      * @retval kErrorNone            Successfully started scanning the channel.
602      * @retval kErrorBusy            The radio is performing energy scanning.
603      * @retval kErrorInvalidState    The radio was disabled or transmitting.
604      * @retval kErrorNotImplemented  Energy scan is not supported by radio link.
605      *
606      */
EnergyScan(uint8_t aScanChannel,uint16_t aScanDuration)607     Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
608     {
609         OT_UNUSED_VARIABLE(aScanChannel);
610         OT_UNUSED_VARIABLE(aScanDuration);
611 
612         return
613 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
614             mSubMac.EnergyScan(aScanChannel, aScanDuration);
615 #else
616             kErrorNotImplemented;
617 #endif
618     }
619 
620     /**
621      * Returns the noise floor value (currently use the radio receive sensitivity value).
622      *
623      * @returns The noise floor value in dBm.
624      *
625      */
GetNoiseFloor(void) const626     int8_t GetNoiseFloor(void) const
627     {
628         return
629 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
630             mSubMac.GetNoiseFloor();
631 #else
632             kDefaultNoiseFloor;
633 #endif
634     }
635 
636     /**
637      * Gets a reference to the `SubMac` instance.
638      *
639      * @returns A reference to the `SubMac` instance.
640      *
641      */
GetSubMac(void)642     SubMac &GetSubMac(void) { return mSubMac; }
643 
644     /**
645      * Gets a reference to the `SubMac` instance.
646      *
647      * @returns A reference to the `SubMac` instance.
648      *
649      */
GetSubMac(void) const650     const SubMac &GetSubMac(void) const { return mSubMac; }
651 
652     /**
653      * Returns a reference to the current MAC key (for Key Mode 1) for a given Frame.
654      *
655      * @param[in] aFrame    The frame for which to get the MAC key.
656      *
657      * @returns A reference to the current MAC key.
658      *
659      */
660     const KeyMaterial *GetCurrentMacKey(const Frame &aFrame) const;
661 
662     /**
663      * Returns a reference to the temporary MAC key (for Key Mode 1) for a given Frame based on a given
664      * Key Sequence.
665      *
666      * @param[in] aFrame        The frame for which to get the MAC key.
667      * @param[in] aKeySequence  The Key Sequence number (MUST be one off (+1 or -1) from current key sequence number).
668      *
669      * @returns A reference to the temporary MAC key.
670      *
671      */
672     const KeyMaterial *GetTemporaryMacKey(const Frame &aFrame, uint32_t aKeySequence) const;
673 
674 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
675     /**
676      * Sets the current MAC frame counter value from the value from a `TxFrame`.
677      *
678      * @param[in] TxFrame  The `TxFrame` from which to get the counter value.
679      *
680      * @retval kErrorNone            If successful.
681      * @retval kErrorInvalidState    If the raw link-layer isn't enabled.
682      *
683      */
684     void SetMacFrameCounter(TxFrame &aFrame);
685 #endif
686 
687 private:
688     static constexpr int8_t kDefaultNoiseFloor = Radio::kDefaultReceiveSensitivity;
689 
690     SubMac mSubMac;
691 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
692     Trel::Link mTrel;
693 #endif
694 
695     // `TxFrames` member definition should be after `mSubMac`, `mTrel`
696     // definitions to allow it to use their methods from its
697     // constructor.
698     TxFrames mTxFrames;
699 
700 #if !OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
701     ShortAddress mShortAddress;
702     ExtAddress   mExtAddress;
703 #endif
704 };
705 
706 /**
707  * @}
708  *
709  */
710 
711 } // namespace Mac
712 } // namespace ot
713 
714 #endif // MAC_LINKS_HPP_
715