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 ******************************************************************/
24 * This file contains the APIs for EDR adapter.
27 #include "caedradapter.h"
29 #include "caedrinterface.h"
30 #include "caadapterutils.h"
32 #include "caqueueingthread.h"
33 #include "oic_malloc.h"
34 #include "caremotehandler.h"
38 * Logging tag for module name.
40 #define TAG "OIC_CA_EDR_ADAP"
43 * Reference to threadpool.
45 static ca_thread_pool_t g_edrThreadPool = NULL;
48 * Queue handle for Send Data
50 static CAQueueingThread_t *g_sendQueueHandle = NULL;
53 * Queue handle for Receive Data
55 static CAQueueingThread_t *g_recvQueueHandle = NULL;
58 * Storing Adapter state information
60 static bool g_adapterState = true;
63 * Maintains the callback to be notified on receival of network packets from other
66 static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
69 * Maintains the callback to be notified on local bluetooth adapter status change.
71 static CAAdapterChangeCallback g_adapterChangeCallback = NULL;
74 * error Callback to CA adapter
76 static CAErrorHandleCallback g_errorCallback = NULL;
79 * Information of local Bluetooth adapter.
81 static CAEndpoint_t *g_localConnectivity = NULL;
84 * Storing Rfcommserver state information
86 static bool g_serverState = false;
88 static CAResult_t CAStartServer();
89 static CAResult_t CAEDRInitializeQueueHandlers();
90 CAResult_t CAEDRInitializeSendHandler();
91 CAResult_t CAEDRInitializeReceiveHandler();
92 void CAAdapterTerminateQueues();
93 void CAAdapterDataSendHandler(void *context);
94 void CAAdapterDataReceiverHandler(void *context);
95 CAResult_t CAAdapterStopQueue();
96 void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
97 uint32_t *sentLength);
98 void CAEDRNotifyNetworkStatus(CANetworkStatus_t status);
99 void CAEDROnNetworkStatusChanged(void *context);
100 CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
101 const uint8_t *data, uint32_t dataLength, uint32_t *sentLength);
102 CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity, CANetworkStatus_t status);
103 CAResult_t CAEDRClientSendData(const char *remoteAddress, const uint8_t *data,
104 uint32_t dataLength);
107 * @fn CACreateEDRData
108 * @brief Helper function to create CAEDRData
110 static CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, const uint8_t *data,
111 uint32_t dataLength);
115 * @brief Free the Created EDR data
117 static void CAFreeEDRData(CAEDRData *edrData);
120 * @fn CAEDRFreeNetworkEvent
121 * @brief Free the memory associated with @event.
123 void CAEDRFreeNetworkEvent(CAEDRNetworkEvent *event);
125 static void CAEDRDataDestroyer(void *data, uint32_t size);
127 static void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
128 uint32_t dataLength, CAResult_t result);
130 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
131 CANetworkPacketReceivedCallback packetReceivedCallback,
132 CAAdapterChangeCallback netCallback,
133 CAConnectionChangeCallback connCallback,
134 CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
137 VERIFY_NON_NULL(registerCallback, TAG, "register callback is NULL");
138 VERIFY_NON_NULL(packetReceivedCallback, TAG, "data receive callback is NULL");
139 VERIFY_NON_NULL(netCallback, TAG, "adapter state change callback is NULL");
140 VERIFY_NON_NULL(connCallback, TAG, "connection state change callback is NULL");
141 VERIFY_NON_NULL(handle, TAG, "Thread pool handle is NULL");
143 // Register the callbacks
144 g_edrThreadPool = handle;
145 g_networkPacketReceivedCallback = packetReceivedCallback;
146 g_adapterChangeCallback = netCallback;
147 g_errorCallback = errorCallback;
149 // Initialize EDR Network Monitor
150 CAResult_t res = CAEDRInitializeNetworkMonitor(handle);
151 if (CA_STATUS_OK != res)
153 OIC_LOG_V(ERROR, TAG, "EDR N/w Monitor Initialize failed!, error number [%d]", res);
157 CAEDRSetNetworkChangeCallback(CAEDRNotifyNetworkStatus);
158 CAEDRSetPacketReceivedCallback(CAAdapterRecvData);
159 CAEDRSetErrorHandler(CAEDRErrorHandler);
160 res = CAEDRClientInitialize();
161 if (CA_STATUS_OK != res)
163 OIC_LOG_V(ERROR, TAG, "EDR Client Initialize failed, error number [%d]", res);
167 res = CAEDRServerInitialize(handle);
168 if (CA_STATUS_OK != res)
170 OIC_LOG_V(ERROR, TAG, "EDR Server Initialize failed, error number [%d]", res);
174 static const CAConnectivityHandler_t handler =
176 .startAdapter = CAStartEDR,
177 .stopAdapter = CAStopEDR,
178 .startListenServer = CAStartEDRListeningServer,
179 .stopListenServer = CAStopEDRListeningServer,
180 .startDiscoveryServer = CAStartEDRDiscoveryServer,
181 .sendData = CASendEDRUnicastData,
182 .sendDataToAll = CASendEDRMulticastData,
183 .GetnetInfo = CAGetEDRInterfaceInformation,
184 .readData = CAReadEDRData,
185 .terminate = CATerminateEDR,
186 .cType = CA_ADAPTER_RFCOMM_BTEDR
188 registerCallback(handler);
190 OIC_LOG(DEBUG, TAG, "OUT");
194 CAResult_t CAStartEDR()
196 //Start Monitoring EDR Network
197 CAResult_t ret = CAEDRStartNetworkMonitor();
198 if (CA_STATUS_OK != ret)
200 OIC_LOG(ERROR, TAG, "Failed to Start n/w monitor");
203 // Get Bluetooth adapter state
204 bool adapterState = false;
205 if (CA_STATUS_OK != CAEDRGetAdapterEnableState(&adapterState))
207 OIC_LOG(ERROR, TAG, "Failed to get adapter enable state");
208 return CA_STATUS_FAILED;
211 if (false == adapterState)
213 OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!");
214 g_adapterState = false;
215 return CA_ADAPTER_NOT_ENABLED;
218 if (CA_STATUS_OK != (ret = CAEDRClientSetCallbacks()))
220 OIC_LOG_V(ERROR, TAG, "Start Network Monitor failed!, error number [%d] ",
224 // Initialize Send/Receive data message queues
225 if (CA_STATUS_OK != (ret = CAEDRInitializeQueueHandlers()))
227 OIC_LOG_V(ERROR, TAG,
228 "CAAdapterInitializeQueues failed!, error number [%d] ", ret);
230 return CA_STATUS_FAILED;
233 // Start Send/Receive data message queues
234 if (CA_STATUS_OK != (ret = CAAdapterStartQueue()))
236 OIC_LOG_V(ERROR, TAG, "CAAdapterStartQueue failed!, error number [%d] ", ret);
242 CAResult_t CAStartEDRListeningServer()
244 return CAStartServer();
247 CAResult_t CAStopEDRListeningServer()
249 return CAEDRServerStop();
252 CAResult_t CAStartEDRDiscoveryServer()
255 // Start device discovery
256 CAResult_t result = CAEDRStartDeviceDiscovery();
257 if(CA_STATUS_OK != result)
259 OIC_LOG(DEBUG, TAG, "Failed to Start Device discovery");
263 return CAStartServer();
266 int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
267 uint32_t dataLength, CADataType_t dataType)
270 VERIFY_NON_NULL_RET(remoteEndpoint, TAG, "Remote endpoint is null", -1);
271 VERIFY_NON_NULL_RET(data, TAG, "Data is null", -1);
276 OIC_LOG(ERROR, TAG, "Invalid input: data length is zero!");
280 if (0 == strlen(remoteEndpoint->addr))
282 OIC_LOG(ERROR, TAG, "Invalid input: EDR Address is empty!");
286 uint32_t sentLength = 0;
287 const char *serviceUUID = OIC_EDR_SERVICE_ID;
288 const char *address = remoteEndpoint->addr;
289 CAResult_t err = CAAdapterSendData(address, serviceUUID, data, dataLength, &sentLength);
290 if (CA_STATUS_OK != err)
292 OIC_LOG_V(ERROR, TAG, "Send unicast data failed!, error num [%d]", err);
293 g_errorCallback(remoteEndpoint, data, dataLength, err);
300 int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength,
301 CADataType_t dataType)
303 OIC_LOG(DEBUG, TAG, "IN - CASendEDRMulticastData");
307 VERIFY_NON_NULL_RET(data, TAG, "Data is null", -1);
311 OIC_LOG(ERROR, TAG, "Invalid input: data length is zero!");
315 uint32_t sentLen = 0;
316 const char *serviceUUID = OIC_EDR_SERVICE_ID;
317 CAResult_t err = CAAdapterSendData(NULL, serviceUUID, data, dataLength, &sentLen);
318 if (CA_STATUS_OK != err)
320 OIC_LOG_V(ERROR, TAG, "Send multicast data failed!, error num [%d]", err);
321 g_errorCallback(endpoint, data, dataLength, err);
325 OIC_LOG(DEBUG, TAG, "OUT - CASendEDRMulticastData");
329 CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
331 VERIFY_NON_NULL(info, TAG, "LocalConnectivity info is null");
333 CAResult_t err = CA_STATUS_OK;
335 if (CA_STATUS_OK != (err = CAEDRGetInterfaceInformation(info)))
337 OIC_LOG_V(ERROR, TAG, "Failed to get local interface information!, error num [%d]", err);
345 CAResult_t CAReadEDRData()
347 return CAEDRManagerReadData();
350 CAResult_t CAStopEDR()
352 // Stop RFComm server if it is running
355 // Stop network monitor
356 CAEDRStopNetworkMonitor();
359 CAEDRClientUnsetCallbacks();
361 // Disconnect all the client connections
362 CAEDRClientDisconnectAll();
364 // Stop Send and receive Queue
365 CAAdapterStopQueue();
370 void CATerminateEDR()
372 // Terminate EDR Network Monitor
373 CAEDRTerminateNetworkMonitor();
375 // Terminate Send/Receive data messages queues
376 CAAdapterTerminateQueues();
378 g_networkPacketReceivedCallback = NULL;
379 g_adapterChangeCallback = NULL;
381 // Terminate thread pool
382 g_edrThreadPool = NULL;
384 // Terminate EDR Client
385 CAEDRClientTerminate();
387 // Terminate EDR Server
388 CAEDRServerTerminate();
390 // Free LocalConnectivity information
391 CAFreeEndpoint(g_localConnectivity);
392 g_localConnectivity = NULL;
395 CAResult_t CAStartServer()
397 if (false == g_adapterState)
399 OIC_LOG(DEBUG, TAG, "Bluetooth adapter is disabled!");
400 // Setting g_serverState for starting Rfcommserver when adapter starts
401 g_serverState = true;
405 CAResult_t err = CA_STATUS_OK;
406 if (CA_STATUS_OK != (err = CAEDRServerStart()))
408 OIC_LOG_V(ERROR, TAG, "Failed to start RFCOMM server!, error num [%d]",
416 CAResult_t CAEDRInitializeQueueHandlers()
418 if (CA_STATUS_OK == CAEDRInitializeSendHandler()
419 && CA_STATUS_OK == CAEDRInitializeReceiveHandler())
421 OIC_LOG(DEBUG, TAG, "Queue is initialized!");
425 return CA_STATUS_FAILED;
428 CAResult_t CAEDRInitializeSendHandler()
430 // Check if the message queue is already initialized
431 if (g_sendQueueHandle)
433 OIC_LOG(DEBUG, TAG, "Already queue is initialized!");
437 g_sendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
438 if (!g_sendQueueHandle)
440 OIC_LOG(ERROR, TAG, "Memory allocation failed!");
441 return CA_MEMORY_ALLOC_FAILED;
444 if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_edrThreadPool,
445 CAAdapterDataSendHandler, CAEDRDataDestroyer))
447 OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread");
448 return CA_STATUS_FAILED;
453 CAResult_t CAEDRInitializeReceiveHandler()
455 // Check if the message queue is already initialized
456 if (g_recvQueueHandle)
458 OIC_LOG(DEBUG, TAG, "Already queue is initialized!");
462 g_recvQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
463 if (!g_recvQueueHandle)
465 OIC_LOG(ERROR, TAG, "Memory allocation failed!");
466 return CA_MEMORY_ALLOC_FAILED;
470 if (CA_STATUS_OK != CAQueueingThreadInitialize(g_recvQueueHandle, g_edrThreadPool,
471 CAAdapterDataReceiverHandler,
474 OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread");
475 OICFree(g_recvQueueHandle);
476 g_recvQueueHandle = NULL;
477 return CA_STATUS_FAILED;
483 void CAAdapterTerminateQueues()
485 if (g_sendQueueHandle)
487 CAQueueingThreadDestroy(g_sendQueueHandle);
488 g_sendQueueHandle = NULL;
490 if (g_recvQueueHandle)
492 CAQueueingThreadDestroy(g_recvQueueHandle);
493 g_recvQueueHandle = NULL;
497 void CAAdapterDataSendHandler(void *context)
499 OIC_LOG(DEBUG, TAG, "IN - CAAdapterDataSendHandler");
501 CAEDRData *message = (CAEDRData *) context;
504 OIC_LOG(ERROR, TAG, "Failed to get message!");
508 if (!message->remoteEndpoint)
510 OIC_LOG(DEBUG, TAG, "remoteEndpoint is not available");
514 const char *remoteAddress = message->remoteEndpoint->addr;
517 OIC_LOG(ERROR, TAG, "EDR Send Message error");
518 //Error cannot be sent if remote address is NULL
522 CAResult_t result = CAEDRClientSendData(remoteAddress, message->data, message->dataLen);
523 if(CA_STATUS_OK != result)
525 OIC_LOG(ERROR, TAG, "CAEDRClientSendData API failed");
526 CAEDRErrorHandler(remoteAddress, message->data, message->dataLen, result);
530 OIC_LOG(DEBUG, TAG, "OUT");
533 CAResult_t CAEDRClientSendData(const char *remoteAddress, const uint8_t *data,
536 CAResult_t result = CA_SEND_FAILED;
538 // Send the first segment with the header.
539 if ((NULL != remoteAddress) && (0 < strlen(remoteAddress))) //Unicast data
541 result = CAEDRClientSendUnicastData(remoteAddress, data, dataLength);
542 if (CA_STATUS_OK != result)
544 OIC_LOG(ERROR, TAG, "Failed to send unicast data !");
550 OIC_LOG_V(DEBUG, TAG, "sending multicast data : %s", data);
551 result = CAEDRClientSendMulticastData(data, dataLength);
553 if (CA_STATUS_OK != result)
555 OIC_LOG(ERROR, TAG, "Failed to send multicast data !");
562 void CAAdapterDataReceiverHandler(void *context)
564 OIC_LOG(DEBUG, TAG, "IN_CAAdapterDataReceiverHandler");
566 if (NULL == g_networkPacketReceivedCallback)
568 OIC_LOG(ERROR, TAG, "g_networkPacketReceivedCallback is NULL");
572 CAEDRData *message = (CAEDRData *) context;
573 if (NULL == message || NULL == message->remoteEndpoint)
575 OIC_LOG(ERROR, TAG, "Failed to get message!");
579 CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
580 CA_ADAPTER_RFCOMM_BTEDR,
581 message->remoteEndpoint->addr,
586 OIC_LOG(ERROR, TAG, "remoteEndpoint is NULL");
590 OIC_LOG(DEBUG, TAG, "Sending data up !");
592 const CASecureEndpoint_t sep = { .endpoint = *remoteEndpoint };
594 g_networkPacketReceivedCallback(&sep, message->data, message->dataLen);
596 CAFreeEndpoint(remoteEndpoint);
598 OIC_LOG(DEBUG, TAG, "OUT_CAAdapterDataReceiverHandler");
601 CAResult_t CAAdapterStartQueue()
603 // Start send queue thread
604 if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
606 OIC_LOG(ERROR, TAG, "Failed to Start Send Data Thread");
607 CAEDRClientUnsetCallbacks();
608 //Disconnect all the client connections
609 CAEDRClientDisconnectAll();
610 return CA_STATUS_FAILED;
613 // Start receive queue thread
614 if (CA_STATUS_OK != CAQueueingThreadStart(g_recvQueueHandle))
616 OIC_LOG(ERROR, TAG, "Failed to Start Receive Data Thread");
617 CAEDRClientUnsetCallbacks();
618 //Disconnect all the client connections
619 CAEDRClientDisconnectAll();
620 return CA_STATUS_FAILED;
626 CAResult_t CAAdapterStopQueue()
628 //Stop send queue thread
629 CAQueueingThreadStop(g_sendQueueHandle);
631 //Stop receive queue thread
632 CAQueueingThreadStop(g_recvQueueHandle);
637 void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
638 uint32_t *sentLength)
640 if (false == g_adapterState)
642 OIC_LOG_V(ERROR, TAG, "Bluetooth adapter is disabled!");
648 VERIFY_NON_NULL_VOID(data, TAG, "Data is null");
649 VERIFY_NON_NULL_VOID(sentLength, TAG, "Sent data length holder is null");
651 // Create remote endpoint
652 CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
653 CA_ADAPTER_RFCOMM_BTEDR,
655 if (NULL == remoteEndpoint)
657 OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !");
661 // Add message to data queue
662 CAEDRData *edrData = CACreateEDRData(remoteEndpoint, data, dataLength);
663 CAQueueingThreadAddData(g_recvQueueHandle, edrData, sizeof(CAEDRData));
664 *sentLength = dataLength;
666 // Free remote endpoint
667 CAFreeEndpoint(remoteEndpoint);
670 void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
671 uint32_t dataLength, CAResult_t result)
674 VERIFY_NON_NULL_VOID(data, TAG, "Data is null");
676 // Create remote endpoint
677 CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(0, CA_ADAPTER_RFCOMM_BTEDR,
681 OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !");
685 g_errorCallback(remoteEndpoint, data, dataLength, result);
687 // Free remote endpoint
688 CAFreeEndpoint(remoteEndpoint);
691 CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const uint8_t *data,
692 uint32_t dataLength, uint32_t *sentLength)
694 OIC_LOG(DEBUG, TAG, "IN - CAAdapterSendData");
696 if (false == g_adapterState)
698 OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!");
700 return CA_ADAPTER_NOT_ENABLED;
703 VERIFY_NON_NULL(serviceUUID, TAG, "service UUID is null");
704 VERIFY_NON_NULL(data, TAG, "Data is null");
705 VERIFY_NON_NULL(sentLength, TAG, "Sent data length holder is null");
707 // Create remote endpoint
708 CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
709 CA_ADAPTER_RFCOMM_BTEDR,
711 if (NULL == remoteEndpoint)
713 OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !");
714 return CA_MEMORY_ALLOC_FAILED;
717 // Add message to data queue
718 CAEDRData *edrData = CACreateEDRData(remoteEndpoint, data, dataLength);
719 CAQueueingThreadAddData(g_sendQueueHandle, edrData, sizeof (CAEDRData));
720 *sentLength = dataLength;
722 // Free remote endpoint
723 CAFreeEndpoint(remoteEndpoint);
725 OIC_LOG(DEBUG, TAG, "OUT - CAAdapterSendData");
729 void CAEDRNotifyNetworkStatus(CANetworkStatus_t status)
731 // Create localconnectivity
732 if (NULL == g_localConnectivity)
734 CAEDRGetInterfaceInformation(&g_localConnectivity);
737 if (CA_INTERFACE_UP == status)
739 if (false == g_adapterState)
741 // Get Bluetooth adapter state
742 bool adapterState = false;
743 if (CA_STATUS_OK != CAEDRGetAdapterEnableState(&adapterState))
745 OIC_LOG(ERROR, TAG, "Failed to get adapter enable state");
749 if (false == adapterState)
751 OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!");
752 g_adapterState = false;
755 CAEDRClientSetCallbacks();
756 g_adapterState = true;
757 CAAdapterStartQueue();
758 // starting RFCommServer
759 if (true == g_serverState)
762 g_serverState = false;
768 g_adapterState = false;
771 // Notify to upper layer
772 if (g_adapterChangeCallback && g_localConnectivity && g_edrThreadPool)
774 // Add notification task to thread pool
775 CAEDRNetworkEvent *event = CAEDRCreateNetworkEvent(g_localConnectivity, status);
778 if (CA_STATUS_OK != ca_thread_pool_add_task(g_edrThreadPool,
779 CAEDROnNetworkStatusChanged,event))
781 OIC_LOG(ERROR, TAG, "Failed to create threadpool!");
788 void CAEDROnNetworkStatusChanged(void *context)
792 OIC_LOG(ERROR, TAG, "context is NULL!");
796 CAEDRNetworkEvent *networkEvent = (CAEDRNetworkEvent *) context;
798 // Notify to upper layer
799 if (g_adapterChangeCallback)
801 g_adapterChangeCallback(networkEvent->info->adapter, networkEvent->status);
804 // Free the created Network event
805 CAEDRFreeNetworkEvent(networkEvent);
808 CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity,
809 CANetworkStatus_t status)
811 VERIFY_NON_NULL_RET(connectivity, TAG, "connectivity is NULL", NULL);
813 // Create CAEDRNetworkEvent
814 CAEDRNetworkEvent *event = (CAEDRNetworkEvent *) OICMalloc(sizeof(CAEDRNetworkEvent));
817 OIC_LOG(ERROR, TAG, "Failed to allocate memory to network event!");
821 // Create duplicate of Local connectivity
822 event->info = CACloneEndpoint(connectivity);
823 event->status = status;
827 void CAEDRFreeNetworkEvent(CAEDRNetworkEvent *event)
831 CAFreeEndpoint(event->info);
836 CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint,
837 const uint8_t *data, uint32_t dataLength)
839 CAEDRData *edrData = (CAEDRData *) OICCalloc(1, sizeof(*edrData));
842 OIC_LOG(ERROR, TAG, "Memory allocation failed!");
846 edrData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
848 edrData->data = OICMalloc(dataLength);
849 if (NULL == edrData->data)
851 OIC_LOG(ERROR, TAG, "Memory allocation failed!");
852 CAFreeEDRData(edrData);
855 memcpy(edrData->data, data, dataLength);
856 edrData->dataLen = dataLength;
861 void CAFreeEDRData(CAEDRData *edrData)
863 VERIFY_NON_NULL_VOID(edrData, TAG, "edrData is NULL");
865 CAFreeEndpoint(edrData->remoteEndpoint);
866 OICFree(edrData->data);
870 void CAEDRDataDestroyer(void *data, uint32_t size)
872 if ((size_t)size < sizeof(CAEDRData))
874 OIC_LOG_V(ERROR, TAG, "Destroy data too small %p %d", data, size);
876 CAEDRData *edrdata = (CAEDRData *) data;
878 CAFreeEDRData(edrdata);