1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 * This file contains the APIs for TCP Adapter.
25 #ifndef CA_TCP_ADAPTER_H_
26 #define CA_TCP_ADAPTER_H_
29 #include "caadapterinterface.h"
30 #include "cathreadpool.h"
31 #include "cainterface.h"
40 typedef enum CAProtocol
48 * TCP Connection State.
55 } CATCPConnectionState_t;
58 * TCP Session Information for IPv4 TCP transport
62 CASecureEndpoint_t sep; /**< secure endpoint information */
63 int fd; /**< file descriptor info */
64 unsigned char* data; /**< received data from remote device */
65 size_t len; /**< received data length */
66 size_t totalLen; /**< total data length required to receive */
67 CAProtocol_t protocol; /**< application-level protocol */
68 CATCPConnectionState_t state; /**< current tcp session state */
72 * API to initialize TCP Interface.
73 * @param[in] registerCallback Callback to register TCP interfaces to
74 * Connectivity Abstraction Layer.
75 * @param[in] networkPacketCallback Callback to notify request and
76 * response messages from server(s)
77 * started at Connectivity Abstraction Layer.
78 * @param[in] netCallback Callback to notify the adapter changes
79 * to Connectivity Abstraction Layer.
80 * @param[in] connCallback Callback to notify the connection changes
81 * to Connectivity Abstraction Layer.
82 * @param[in] errorCallback Callback to notify the network errors to
83 * Connectivity Abstraction Layer.
84 * @param[in] handle Threadpool Handle.
85 * @return ::CA_STATUS_OK or Appropriate error code
87 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
88 CANetworkPacketReceivedCallback networkPacketCallback,
89 CAAdapterChangeCallback netCallback,
90 CAConnectionChangeCallback connCallback,
91 CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
94 * Start TCP Interface adapter.
95 * @return ::CA_STATUS_OK or Appropriate error code.
97 CAResult_t CAStartTCP();
100 * Start listening server for receiving connect requests.
101 * Transport Specific Behavior:
102 * TCP Starts Listening Server on a particular interface and prefixed port
103 * number and as per OIC Specification.
104 * @return ::CA_STATUS_OK or Appropriate error code.
106 CAResult_t CAStartTCPListeningServer();
109 * Stops listening server from receiving connect requests.
110 * Transport Specific Behavior:
111 * TCP Stops Listening Server on a particular interface and prefixed port
112 * number and as per OIC Specification.
113 * @return ::CA_STATUS_OK or Appropriate error code.
115 CAResult_t CAStopTCPListeningServer();
118 * Start discovery servers for receiving advertisements.
119 * Transport Specific Behavior:
120 * TCP Starts Discovery server on a particular interface and prefixed port
121 * number as per OIC Specification.
122 * @return ::CA_STATUS_OK or Appropriate error code.
124 CAResult_t CAStartTCPDiscoveryServer();
127 * Sends data to the endpoint using the adapter connectivity.
128 * @param[in] endpoint Remote Endpoint information (like ipaddress,
129 * port, reference uri and transport type) to
130 * which the unicast data has to be sent.
131 * @param[in] data Data which is required to be sent.
132 * @param[in] dataLen Size of data to be sent.
133 * @param[in] dataType Data type which is REQUEST or RESPONSE.
134 * @note dataLen must be > 0.
135 * @return The number of bytes sent on the network, or -1 upon error.
137 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
138 const void *data, uint32_t dataLen,
139 CADataType_t dataType);
142 * Send Multicast data to the endpoint using the TCP connectivity.
143 * @param[in] endpoint Remote Endpoint information (like ipaddress,
145 * @param[in] data Data which is required to be sent.
146 * @param[in] dataLen Size of data to be sent.
147 * @param[in] dataType Data type which is REQUEST or RESPONSE.
148 * @note dataLen must be > 0.
149 * @return The number of bytes sent on the network, or -1 upon error.
151 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
152 const void *data, uint32_t dataLen,
153 CADataType_t dataType);
156 * Get TCP Connectivity network information.
157 * @param[out] info Local connectivity information structures.
158 * @note info is allocated in this API and should be freed by the caller.
159 * @param[out] size Number of local connectivity structures.
160 * @return ::CA_STATUS_OK or Appropriate error code.
162 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
165 * Read Synchronous API callback.
166 * @return ::CA_STATUS_OK or Appropriate error code.
168 CAResult_t CAReadTCPData();
171 * Stops Unicast, servers and close the sockets.
172 * @return ::CA_STATUS_OK or Appropriate error code.
174 CAResult_t CAStopTCP();
177 * Terminate the TCP connectivity adapter.
178 * Configuration information will be deleted from further use.
180 void CATerminateTCP();
183 * Set connection status changes callback to process KeepAlive.
184 * connection informations are delivered these callbacks.
185 * @param[in] ConnHandler Connection status changes callback.
187 void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler);
193 #endif // CA_TCP_ADAPTER_H_