xref: /aosp_15_r20/external/openthread/src/ncp/multipan_platform.cpp (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker /*
2*cfb92d14SAndroid Build Coastguard Worker  *    Copyright (c) 2023, The OpenThread Authors.
3*cfb92d14SAndroid Build Coastguard Worker  *    All rights reserved.
4*cfb92d14SAndroid Build Coastguard Worker  *
5*cfb92d14SAndroid Build Coastguard Worker  *    Redistribution and use in source and binary forms, with or without
6*cfb92d14SAndroid Build Coastguard Worker  *    modification, are permitted provided that the following conditions are met:
7*cfb92d14SAndroid Build Coastguard Worker  *    1. Redistributions of source code must retain the above copyright
8*cfb92d14SAndroid Build Coastguard Worker  *       notice, this list of conditions and the following disclaimer.
9*cfb92d14SAndroid Build Coastguard Worker  *    2. Redistributions in binary form must reproduce the above copyright
10*cfb92d14SAndroid Build Coastguard Worker  *       notice, this list of conditions and the following disclaimer in the
11*cfb92d14SAndroid Build Coastguard Worker  *       documentation and/or other materials provided with the distribution.
12*cfb92d14SAndroid Build Coastguard Worker  *    3. Neither the name of the copyright holder nor the
13*cfb92d14SAndroid Build Coastguard Worker  *       names of its contributors may be used to endorse or promote products
14*cfb92d14SAndroid Build Coastguard Worker  *       derived from this software without specific prior written permission.
15*cfb92d14SAndroid Build Coastguard Worker  *
16*cfb92d14SAndroid Build Coastguard Worker  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17*cfb92d14SAndroid Build Coastguard Worker  *    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*cfb92d14SAndroid Build Coastguard Worker  *    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19*cfb92d14SAndroid Build Coastguard Worker  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20*cfb92d14SAndroid Build Coastguard Worker  *    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21*cfb92d14SAndroid Build Coastguard Worker  *    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*cfb92d14SAndroid Build Coastguard Worker  *    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23*cfb92d14SAndroid Build Coastguard Worker  *    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*cfb92d14SAndroid Build Coastguard Worker  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25*cfb92d14SAndroid Build Coastguard Worker  *    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*cfb92d14SAndroid Build Coastguard Worker  */
27*cfb92d14SAndroid Build Coastguard Worker 
28*cfb92d14SAndroid Build Coastguard Worker /**
29*cfb92d14SAndroid Build Coastguard Worker  * @file
30*cfb92d14SAndroid Build Coastguard Worker  *   This file implements the multipan radio platform callbacks into OpenThread and default/weak radio platform APIs.
31*cfb92d14SAndroid Build Coastguard Worker  */
32*cfb92d14SAndroid Build Coastguard Worker 
33*cfb92d14SAndroid Build Coastguard Worker #include <openthread/instance.h>
34*cfb92d14SAndroid Build Coastguard Worker #include <openthread/platform/multipan.h>
35*cfb92d14SAndroid Build Coastguard Worker 
36*cfb92d14SAndroid Build Coastguard Worker #include "common/as_core_type.hpp"
37*cfb92d14SAndroid Build Coastguard Worker #include "common/code_utils.hpp"
38*cfb92d14SAndroid Build Coastguard Worker #include "instance/instance.hpp"
39*cfb92d14SAndroid Build Coastguard Worker #include "ncp/ncp_base.hpp"
40*cfb92d14SAndroid Build Coastguard Worker 
41*cfb92d14SAndroid Build Coastguard Worker using namespace ot;
42*cfb92d14SAndroid Build Coastguard Worker 
43*cfb92d14SAndroid Build Coastguard Worker //---------------------------------------------------------------------------------------------------------------------
44*cfb92d14SAndroid Build Coastguard Worker // otPlatRadio callbacks
45*cfb92d14SAndroid Build Coastguard Worker 
otPlatMultipanIidToInstance(uint8_t aIid)46*cfb92d14SAndroid Build Coastguard Worker otInstance *otPlatMultipanIidToInstance(uint8_t aIid)
47*cfb92d14SAndroid Build Coastguard Worker {
48*cfb92d14SAndroid Build Coastguard Worker     Ncp::NcpBase *ncpBase = Ncp::NcpBase::GetNcpInstance();
49*cfb92d14SAndroid Build Coastguard Worker     OT_ASSERT(ncpBase);
50*cfb92d14SAndroid Build Coastguard Worker 
51*cfb92d14SAndroid Build Coastguard Worker     return ncpBase->IidToInstance(aIid);
52*cfb92d14SAndroid Build Coastguard Worker }
53*cfb92d14SAndroid Build Coastguard Worker 
otPlatMultipanInstanceToIid(otInstance * aInstance)54*cfb92d14SAndroid Build Coastguard Worker uint8_t otPlatMultipanInstanceToIid(otInstance *aInstance)
55*cfb92d14SAndroid Build Coastguard Worker {
56*cfb92d14SAndroid Build Coastguard Worker     Ncp::NcpBase *ncpBase = Ncp::NcpBase::GetNcpInstance();
57*cfb92d14SAndroid Build Coastguard Worker     OT_ASSERT(ncpBase);
58*cfb92d14SAndroid Build Coastguard Worker 
59*cfb92d14SAndroid Build Coastguard Worker     return ncpBase->InstanceToIid(static_cast<ot::Instance *>(aInstance));
60*cfb92d14SAndroid Build Coastguard Worker }
61*cfb92d14SAndroid Build Coastguard Worker 
62*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
63*cfb92d14SAndroid Build Coastguard Worker 
otPlatMultipanSwitchoverDone(otInstance * aInstance,bool success)64*cfb92d14SAndroid Build Coastguard Worker void otPlatMultipanSwitchoverDone(otInstance *aInstance, bool success)
65*cfb92d14SAndroid Build Coastguard Worker {
66*cfb92d14SAndroid Build Coastguard Worker     Ncp::NcpBase *ncpBase = Ncp::NcpBase::GetNcpInstance();
67*cfb92d14SAndroid Build Coastguard Worker     OT_ASSERT(ncpBase);
68*cfb92d14SAndroid Build Coastguard Worker 
69*cfb92d14SAndroid Build Coastguard Worker     ncpBase->NotifySwitchoverDone(aInstance, success);
70*cfb92d14SAndroid Build Coastguard Worker 
71*cfb92d14SAndroid Build Coastguard Worker     return;
72*cfb92d14SAndroid Build Coastguard Worker }
73*cfb92d14SAndroid Build Coastguard Worker 
74*cfb92d14SAndroid Build Coastguard Worker #else // OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
75*cfb92d14SAndroid Build Coastguard Worker 
76*cfb92d14SAndroid Build Coastguard Worker // default implementation
otPlatMultipanSwitchoverDone(otInstance * aInstance,bool success)77*cfb92d14SAndroid Build Coastguard Worker OT_TOOL_WEAK void otPlatMultipanSwitchoverDone(otInstance *aInstance, bool success)
78*cfb92d14SAndroid Build Coastguard Worker {
79*cfb92d14SAndroid Build Coastguard Worker     OT_UNUSED_VARIABLE(aInstance);
80*cfb92d14SAndroid Build Coastguard Worker     OT_UNUSED_VARIABLE(success);
81*cfb92d14SAndroid Build Coastguard Worker }
82*cfb92d14SAndroid Build Coastguard Worker 
83*cfb92d14SAndroid Build Coastguard Worker #endif // OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
84*cfb92d14SAndroid Build Coastguard Worker 
85*cfb92d14SAndroid Build Coastguard Worker //---------------------------------------------------------------------------------------------------------------------
86*cfb92d14SAndroid Build Coastguard Worker // Default/weak implementation of multipan APIs
87*cfb92d14SAndroid Build Coastguard Worker 
otPlatMultipanGetActiveInstance(otInstance ** aInstance)88*cfb92d14SAndroid Build Coastguard Worker OT_TOOL_WEAK otError otPlatMultipanGetActiveInstance(otInstance **aInstance)
89*cfb92d14SAndroid Build Coastguard Worker {
90*cfb92d14SAndroid Build Coastguard Worker     OT_UNUSED_VARIABLE(aInstance);
91*cfb92d14SAndroid Build Coastguard Worker 
92*cfb92d14SAndroid Build Coastguard Worker     return kErrorNotImplemented;
93*cfb92d14SAndroid Build Coastguard Worker }
94*cfb92d14SAndroid Build Coastguard Worker 
otPlatMultipanSetActiveInstance(otInstance * aInstance,bool aCompletePending)95*cfb92d14SAndroid Build Coastguard Worker OT_TOOL_WEAK otError otPlatMultipanSetActiveInstance(otInstance *aInstance, bool aCompletePending)
96*cfb92d14SAndroid Build Coastguard Worker {
97*cfb92d14SAndroid Build Coastguard Worker     OT_UNUSED_VARIABLE(aInstance);
98*cfb92d14SAndroid Build Coastguard Worker     OT_UNUSED_VARIABLE(aCompletePending);
99*cfb92d14SAndroid Build Coastguard Worker 
100*cfb92d14SAndroid Build Coastguard Worker     return kErrorNotImplemented;
101*cfb92d14SAndroid Build Coastguard Worker }
102