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