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"
40 * @brief Logging tag for module name
42 #define IP_ADAPTER_TAG "IP_ADAP"
46 * @brief Port to listen for incoming data
52 * @brief Secured (unicast) port number as defined in COAP Specification, RFC-7252.
54 #define CA_SECURE_PORT 5684
58 * @brief Multicast port number as defined in COAP Specification, RFC-7252.
60 #define CA_MCAST_PORT 5683
63 * @def CA_MULTICAST_IP
64 * @brief Multicast IP Address as defined in COAP Specification, RFC-7252.
66 #define CA_MULTICAST_IP "224.0.1.187"
70 * @brief Holds inter thread ip data information.
74 CARemoteEndpoint_t *remoteEndpoint;
80 * @var g_networkPacketCallback
81 * @brief Network Packet Received Callback to CA
83 static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
86 * @var g_networkChangeCallback
87 * @brief Network Changed Callback to CA
89 static CANetworkChangeCallback g_networkChangeCallback = NULL;
92 * @var g_sendQueueHandle
93 * @brief Queue handle for Send Data
95 static CAQueueingThread_t *g_sendQueueHandle = NULL;
99 * @brief ThreadPool for storing ca_thread_pool_t handle passed from CA
101 static ca_thread_pool_t g_threadPool = NULL;
103 static CAResult_t CAIPInitializeQueueHandles();
105 static void CAIPDeinitializeQueueHandles();
107 static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
108 CANetworkStatus_t status);
110 static void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status);
112 static void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port, const void *data,
113 uint32_t dataLength, bool isSecured);
115 static uint32_t CAIPPacketSendCB(const char *ipAddress, uint16_t port,
116 const void *data, uint32_t dataLength);
119 static CAResult_t CAIPStopServers();
121 static void CAIPSendDataThread(void *threadData);
123 static CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint,
124 const void *data, uint32_t dataLength);
125 void CAFreeIPData(CAIPData *ipData);
127 static void CADataDestroyer(void *data, uint32_t size);
129 CAResult_t CAIPInitializeQueueHandles()
131 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
133 // Check if the message queue is already initialized
134 if (g_sendQueueHandle)
136 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "send queue handle is already initialized!");
140 // Create send message queue
141 g_sendQueueHandle = OICMalloc(sizeof(CAQueueingThread_t));
142 if (!g_sendQueueHandle)
144 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
145 return CA_MEMORY_ALLOC_FAILED;
148 if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_threadPool,
149 CAIPSendDataThread, CADataDestroyer))
151 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize send queue thread");
152 OICFree(g_sendQueueHandle);
153 g_sendQueueHandle = NULL;
154 return CA_STATUS_FAILED;
157 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
161 void CAIPDeinitializeQueueHandles()
163 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
165 CAQueueingThreadDestroy(g_sendQueueHandle);
166 OICFree(g_sendQueueHandle);
167 g_sendQueueHandle = NULL;
169 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
172 void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
174 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
176 VERIFY_NON_NULL_VOID(address, IP_ADAPTER_TAG, "address is NULL");
178 CALocalConnectivity_t *localEndpoint = CAAdapterCreateLocalEndpoint(CA_IPV4, address);
181 OIC_LOG(ERROR, IP_ADAPTER_TAG, "localEndpoint creation failed!");
185 localEndpoint->addressInfo.IP.port = port;
187 if (g_networkChangeCallback)
189 g_networkChangeCallback(localEndpoint, status);
193 OIC_LOG(ERROR, IP_ADAPTER_TAG, "g_networkChangeCallback is NULL");
196 CAAdapterFreeLocalEndpoint(localEndpoint);
198 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
201 void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
203 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
205 VERIFY_NON_NULL_VOID(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL");
207 if (CA_INTERFACE_UP == status)
209 uint16_t port = CA_PORT;
210 CAResult_t ret = CAIPStartUnicastServer(ipAddress, &port, false, false);
211 if (CA_STATUS_OK == ret)
213 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port", port);
217 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start Unicast server port[%d]", ret);
221 port = CA_SECURE_PORT;
222 ret = CAIPStartUnicastServer(ipAddress, &port, false, true);
223 if (CA_STATUS_OK == ret)
225 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Secure Unicast server started on %d", port);
229 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start secure Unicast server [%d]",
233 ret = CAIPStartMulticastServer(ipAddress, CA_MULTICAST_IP, CA_MCAST_PORT);
234 if (CA_STATUS_OK == ret)
236 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Multicast server started on port[%d]",
241 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to start Multicast server port[%d]",
245 // Notify network change to CA
246 CAIPNotifyNetworkChange(ipAddress, port, status);
250 CAIPNotifyNetworkChange(ipAddress, 0, status);
252 // Stop Unicast, Secured unicast and Multicast servers
253 CAIPStopServer(ipAddress);
256 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
260 uint32_t CAIPPacketSendCB(const char *ipAddress, uint16_t port,
261 const void *data, uint32_t dataLength)
263 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
265 VERIFY_NON_NULL_RET(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL", 0);
267 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data is NULL", 0);
269 uint32_t sentLength = CAIPSendData(ipAddress, port, data, dataLength, false, true);
271 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Successfully sent %d of encrypted data!", sentLength);
273 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
279 void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port, const void *data,
280 uint32_t dataLength, bool isSecured)
282 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
284 VERIFY_NON_NULL_VOID(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL");
286 VERIFY_NON_NULL_VOID(data, IP_ADAPTER_TAG, "data is NULL");
288 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Address: %s, port:%d", ipAddress, port);
290 // CA is freeing this memory
291 CARemoteEndpoint_t *endPoint = CAAdapterCreateRemoteEndpoint(CA_IPV4, ipAddress, NULL );
294 OIC_LOG(ERROR, IP_ADAPTER_TAG, "EndPoint creation failed!");
297 endPoint->addressInfo.IP.port = port;
298 endPoint->isSecured = isSecured;
300 void *buf = OICCalloc(dataLength + 1, sizeof(char));
303 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory Allocation failed!");
304 CAAdapterFreeRemoteEndpoint(endPoint);
307 memcpy(buf, data, dataLength);
308 if (g_networkPacketCallback)
310 g_networkPacketCallback(endPoint, buf, dataLength);
315 CAAdapterFreeRemoteEndpoint(endPoint);
318 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
321 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
322 CANetworkPacketReceivedCallback networkPacketCallback,
323 CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
325 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
326 VERIFY_NON_NULL(registerCallback, IP_ADAPTER_TAG, "registerCallback");
327 VERIFY_NON_NULL(networkPacketCallback, IP_ADAPTER_TAG, "networkPacketCallback");
328 VERIFY_NON_NULL(netCallback, IP_ADAPTER_TAG, "netCallback");
329 VERIFY_NON_NULL(handle, IP_ADAPTER_TAG, "thread pool handle");
331 g_threadPool = handle;
332 g_networkChangeCallback = netCallback;
333 g_networkPacketCallback = networkPacketCallback;
335 CAResult_t ret = CAIPInitializeNetworkMonitor(g_threadPool);
336 if (CA_STATUS_OK != ret)
338 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor![%d]", ret);
341 CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
343 ret = CAIPInitializeServer(g_threadPool);
344 if (CA_STATUS_OK != ret)
346 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize server![%d]", ret);
351 CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
353 CAAdapterNetDtlsInit();
355 CADTLSSetAdapterCallbacks(CAIPPacketReceivedCB, CAIPPacketSendCB, DTLS_IP);
358 CAConnectivityHandler_t ipHandler;
359 ipHandler.startAdapter = CAStartIP;
360 ipHandler.startListenServer = CAStartIPListeningServer;
361 ipHandler.startDiscoveryServer = CAStartIPDiscoveryServer;
362 ipHandler.sendData = CASendIPUnicastData;
363 ipHandler.sendDataToAll = CASendIPMulticastData;
364 ipHandler.GetnetInfo = CAGetIPInterfaceInformation;
365 ipHandler.readData = CAReadIPData;
366 ipHandler.stopAdapter = CAStopIP;
367 ipHandler.terminate = CATerminateIP;
368 registerCallback(ipHandler, CA_IPV4);
370 if (CA_STATUS_OK != CAIPInitializeQueueHandles())
372 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize Queue Handle");
374 return CA_STATUS_FAILED;
377 OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT IntializeIP is Success");
381 CAResult_t CAStartIP()
383 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
385 // Start monitoring IP network
386 CAResult_t ret = CAIPStartNetworkMonitor();
387 if (CA_STATUS_OK != ret)
389 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start n/w monitor");
393 // Start send queue thread
394 if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
396 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start Send Data Thread");
397 return CA_STATUS_FAILED;
400 bool retVal = CAIPIsConnected();
403 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IP is not Connected");
407 u_arraylist_t *netInterfaceList = u_arraylist_create();
409 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
411 ret = CAIPGetInterfaceInfo(&netInterfaceList);
412 if (CA_STATUS_OK != ret)
414 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
415 CAClearNetInterfaceInfoList(netInterfaceList);
419 uint32_t listIndex = 0;
420 uint32_t listLength = u_arraylist_length(netInterfaceList);
421 for (listIndex = 0; listIndex < listLength; listIndex++)
423 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
428 uint16_t unicastPort = CA_PORT;
429 ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, false);
430 if (CA_STATUS_OK == ret)
432 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Unicast server started on %d port",
437 unicastPort = CA_SECURE_PORT;
438 ret = CAIPStartUnicastServer(netInfo->ipAddress, &unicastPort, false, true);
440 if (CA_STATUS_OK == ret)
442 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
443 "Secure Unicast server started on %d port", unicastPort);
447 CAClearNetInterfaceInfoList(netInterfaceList);
448 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
452 CAResult_t CAStartIPListeningServer()
454 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
456 bool retVal = CAIPIsConnected();
459 OIC_LOG(DEBUG, IP_ADAPTER_TAG,
460 "IP not Connected. Couldn't start multicast server");
464 u_arraylist_t *netInterfaceList = u_arraylist_create();
466 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
468 CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
469 if (CA_STATUS_OK != ret)
471 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
472 CAClearNetInterfaceInfoList(netInterfaceList);
476 uint32_t listIndex = 0;
477 uint32_t listLength = u_arraylist_length(netInterfaceList);
478 for (listIndex = 0; listIndex < listLength; listIndex++)
481 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
487 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Ip address for multicast interface %s",
489 ret = CAIPStartMulticastServer(netInfo->ipAddress, CA_MULTICAST_IP, CA_MCAST_PORT);
490 if (CA_STATUS_OK == ret)
492 OIC_LOG(INFO, IP_ADAPTER_TAG, "Multicast Server is Started Successfully");
496 CAClearNetInterfaceInfoList(netInterfaceList);
497 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
501 CAResult_t CAStartIPDiscoveryServer()
503 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
504 return CAStartIPListeningServer();
507 int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
510 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
512 VERIFY_NON_NULL_RET(remoteEndpoint, IP_ADAPTER_TAG, "remoteEndpoint", -1);
513 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
514 VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
518 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
522 // Create IPData to add to queue
523 CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength);
526 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
531 // Add message to send queue
532 CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
534 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
539 int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
541 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
543 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
544 VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
548 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
552 // Create IPData to add to queue
553 CAIPData *ipData = CACreateIPData(NULL, data, dataLength);
556 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
561 // Add message to send queue
562 CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
564 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
569 CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
571 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
573 VERIFY_NON_NULL(info, IP_ADAPTER_TAG, "info is NULL");
574 VERIFY_NON_NULL(size, IP_ADAPTER_TAG, "size is NULL");
576 bool retVal = CAIPIsConnected();
579 OIC_LOG(ERROR, IP_ADAPTER_TAG,
580 "Failed to get interface address, IP not Connected");
581 return CA_ADAPTER_NOT_ENABLED;
584 u_arraylist_t *netInterfaceList = u_arraylist_create();
586 VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
588 CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
589 if (CA_STATUS_OK != ret)
591 OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "CAIPGetInterfaceInfo failed:%d", ret);
592 CAClearNetInterfaceInfoList(netInterfaceList);
596 uint32_t listLength = u_arraylist_length(netInterfaceList);
597 uint32_t netInfoSize = listLength;
602 netInfoSize = listLength * 2;
606 CALocalConnectivity_t *conInfo = (CALocalConnectivity_t *) OICCalloc(
607 netInfoSize, sizeof(CALocalConnectivity_t));
610 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Malloc Failed");
611 CAClearNetInterfaceInfoList(netInterfaceList);
612 return CA_MEMORY_ALLOC_FAILED;
615 uint32_t listIndex = 0;
617 for (listIndex = 0; listIndex < listLength; listIndex++)
619 CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex);
625 conInfo[count].type = CA_IPV4;
626 conInfo[count].isSecured = false;
627 conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, false);
628 strncpy(conInfo[count].addressInfo.IP.ipAddress, netInfo->ipAddress,
629 strlen(netInfo->ipAddress));
632 // copy secure unicast server information
635 conInfo[count].type = CA_IPV4;
636 conInfo[count].isSecured = true;
637 conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, true);
638 strncpy(conInfo[count].addressInfo.IP.ipAddress, netInfo->ipAddress,
639 strlen(netInfo->ipAddress));
646 CAClearNetInterfaceInfoList(netInterfaceList);
648 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
652 CAResult_t CAReadIPData()
654 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
656 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
660 CAResult_t CAIPStopServers()
662 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
664 // Stop all unicast and multicast servers.
665 if (CA_STATUS_OK == CAIPStopAllServers())
667 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAIPStopAllServers success");
670 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
674 CAResult_t CAStopIP()
676 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
679 CAAdapterNetDtlsDeInit();
682 // Stop IP network monitor
683 CAIPStopNetworkMonitor();
685 // Stop send queue thread
686 if (g_sendQueueHandle)
688 CAQueueingThreadStop(g_sendQueueHandle);
691 // Stop Unicast, Secured unicast and Multicast servers running
694 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
700 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
706 CADTLSSetAdapterCallbacks(NULL, NULL, DTLS_IP);
709 CAIPSetPacketReceiveCallback(NULL);
711 // Terminate IP server
712 CAIPTerminateServer();
714 // Terminate network monitor
715 CAIPSetConnectionStateChangeCallback(NULL);
716 CAIPTerminateNetworkMonitor();
718 // Terminate message queue handler
719 CAIPDeinitializeQueueHandles();
721 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
724 void CAIPSendDataThread(void *threadData)
726 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
728 CAIPData *ipData = (CAIPData *) threadData;
731 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
735 //If remoteEndpoint is NULL, its Multicast, else its Unicast.
736 if (ipData->remoteEndpoint)
738 //Processing for sending unicast
739 char *address = ipData->remoteEndpoint->addressInfo.IP.ipAddress;
740 uint16_t port = ipData->remoteEndpoint->addressInfo.IP.port;
743 if (!ipData->remoteEndpoint->isSecured)
745 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
746 CAIPSendData(address, port, ipData->data, ipData->dataLen, false,
747 ipData->remoteEndpoint->isSecured);
751 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
752 uint8_t cacheFlag = 0;
753 CAResult_t result = CAAdapterNetDtlsEncrypt(address, port, ipData->data,
754 ipData->dataLen, &cacheFlag,
757 if (CA_STATUS_OK != result)
759 OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
761 OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
762 "CAAdapterNetDtlsEncrypt returned with cache[%d]", cacheFlag);
765 CAIPSendData(address, port, ipData->data, ipData->dataLen, false,
766 ipData->remoteEndpoint->isSecured);
771 //Processing for sending multicast
772 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
773 CAIPSendData(CA_MULTICAST_IP, CA_MCAST_PORT, ipData->data,
774 ipData->dataLen, true, false);
777 OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
780 CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
783 VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
785 CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
788 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
792 ipData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
793 ipData->data = (void *) OICMalloc(dataLength);
796 OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
797 CAFreeIPData(ipData);
801 memcpy(ipData->data, data, dataLength);
802 ipData->dataLen = dataLength;
807 void CAFreeIPData(CAIPData *ipData)
809 VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
811 CAAdapterFreeRemoteEndpoint(ipData->remoteEndpoint);
812 OICFree(ipData->data);
816 void CADataDestroyer(void *data, uint32_t size)
818 CAIPData *etdata = (CAIPData *) data;
820 CAFreeIPData(etdata);