• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2022, 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 provides an example on how to implement an OpenThread vendor interface to RCP.
32  */
33 
34 #include "openthread-posix-config.h"
35 
36 #if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_VENDOR
37 
38 #include "vendor_interface.hpp"
39 #include "common/new.hpp"
40 
41 namespace ot {
42 namespace Posix {
43 using ot::Spinel::SpinelInterface;
44 
45 /**
46  * This class defines the vendor implementation object.
47  *
48  */
49 class VendorInterfaceImpl
50 {
51 public:
VendorInterfaceImpl(SpinelInterface::ReceiveFrameCallback aCallback,void * aCallbackContext,SpinelInterface::RxFrameBuffer & aFrameBuffer)52     explicit VendorInterfaceImpl(SpinelInterface::ReceiveFrameCallback aCallback,
53                                  void *                                aCallbackContext,
54                                  SpinelInterface::RxFrameBuffer &      aFrameBuffer)
55         : mReceiveFrameCallback(aCallback)
56         , mReceiveFrameContext(aCallbackContext)
57         , mRxFrameBuffer(aFrameBuffer)
58     {
59         OT_UNUSED_VARIABLE(mReceiveFrameCallback);
60         OT_UNUSED_VARIABLE(mReceiveFrameContext);
61         OT_UNUSED_VARIABLE(mRxFrameBuffer);
62     }
63 
64     // TODO: Add vendor code (add methods and/or member variables).
65 
66 private:
67     SpinelInterface::ReceiveFrameCallback mReceiveFrameCallback;
68     void *                                mReceiveFrameContext;
69     SpinelInterface::RxFrameBuffer &      mRxFrameBuffer;
70 };
71 
72 // ----------------------------------------------------------------------------
73 // `VendorInterface` API
74 // ----------------------------------------------------------------------------
75 
76 static OT_DEFINE_ALIGNED_VAR(sVendorInterfaceImplRaw, sizeof(VendorInterfaceImpl), uint64_t);
77 
VendorInterface(SpinelInterface::ReceiveFrameCallback aCallback,void * aCallbackContext,SpinelInterface::RxFrameBuffer & aFrameBuffer)78 VendorInterface::VendorInterface(SpinelInterface::ReceiveFrameCallback aCallback,
79                                  void *                                aCallbackContext,
80                                  SpinelInterface::RxFrameBuffer &      aFrameBuffer)
81 {
82     new (&sVendorInterfaceImplRaw) VendorInterfaceImpl(aCallback, aCallbackContext, aFrameBuffer);
83     OT_UNUSED_VARIABLE(sVendorInterfaceImplRaw);
84 }
85 
~VendorInterface(void)86 VendorInterface::~VendorInterface(void)
87 {
88     Deinit();
89 }
90 
Init(const Url::Url & aRadioUrl)91 otError VendorInterface::Init(const Url::Url &aRadioUrl)
92 {
93     OT_UNUSED_VARIABLE(aRadioUrl);
94 
95     // TODO: Implement vendor code here.
96 
97     return OT_ERROR_NONE;
98 }
99 
Deinit(void)100 void VendorInterface::Deinit(void)
101 {
102     // TODO: Implement vendor code here.
103 }
104 
GetBusSpeed(void) const105 uint32_t VendorInterface::GetBusSpeed(void) const
106 {
107     return 1000000;
108 }
109 
OnRcpReset(void)110 void VendorInterface::OnRcpReset(void)
111 {
112     // TODO: Implement vendor code here.
113 }
114 
UpdateFdSet(fd_set & aReadFdSet,fd_set & aWriteFdSet,int & aMaxFd,struct timeval & aTimeout)115 void VendorInterface::UpdateFdSet(fd_set &aReadFdSet, fd_set &aWriteFdSet, int &aMaxFd, struct timeval &aTimeout)
116 {
117     OT_UNUSED_VARIABLE(aReadFdSet);
118     OT_UNUSED_VARIABLE(aWriteFdSet);
119     OT_UNUSED_VARIABLE(aMaxFd);
120     OT_UNUSED_VARIABLE(aTimeout);
121 
122     // TODO: Implement vendor code here.
123 }
124 
Process(const RadioProcessContext & aContext)125 void VendorInterface::Process(const RadioProcessContext &aContext)
126 {
127     OT_UNUSED_VARIABLE(aContext);
128 
129     // TODO: Implement vendor code here.
130 }
131 
WaitForFrame(uint64_t aTimeoutUs)132 otError VendorInterface::WaitForFrame(uint64_t aTimeoutUs)
133 {
134     OT_UNUSED_VARIABLE(aTimeoutUs);
135 
136     // TODO: Implement vendor code here.
137 
138     return OT_ERROR_NONE;
139 }
140 
SendFrame(const uint8_t * aFrame,uint16_t aLength)141 otError VendorInterface::SendFrame(const uint8_t *aFrame, uint16_t aLength)
142 {
143     OT_UNUSED_VARIABLE(aFrame);
144     OT_UNUSED_VARIABLE(aLength);
145 
146     // TODO: Implement vendor code here.
147 
148     return OT_ERROR_NONE;
149 }
150 
ResetConnection(void)151 otError VendorInterface::ResetConnection(void)
152 {
153     // TODO: Implement vendor code here.
154 
155     return OT_ERROR_NONE;
156 }
157 
GetRcpInterfaceMetrics(void)158 const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void)
159 {
160     // TODO: Implement vendor code here.
161 
162     return nullptr;
163 }
164 } // namespace Posix
165 } // namespace ot
166 
167 #endif // OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_VENDOR
168