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