replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / catcpadapter.h
index 14b2c8e..536f8f6 100644 (file)
 #include "cacommon.h"
 #include "caadapterinterface.h"
 #include "cathreadpool.h"
+#include "cainterface.h"
+#include <coap/pdu.h>
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
+
+typedef enum CAProtocol
+{
+    UNKNOWN = 0,
+    TLS,
+    COAP
+} CAProtocol_t;
+
+/**
+ * TCP Connection State.
+ */
+typedef enum
+{
+    CONNECTING = 0,
+    CONNECTED,
+    DISCONNECTED
+} CATCPConnectionState_t;
+
 /**
- * TCP Server Information for IPv4 TCP transport
+ * TCP Session Information for IPv4 TCP transport
  */
 typedef struct
 {
-    char addr[MAX_ADDR_STR_SIZE_CA];    /**< TCP Server address */
-    CASocket_t u4tcp;                   /**< TCP Server port */
-} CATCPServerInfo_t;
+    CASecureEndpoint_t sep;             /**< secure endpoint information */
+    int fd;                             /**< file descriptor info */
+    unsigned char* data;                /**< received data from remote device */
+    size_t len;                         /**< received data length */
+    size_t totalLen;                    /**< total coap data length required to receive */
+    unsigned char tlsdata[18437];       /**< 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;
 
 /**
  * API to initialize TCP Interface.
@@ -50,7 +78,9 @@ typedef struct
  * @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.
@@ -59,7 +89,8 @@ typedef struct
  */
 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback networkPacketCallback,
-                           CANetworkChangeCallback netCallback,
+                           CAAdapterChangeCallback netCallback,
+                           CAConnectionChangeCallback connCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
 
 /**
@@ -69,6 +100,16 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
 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
@@ -102,11 +143,13 @@ CAResult_t CAStartTCPDiscoveryServer();
  *                              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.
@@ -114,11 +157,13 @@ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
  *                              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.
@@ -147,6 +192,13 @@ CAResult_t CAStopTCP();
  */
 void CATerminateTCP();
 
+/**
+ * Set connection status changes callback to process KeepAlive.
+ * connection informations are delivered these callbacks.
+ * @param[in]   ConnHandler     Connection status changes callback.
+ */
+void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif