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