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_SPINEL_VENDOR_INTERFACE_ENABLE
37 
38 #include "vendor_interface.hpp"
39 #include "common/code_utils.hpp"
40 #include "common/new.hpp"
41 
42 namespace ot {
43 namespace Posix {
44 using ot::Spinel::SpinelInterface;
45 
46 /**
47  * Defines the vendor implementation object.
48  */
49 class VendorInterfaceImpl
50 {
51 public:
VendorInterfaceImpl(const Url::Url & aRadioUrl)52     explicit VendorInterfaceImpl(const Url::Url &aRadioUrl)
53         : mRadioUrl(aRadioUrl)
54     {
55     }
56 
57     // TODO: Add vendor code (add methods and/or member variables).
58 
59 private:
60     const Url::Url &mRadioUrl;
61 };
62 
63 // ----------------------------------------------------------------------------
64 // `VendorInterface` API
65 // ----------------------------------------------------------------------------
66 
67 static OT_DEFINE_ALIGNED_VAR(sVendorInterfaceImplRaw, sizeof(VendorInterfaceImpl), uint64_t);
68 
VendorInterface(const Url::Url & aRadioUrl)69 VendorInterface::VendorInterface(const Url::Url &aRadioUrl)
70 {
71     new (&sVendorInterfaceImplRaw) VendorInterfaceImpl(aRadioUrl);
72     OT_UNUSED_VARIABLE(sVendorInterfaceImplRaw);
73 }
74 
~VendorInterface(void)75 VendorInterface::~VendorInterface(void) { Deinit(); }
76 
Init(ReceiveFrameCallback aCallback,void * aCallbackContext,RxFrameBuffer & aFrameBuffer)77 otError VendorInterface::Init(ReceiveFrameCallback aCallback, void *aCallbackContext, RxFrameBuffer &aFrameBuffer)
78 {
79     OT_UNUSED_VARIABLE(aCallback);
80     OT_UNUSED_VARIABLE(aCallbackContext);
81     OT_UNUSED_VARIABLE(aFrameBuffer);
82 
83     // TODO: Implement vendor code here.
84 
85     return OT_ERROR_NONE;
86 }
87 
Deinit(void)88 void VendorInterface::Deinit(void)
89 {
90     // TODO: Implement vendor code here.
91 }
92 
GetBusSpeed(void) const93 uint32_t VendorInterface::GetBusSpeed(void) const { return 1000000; }
94 
HardwareReset(void)95 otError VendorInterface::HardwareReset(void)
96 {
97     // TODO: Implement vendor code here.
98 
99     return OT_ERROR_NOT_IMPLEMENTED;
100 }
101 
UpdateFdSet(void * aMainloopContext)102 void VendorInterface::UpdateFdSet(void *aMainloopContext)
103 {
104     OT_UNUSED_VARIABLE(aMainloopContext);
105 
106     // TODO: Implement vendor code here.
107 }
108 
Process(const void * aMainloopContext)109 void VendorInterface::Process(const void *aMainloopContext)
110 {
111     OT_UNUSED_VARIABLE(aMainloopContext);
112 
113     // TODO: Implement vendor code here.
114 }
115 
WaitForFrame(uint64_t aTimeoutUs)116 otError VendorInterface::WaitForFrame(uint64_t aTimeoutUs)
117 {
118     OT_UNUSED_VARIABLE(aTimeoutUs);
119 
120     // TODO: Implement vendor code here.
121 
122     return OT_ERROR_NONE;
123 }
124 
SendFrame(const uint8_t * aFrame,uint16_t aLength)125 otError VendorInterface::SendFrame(const uint8_t *aFrame, uint16_t aLength)
126 {
127     OT_UNUSED_VARIABLE(aFrame);
128     OT_UNUSED_VARIABLE(aLength);
129 
130     // TODO: Implement vendor code here.
131 
132     return OT_ERROR_NONE;
133 }
134 
GetRcpInterfaceMetrics(void) const135 const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void) const
136 {
137     // TODO: Implement vendor code here.
138 
139     return nullptr;
140 }
141 } // namespace Posix
142 } // namespace ot
143 
144 #endif // OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE
145