#include "caadapterinterface.h"
#include "cathreadpool.h"
#include "cainterface.h"
+#include <coap/pdu.h>
#ifdef __cplusplus
extern "C"
{
#endif
+// TLS data max size (rfc5246: TLSCiphertext max (2^14+2048+5))
+#define TLS_DATA_MAX_SIZE 18437
+
+typedef enum CAProtocol
+{
+ UNKNOWN = 0,
+ TLS,
+ COAP
+} CAProtocol_t;
+
+/**
+ * TCP Connection State.
+ */
+typedef enum
+{
+ CONNECTING = 0,
+ CONNECTED,
+ DISCONNECTED
+} CATCPConnectionState_t;
+
/**
* TCP Session Information for IPv4 TCP transport
*/
{
CASecureEndpoint_t sep; /**< secure endpoint information */
int fd; /**< file descriptor info */
- void *recvData; /**< received data from remote device*/
- size_t recvDataLen; /**< received data length */
- size_t totalDataLen; /**< total data length */
+ unsigned char* data; /**< received data from remote device */
+ size_t len; /**< received data length */
+ size_t totalLen; /**< total coap data length required to receive */
+ size_t bufLen; /**< Buffer length. Buffer will be grown dynamically with respect to data received. */
+ unsigned char *tlsdata; /**< tls data(rfc5246: TLSCiphertext max (2^14+2048+5)) */
+ size_t tlsLen; /**< received tls data length */
+ CAProtocol_t protocol; /**< application-level protocol */
+ CATCPConnectionState_t state; /**< current tcp session state */
+ bool isClient; /**< Host Mode of Operation. */
} CATCPSessionInfo_t;
/**
* @param[in] networkPacketCallback Callback to notify request and
* response messages from server(s)
* started at Connectivity Abstraction Layer.
- * @param[in] netCallback Callback to notify the network additions
+ * @param[in] netCallback Callback to notify the adapter changes
+ * to Connectivity Abstraction Layer.
+ * @param[in] connCallback Callback to notify the connection changes
* to Connectivity Abstraction Layer.
* @param[in] errorCallback Callback to notify the network errors to
* Connectivity Abstraction Layer.
*/
CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback networkPacketCallback,
- CANetworkChangeCallback netCallback,
+ CAAdapterChangeCallback netCallback,
+ CAConnectionChangeCallback connCallback,
CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
/**
CAResult_t CAStartTCP();
/**
+ * Disconnect TCP session.
+ * When there is no transmission for a long time.
+ * Some carrier Vendor is blocking data.
+ * Thur, TCP Session is cleaned through this function.
+ * @param[in] endpoint Remote Endpoint information (like ipaddress,
+ * port)
+ */
+CAResult_t CATCPDisconnectSession(const CAEndpoint_t *endpoint);
+
+/**
* Start listening server for receiving connect requests.
* Transport Specific Behavior:
* TCP Starts Listening Server on a particular interface and prefixed port
* which the unicast data has to be sent.
* @param[in] data Data which is required to be sent.
* @param[in] dataLen Size of data to be sent.
+ * @param[in] dataType Data type which is REQUEST or RESPONSE.
* @note dataLen must be > 0.
* @return The number of bytes sent on the network, or -1 upon error.
*/
int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
- const void *data, uint32_t dataLen);
+ const void *data, uint32_t dataLen,
+ CADataType_t dataType);
/**
* Send Multicast data to the endpoint using the TCP connectivity.
* port)
* @param[in] data Data which is required to be sent.
* @param[in] dataLen Size of data to be sent.
+ * @param[in] dataType Data type which is REQUEST or RESPONSE.
* @note dataLen must be > 0.
* @return The number of bytes sent on the network, or -1 upon error.
*/
int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
- const void *data, uint32_t dataLen);
+ const void *data, uint32_t dataLen,
+ CADataType_t dataType);
/**
* Get TCP Connectivity network information.
*/
void CATerminateTCP();
+#ifdef TCP_ADAPTER
/**
- * Set connected callback and disconnected callback to process KeepAlive.
+ * Set connection status changes callback to process KeepAlive.
* connection informations are delivered these callbacks.
- * @param[in] ConnHandler Connected callback.
- * @param[in] DisconnHandler Disconnected Callback.
+ * @param[in] ConnHandler Connection status changes callback.
*/
-void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler,
- CAKeepAliveDisconnectedCallback DisconnHandler);
+void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler);
+#endif
#ifdef __cplusplus
} /* extern "C" */