Imported Upstream version 1.1.0
[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
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 /**
39  * TCP Session Information for IPv4 TCP transport
40  */
41 typedef struct
42 {
43     CASecureEndpoint_t sep;             /**< secure endpoint information */
44     int fd;                             /**< file descriptor info */
45     void *recvData;                     /**< received data from remote device*/
46     size_t recvDataLen;                 /**< received data length */
47     size_t totalDataLen;                /**< total data length */
48 } CATCPSessionInfo_t;
49
50 /**
51  * API to initialize TCP Interface.
52  * @param[in] registerCallback      Callback to register TCP interfaces to
53  *                                  Connectivity Abstraction Layer.
54  * @param[in] networkPacketCallback Callback to notify request and
55  *                                  response messages from server(s)
56  *                                  started at Connectivity Abstraction Layer.
57  * @param[in] netCallback           Callback to notify the network additions
58  *                                  to Connectivity Abstraction Layer.
59  * @param[in] errorCallback         Callback to notify the network errors to
60  *                                  Connectivity Abstraction Layer.
61  * @param[in] handle                Threadpool Handle.
62  * @return  ::CA_STATUS_OK or Appropriate error code
63  */
64 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
65                            CANetworkPacketReceivedCallback networkPacketCallback,
66                            CANetworkChangeCallback netCallback,
67                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
68
69 /**
70  * Start TCP Interface adapter.
71  * @return  ::CA_STATUS_OK or Appropriate error code.
72  */
73 CAResult_t CAStartTCP();
74
75 /**
76  * Start listening server for receiving connect requests.
77  * Transport Specific Behavior:
78  * TCP Starts Listening Server on a particular interface and prefixed port
79  * number and as per OIC Specification.
80  * @return  ::CA_STATUS_OK or Appropriate error code.
81  */
82 CAResult_t CAStartTCPListeningServer();
83
84 /**
85  * Stops listening server from receiving connect requests.
86  * Transport Specific Behavior:
87  * TCP Stops Listening Server on a particular interface and prefixed port
88  * number and as per OIC Specification.
89  * @return  ::CA_STATUS_OK or Appropriate error code.
90  */
91 CAResult_t CAStopTCPListeningServer();
92
93 /**
94  * Start discovery servers for receiving advertisements.
95  * Transport Specific Behavior:
96  * TCP Starts Discovery server on a particular interface and prefixed port
97  * number as per OIC Specification.
98  * @return  ::CA_STATUS_OK or Appropriate error code.
99  */
100 CAResult_t CAStartTCPDiscoveryServer();
101
102 /**
103  * Sends data to the endpoint using the adapter connectivity.
104  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
105  *                              port, reference uri and transport type) to
106  *                              which the unicast data has to be sent.
107  * @param[in]   data           Data which is required to be sent.
108  * @param[in]   dataLen        Size of data to be sent.
109  * @note  dataLen must be > 0.
110  * @return  The number of bytes sent on the network, or -1 upon error.
111  */
112 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
113                              const void *data, uint32_t dataLen);
114
115 /**
116  * Send Multicast data to the endpoint using the TCP connectivity.
117  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
118  *                              port)
119  * @param[in]   data           Data which is required to be sent.
120  * @param[in]   dataLen        Size of data to be sent.
121  * @note  dataLen must be > 0.
122  * @return  The number of bytes sent on the network, or -1 upon error.
123  */
124 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
125                                const void *data, uint32_t dataLen);
126
127 /**
128  * Get TCP Connectivity network information.
129  * @param[out]   info        Local connectivity information structures.
130  * @note info is allocated in this API and should be freed by the caller.
131  * @param[out]   size        Number of local connectivity structures.
132  * @return  ::CA_STATUS_OK or Appropriate error code.
133  */
134 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
135
136 /**
137  * Read Synchronous API callback.
138  * @return  ::CA_STATUS_OK or Appropriate error code.
139  */
140 CAResult_t CAReadTCPData();
141
142 /**
143  * Stops Unicast, servers and close the sockets.
144  * @return  ::CA_STATUS_OK or Appropriate error code.
145  */
146 CAResult_t CAStopTCP();
147
148 /**
149  * Terminate the TCP connectivity adapter.
150  * Configuration information will be deleted from further use.
151  */
152 void CATerminateTCP();
153
154 /**
155  * Set connected callback and disconnected callback to process KeepAlive.
156  * connection informations are delivered these callbacks.
157  * @param[in]   ConnHandler     Connected callback.
158  * @param[in]   DisconnHandler  Disconnected Callback.
159  */
160 void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler,
161                                 CAKeepAliveDisconnectedCallback DisconnHandler);
162
163 #ifdef __cplusplus
164 } /* extern "C" */
165 #endif
166
167 #endif  // CA_TCP_ADAPTER_H_