1 /******************************************************************
3 * Copyright 2014 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 ******************************************************************/
20 #include "caipadapter.h"
27 #include "caipinterface.h"
28 #include "caqueueingthread.h"
29 #include "caadapterutils.h"
31 #include "caadapternetdtls.h"
34 #include "uarraylist.h"
36 #include "oic_malloc.h"
37 #include "oic_string.h"
41 * @brief Logging tag for module name
43 #define IP_ADAPTER_TAG "IP_ADAP"
47 * @brief Port to listen for incoming data
53 * @brief Secured (unicast) port number as defined in COAP Specification, RFC-7252.
55 #define CA_SECURE_PORT 5684
59 * @brief Multicast port number as defined in COAP Specification, RFC-7252.
61 #define CA_MCAST_PORT 5683
64 * @def CA_MULTICAST_IP
65 * @brief Multicast IP Address as defined in COAP Specification, RFC-7252.
67 #define CA_MULTICAST_IP "224.0.1.187"
71 * @brief Holds inter thread ip data information.
75 CAEndpoint_t *remoteEndpoint;
82 * @var g_networkPacketCallback
83 * @brief Network Packet Received Callback to CA
85 static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
88 * @var g_networkChangeCallback
89 * @brief Network Changed Callback to CA
91 static CANetworkChangeCallback g_networkChangeCallback = NULL;
94 * @var g_sendQueueHandle
95 * @brief Queue handle for Send Data
97 static CAQueueingThread_t *g_sendQueueHandle = NULL;
101 * @brief ThreadPool for storing ca_thread_pool_t handle passed from CA
103 static ca_thread_pool_t g_threadPool = NULL;
105 static CAResult_t CAIPInitializeQueueHandles();
107 static void CAIPDeinitializeQueueHandles();
109 static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
110 CANetworkStatus_t status);
112 static void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status);
114 static void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint,
115 const void *data, uint32_t dataLength);
117 static uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint,
118 const void *data, uint32_t dataLength);
121 static CAResult_t CAIPStopServers();
123 static void CAIPSendDataThread(void *threadData);
125 static CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
126 const void *data, uint32_t dataLength,
128 void CAFreeIPData(CAIPData *ipData);
130 static void CADataDestroyer(void *data, uint32_t size);
132 CAResult_t CAIPInitializeQueueHandles()
134 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
136 // Check if the message queue is already initialized
137 if (g_sendQueueHandle)
139 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "send queue handle is already initialized!");
143 // Create send message queue
144 g_sendQueueHandle = OICMalloc(sizeof(CAQueueingThread_t));
145 if (!g_sendQueueHandle)
147 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
148 return CA_MEMORY_ALLOC_FAILED;
151 if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_threadPool,
152 CAIPSendDataThread, CADataDestroyer))
154 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize send queue thread");
155 OICFree(g_sendQueueHandle);
156 g_sendQueueHandle = NULL;
157 return CA_STATUS_FAILED;
160 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
164 void CAIPDeinitializeQueueHandles()
166 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
168 CAQueueingThreadDestroy(g_sendQueueHandle);
169 OICFree(g_sendQueueHandle);
170 g_sendQueueHandle = NULL;
172 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
175 void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
177 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
179 VERIFY_NON_NULL_VOID(address, IP_ADAPTER_TAG, "address is NULL");
181 CAEndpoint_t *localEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_IP, address, port);
184 OIC_LOG(ERROR, IP_ADAPTER_TAG, "localEndpoint creation failed!");
188 if (g_networkChangeCallback)
190 g_networkChangeCallback(localEndpoint, status);
194 OIC_LOG(ERROR, IP_ADAPTER_TAG, "g_networkChangeCallback is NULL");
197 CAAdapterFreeEndpoint(localEndpoint);
199 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
202 void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
204 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
206 VERIFY_NON_NULL_VOID(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL");
208 if (CA_INTERFACE_UP == status)
210 uint16_t port = CA_PORT;
211 CAResult_t ret = CAIPStartUnicastServer(ipAddress, &port, false, false);
212 if (CA_STATUS_OK == ret)
214 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port", port);
218 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start Unicast server port[%d]", ret);
222 port = CA_SECURE_PORT;
223 ret = CAIPStartUnicastServer(ipAddress, &port, false, true);
224 if (CA_STATUS_OK == ret)
226 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Secure Unicast server started on %d", port);
230 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start secure Unicast server [%d]",
234 ret = CAIPStartMulticastServer(ipAddress, CA_MULTICAST_IP, CA_MCAST_PORT);
235 if (CA_STATUS_OK == ret)
237 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Multicast server started on port[%d]",
242 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start Multicast server port[%d]",
246 // Notify network change to CA
247 CAIPNotifyNetworkChange(ipAddress, port, status);
251 CAIPNotifyNetworkChange(ipAddress, 0, status);
253 // Stop Unicast, Secured unicast and Multicast servers
254 CAIPStopServer(ipAddress);
257 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
261 uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
263 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
265 VERIFY_NON_NULL_RET(endpoint, IP_ADAPTER_TAG, "endpoint is NULL", 0);
266 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data is NULL", 0);
268 uint32_t sentLength = CAIPSendData(endpoint, data, dataLength, false);
270 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Successfully sent %d of encrypted data!", sentLength);
272 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
278 void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
281 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
283 VERIFY_NON_NULL_VOID(endpoint, IP_ADAPTER_TAG, "ipAddress is NULL");
284 VERIFY_NON_NULL_VOID(data, IP_ADAPTER_TAG, "data is NULL");
286 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port);
288 void *buf = OICCalloc(dataLength + 1, sizeof (char));
291 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory Allocation failed!");
294 memcpy(buf, data, dataLength);
296 if (g_networkPacketCallback)
298 g_networkPacketCallback(endpoint, buf, dataLength);
305 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
308 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
309 CANetworkPacketReceivedCallback networkPacketCallback,
310 CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
312 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
313 VERIFY_NON_NULL(registerCallback, IP_ADAPTER_TAG, "registerCallback");
314 VERIFY_NON_NULL(networkPacketCallback, IP_ADAPTER_TAG, "networkPacketCallback");
315 VERIFY_NON_NULL(netCallback, IP_ADAPTER_TAG, "netCallback");
316 VERIFY_NON_NULL(handle, IP_ADAPTER_TAG, "thread pool handle");
318 g_threadPool = handle;
319 g_networkChangeCallback = netCallback;
320 g_networkPacketCallback = networkPacketCallback;
322 CAResult_t ret = CAIPInitializeNetworkMonitor(g_threadPool);
323 if (CA_STATUS_OK != ret)
325 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor![%d]", ret);
328 CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
330 ret = CAIPInitializeServer(g_threadPool);
331 if (CA_STATUS_OK != ret)
333 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize server![%d]", ret);
338 CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
340 CAAdapterNetDtlsInit();
342 CADTLSSetAdapterCallbacks(CAIPPacketReceivedCB, CAIPPacketSendCB, 0);
345 CAConnectivityHandler_t ipHandler;
346 ipHandler.startAdapter = CAStartIP;
347 ipHandler.startListenServer = CAStartIPListeningServer;
348 ipHandler.startDiscoveryServer = CAStartIPDiscoveryServer;
349 ipHandler.sendData = CASendIPUnicastData;
350 ipHandler.sendDataToAll = CASendIPMulticastData;
351 ipHandler.GetnetInfo = CAGetIPInterfaceInformation;
352 ipHandler.readData = CAReadIPData;
353 ipHandler.stopAdapter = CAStopIP;
354 ipHandler.terminate = CATerminateIP;
355 registerCallback(ipHandler, CA_ADAPTER_IP);
357 if (CA_STATUS_OK != CAIPInitializeQueueHandles())
359 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize Queue Handle");
361 return CA_STATUS_FAILED;
364 OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT IntializeIP is Success");
368 CAResult_t CAStartIP()
370 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
372 // Start monitoring IP network
373 CAResult_t ret = CAIPStartNetworkMonitor();
374 if (CA_STATUS_OK != ret)
376 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start n/w monitor");
380 // Start send queue thread
381 if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
383 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start Send Data Thread");
384 return CA_STATUS_FAILED;
387 bool retVal = CAIPIsConnected();
390 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IP is not Connected");
394 u_arraylist_t *netInterfaceList = u_arraylist_create();
396 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
398 ret = CAIPGetInterfaceInfo(&netInterfaceList);
399 if (CA_STATUS_OK != ret)
401 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
402 CAClearNetInterfaceInfoList(netInterfaceList);
406 uint32_t listIndex = 0;
407 uint32_t listLength = u_arraylist_length(netInterfaceList);
408 for (listIndex = 0; listIndex < listLength; listIndex++)
410 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
415 uint16_t unicastPort = CA_PORT;
416 ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, false);
417 if (CA_STATUS_OK == ret)
419 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port",
424 unicastPort = CA_SECURE_PORT;
425 ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, true);
427 if (CA_STATUS_OK == ret)
429 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
430 "Secure Unicast server started on %d port", unicastPort);
434 CAClearNetInterfaceInfoList(netInterfaceList);
435 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
439 CAResult_t CAStartIPListeningServer()
441 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
443 bool retVal = CAIPIsConnected();
446 OIC_LOG(DEBUG, IP_ADAPTER_TAG,
447 "IP not Connected. Couldn't start multicast server");
451 u_arraylist_t *netInterfaceList = u_arraylist_create();
453 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
455 CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
456 if (CA_STATUS_OK != ret)
458 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
459 CAClearNetInterfaceInfoList(netInterfaceList);
463 uint32_t listIndex = 0;
464 uint32_t listLength = u_arraylist_length(netInterfaceList);
465 for (listIndex = 0; listIndex < listLength; listIndex++)
468 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
474 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Ip address for multicast interface %s",
476 ret = CAIPStartMulticastServer(netInfo->ipAddress, CA_MULTICAST_IP, CA_MCAST_PORT);
477 if (CA_STATUS_OK == ret)
479 OIC_LOG(INFO, IP_ADAPTER_TAG, "Multicast Server is Started Successfully");
483 CAClearNetInterfaceInfoList(netInterfaceList);
484 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
488 CAResult_t CAStartIPDiscoveryServer()
490 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
491 return CAStartIPListeningServer();
494 int32_t CASendIPUnicastData(const CAEndpoint_t *remoteEndpoint,
495 const void *data, uint32_t dataLength)
497 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
499 VERIFY_NON_NULL_RET(remoteEndpoint, IP_ADAPTER_TAG, "remoteEndpoint", -1);
500 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
501 VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
505 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
509 // Create IPData to add to queue
510 CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, false);
513 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
518 // Add message to send queue
519 CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
521 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
526 int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
528 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
530 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
531 VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
535 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
539 // Create IPData to add to queue
540 CAIPData *ipData = CACreateIPData(endpoint, data, dataLength, true);
543 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
548 // Add message to send queue
549 CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
551 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
556 CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
558 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
560 VERIFY_NON_NULL(info, IP_ADAPTER_TAG, "info is NULL");
561 VERIFY_NON_NULL(size, IP_ADAPTER_TAG, "size is NULL");
563 bool retVal = CAIPIsConnected();
566 OIC_LOG(ERROR, IP_ADAPTER_TAG,
567 "Failed to get interface address, IP not Connected");
568 return CA_ADAPTER_NOT_ENABLED;
571 u_arraylist_t *netInterfaceList = u_arraylist_create();
573 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
575 CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
576 if (CA_STATUS_OK != ret)
578 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "CAIPGetInterfaceInfo failed:%d", ret);
579 CAClearNetInterfaceInfoList(netInterfaceList);
583 uint32_t listLength = u_arraylist_length(netInterfaceList);
584 uint32_t netInfoSize = listLength;
589 netInfoSize = listLength * 2;
593 CAEndpoint_t *conInfo = (CAEndpoint_t *)OICCalloc(netInfoSize, sizeof (CAEndpoint_t));
596 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Malloc Failed");
597 CAClearNetInterfaceInfoList(netInterfaceList);
598 return CA_MEMORY_ALLOC_FAILED;
601 uint32_t listIndex = 0;
603 for (listIndex = 0; listIndex < listLength; listIndex++)
605 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
611 conInfo[count].adapter = CA_ADAPTER_IP;
612 conInfo[count].flags = 0;
613 conInfo[count].port = CAGetServerPortNum(netInfo->ipAddress, false);
614 OICStrcpy(conInfo[count].addr,
615 sizeof(conInfo[count].addr),
619 // copy secure unicast server information
622 conInfo[count].adapter = CA_ADAPTER_IP;
623 conInfo[count].flags = CA_SECURE;
624 conInfo[count].port = CAGetServerPortNum(netInfo->ipAddress, true);
625 OICStrcpy(conInfo[count].addr,
626 sizeof(conInfo[count].addr),
634 CAClearNetInterfaceInfoList(netInterfaceList);
636 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
640 CAResult_t CAReadIPData()
642 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
644 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
648 CAResult_t CAIPStopServers()
650 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
652 // Stop all unicast and multicast servers.
653 if (CA_STATUS_OK == CAIPStopAllServers())
655 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAIPStopAllServers success");
658 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
662 CAResult_t CAStopIP()
664 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
667 CAAdapterNetDtlsDeInit();
670 // Stop IP network monitor
671 CAIPStopNetworkMonitor();
673 // Stop send queue thread
674 if (g_sendQueueHandle)
676 CAQueueingThreadStop(g_sendQueueHandle);
679 // Stop Unicast, Secured unicast and Multicast servers running
682 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
688 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
694 CADTLSSetAdapterCallbacks(NULL, NULL, 0);
697 CAIPSetPacketReceiveCallback(NULL);
699 // Terminate IP server
700 CAIPTerminateServer();
702 // Terminate network monitor
703 CAIPSetConnectionStateChangeCallback(NULL);
704 CAIPTerminateNetworkMonitor();
706 // Terminate message queue handler
707 CAIPDeinitializeQueueHandles();
709 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
712 void CAIPSendDataThread(void *threadData)
714 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
716 CAIPData *ipData = (CAIPData *) threadData;
719 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
723 if (ipData->isMulticast)
725 //Processing for sending multicast
726 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
727 strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
728 ipData->remoteEndpoint->port = CA_MCAST_PORT;
729 CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
733 //Processing for sending unicast
735 if (ipData->remoteEndpoint->flags & CA_SECURE)
737 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
738 CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
739 ipData->data, ipData->dataLen);
740 if (CA_STATUS_OK != result)
742 OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
744 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
745 "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
749 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
750 CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
753 CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
757 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
760 CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
761 uint32_t dataLength, bool isMulticast)
763 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
765 CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
768 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
772 ipData->remoteEndpoint = CAAdapterCloneEndpoint(remoteEndpoint);
773 ipData->data = (void *) OICMalloc(dataLength);
776 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
777 CAFreeIPData(ipData);
781 memcpy(ipData->data, data, dataLength);
782 ipData->dataLen = dataLength;
784 ipData->isMulticast = isMulticast;
789 void CAFreeIPData(CAIPData *ipData)
791 VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
793 CAAdapterFreeEndpoint(ipData->remoteEndpoint);
794 OICFree(ipData->data);
798 void CADataDestroyer(void *data, uint32_t size)
800 CAIPData *etdata = (CAIPData *) data;
802 CAFreeIPData(etdata);