1 /*
2 * Copyright (c) 2016-2018, 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 implements the callbacks from `SubMac` layer into `Mac` or `LinkRaw`.
32 */
33
34 #include "sub_mac.hpp"
35
36 #include "instance/instance.hpp"
37
38 namespace ot {
39 namespace Mac {
40
Callbacks(Instance & aInstance)41 SubMac::Callbacks::Callbacks(Instance &aInstance)
42 : InstanceLocator(aInstance)
43 {
44 }
45
46 #if OPENTHREAD_FTD || OPENTHREAD_MTD
47
ReceiveDone(RxFrame * aFrame,Error aError)48 void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError)
49 {
50 #if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
51 if (Get<LinkRaw>().IsEnabled())
52 {
53 Get<LinkRaw>().InvokeReceiveDone(aFrame, aError);
54 }
55 else
56 #endif
57 {
58 Get<Mac>().HandleReceivedFrame(aFrame, aError);
59 }
60 }
61
RecordCcaStatus(bool aCcaSuccess,uint8_t aChannel)62 void SubMac::Callbacks::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
63 {
64 Get<Mac>().RecordCcaStatus(aCcaSuccess, aChannel);
65 }
66
RecordFrameTransmitStatus(const TxFrame & aFrame,Error aError,uint8_t aRetryCount,bool aWillRetx)67 void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
68 Error aError,
69 uint8_t aRetryCount,
70 bool aWillRetx)
71 {
72 Get<Mac>().RecordFrameTransmitStatus(aFrame, aError, aRetryCount, aWillRetx);
73 }
74
TransmitDone(TxFrame & aFrame,RxFrame * aAckFrame,Error aError)75 void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
76 {
77 #if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
78 if (Get<LinkRaw>().IsEnabled())
79 {
80 Get<LinkRaw>().InvokeTransmitDone(aFrame, aAckFrame, aError);
81 }
82 else
83 #endif
84 {
85 Get<Mac>().HandleTransmitDone(aFrame, aAckFrame, aError);
86 }
87 }
88
EnergyScanDone(int8_t aMaxRssi)89 void SubMac::Callbacks::EnergyScanDone(int8_t aMaxRssi)
90 {
91 #if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
92 if (Get<LinkRaw>().IsEnabled())
93 {
94 Get<LinkRaw>().InvokeEnergyScanDone(aMaxRssi);
95 }
96 else
97 #endif
98 {
99 Get<Mac>().EnergyScanDone(aMaxRssi);
100 }
101 }
102
FrameCounterUsed(uint32_t aFrameCounter)103 void SubMac::Callbacks::FrameCounterUsed(uint32_t aFrameCounter)
104 {
105 Get<KeyManager>().MacFrameCounterUsed(aFrameCounter);
106 }
107
108 #elif OPENTHREAD_RADIO
109
ReceiveDone(RxFrame * aFrame,Error aError)110 void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError) { Get<LinkRaw>().InvokeReceiveDone(aFrame, aError); }
111
RecordCcaStatus(bool,uint8_t)112 void SubMac::Callbacks::RecordCcaStatus(bool, uint8_t) {}
113
RecordFrameTransmitStatus(const TxFrame & aFrame,Error aError,uint8_t aRetryCount,bool aWillRetx)114 void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
115 Error aError,
116 uint8_t aRetryCount,
117 bool aWillRetx)
118 {
119 Get<LinkRaw>().RecordFrameTransmitStatus(aFrame, aError, aRetryCount, aWillRetx);
120 }
121
TransmitDone(TxFrame & aFrame,RxFrame * aAckFrame,Error aError)122 void SubMac::Callbacks::TransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
123 {
124 Get<LinkRaw>().InvokeTransmitDone(aFrame, aAckFrame, aError);
125 }
126
EnergyScanDone(int8_t aMaxRssi)127 void SubMac::Callbacks::EnergyScanDone(int8_t aMaxRssi) { Get<LinkRaw>().InvokeEnergyScanDone(aMaxRssi); }
128
FrameCounterUsed(uint32_t aFrameCounter)129 void SubMac::Callbacks::FrameCounterUsed(uint32_t aFrameCounter) { OT_UNUSED_VARIABLE(aFrameCounter); }
130
131 #endif // OPENTHREAD_RADIO
132
133 } // namespace Mac
134 } // namespace ot
135