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