Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caadapternetdtls.h
index debf3d3..c1d5349 100644 (file)
@@ -26,6 +26,7 @@
 #include "caadapterutils.h"
 #include "ocsecurityconfig.h"
 #include "cainterface.h"
+#include "cacommon.h"
 
 /**
  *   Currently DTLS supported adapters(2) WIFI and ETHENET for linux platform.
  */
 extern void OCGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
 
-typedef void (*CAPacketReceivedCallback)(const char *ipAddress, const uint16_t port,
-         const void *data, const uint32_t dataLength, const bool isSecured);
+typedef void (*CAPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+                                         const void *data, uint32_t dataLength);
 
-typedef uint32_t (*CAPacketSendCallback)(const char *ipAddress, const uint16_t port,
-        const void *data, const uint32_t dataLength);
+typedef void (*CAPacketSendCallback)(CAEndpoint_t *endpoint,
+                                         const void *data, uint32_t dataLength);
 
 /**
  * @struct stCAAdapterCallbacks_t
@@ -60,6 +61,8 @@ typedef struct CAAdapterCallbacks
  */
 typedef struct stCADtlsContext
 {
+    u_arraylist_t *peerInfoList;        /**< peerInfo list which holds the mapping between
+                                             peer id to it's n/w address */
     u_arraylist_t *cacheList;            /**< PDU's are cached until DTLS session is formed. */
     struct dtls_context_t *dtlsContext;  /**< Pointer to tinyDTLS context. */
     struct stPacketInfo *packetInfo;     /**< used by callback during
@@ -116,20 +119,9 @@ typedef struct CACacheMessage
 {
     void *data;
     uint32_t dataLen;
-    stCADtlsAddrInfo_t *destSession;
+    stCADtlsAddrInfo_t destSession;
 } stCACacheMessage_t;
 
-/**
- * @enum eDtlsAdapterType_t
- * @brief This enum is used as array index for storing adapter level callbacks.
- *        So Keeping 0 instead of "1 << 0". It is not going to be used as addition
- *        and removal of adapter.
- *
- */
-typedef enum
-{
-    DTLS_IP = 0,
-} eDtlsAdapterType_t;
 
 /**
  * @fn  CADTLSSetAdapterCallbacks
@@ -143,7 +135,8 @@ typedef enum
  *
  */
 void CADTLSSetAdapterCallbacks(CAPacketReceivedCallback recvCallback,
-                               CAPacketSendCallback sendCallback, eDtlsAdapterType_t type);
+                               CAPacketSendCallback sendCallback,
+                               CATransportAdapter_t type);
 
 /**
  * @brief   Register callback to get DTLS PSK credentials.
@@ -153,6 +146,70 @@ void CADTLSSetAdapterCallbacks(CAPacketReceivedCallback recvCallback,
 void CADTLSSetCredentialsCallback(CAGetDTLSCredentialsHandler credCallback);
 
 /**
+ * Select the cipher suite for dtls handshake
+ *
+ * @param[in] cipher    cipher suite
+ *                             0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA
+ *                             0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
+ *                             0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
+ *
+ * @retval  CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t CADtlsSelectCipherSuite(const dtls_cipher_t cipher);
+
+/**
+ * Enable anonymous ECDH cipher suite for dtls handshake
+ *
+ * @param[in] enable  TRUE/FALSE enables/disables anonymous cipher suite
+ *
+ * @retval  CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t CADtlsEnableAnonECDHCipherSuite(const bool enable);
+
+/**
+ * Initiate DTLS handshake with selected cipher suite
+ *
+ * @param[in] endpoint  information of network address
+ *
+ * @retval  CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t CADtlsInitiateHandshake(const CAEndpoint_t *endpoint);
+
+/**
+ * Close the DTLS session
+ *
+ * @param[in] endpoint  information of network address
+ *
+ * @retval  CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t CADtlsClose(const CAEndpoint_t *endpoint);
+
+/**
+ * Generate ownerPSK using PRF
+ * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
+ *                                    'ID of new device(Resource Server)',
+ *                                    'ID of owner smart-phone(Provisioning Server)')
+ *
+ * @param[in] endpoint  information of network address
+ * @param[in] label  Ownership transfer method e.g)"oic.sec.doxm.jw"
+ * @param[in] labelLen  Byte length of label
+ * @param[in] rsrcServerDeviceID  ID of new device(Resource Server)
+ * @param[in] rsrcServerDeviceIDLen  Byte length of rsrcServerDeviceID
+ * @param[in] provServerDeviceID  label of previous owner
+ * @param[in] provServerDeviceIDLen  byte length of provServerDeviceID
+ * @param[in,out] ownerPSK  Output buffer for owner PSK
+ * @param[in] ownerPSKSize  Byte length of the ownerPSK to be generated
+ *
+ * @retval  CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t CADtlsGenerateOwnerPSK(const CAEndpoint_t *endpoint,
+                    const uint8_t* label, const size_t labelLen,
+                    const uint8_t* rsrcServerDeviceID, const size_t rsrcServerDeviceIDLen,
+                    const uint8_t* provServerDeviceID, const size_t provServerDeviceIDLen,
+                    uint8_t* ownerPSK, const size_t ownerPSKSize);
+;
+
+/**
  * @fn  CAAdapterNetDtlsInit
  * @brief  initialize tinyDTLS library and other necessary intialization.
  *
@@ -181,15 +238,11 @@ void CAAdapterNetDtlsDeInit();
  *              a new DTLS handshake is started, pdu info is
  *              cached to be send when session setup is finished.
  *
- * @param[in]  remoteAddress  address to which data will be sent.
+ * @param[in]  endpoint  address to which data will be sent.
  * @param[in]  port  port to which data will be sent.
  * @param[in]  data  length of data.
  * @param[in]  dataLen  length of given data
- * @param[out]  decdata  output variable to store the starting address
- *                        of decrypted plaintext.
- * @param[out]  cacheFlag  utput variable to indicate if pdu
- *                        is cached and inform the caller to
- *                       NOT free the memory holding pdu.
+ *
  * @return  0 on success otherwise a positive error value.
  * @retval  CA_STATUS_OK  Successful
  * @retval  CA_STATUS_INVALID_PARAM  Invalid input argumets
@@ -197,12 +250,9 @@ void CAAdapterNetDtlsDeInit();
  *
  */
 
-CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
-                                   const uint16_t port,
+CAResult_t CAAdapterNetDtlsEncrypt(const CAEndpoint_t *endpoint,
                                    void *data,
-                                   uint32_t dataLen,
-                                   uint8_t *cacheFlag,
-                                   eDtlsAdapterType_t type);
+                                   uint32_t dataLen);
 
 /**
  * @fn  CAAdapterNetDtlsDecrypt
@@ -219,11 +269,9 @@ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
  * @retval  CA_STATUS_FAILED Operation failed
  *
  */
-CAResult_t CAAdapterNetDtlsDecrypt(const char *remoteAddress,
-                                   const uint16_t port,
+CAResult_t CAAdapterNetDtlsDecrypt(const CAEndpoint_t *endpoint,
                                    uint8_t *data,
-                                   uint32_t dataLen,
-                                   eDtlsAdapterType_t type);
+                                   uint32_t dataLen);
 
 #endif /* CA_ADAPTER_NET_DTLS_H_ */