• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2021, 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 OpenThread TCP API.
32  */
33 
34 #include "openthread-core-config.h"
35 
36 #if OPENTHREAD_CONFIG_TCP_ENABLE
37 
38 #include <openthread/tcp.h>
39 
40 #include "common/as_core_type.hpp"
41 #include "common/locator_getters.hpp"
42 
43 using namespace ot;
44 
otTcpEndpointInitialize(otInstance * aInstance,otTcpEndpoint * aEndpoint,const otTcpEndpointInitializeArgs * aArgs)45 otError otTcpEndpointInitialize(otInstance *                       aInstance,
46                                 otTcpEndpoint *                    aEndpoint,
47                                 const otTcpEndpointInitializeArgs *aArgs)
48 {
49     return AsCoreType(aEndpoint).Initialize(AsCoreType(aInstance), *aArgs);
50 }
51 
otTcpEndpointGetInstance(otTcpEndpoint * aEndpoint)52 otInstance *otTcpEndpointGetInstance(otTcpEndpoint *aEndpoint)
53 {
54     return &AsCoreType(aEndpoint).GetInstance();
55 }
56 
otTcpEndpointGetContext(otTcpEndpoint * aEndpoint)57 void *otTcpEndpointGetContext(otTcpEndpoint *aEndpoint)
58 {
59     return AsCoreType(aEndpoint).GetContext();
60 }
61 
otTcpGetLocalAddress(const otTcpEndpoint * aEndpoint)62 const otSockAddr *otTcpGetLocalAddress(const otTcpEndpoint *aEndpoint)
63 {
64     return &AsCoreType(aEndpoint).GetLocalAddress();
65 }
66 
otTcpGetPeerAddress(const otTcpEndpoint * aEndpoint)67 const otSockAddr *otTcpGetPeerAddress(const otTcpEndpoint *aEndpoint)
68 {
69     return &AsCoreType(aEndpoint).GetPeerAddress();
70 }
71 
otTcpBind(otTcpEndpoint * aEndpoint,const otSockAddr * aSockName)72 otError otTcpBind(otTcpEndpoint *aEndpoint, const otSockAddr *aSockName)
73 {
74     return AsCoreType(aEndpoint).Bind(AsCoreType(aSockName));
75 }
76 
otTcpConnect(otTcpEndpoint * aEndpoint,const otSockAddr * aSockName,uint32_t aFlags)77 otError otTcpConnect(otTcpEndpoint *aEndpoint, const otSockAddr *aSockName, uint32_t aFlags)
78 {
79     return AsCoreType(aEndpoint).Connect(AsCoreType(aSockName), aFlags);
80 }
81 
otTcpSendByReference(otTcpEndpoint * aEndpoint,otLinkedBuffer * aBuffer,uint32_t aFlags)82 otError otTcpSendByReference(otTcpEndpoint *aEndpoint, otLinkedBuffer *aBuffer, uint32_t aFlags)
83 {
84     return AsCoreType(aEndpoint).SendByReference(*aBuffer, aFlags);
85 }
86 
otTcpSendByExtension(otTcpEndpoint * aEndpoint,size_t aNumBytes,uint32_t aFlags)87 otError otTcpSendByExtension(otTcpEndpoint *aEndpoint, size_t aNumBytes, uint32_t aFlags)
88 {
89     return AsCoreType(aEndpoint).SendByExtension(aNumBytes, aFlags);
90 }
91 
otTcpReceiveByReference(otTcpEndpoint * aEndpoint,const otLinkedBuffer ** aBuffer)92 otError otTcpReceiveByReference(otTcpEndpoint *aEndpoint, const otLinkedBuffer **aBuffer)
93 {
94     return AsCoreType(aEndpoint).ReceiveByReference(*aBuffer);
95 }
96 
otTcpReceiveContiguify(otTcpEndpoint * aEndpoint)97 otError otTcpReceiveContiguify(otTcpEndpoint *aEndpoint)
98 {
99     return AsCoreType(aEndpoint).ReceiveContiguify();
100 }
101 
otTcpCommitReceive(otTcpEndpoint * aEndpoint,size_t aNumBytes,uint32_t aFlags)102 otError otTcpCommitReceive(otTcpEndpoint *aEndpoint, size_t aNumBytes, uint32_t aFlags)
103 {
104     return AsCoreType(aEndpoint).CommitReceive(aNumBytes, aFlags);
105 }
106 
otTcpSendEndOfStream(otTcpEndpoint * aEndpoint)107 otError otTcpSendEndOfStream(otTcpEndpoint *aEndpoint)
108 {
109     return AsCoreType(aEndpoint).SendEndOfStream();
110 }
111 
otTcpAbort(otTcpEndpoint * aEndpoint)112 otError otTcpAbort(otTcpEndpoint *aEndpoint)
113 {
114     return AsCoreType(aEndpoint).Abort();
115 }
116 
otTcpEndpointDeinitialize(otTcpEndpoint * aEndpoint)117 otError otTcpEndpointDeinitialize(otTcpEndpoint *aEndpoint)
118 {
119     return AsCoreType(aEndpoint).Deinitialize();
120 }
121 
otTcpListenerInitialize(otInstance * aInstance,otTcpListener * aListener,const otTcpListenerInitializeArgs * aArgs)122 otError otTcpListenerInitialize(otInstance *                       aInstance,
123                                 otTcpListener *                    aListener,
124                                 const otTcpListenerInitializeArgs *aArgs)
125 {
126     return AsCoreType(aListener).Initialize(AsCoreType(aInstance), *aArgs);
127 }
128 
otTcpListenerGetInstance(otTcpListener * aListener)129 otInstance *otTcpListenerGetInstance(otTcpListener *aListener)
130 {
131     return &AsCoreType(aListener).GetInstance();
132 }
133 
otTcpListenerGetContext(otTcpListener * aListener)134 void *otTcpListenerGetContext(otTcpListener *aListener)
135 {
136     return AsCoreType(aListener).GetContext();
137 }
138 
otTcpListen(otTcpListener * aListener,const otSockAddr * aSockName)139 otError otTcpListen(otTcpListener *aListener, const otSockAddr *aSockName)
140 {
141     return AsCoreType(aListener).Listen(AsCoreType(aSockName));
142 }
143 
otTcpStopListening(otTcpListener * aListener)144 otError otTcpStopListening(otTcpListener *aListener)
145 {
146     return AsCoreType(aListener).StopListening();
147 }
148 
otTcpListenerDeinitialize(otTcpListener * aListener)149 otError otTcpListenerDeinitialize(otTcpListener *aListener)
150 {
151     return AsCoreType(aListener).Deinitialize();
152 }
153 
154 #endif // OPENTHREAD_CONFIG_TCP_ENABLE
155