#endif
#include "camutex.h"
#include "uarraylist.h"
+#include "caremotehandler.h"
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
* @def IP_ADAPTER_TAG
* @brief Logging tag for module name
*/
-#define IP_ADAPTER_TAG "IP_ADAP"
+#define IP_ADAPTER_TAG "IPAD"
/**
* @def CA_PORT
* @brief Port to listen for incoming data
*/
-#define CA_PORT 6298
+#ifdef ARDUINO
+#define CA_PORT 55555
+#else
+#define CA_PORT 0
+#endif
/**
* @def CA_SECURE_PORT
*/
#define CA_MULTICAST_IP "224.0.1.187"
+#ifndef SINGLE_THREAD
/**
* @var CAIPData
* @brief Holds inter thread ip data information.
} CAIPData;
/**
+ * @var g_sendQueueHandle
+ * @brief Queue handle for Send Data
+ */
+static CAQueueingThread_t *g_sendQueueHandle = NULL;
+#endif
+
+/**
* @var g_networkPacketCallback
* @brief Network Packet Received Callback to CA
*/
static CANetworkChangeCallback g_networkChangeCallback = NULL;
/**
- * @var g_sendQueueHandle
- * @brief Queue handle for Send Data
+ * @var g_errorCallback
+ * @brief error Callback to CA adapter
*/
-static CAQueueingThread_t *g_sendQueueHandle = NULL;
+static CAErrorHandleCallback g_errorCallback = NULL;
/**
* @var g_threadPool
*/
static ca_thread_pool_t g_threadPool = NULL;
-static CAResult_t CAIPInitializeQueueHandles();
-
-static void CAIPDeinitializeQueueHandles();
-
static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
- CANetworkStatus_t status);
+ CANetworkStatus_t status);
static void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status);
static void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint,
- const void *data, uint32_t dataLength);
+ const void *data, uint32_t dataLength);
+static void CAIPErrorHandler(const CAEndpoint_t *endpoint, const void *data,
+ uint32_t dataLength, CAResult_t result);
#ifdef __WITH_DTLS__
static uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint,
- const void *data, uint32_t dataLength);
+ const void *data, uint32_t dataLength);
#endif
static CAResult_t CAIPStopServers();
+#ifndef SINGLE_THREAD
+
+static CAResult_t CAIPInitializeQueueHandles();
+
+static void CAIPDeinitializeQueueHandles();
+
static void CAIPSendDataThread(void *threadData);
static CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
- const void *data, uint32_t dataLength,
- bool isMulticast);
+ const void *data, uint32_t dataLength, bool isMulticast);
void CAFreeIPData(CAIPData *ipData);
static void CADataDestroyer(void *data, uint32_t size);
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
}
+void CAIPSendDataThread(void *threadData)
+{
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+
+ CAIPData *ipData = (CAIPData *) threadData;
+ uint32_t sentData = -1;
+
+ if (!ipData)
+ {
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
+ return;
+ }
+
+ if (ipData->isMulticast)
+ {
+ //Processing for sending multicast
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
+ strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
+ ipData->remoteEndpoint->port = CA_MCAST_PORT;
+ sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
+ }
+ else
+ {
+ //Processing for sending unicast
+#ifdef __WITH_DTLS__
+ if (ipData->remoteEndpoint->flags & CA_SECURE)
+ {
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
+ CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
+ ipData->data, ipData->dataLen);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
+ sentData = 0;
+ }
+ OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
+ "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
+ }
+ else
+ {
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
+ sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
+ }
+#else
+ sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
+#endif
+ }
+
+ if (0 == sentData)
+ {
+ g_errorCallback(ipData->remoteEndpoint, ipData->data, ipData->dataLen,
+ CA_SEND_FAILED);
+ }
+
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+}
+
+CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
+ uint32_t dataLength, bool isMulticast)
+{
+ VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
+
+ CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
+ if (!ipData)
+ {
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
+ return NULL;
+ }
+
+ ipData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
+ ipData->data = (void *) OICMalloc(dataLength);
+ if (!ipData->data)
+ {
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
+ CAFreeIPData(ipData);
+ return NULL;
+ }
+
+ memcpy(ipData->data, data, dataLength);
+ ipData->dataLen = dataLength;
+
+ ipData->isMulticast = isMulticast;
+
+ return ipData;
+}
+
+void CAFreeIPData(CAIPData *ipData)
+{
+ VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
+
+ CAFreeEndpoint(ipData->remoteEndpoint);
+ OICFree(ipData->data);
+ OICFree(ipData);
+}
+
+void CADataDestroyer(void *data, uint32_t size)
+{
+ CAIPData *etdata = (CAIPData *) data;
+
+ CAFreeIPData(etdata);
+}
+#endif
+
void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
VERIFY_NON_NULL_VOID(address, IP_ADAPTER_TAG, "address is NULL");
- CAEndpoint_t *localEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_IP, address, port);
+ CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
+ CA_ADAPTER_IP,
+ address, port);
if (!localEndpoint)
{
OIC_LOG(ERROR, IP_ADAPTER_TAG, "localEndpoint creation failed!");
OIC_LOG(ERROR, IP_ADAPTER_TAG, "g_networkChangeCallback is NULL");
}
- CAAdapterFreeEndpoint(localEndpoint);
+ CAFreeEndpoint(localEndpoint);
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
}
if (CA_INTERFACE_UP == status)
{
uint16_t port = CA_PORT;
- CAResult_t ret = CAIPStartUnicastServer(ipAddress, &port, false, false);
+ CAResult_t ret = CAIPStartUnicastServer(ipAddress, &port, false);
if (CA_STATUS_OK == ret)
{
OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port", port);
#ifdef __WITH_DTLS__
port = CA_SECURE_PORT;
- ret = CAIPStartUnicastServer(ipAddress, &port, false, true);
+ ret = CAIPStartUnicastServer(ipAddress, &port, true);
if (CA_STATUS_OK == ret)
{
OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Secure Unicast server started on %d", port);
uint32_t sentLength = CAIPSendData(endpoint, data, dataLength, false);
+ if (sentLength == 0)
+ {
+ g_errorCallback(endpoint, data, dataLength, CA_SEND_FAILED);
+ }
+
OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Successfully sent %d of encrypted data!", sentLength);
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
#endif
void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
- uint32_t dataLength)
+ uint32_t dataLength)
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
{
OICFree(buf);
}
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+}
+
+void CAIPErrorHandler (const CAEndpoint_t *endpoint, const void *data,
+ uint32_t dataLength, CAResult_t result)
+{
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+
+ VERIFY_NON_NULL_VOID(endpoint, IP_ADAPTER_TAG, "endpoint is NULL");
+
+ VERIFY_NON_NULL_VOID(data, IP_ADAPTER_TAG, "data is NULL");
+
+ void *buf = (void*)OICMalloc(sizeof(char) * dataLength);
+ if (!buf)
+ {
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory Allocation failed!");
+ return;
+ }
+ memcpy(buf, data, dataLength);
+ if (g_errorCallback)
+ {
+ g_errorCallback(endpoint, buf, dataLength, result);
+ }
+ else
+ {
+ OICFree(buf);
+ }
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+
+ return;
+}
+
+int32_t CAIPSendDataInternal(const CAEndpoint_t *remoteEndpoint, const void *data,
+ uint32_t dataLength, bool isMulticast)
+{
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+#ifdef SINGLE_THREAD
+
+ // If remoteEndpoint is NULL, its Multicast, else its Unicast.
+ if(!isMulticast)
+ {
+ CAIPSendData(remoteEndpoint, data, dataLength, false);
+ }
+ else
+ {
+ CAEndpoint_t ep = { 0 };
+ strcpy(ep.addr, CA_MULTICAST_IP);
+ ep.port = CA_MCAST_PORT;
+ CAIPSendData(&ep, data, dataLength, true);
+ }
+#else
+ VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
+
+ // Create IPData to add to queue
+ CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, isMulticast);
+
+ if (!ipData)
+ {
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
+ return -1;
+ }
+ else
+ {
+ // Add message to send queue
+ CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
+ }
+#endif
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+ return dataLength;
}
CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback networkPacketCallback,
- CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
+ CANetworkChangeCallback netCallback,
+ CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
VERIFY_NON_NULL(registerCallback, IP_ADAPTER_TAG, "registerCallback");
VERIFY_NON_NULL(networkPacketCallback, IP_ADAPTER_TAG, "networkPacketCallback");
VERIFY_NON_NULL(netCallback, IP_ADAPTER_TAG, "netCallback");
+#ifndef SINGLE_THREAD
VERIFY_NON_NULL(handle, IP_ADAPTER_TAG, "thread pool handle");
+#endif
g_threadPool = handle;
g_networkChangeCallback = netCallback;
g_networkPacketCallback = networkPacketCallback;
+ g_errorCallback = errorCallback;
CAResult_t ret = CAIPInitializeNetworkMonitor(g_threadPool);
if (CA_STATUS_OK != ret)
{
- OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor![%d]", ret);
+ OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor[%d]", ret);
return ret;
}
CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
}
CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
+ CAIPSetErrorHandleCallback(CAIPErrorHandler);
#ifdef __WITH_DTLS__
CAAdapterNetDtlsInit();
ipHandler.terminate = CATerminateIP;
registerCallback(ipHandler, CA_ADAPTER_IP);
+#ifndef SINGLE_THREAD
if (CA_STATUS_OK != CAIPInitializeQueueHandles())
{
OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize Queue Handle");
CATerminateIP();
return CA_STATUS_FAILED;
}
-
- OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT IntializeIP is Success");
+#endif
+ OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}
return ret;
}
+#ifndef SINGLE_THREAD
// Start send queue thread
if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
{
OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start Send Data Thread");
return CA_STATUS_FAILED;
}
+#endif
bool retVal = CAIPIsConnected();
if (false == retVal)
return CA_STATUS_OK;
}
+#ifdef ARDUINO
+ uint16_t unicastPort = CA_PORT;
+ // Address is hardcoded as we are using Single Interface
+ ret = CAIPStartUnicastServer("0.0.0.0", &unicastPort, false);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Start unicast serv failed[%d]", ret);
+
+ }
+#else
u_arraylist_t *netInterfaceList = u_arraylist_create();
VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
continue;
}
uint16_t unicastPort = CA_PORT;
- ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, false);
+ ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false);
if (CA_STATUS_OK == ret)
{
OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port",
#ifdef __WITH_DTLS__
unicastPort = CA_SECURE_PORT;
- ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, true);
+ ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, true);
if (CA_STATUS_OK == ret)
{
#endif
}
CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return ret;
}
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+ CAResult_t ret = CA_STATUS_OK;
bool retVal = CAIPIsConnected();
if (false == retVal)
{
- OIC_LOG(DEBUG, IP_ADAPTER_TAG,
- "IP not Connected. Couldn't start multicast server");
- return CA_STATUS_OK;
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IP not Connected");
+ return ret;
}
+#ifdef ARDUINO
+ //uint16_t multicastPort = CA_MCAST_PORT;
+ ret = CAIPStartMulticastServer("0.0.0.0", CA_MULTICAST_IP, CA_MCAST_PORT);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Start multicast failed[%d]", ret);
+ }
+#else
u_arraylist_t *netInterfaceList = u_arraylist_create();
VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
- CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
+ ret = CAIPGetInterfaceInfo(&netInterfaceList);
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
}
CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return ret;
}
CAResult_t CAStartIPDiscoveryServer()
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+ /* Both listening and discovery server are same */
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return CAStartIPListeningServer();
}
VERIFY_NON_NULL_RET(remoteEndpoint, IP_ADAPTER_TAG, "remoteEndpoint", -1);
VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
- VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
-
if (0 == dataLength)
{
OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
return -1;
}
- // Create IPData to add to queue
- CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, false);
- if (!ipData)
- {
- OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
- return -1;
- }
- else
- {
- // Add message to send queue
- CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
-
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
- return dataLength;
- }
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+ return CAIPSendDataInternal(remoteEndpoint, data, dataLength, false);
}
int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
- VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
-
if (0 == dataLength)
{
OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
return -1;
}
- // Create IPData to add to queue
- CAIPData *ipData = CACreateIPData(endpoint, data, dataLength, true);
- if (!ipData)
- {
- OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
- return -1;
- }
- else
- {
- // Add message to send queue
- CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
-
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
- return dataLength;
- }
+ OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+ return CAIPSendDataInternal(endpoint, data, dataLength, true);
}
CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
bool retVal = CAIPIsConnected();
if (false == retVal)
{
- OIC_LOG(ERROR, IP_ADAPTER_TAG,
- "Failed to get interface address, IP not Connected");
+ OIC_LOG(ERROR, IP_ADAPTER_TAG, "IP not Connected");
return CA_ADAPTER_NOT_ENABLED;
}
CAResult_t CAReadIPData()
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
-
+ CAIPPullData();
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}
// Stop IP network monitor
CAIPStopNetworkMonitor();
+#ifndef SINGLE_THREAD
// Stop send queue thread
if (g_sendQueueHandle)
{
CAQueueingThreadStop(g_sendQueueHandle);
}
+#endif
// Stop Unicast, Secured unicast and Multicast servers running
- CAIPStopServers();
+ CAResult_t result = CAIPStopServers();
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "stop srv fail:%d", result);
+ }
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
- return CA_STATUS_OK;
+ return result;
}
void CATerminateIP()
CAIPSetConnectionStateChangeCallback(NULL);
CAIPTerminateNetworkMonitor();
+#ifndef SINGLE_THREAD
// Terminate message queue handler
CAIPDeinitializeQueueHandles();
-
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
-}
-
-void CAIPSendDataThread(void *threadData)
-{
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
-
- CAIPData *ipData = (CAIPData *) threadData;
- if (!ipData)
- {
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
- return;
- }
-
- if (ipData->isMulticast)
- {
- //Processing for sending multicast
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
- strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
- ipData->remoteEndpoint->port = CA_MCAST_PORT;
- CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
- }
- else
- {
- //Processing for sending unicast
-#ifdef __WITH_DTLS__
- if (ipData->remoteEndpoint->flags & CA_SECURE)
- {
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
- CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
- ipData->data, ipData->dataLen);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
- }
- OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
- "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
- }
- else
- {
- OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
- CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
- }
-#else
- CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
#endif
- }
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
}
-
-CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength, bool isMulticast)
-{
- VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
-
- CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
- if (!ipData)
- {
- OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
- return NULL;
- }
-
- ipData->remoteEndpoint = CAAdapterCloneEndpoint(remoteEndpoint);
- ipData->data = (void *) OICMalloc(dataLength);
- if (!ipData->data)
- {
- OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
- CAFreeIPData(ipData);
- return NULL;
- }
-
- memcpy(ipData->data, data, dataLength);
- ipData->dataLen = dataLength;
-
- ipData->isMulticast = isMulticast;
-
- return ipData;
-}
-
-void CAFreeIPData(CAIPData *ipData)
-{
- VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
-
- CAAdapterFreeEndpoint(ipData->remoteEndpoint);
- OICFree(ipData->data);
- OICFree(ipData);
-}
-
-void CADataDestroyer(void *data, uint32_t size)
-{
- CAIPData *etdata = (CAIPData *) data;
-
- CAFreeIPData(etdata);
-}
-