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