wrap CAcloseSslConnectionFreeEndpoint method with __TIZEN__ flag
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / catcpadapter.h
1 /* ****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the APIs for TCP Adapter.
24  */
25 #ifndef CA_TCP_ADAPTER_H_
26 #define CA_TCP_ADAPTER_H_
27
28 #include "cacommon.h"
29 #include "caadapterinterface.h"
30 #include "cathreadpool.h"
31 #include "cainterface.h"
32 #include <coap/pdu.h>
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 // TLS data max size (rfc5246: TLSCiphertext max (2^14+2048+5))
40 #define TLS_DATA_MAX_SIZE 18437
41
42 typedef enum CAProtocol
43 {
44     UNKNOWN = 0,
45     TLS,
46     COAP
47 } CAProtocol_t;
48
49 /**
50  * TCP Connection State.
51  */
52 typedef enum
53 {
54     CONNECTING = 0,
55     CONNECTED,
56     DISCONNECTED
57 } CATCPConnectionState_t;
58
59 /**
60  * TCP Session Information for IPv4 TCP transport
61  */
62 typedef struct
63 {
64     CASecureEndpoint_t sep;             /**< secure endpoint information */
65     int fd;                             /**< file descriptor info */
66     unsigned char* data;                /**< received data from remote device */
67     size_t len;                         /**< received data length */
68     size_t totalLen;                    /**< total coap data length required to receive */
69     size_t bufLen;                      /**< Buffer length. Buffer will be grown dynamically with respect to data received. */
70     unsigned char *tlsdata;             /**< tls data(rfc5246: TLSCiphertext max (2^14+2048+5)) */
71     size_t tlsLen;                      /**< received tls data length */
72     CAProtocol_t protocol;              /**< application-level protocol */
73     CATCPConnectionState_t state;       /**< current tcp session state */
74     bool isClient;                      /**< Host Mode of Operation. */
75 } CATCPSessionInfo_t;
76
77 /**
78  * API to initialize TCP Interface.
79  * @param[in] registerCallback      Callback to register TCP interfaces to
80  *                                  Connectivity Abstraction Layer.
81  * @param[in] networkPacketCallback Callback to notify request and
82  *                                  response messages from server(s)
83  *                                  started at Connectivity Abstraction Layer.
84  * @param[in] netCallback           Callback to notify the adapter changes
85  *                                  to Connectivity Abstraction Layer.
86  * @param[in] connCallback          Callback to notify the connection changes
87  *                                  to Connectivity Abstraction Layer.
88  * @param[in] errorCallback         Callback to notify the network errors to
89  *                                  Connectivity Abstraction Layer.
90  * @param[in] handle                Threadpool Handle.
91  * @return  ::CA_STATUS_OK or Appropriate error code
92  */
93 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
94                            CANetworkPacketReceivedCallback networkPacketCallback,
95                            CAAdapterChangeCallback netCallback,
96                            CAConnectionChangeCallback connCallback,
97                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
98
99 /**
100  * Start TCP Interface adapter.
101  * @return  ::CA_STATUS_OK or Appropriate error code.
102  */
103 CAResult_t CAStartTCP();
104
105 /**
106  * Disconnect TCP session.
107  * When there is no transmission for a long time.
108  * Some carrier Vendor is blocking data.
109  * Thur, TCP Session is cleaned through this function.
110  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
111  *                             port)
112  */
113 CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint);
114
115 /**
116  * Enable or disable skip closing TCP servers
117  * when network interface is down.
118  *
119  * @param[in]   state    true to skip closing TCP servers,
120  *                       otherwise false.
121  */
122 void CATCPSkipCloseOnInterfaceDown(bool state);
123
124 /**
125  * Start listening server for receiving connect requests.
126  * Transport Specific Behavior:
127  * TCP Starts Listening Server on a particular interface and prefixed port
128  * number and as per OIC Specification.
129  * @return  ::CA_STATUS_OK or Appropriate error code.
130  */
131 CAResult_t CAStartTCPListeningServer();
132
133 /**
134  * Stops listening server from receiving connect requests.
135  * Transport Specific Behavior:
136  * TCP Stops Listening Server on a particular interface and prefixed port
137  * number and as per OIC Specification.
138  * @return  ::CA_STATUS_OK or Appropriate error code.
139  */
140 CAResult_t CAStopTCPListeningServer();
141
142 /**
143  * Start discovery servers for receiving advertisements.
144  * Transport Specific Behavior:
145  * TCP Starts Discovery server on a particular interface and prefixed port
146  * number as per OIC Specification.
147  * @return  ::CA_STATUS_OK or Appropriate error code.
148  */
149 CAResult_t CAStartTCPDiscoveryServer();
150
151 /**
152  * Sends data to the endpoint using the adapter connectivity.
153  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
154  *                              port, reference uri and transport type) to
155  *                              which the unicast data has to be sent.
156  * @param[in]   data           Data which is required to be sent.
157  * @param[in]   dataLen        Size of data to be sent.
158  * @param[in]   dataType       Data type which is REQUEST or RESPONSE.
159  * @note  dataLen must be > 0.
160  * @return  The number of bytes sent on the network, or -1 upon error.
161  */
162 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
163                              const void *data, uint32_t dataLen,
164                              CADataType_t dataType);
165
166 /**
167  * Send Multicast data to the endpoint using the TCP connectivity.
168  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
169  *                              port)
170  * @param[in]   data           Data which is required to be sent.
171  * @param[in]   dataLen        Size of data to be sent.
172  * @param[in]   dataType       Data type which is REQUEST or RESPONSE.
173  * @note  dataLen must be > 0.
174  * @return  The number of bytes sent on the network, or -1 upon error.
175  */
176 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
177                                const void *data, uint32_t dataLen,
178                                CADataType_t dataType);
179
180 /**
181  * Get TCP Connectivity network information.
182  * @param[out]   info        Local connectivity information structures.
183  * @note info is allocated in this API and should be freed by the caller.
184  * @param[out]   size        Number of local connectivity structures.
185  * @return  ::CA_STATUS_OK or Appropriate error code.
186  */
187 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
188
189 /**
190  * Read Synchronous API callback.
191  * @return  ::CA_STATUS_OK or Appropriate error code.
192  */
193 CAResult_t CAReadTCPData();
194
195 /**
196  * Stops Unicast, servers and close the sockets.
197  * @return  ::CA_STATUS_OK or Appropriate error code.
198  */
199 CAResult_t CAStopTCP();
200
201 /**
202  * Terminate the TCP connectivity adapter.
203  * Configuration information will be deleted from further use.
204  */
205 void CATerminateTCP();
206
207 #ifdef TCP_ADAPTER
208 /**
209  * Set connection status changes callback to process KeepAlive.
210  * connection informations are delivered these callbacks.
211  * @param[in]   ConnHandler     Connection status changes callback.
212  */
213 void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler);
214 #endif
215
216 #ifdef __cplusplus
217 } /* extern "C" */
218 #endif
219
220 #endif  // CA_TCP_ADAPTER_H_