Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / caleadapter.c
index afd362e..571a890 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* ****************************************************************
  *
  * Copyright 2014 Samsung Electronics All Rights Reserved.
  *
 #include "caremotehandler.h"
 
 /**
- * @var CALEADAPTER_TAG
- * @brief Logging tag for module name.
+ * Logging tag for module name.
  */
 #define CALEADAPTER_TAG "LAD"
 
+
 /**
- * @var g_networkCallback
- * @brief Callback to provide the status of the network change to CA layer.
+ * Stores the information of the Data to be sent from the queues.
+ *
+ * This structure will be pushed to the sender/receiver queue for
+ * processing.
+ */
+typedef struct
+{
+    /// Remote endpoint contains the information of remote device.
+    CAEndpoint_t *remoteEndpoint;
+
+    /// Data to be transmitted over LE transport.
+    uint8_t *data;
+
+    /// Length of the data being transmitted.
+    uint32_t dataLen;
+} CALEData_t;
+
+/**
+ * Stores information of all the senders.
+ *
+ * This structure will be used to track and defragment all incoming
+ * data packet.
+ */
+typedef struct
+{
+    uint32_t recvDataLen;
+    uint32_t totalDataLen;
+    uint8_t *defragData;
+    CAEndpoint_t *remoteEndpoint;
+ } CABLESenderInfo_t;
+
+/**
+ * Callback to provide the status of the network change to CA layer.
  */
 static CANetworkChangeCallback g_networkCallback = NULL;
 
 /**
- * @var g_localBLEAddress
- * @brief bleAddress of the local adapter. Value will be initialized to zero, and will
- *        be updated later.
+ * bleAddress of the local adapter. Value will be initialized to zero,
+ * and will be updated later.
  */
-static char g_localBLEAddress[18] = {0};
+static char g_localBLEAddress[18] = { 0 };
 
 /**
- * @var g_isServer
- * @brief Variable to differentiate btw GattServer and GattClient.
+ * Variable to differentiate btw GattServer and GattClient.
  */
 static bool g_isServer = false;
 
 /**
- * @var g_bleIsServerMutex
- * @brief Mutex to synchronize the task to be executed on the GattServer function calls.
+ * Mutex to synchronize the task to be executed on the GattServer
+ * function calls.
  */
 static ca_mutex g_bleIsServerMutex = NULL;
 
 /**
- * @var g_bleNetworkCbMutex
- * @brief Mutex to synchronize the callback to be called for the network changes.
+ * Mutex to synchronize the callback to be called for the network
+ * changes.
  */
 static ca_mutex g_bleNetworkCbMutex = NULL;
 
 /**
- * @var g_bleLocalAddressMutex
- * @brief Mutex to synchronize the updation of the local LE address of the adapter.
+ * Mutex to synchronize the updates of the local LE address of the
+ * adapter.
  */
 static ca_mutex g_bleLocalAddressMutex = NULL;
 
 /**
- * @var g_bleAdapterThreadPool
- * @brief reference to threadpool
+ * Reference to thread pool.
  */
 static ca_thread_pool_t g_bleAdapterThreadPool = NULL;
 
 /**
- * @var g_bleAdapterThreadPoolMutex
- * @brief Mutex to synchronize the task to be pushed to thread pool.
+ * Mutex to synchronize the task to be pushed to thread pool.
  */
 static ca_mutex g_bleAdapterThreadPoolMutex = NULL;
 
 /**
- * @var g_bleClientSendDataMutex
- * @brief Mutex to synchronize the queing of the data from SenderQueue.
+ * Mutex to synchronize the queing of the data from SenderQueue.
  */
 static ca_mutex g_bleClientSendDataMutex = NULL;
 
 /**
- * @var g_bleClientReceiveDataMutex
- * @brief Mutex to synchronize the queing of the data from ReceiverQueue.
+ * Mutex to synchronize the queing of the data from ReceiverQueue.
  */
-static ca_mutex g_bleClientReceiveDataMutex = NULL;
+static ca_mutex g_bleReceiveDataMutex = NULL;
 
 
 /**
- * @var g_bleServerSendDataMutex
- * @brief Mutex to synchronize the queing of the data from SenderQueue.
+ * Mutex to synchronize the queing of the data from SenderQueue.
  */
 static ca_mutex g_bleServerSendDataMutex = NULL;
 
 /**
- * @var g_bleServerReceiveDataMutex
- * @brief Mutex to synchronize the queing of the data from ReceiverQueue.
- */
-static ca_mutex g_bleServerReceiveDataMutex = NULL;
-
-/**
- * @var g_bleAdapterReqRespCbMutex
- * @brief Mutex to synchronize the callback to be called for the adapterReqResponse.
+ * Mutex to synchronize the callback to be called for the
+ * adapterReqResponse.
  */
 static ca_mutex g_bleAdapterReqRespCbMutex = NULL;
 
 /**
- * @var g_networkPacketReceivedCallback
- * @brief Callback to be called when network packet recieved from either GattServer or GattClient.
+ * Callback to be called when network packet received from either
+ * GattServer or GattClient.
  */
 static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
 
 /**
- * @var g_errorHandler
- * @brief Callback to notify error from the BLE adapter
+ * Callback to notify error from the BLE adapter.
  */
 static CAErrorHandleCallback g_errorHandler = NULL;
 
 /**
- * @var g_bleAdapterState
- * @brief Storing Adapter state information
+ * Storing Adapter state information.
  */
 static CAAdapterState_t g_bleAdapterState = CA_ADAPTER_DISABLED;
 
 /**
- * @ENUM CALeServerStatus
- * @brief status of BLE Server Status
- *  This ENUM provides information of LE Adapter Server status
+ * BLE Server Status.
+ *
+ * This enumeration provides information of LE Adapter Server status.
  */
 typedef enum
 {
@@ -151,139 +167,246 @@ typedef enum
 } CALeServerStatus;
 
 /**
- * @var gLeServerStatus
- * @brief structure to maintain the status of the server.
+ * Structure to maintain the status of the server.
  */
 static CALeServerStatus gLeServerStatus = CA_SERVER_NOTSTARTED;
 
 /**
-* @fn  CALERegisterNetworkNotifications
-* @brief  This function is used to register network change notification callback.
-*
-* @param[in]  netCallback CANetworkChangeCallback callback which will be set for the change in nwk.
-*
-* @return  0 on success otherwise a positive error value.
-* @retval  CA_STATUS_OK  Successful
-* @retval  CA_STATUS_INVALID_PARAM  Invalid input argumets
-* @retval  CA_STATUS_FAILED Operation failed
-*
-*/
-CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
+ * Register network change notification callback.
+ *
+ * @param[in]  netCallback CANetworkChangeCallback callback which will
+ *                         be set for the change in network.
+ *
+ * @return  0 on success otherwise a positive error value.
+ * @retval  ::CA_STATUS_OK  Successful.
+ * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval  ::CA_STATUS_FAILED Operation failed.
+ *
+ */
+static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
 
 /**
-* @fn  CASetBleAdapterThreadPoolHandle
-* @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
-*
-* @param[in] handle - Thread pool handle which is given by above layer for using thread
-*                     creation task.
-*
-* @return  void
-*
-*/
-void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle);
+ * Set the thread pool handle which is required for spawning new
+ * thread.
+ *
+ * @param[in] handle Thread pool handle which is given by above layer
+ *                   for using thread creation task.
+ *
+ */
+static void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
-* @fn  CALEDeviceStateChangedCb
-* @brief  This function is used to call the callback to the upper layer when the device state gets
-*         changed.
-*
-* @param[in]  adapter_state New state of the adapter to be notified to the upper layer.
-*
-* @return  None.
-*
-*/
-void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state);
+ * Call the callback to the upper layer when the device state gets
+ * changed.
+ *
+ * @param[in] adapter_state New state of the adapter to be notified to
+ *                          the upper layer.
+ */
+static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state);
 
 /**
-* @fn  CAInitBleAdapterMutex
-* @brief  Used to initialize all required mutex variable for LE Adapter implementation.
-*
-* @return  0 on success otherwise a positive error value.
-* @retval  CA_STATUS_OK  Successful
-* @retval  CA_STATUS_INVALID_PARAM  Invalid input argumets
-* @retval  CA_STATUS_FAILED Operation failed
-*
-*/
-CAResult_t CAInitLEAdapterMutex();
+ * Used to initialize all required mutex variable for LE Adapter
+ * implementation.
+ *
+ * @return  0 on success otherwise a positive error value.
+ * @retval  ::CA_STATUS_OK  Successful.
+ * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval  ::CA_STATUS_FAILED Operation failed.
+ *
+ */
+static CAResult_t CAInitLEAdapterMutex();
 
 /**
-* @fn  CATerminateBleAdapterMutex
-* @brief  Used to terminate all required mutex variable for LE adapter implementation.
-*
-* @return  void
-*/
-void CATerminateLEAdapterMutex();
+ * Terminate all required mutex variables for LE adapter
+ * implementation.
+ */
+static void CATerminateLEAdapterMutex();
 
 /**
-* @fn  CALEErrorHandler
-* @brief  prepares and notify error through error callback
-*
-* @return  void
-*/
-static void CALEErrorHandler(const char *remoteAddress, const void *data, uint32_t dataLen,
+ * Prepares and notify error through error callback.
+ */
+static void CALEErrorHandler(const char *remoteAddress,
+                             const uint8_t *data,
+                             uint32_t dataLen,
                              CAResult_t result);
 
 #ifndef SINGLE_THREAD
 /**
- * @var g_dataReceiverHandlerState
- * @brief Stop condition of recvhandler.
+ * Stop condition of recvhandler.
  */
 static bool g_dataReceiverHandlerState = false;
 
 /**
- * @var g_bleClientSendQueueHandle
- * @brief Queue to process the outgoing packets from GATTClient.
+ * Sender information.
+ */
+static u_arraylist_t *g_senderInfo = NULL;
+
+/**
+ * Queue to process the outgoing packets from GATTClient.
  */
 static CAQueueingThread_t *g_bleClientSendQueueHandle = NULL;
 
 /**
- * @var g_bleClientReceiverQueue
- * @brief Queue to process the incoming packets to GATT Client.
+ * Queue to process the incoming packets to GATT Client.
  */
-static CAQueueingThread_t *g_bleClientReceiverQueue = NULL;
+static CAQueueingThread_t *g_bleReceiverQueue = NULL;
 
 /**
- * @var g_bleServerSendQueueHandle
- * @brief Queue to process the outgoing packets from GATTServer.
+ * Queue to process the outgoing packets from GATTServer.
  */
 static CAQueueingThread_t *g_bleServerSendQueueHandle = NULL;
 
 /**
- * @var g_bleServerReceiverQueue
- * @brief Queue to process the incoming packets to GATTServer
+ * This function will be associated with the sender queue for
+ * GattServer.
+ *
+ * This function will fragment the data to the MTU of the transport
+ * and send the data in fragments to the adapters. The function will
+ * be blocked until all data is sent out from the adapter.
+ *
+ * @param[in] threadData Data pushed to the queue which contains the
+ *                       info about RemoteEndpoint and Data.
  */
-static CAQueueingThread_t *g_bleServerReceiverQueue = NULL;
+static void CALEServerSendDataThread(void *threadData);
 
 /**
-* @fn  CALEDataDestroyer
-* @brief  Used to free data
-*
-* @return  void
-*/
-static void CALEDataDestroyer(void *data, uint32_t size);
+ * This function will be associated with the sender queue for
+ * GattClient.
+ *
+ * This function will fragment the data to the MTU of the transport
+ * and send the data in fragments to the adapters. The function will
+ * be blocked until all data is sent out from the adapter.
+ *
+ * @param[in] threadData Data pushed to the queue which contains the
+ *                       info about RemoteEndpoint and Data.
+ */
+static void CALEClientSendDataThread(void *threadData);
 
-void CAInitLEQueues()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+/**
+ * This function will be associated with the receiver queue.
+ *
+ * This function will defragment the received data from each sender
+ * respectively and will send it up to CA layer.  Respective sender's
+ * header will provide the length of the data sent.
+ *
+ * @param[in] threadData Data pushed to the queue which contains the
+ *                       info about RemoteEndpoint and Data.
+ */
+static void CALEDataReceiverHandler(void *threadData);
 
-    CAResult_t result = CAInitLEServerQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerQueues failed");
-        return;
-    }
+/**
+ * This function will stop all queues created for GattServer and
+ * GattClient. All four queues will be be stopped with this function
+ * invocations.
+ */
+static void CAStopLEQueues();
 
-    result = CAInitLEClientQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return;
-    }
+/**
+ * This function will terminate all queues created for GattServer and
+ * GattClient. All four queues will be be terminated with this
+ * function invocations.
+ */
+static void CATerminateLEQueues();
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-}
+/**
+ * This function will initalize the Receiver and Sender queues for
+ * GattServer. This function will in turn call the functions
+ * CAInitBleServerReceiverQueue() and CAInitBleServerSenderQueue() to
+ * initialize the queues.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CAInitLEServerQueues();
+
+/**
+ * This function will initalize the Receiver and Sender queues for
+ * GattClient. This function will inturn call the functions
+ * CAInitBleClientReceiverQueue() and CAInitBleClientSenderQueue() to
+ * initialize the queues.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ *
+ */
+static CAResult_t CAInitLEClientQueues();
+
+/**
+ * This function will initalize the Receiver queue for
+ * GattServer. This will initialize the queue to process the function
+ * CABLEServerSendDataThread() when ever the task is added to this
+ * queue.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CAInitLEServerSenderQueue();
+
+/**
+ * This function will initalize the Receiver queue for
+ * GattClient. This will initialize the queue to process the function
+ * CABLEClientSendDataThread() when ever the task is added to this
+ * queue.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CAInitLEClientSenderQueue();
+
+/**
+ * This function will initialize the Receiver queue for
+ * LEAdapter. This will initialize the queue to process the function
+ * CABLEDataReceiverHandler() when ever the task is added to this
+ * queue.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ * @retval ::CA_STATUS_OK  Successful
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments
+ * @retval ::CA_STATUS_FAILED Operation failed
+ *
+ */
+static CAResult_t CAInitLEReceiverQueue();
+
+/**
+ * This function will create the Data required to send it in the
+ * queue.
+ *
+ * @param[in] remoteEndpoint Remote endpoint information of the
+ *                           server.
+ * @param[in] data           Data to be transmitted from LE.
+ * @param[in] dataLength     Length of the Data being transmitted.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
+                                  const uint8_t *data,
+                                  uint32_t dataLength);
+
+/**
+ * Used to free the BLE information stored in the sender/receiver
+ * queues.
+ *
+ * @param[in] bleData Information for a particular data segment.
+ */
+static void CAFreeLEData(CALEData_t *bleData);
+
+/**
+ * Free data.
+ */
+static void CALEDataDestroyer(void *data, uint32_t size);
 
-CAResult_t CAInitLEServerQueues()
+static CAResult_t CAInitLEServerQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -297,7 +420,7 @@ CAResult_t CAInitLEServerQueues()
         return CA_STATUS_FAILED;
     }
 
-    result = CAInitLEServerReceiverQueue();
+    result = CAInitLEReceiverQueue();
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerReceiverQueue failed");
@@ -313,7 +436,7 @@ CAResult_t CAInitLEServerQueues()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitLEClientQueues()
+static CAResult_t CAInitLEClientQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -327,7 +450,7 @@ CAResult_t CAInitLEClientQueues()
         return CA_STATUS_FAILED;
     }
 
-    result = CAInitLEClientReceiverQueue();
+    result = CAInitLEReceiverQueue();
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientReceiverQueue failed");
@@ -343,39 +466,49 @@ CAResult_t CAInitLEClientQueues()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitLEServerSenderQueue()
+static CAResult_t CAInitLEReceiverQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
     // Check if the message queue is already initialized
-    if (g_bleServerSendQueueHandle)
+    if (g_bleReceiverQueue)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Queue is already initialized!");
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
         return CA_STATUS_OK;
     }
 
-    // Create send message queue
-    g_bleServerSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_bleServerSendQueueHandle)
+    // Create recv message queue
+    g_bleReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleReceiverQueue)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerSendQueueHandle,
-                                                   g_bleAdapterThreadPool,
-                                                   CALEServerSendDataThread, CALEDataDestroyer))
+    g_senderInfo = u_arraylist_create();
+    if (!g_senderInfo)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ClientInfo memory allcation failed!");
+        OICFree(g_bleReceiverQueue);
+        g_bleReceiverQueue = NULL;
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleReceiverQueue, g_bleAdapterThreadPool,
+            CALEDataReceiverHandler, CALEDataDestroyer))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_bleServerSendQueueHandle);
-        g_bleServerSendQueueHandle = NULL;
+        OICFree(g_bleReceiverQueue);
+        g_bleReceiverQueue = NULL;
+        u_arraylist_free(&g_senderInfo);
         return CA_STATUS_FAILED;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerSendQueueHandle))
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleReceiverQueue))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleServerSendQueueHandle);
-        g_bleServerSendQueueHandle = NULL;
+        OICFree(g_bleReceiverQueue);
+        g_bleReceiverQueue = NULL;
+        u_arraylist_free(&g_senderInfo);
         return CA_STATUS_FAILED;
     }
 
@@ -383,39 +516,39 @@ CAResult_t CAInitLEServerSenderQueue()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitLEClientSenderQueue()
+static CAResult_t CAInitLEServerSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    if (g_bleClientSendQueueHandle)
+    // Check if the message queue is already initialized
+    if (g_bleServerSendQueueHandle)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Queue is already initialized!");
         return CA_STATUS_OK;
     }
 
     // Create send message queue
-    g_bleClientSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_bleClientSendQueueHandle)
+    g_bleServerSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleServerSendQueueHandle)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientSendQueueHandle,
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerSendQueueHandle,
                                                    g_bleAdapterThreadPool,
-                                                   CALEClientSendDataThread, CALEDataDestroyer))
+                                                   CALEServerSendDataThread, CALEDataDestroyer))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_bleClientSendQueueHandle);
-        g_bleClientSendQueueHandle = NULL;
+        OICFree(g_bleServerSendQueueHandle);
+        g_bleServerSendQueueHandle = NULL;
         return CA_STATUS_FAILED;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientSendQueueHandle))
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerSendQueueHandle))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleClientSendQueueHandle);
-        g_bleClientSendQueueHandle = NULL;
+        OICFree(g_bleServerSendQueueHandle);
+        g_bleServerSendQueueHandle = NULL;
         return CA_STATUS_FAILED;
     }
 
@@ -423,82 +556,61 @@ CAResult_t CAInitLEClientSenderQueue()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitLEServerReceiverQueue()
+static void CALEClearSenderInfo()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    // Check if the message queue is already initialized
-    if (g_bleServerReceiverQueue)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
-    }
 
-    // Create send message queue
-    g_bleServerReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_bleServerReceiverQueue)
+    uint32_t listIndex = 0;
+    uint32_t listLength = u_arraylist_length(g_senderInfo);
+    for (listIndex = 0; listIndex < listLength; listIndex++)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        OICFree(g_bleServerSendQueueHandle);
-        return CA_MEMORY_ALLOC_FAILED;
-    }
-
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerReceiverQueue, g_bleAdapterThreadPool,
-            CALEServerDataReceiverHandler, CALEDataDestroyer))
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_bleServerReceiverQueue);
-        g_bleServerReceiverQueue = NULL;
-        return CA_STATUS_FAILED;
-    }
+        CABLESenderInfo_t *info = (CABLESenderInfo_t *) u_arraylist_get(g_senderInfo, listIndex);
+        if(!info)
+        {
+            continue;
+        }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerReceiverQueue))
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleServerReceiverQueue);
-        g_bleServerReceiverQueue = NULL;
-        return CA_STATUS_FAILED;
+        OICFree(info->defragData);
+        CAFreeEndpoint(info->remoteEndpoint);
+        OICFree(info);
     }
-
+    u_arraylist_free(&g_senderInfo);
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
-CAResult_t CAInitLEClientReceiverQueue()
+static CAResult_t CAInitLEClientSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    // Check if the message queue is already initialized
-    if (g_bleClientReceiverQueue)
+    if (g_bleClientSendQueueHandle)
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
+        return CA_STATUS_OK;
     }
-    else
+
+    // Create send message queue
+    g_bleClientSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleClientSendQueueHandle)
     {
-        // Create send message queue
-        g_bleClientReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-        if (!g_bleClientReceiverQueue)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-            OICFree(g_bleClientSendQueueHandle);
-            return CA_MEMORY_ALLOC_FAILED;
-        }
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
 
-        if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientReceiverQueue,
-                                                       g_bleAdapterThreadPool,
-                                                       CALEClientDataReceiverHandler, NULL))
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-            OICFree(g_bleClientSendQueueHandle);
-            OICFree(g_bleClientReceiverQueue);
-            g_bleClientReceiverQueue = NULL;
-            return CA_STATUS_FAILED;
-        }
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientSendQueueHandle,
+                                                   g_bleAdapterThreadPool,
+                                                   CALEClientSendDataThread, CALEDataDestroyer))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
     }
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientReceiverQueue))
+
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientSendQueueHandle))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleClientReceiverQueue);
-        g_bleClientReceiverQueue = NULL;
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
         return CA_STATUS_FAILED;
     }
 
@@ -506,7 +618,7 @@ CAResult_t CAInitLEClientReceiverQueue()
     return CA_STATUS_OK;
 }
 
-void CAStopLEQueues()
+static void CAStopLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -517,13 +629,6 @@ void CAStopLEQueues()
     }
     ca_mutex_unlock(g_bleClientSendDataMutex);
 
-    ca_mutex_lock(g_bleClientReceiveDataMutex);
-    if (NULL != g_bleClientReceiverQueue)
-    {
-        CAQueueingThreadStop(g_bleClientReceiverQueue);
-    }
-    ca_mutex_unlock(g_bleClientReceiveDataMutex);
-
     ca_mutex_lock(g_bleServerSendDataMutex);
     if (NULL != g_bleServerSendQueueHandle)
     {
@@ -531,17 +636,17 @@ void CAStopLEQueues()
     }
     ca_mutex_unlock(g_bleServerSendDataMutex);
 
-    ca_mutex_lock(g_bleServerReceiveDataMutex);
-    if (NULL != g_bleServerReceiverQueue)
+    ca_mutex_lock(g_bleReceiveDataMutex);
+    if (NULL != g_bleReceiverQueue)
     {
-        CAQueueingThreadStop(g_bleServerReceiverQueue);
+        CAQueueingThreadStop(g_bleReceiverQueue);
     }
-    ca_mutex_unlock(g_bleServerReceiveDataMutex);
+    ca_mutex_unlock(g_bleReceiveDataMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CATerminateLEQueues()
+static void CATerminateLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -549,129 +654,61 @@ void CATerminateLEQueues()
     OICFree(g_bleClientSendQueueHandle);
     g_bleClientSendQueueHandle = NULL;
 
-
-    CAQueueingThreadDestroy(g_bleClientReceiverQueue);
-    OICFree(g_bleClientReceiverQueue);
-    g_bleClientReceiverQueue = NULL;
-
-
     CAQueueingThreadDestroy(g_bleServerSendQueueHandle);
     OICFree(g_bleServerSendQueueHandle);
     g_bleServerSendQueueHandle = NULL;
 
+    CAQueueingThreadDestroy(g_bleReceiverQueue);
+    OICFree(g_bleReceiverQueue);
+    g_bleReceiverQueue = NULL;
 
-    CAQueueingThreadDestroy(g_bleServerReceiverQueue);
-    OICFree(g_bleServerReceiverQueue);
-    g_bleServerReceiverQueue = NULL;
+    CALEClearSenderInfo();
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CALEServerDataReceiverHandler(void *threadData)
+static CAResult_t CALEGetSenderInfo(const char *leAddress,
+                                    CABLESenderInfo_t **senderInfo,
+                                    uint32_t *senderIndex)
 {
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    static uint32_t recvDataLen = 0;
-    static uint32_t totalDataLen = 0;
-    static char *defragData = NULL;
-    static bool isHeaderAvailable = false;
-    static CAEndpoint_t *remoteEndpoint = NULL;
-
-    ca_mutex_lock(g_bleServerReceiveDataMutex);
-
-    if (g_dataReceiverHandlerState)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        CALEData_t *bleData = (CALEData_t *) threadData;
-        if (!bleData)
+    VERIFY_NON_NULL_RET(leAddress,
+                        CALEADAPTER_TAG,
+                        "NULL BLE address argument",
+                        CA_STATUS_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(senderIndex,
+                        CALEADAPTER_TAG,
+                        "NULL index argument",
+                        CA_STATUS_INVALID_PARAM);
+
+    const uint32_t listLength = u_arraylist_length(g_senderInfo);
+    const uint32_t addrLength = strlen(leAddress);
+    for (uint32_t index = 0; index < listLength; index++)
+    {
+        CABLESenderInfo_t *info = (CABLESenderInfo_t *) u_arraylist_get(g_senderInfo, index);
+        if(!info || !(info->remoteEndpoint))
         {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bleData!");
-            return;
+            continue;
         }
 
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        if (!isHeaderAvailable)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-            totalDataLen = CAParseHeader((char*)bleData->data);
-
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Total data to be accumulated [%d] bytes", totalDataLen);
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "data received in the first packet [%d] bytes", bleData->dataLen);
-
-            defragData = (char *) OICCalloc(totalDataLen + 1, sizeof(char));
-            if (NULL == defragData)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-                return;
-            }
-
-            const char *remoteAddress = bleData->remoteEndpoint->addr;
-
-            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
-                                                    remoteAddress, 0);
-
-            memcpy(defragData + recvDataLen, bleData->data + CA_HEADER_LENGTH,
-                   bleData->dataLen - CA_HEADER_LENGTH);
-            recvDataLen += bleData->dataLen - CA_HEADER_LENGTH;
-            isHeaderAvailable = true;
-        }
-        else
-        {
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Copying the data of length [%d]", bleData->dataLen);
-            memcpy(defragData + recvDataLen, bleData->data, bleData->dataLen);
-            recvDataLen += bleData->dataLen ;
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "totalDatalength  [%d] recveived Datalen [%d]",
-                      totalDataLen, recvDataLen);
-        }
-        if (totalDataLen == recvDataLen)
+        if(!strncmp(info->remoteEndpoint->addr, leAddress, addrLength))
         {
-            ca_mutex_lock(g_bleAdapterReqRespCbMutex);
-            if (NULL == g_networkPacketReceivedCallback)
+            *senderIndex = index;
+            if(senderInfo)
             {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
-                ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
-                return;
+                *senderInfo = info;
             }
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending data up !");
-            g_networkPacketReceivedCallback(remoteEndpoint, defragData, recvDataLen);
-            recvDataLen = 0;
-            totalDataLen = 0;
-            isHeaderAvailable = false;
-            remoteEndpoint = NULL;
-            defragData = NULL;
-            ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
-        }
-
-        if (false == g_dataReceiverHandlerState)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "GATTClient is terminating. Cleaning up");
-            recvDataLen = 0;
-            totalDataLen = 0;
-            isHeaderAvailable = false;
-            OICFree(defragData);
-            CAFreeEndpoint(remoteEndpoint);
-            ca_mutex_unlock(g_bleServerReceiveDataMutex);
-            return;
+            return CA_STATUS_OK;
         }
     }
-    ca_mutex_unlock(g_bleServerReceiveDataMutex);
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+
+    return CA_STATUS_FAILED;
 }
 
-void CALEClientDataReceiverHandler(void *threadData)
+static void CALEDataReceiverHandler(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    static const char *remoteAddress = NULL;
-    static uint32_t recvDataLen = 0;
-    static uint32_t totalDataLen = 0;
-    static char *defragData = NULL;
-    static bool isHeaderAvailable = false;
-    static CAEndpoint_t *remoteEndpoint = NULL;
-
-    ca_mutex_lock(g_bleClientReceiveDataMutex);
+    ca_mutex_lock(g_bleReceiveDataMutex);
 
     if (g_dataReceiverHandlerState)
     {
@@ -680,97 +717,178 @@ void CALEClientDataReceiverHandler(void *threadData)
         CALEData_t *bleData = (CALEData_t *) threadData;
         if (!bleData)
         {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid wifidata!");
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bleData!");
+            ca_mutex_unlock(g_bleReceiveDataMutex);
+            return;
+        }
+
+        if(!(bleData->remoteEndpoint))
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Client RemoteEndPoint NULL!!");
+            ca_mutex_unlock(g_bleReceiveDataMutex);
             return;
         }
 
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
+        CABLESenderInfo_t *senderInfo = NULL;
+        uint32_t senderIndex = 0;
 
-        if (!isHeaderAvailable)
+        if(CA_STATUS_OK != CALEGetSenderInfo(bleData->remoteEndpoint->addr,
+                                                &senderInfo, &senderIndex))
         {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "This is a new client [%s]",
+                                                bleData->remoteEndpoint->addr);
+        }
 
-            totalDataLen = CAParseHeader(bleData->data);
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Total data to be accumulated [%d] bytes",
-                      totalDataLen);
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received in the first packet [%d] bytes",
-                      bleData->dataLen);
+        if(!senderInfo)
+        {
+            CABLESenderInfo_t *newSender = OICMalloc(sizeof(CABLESenderInfo_t));
+            if(!newSender)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed for new sender");
+                ca_mutex_unlock(g_bleReceiveDataMutex);
+                return;
+            }
+            newSender->recvDataLen = 0;
+            newSender->totalDataLen = 0;
+            newSender->defragData = NULL;
+            newSender->remoteEndpoint = NULL;
 
-            defragData = (char *) OICMalloc(sizeof(char) * totalDataLen);
-            if (NULL == defragData)
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
+            newSender->totalDataLen = CAParseHeader(bleData->data,
+                                                    bleData->dataLen);
+            if(!(newSender->totalDataLen))
             {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "Total Data Length is parsed as 0!!!");
+                OICFree(newSender);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
                 return;
             }
 
-            remoteAddress = bleData->remoteEndpoint->addr;
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Total data to be accumulated [%u] bytes",
+                                                newSender->totalDataLen);
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "data received in the first packet [%u] bytes",
+                                                bleData->dataLen);
+
+            newSender->defragData = OICCalloc(newSender->totalDataLen + 1,
+                                              sizeof(*newSender->defragData));
 
-            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
-                                                    remoteAddress, 0);
+            if (NULL == newSender->defragData)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
+                OICFree(newSender);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
+                return;
+            }
 
-            memcpy(defragData, bleData->data + CA_HEADER_LENGTH,
-                   bleData->dataLen - CA_HEADER_LENGTH);
-            recvDataLen += bleData->dataLen - CA_HEADER_LENGTH;
-            isHeaderAvailable = true;
+            const char *remoteAddress = bleData->remoteEndpoint->addr;
+            newSender->remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                                                            CA_ADAPTER_GATT_BTLE, remoteAddress, 0);
+            if (NULL == newSender->remoteEndpoint)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "remoteEndpoint is NULL!");
+                OICFree(newSender->defragData);
+                OICFree(newSender);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
+                return;
+            }
+            memcpy(newSender->defragData, bleData->data + CA_HEADER_LENGTH,
+                    bleData->dataLen - CA_HEADER_LENGTH);
+            newSender->recvDataLen += bleData->dataLen - CA_HEADER_LENGTH;
+            u_arraylist_add(g_senderInfo,(void *)newSender);
+
+            //Getting newSender index position in g_senderInfo array list
+            if(CA_STATUS_OK !=
+                CALEGetSenderInfo(newSender->remoteEndpoint->addr, NULL, &senderIndex))
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "Existing sender index not found!!");
+                OICFree(newSender->defragData);
+                CAFreeEndpoint(newSender->remoteEndpoint);
+                OICFree(newSender);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
+                return;
+            }
+            senderInfo = newSender;
         }
         else
         {
+            if(senderInfo->recvDataLen + bleData->dataLen > senderInfo->totalDataLen)
+            {
+                OIC_LOG_V(ERROR, CALEADAPTER_TAG,
+                            "Data Length exceeding error!! Receiving [%d] total length [%d]",
+                            senderInfo->recvDataLen + bleData->dataLen, senderInfo->totalDataLen);
+                u_arraylist_remove(g_senderInfo, senderIndex);
+                OICFree(senderInfo->defragData);
+                OICFree(senderInfo);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
+                return;
+            }
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Copying the data of length [%d]", bleData->dataLen);
-            memcpy(defragData + recvDataLen, bleData->data, bleData->dataLen);
-            recvDataLen += bleData->dataLen ;
+            memcpy(senderInfo->defragData + senderInfo->recvDataLen, bleData->data,
+                    bleData->dataLen);
+            senderInfo->recvDataLen += bleData->dataLen ;
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "totalDatalength  [%d] recveived Datalen [%d]",
-                      totalDataLen, recvDataLen);
+                                                senderInfo->totalDataLen, senderInfo->recvDataLen);
         }
-        if (totalDataLen == recvDataLen)
+
+        if (senderInfo->totalDataLen == senderInfo->recvDataLen)
         {
             ca_mutex_lock(g_bleAdapterReqRespCbMutex);
             if (NULL == g_networkPacketReceivedCallback)
             {
                 OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
+
+                u_arraylist_remove(g_senderInfo, senderIndex);
+                OICFree(senderInfo->defragData);
+                OICFree(senderInfo);
                 ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
+                ca_mutex_unlock(g_bleReceiveDataMutex);
                 return;
             }
+
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending data up !");
-            g_networkPacketReceivedCallback(remoteEndpoint, defragData, recvDataLen);
-            recvDataLen = 0;
-            totalDataLen = 0;
-            isHeaderAvailable = false;
-            remoteEndpoint = NULL;
-            defragData = NULL;
-            ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
-        }
 
-        if (false == g_dataReceiverHandlerState)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "GATTClient is terminating. Cleaning up");
-            OICFree(defragData);
-            CAFreeEndpoint(remoteEndpoint);
-            ca_mutex_unlock(g_bleClientReceiveDataMutex);
-            return;
+            const CASecureEndpoint_t tmp =
+                {
+                    .endpoint = *senderInfo->remoteEndpoint
+                };
+
+            g_networkPacketReceivedCallback(&tmp,
+                                            senderInfo->defragData,
+                                            senderInfo->recvDataLen);
+            ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
+            u_arraylist_remove(g_senderInfo, senderIndex);
+            senderInfo->remoteEndpoint = NULL;
+            senderInfo->defragData = NULL;
+            OICFree(senderInfo);
         }
     }
-    ca_mutex_unlock(g_bleClientReceiveDataMutex);
+    ca_mutex_unlock(g_bleReceiveDataMutex);
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CALEServerSendDataThread(void *threadData)
+static void CALEServerSendDataThread(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CALEData_t *bleData = (CALEData_t *) threadData;
+    CALEData_t * const bleData = (CALEData_t *) threadData;
     if (!bleData)
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
         return;
     }
 
-    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1);
     VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    int32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+    const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+
+    OIC_LOG_V(DEBUG,
+              CALEADAPTER_TAG,
+              "Server total Data length with header is [%u]",
+              totalLength);
+
+    uint8_t * const dataSegment = OICCalloc(totalLength, 1);
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server total Data length with header is [%d]", totalLength);
-    char *dataSegment = (char *) OICCalloc(totalLength + 1, sizeof(char));
     if (NULL == dataSegment)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
@@ -778,19 +896,21 @@ void CALEServerSendDataThread(void *threadData)
         return;
     }
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    CAResult_t result = CAGenerateHeader(header,
+                                         CA_HEADER_LENGTH,
+                                         bleData->dataLen);
     if (CA_STATUS_OK != result )
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
         OICFree(header);
         OICFree(dataSegment);
-        return ;
+        return;
     }
 
     memcpy(dataSegment, header, CA_HEADER_LENGTH);
     OICFree(header);
 
-    int32_t length = 0;
+    uint32_t length = 0;
     if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
         length = totalLength;
@@ -803,31 +923,49 @@ void CALEServerSendDataThread(void *threadData)
                CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
     }
 
-    int32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
-    int32_t index = 0;
+    uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    uint32_t index = 0;
+
     // Send the first segment with the header.
-     if (NULL != bleData->remoteEndpoint) //Sending Unicast Data
+    if (NULL != bleData->remoteEndpoint) // Sending Unicast Data
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Server Sending Unicast Data");
+
         result = CAUpdateCharacteristicsToGattClient(
                     bleData->remoteEndpoint->addr, dataSegment, length);
+
         if (CA_STATUS_OK != result)
         {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
-            g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+            OIC_LOG_V(ERROR,
+                      CALEADAPTER_TAG,
+                      "Update characteristics failed, result [%d]",
+                      result);
+
+            g_errorHandler(bleData->remoteEndpoint,
+                           bleData->data,
+                           bleData->dataLen,
+                           result);
             OICFree(dataSegment);
             return;
         }
 
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", length);
+        OIC_LOG_V(DEBUG,
+                  CALEADAPTER_TAG,
+                  "Server Sent data length [%u]",
+                  length);
         for (index = 1; index < iter; index++)
         {
             // Send the remaining header.
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
-            result = CAUpdateCharacteristicsToGattClient(
-                         bleData->remoteEndpoint->addr,
-                         bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
-                         CA_SUPPORTED_BLE_MTU_SIZE);
+            OIC_LOG_V(DEBUG,
+                      CALEADAPTER_TAG,
+                      "Sending the chunk number [%u]",
+                      index);
+
+            result =
+                CAUpdateCharacteristicsToGattClient(
+                    bleData->remoteEndpoint->addr,
+                    bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
+                    CA_SUPPORTED_BLE_MTU_SIZE);
             if (CA_STATUS_OK != result)
             {
                 OIC_LOG_V(ERROR, CALEADAPTER_TAG,
@@ -840,10 +978,13 @@ void CALEServerSendDataThread(void *threadData)
                                                CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        int32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen =
+            totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattClient(
                          bleData->remoteEndpoint->addr,
@@ -851,9 +992,14 @@ void CALEServerSendDataThread(void *threadData)
                          remainingLen);
             if (CA_STATUS_OK != result)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                                                   result);
-                g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+                OIC_LOG_V(ERROR,
+                          CALEADAPTER_TAG,
+                          "Update characteristics failed, result [%d]",
+                          result);
+                g_errorHandler(bleData->remoteEndpoint,
+                               bleData->data,
+                               bleData->dataLen,
+                               result);
                 OICFree(dataSegment);
                 return;
             }
@@ -888,10 +1034,10 @@ void CALEServerSendDataThread(void *threadData)
                 OICFree(dataSegment);
                 return;
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", CA_SUPPORTED_BLE_MTU_SIZE);
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%u]", CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        int32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
             // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
@@ -915,7 +1061,7 @@ void CALEServerSendDataThread(void *threadData)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CALEClientSendDataThread(void *threadData)
+static void CALEClientSendDataThread(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -926,11 +1072,11 @@ void CALEClientSendDataThread(void *threadData)
         return;
     }
 
-    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1);
     VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
-    char *dataSegment = (char *) OICCalloc(totalLength + 1, sizeof(char));
+    const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+    uint8_t *dataSegment = OICCalloc(totalLength, 1);
     if (NULL == dataSegment)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
@@ -938,7 +1084,9 @@ void CALEClientSendDataThread(void *threadData)
         return;
     }
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    CAResult_t result = CAGenerateHeader(header,
+                                         CA_HEADER_LENGTH,
+                                         bleData->dataLen);
     if (CA_STATUS_OK != result )
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
@@ -953,37 +1101,51 @@ void CALEClientSendDataThread(void *threadData)
     if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
         length = totalLength;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+        memcpy(dataSegment + CA_HEADER_LENGTH,
+               bleData->data,
+               bleData->dataLen);
     }
     else
     {
         length = CA_SUPPORTED_BLE_MTU_SIZE;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length  [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
+        memcpy(dataSegment + CA_HEADER_LENGTH,
+               bleData->data,
                CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
     }
 
-    uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    const uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
     uint32_t index = 0;
     if (NULL != bleData->remoteEndpoint) //Sending Unicast Data
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Unicast Data");
         // Send the first segment with the header.
-        result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addr,
-                 dataSegment,
-                 length,
-                 LE_UNICAST, 0);
+        result =
+            CAUpdateCharacteristicsToGattServer(
+                bleData->remoteEndpoint->addr,
+                dataSegment,
+                length,
+                LE_UNICAST,
+                0);
 
         if (CA_STATUS_OK != result)
         {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
-            g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+            OIC_LOG_V(ERROR,
+                      CALEADAPTER_TAG,
+                      "Update characteristics failed, result [%d]",
+                      result);
+            g_errorHandler(bleData->remoteEndpoint,
+                           bleData->data,
+                           bleData->dataLen,
+                           result);
             OICFree(dataSegment);
-            return ;
+            return;
         }
 
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
+        OIC_LOG_V(DEBUG,
+                  CALEADAPTER_TAG,
+                  "Client Sent Data length  is [%u]",
+                  length);
+
         for (index = 1; index < iter; index++)
         {
             // Send the remaining header.
@@ -994,8 +1156,10 @@ void CALEClientSendDataThread(void *threadData)
                      LE_UNICAST, 0);
             if (CA_STATUS_OK != result)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                                                   result);
+                OIC_LOG_V(ERROR,
+                          CALEADAPTER_TAG,
+                          "Update characteristics failed, result [%d]",
+                          result);
                 g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
                 OICFree(dataSegment);
                 return;
@@ -1004,10 +1168,11 @@ void CALEClientSendDataThread(void *threadData)
                                                CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattServer(
                      bleData->remoteEndpoint->addr,
@@ -1060,13 +1225,15 @@ void CALEClientSendDataThread(void *threadData)
         }
 
         uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
-        if ( remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
+        if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
-            result = CAUpdateCharacteristicsToAllGattServers(
-                         bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                          remainingLen);
+            result =
+                CAUpdateCharacteristicsToAllGattServers(
+                    bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                    remainingLen);
             if (CA_STATUS_OK != result)
             {
                 OIC_LOG_V(ERROR, CALEADAPTER_TAG,
@@ -1085,10 +1252,12 @@ void CALEClientSendDataThread(void *threadData)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT - CABLEClientSendDataThread");
 }
 
-CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
-                           uint32_t dataLength)
+static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
+                                  const uint8_t *data,
+                                  uint32_t dataLength)
 {
-    CALEData_t *bleData = (CALEData_t *) OICMalloc(sizeof(CALEData_t));
+    CALEData_t * const bleData = OICMalloc(sizeof(CALEData_t));
+
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
@@ -1096,20 +1265,22 @@ CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
     }
 
     bleData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
-    bleData->data = (void *)OICCalloc(dataLength + 1, 1);
+    bleData->data = OICCalloc(dataLength + 1, 1);
+
     if (NULL == bleData->data)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
         CAFreeLEData(bleData);
         return NULL;
     }
+
     memcpy(bleData->data, data, dataLength);
     bleData->dataLen = dataLength;
 
     return bleData;
 }
 
-void CAFreeLEData(CALEData_t *bleData)
+static void CAFreeLEData(CALEData_t *bleData)
 {
     VERIFY_NON_NULL_VOID(bleData, CALEADAPTER_TAG, "Param bleData is NULL");
 
@@ -1118,15 +1289,20 @@ void CAFreeLEData(CALEData_t *bleData)
     OICFree(bleData);
 }
 
-void CALEDataDestroyer(void *data, uint32_t size)
+static void CALEDataDestroyer(void *data, uint32_t size)
 {
+    if ((size_t)size < sizeof(CALEData_t *))
+    {
+        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
+                  "Destroy data too small %p %d", data, size);
+    }
     CALEData_t *ledata = (CALEData_t *) data;
 
     CAFreeLEData(ledata);
 }
 #endif
 
-CAResult_t CAInitLEAdapterMutex()
+static CAResult_t CAInitLEAdapterMutex()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1184,17 +1360,6 @@ CAResult_t CAInitLEAdapterMutex()
         }
     }
 
-    if (NULL == g_bleClientReceiveDataMutex)
-    {
-        g_bleClientReceiveDataMutex = ca_mutex_new();
-        if (NULL == g_bleClientReceiveDataMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            CATerminateLEAdapterMutex();
-            return CA_STATUS_FAILED;
-        }
-    }
-
     if (NULL == g_bleServerSendDataMutex)
     {
         g_bleServerSendDataMutex = ca_mutex_new();
@@ -1206,10 +1371,10 @@ CAResult_t CAInitLEAdapterMutex()
         }
     }
 
-    if (NULL == g_bleServerReceiveDataMutex)
+    if (NULL == g_bleAdapterReqRespCbMutex)
     {
-        g_bleServerReceiveDataMutex = ca_mutex_new();
-        if (NULL == g_bleServerReceiveDataMutex)
+        g_bleAdapterReqRespCbMutex = ca_mutex_new();
+        if (NULL == g_bleAdapterReqRespCbMutex)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             CATerminateLEAdapterMutex();
@@ -1217,13 +1382,12 @@ CAResult_t CAInitLEAdapterMutex()
         }
     }
 
-    if (NULL == g_bleAdapterReqRespCbMutex)
+    if (NULL == g_bleReceiveDataMutex)
     {
-        g_bleAdapterReqRespCbMutex = ca_mutex_new();
-        if (NULL == g_bleAdapterReqRespCbMutex)
+        g_bleReceiveDataMutex = ca_mutex_new();
+        if (NULL == g_bleReceiveDataMutex)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            CATerminateLEAdapterMutex();
             return CA_STATUS_FAILED;
         }
     }
@@ -1232,7 +1396,7 @@ CAResult_t CAInitLEAdapterMutex()
     return CA_STATUS_OK;
 }
 
-void CATerminateLEAdapterMutex()
+static void CATerminateLEAdapterMutex()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1251,25 +1415,220 @@ void CATerminateLEAdapterMutex()
     ca_mutex_free(g_bleClientSendDataMutex);
     g_bleClientSendDataMutex = NULL;
 
-    ca_mutex_free(g_bleClientReceiveDataMutex);
-    g_bleClientReceiveDataMutex = NULL;
-
     ca_mutex_free(g_bleServerSendDataMutex);
     g_bleServerSendDataMutex = NULL;
 
-    ca_mutex_free(g_bleServerReceiveDataMutex);
-    g_bleServerReceiveDataMutex = NULL;
-
     ca_mutex_free(g_bleAdapterReqRespCbMutex);
     g_bleAdapterReqRespCbMutex = NULL;
 
+    ca_mutex_free(g_bleReceiveDataMutex);
+    g_bleReceiveDataMutex = NULL;
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
+/**
+ * Starting LE connectivity adapters.
+ *
+ * As its peer to peer it does not require to start any servers.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStartLE();
+
+/**
+ * Start listening server for receiving multicast search requests.
+ *
+ * Transport Specific Behavior:
+ *   LE  Starts GATT Server with prefixed UUID and Characteristics
+ *   per OIC Specification.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStartLEListeningServer();
+
+/**
+ * Stops listening server from receiving multicast search requests.
+ *
+ * Transport Specific Behavior:
+ *   LE  Starts GATT Server with prefixed UUID and Characteristics
+ *   per OIC Specification.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStopLEListeningServer();
+
+/**
+ * Sarting discovery of servers for receiving multicast
+ * advertisements.
+ *
+ * Transport Specific Behavior:
+ *   LE  Starts GATT Server with prefixed UUID and Characteristics
+ *   per OIC Specification.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ */
+static CAResult_t CAStartLEDiscoveryServer();
+
+/**
+ * Send data to the endpoint using the adapter connectivity.
+ *
+ * @param[in] endpoint Remote Endpoint information (like MAC address,
+ *                     reference URI and connectivity type) to which
+ *                     the unicast data has to be sent.
+ * @param[in] data     Data which required to be sent.
+ * @param[in] dataLen  Size of data to be sent.
+ *
+ * @note  dataLen must be > 0.
+ *
+ * @return The number of bytes sent on the network, or -1 on error.
+ */
+static int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint,
+                                   const void *data,
+                                   uint32_t dataLen);
+
+/**
+ * Send multicast data to the endpoint using the LE connectivity.
+ *
+ * @param[in] endpoint Remote Endpoint information to which the
+ *                     multicast data has to be sent.
+ * @param[in] data     Data which required to be sent.
+ * @param[in] dataLen  Size of data to be sent.
+ *
+ * @note  dataLen must be > 0.
+ *
+ * @return The number of bytes sent on the network, or -1 on error.
+ */
+static int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint,
+                                     const void *data,
+                                     uint32_t dataLen);
+
+/**
+ * Get LE Connectivity network information.
+ *
+ * @param[out] info Local connectivity information structures.
+ * @param[out] size Number of local connectivity structures.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info,
+                                              uint32_t *size);
+
+/**
+ * Read Synchronous API callback.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAReadLEData();
+
+/**
+ * Stopping the adapters and close socket connections.
+ *
+ * LE Stops all GATT servers and GATT Clients.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStopLE();
+
+/**
+ * Terminate the LE connectivity adapter.
+ *
+ * Configuration information will be deleted from further use.
+ */
+static void CATerminateLE();
+
+/**
+ * This function will receive the data from the GattServer and add the
+ * data to the Server receiver queue.
+ *
+ * @param[in] remoteAddress Remote address of the device from where
+ *                          data is received.
+ * @param[in] data          Actual data recevied from the remote
+ *                          device.
+ * @param[in] dataLength    Length of the data received from the
+ *                          remote device.
+ * @param[in] sentLength    Length of the data sent from the remote
+ *                          device.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ *
+ */
+static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
+                                                const uint8_t *data,
+                                                uint32_t dataLength,
+                                                uint32_t *sentLength);
+
+/**
+ * This function will receive the data from the GattClient and add the
+ * data into the Client receiver queue.
+ *
+ * @param[in] remoteAddress Remote address of the device from where
+ *                          data is received.
+ * @param[in] data          Actual data recevied from the remote
+ *                          device.
+ * @param[in] dataLength    Length of the data received from the
+ *                          remote device.
+ * @param[in] sentLength    Length of the data sent from the remote
+ *                          device.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
+                                                const uint8_t *data,
+                                                uint32_t dataLength,
+                                                uint32_t *sentLength);
+
+/**
+ * Set the NetworkPacket received callback to CA layer from adapter
+ * layer.
+ *
+ * @param[in] callback Callback handle sent from the upper layer.
+ */
+static void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
+
+/**
+ * Push the data from CA layer to the Sender processor queue.
+ *
+ * @param[in] remoteEndpoint Remote endpoint information of the
+ *                           server.
+ * @param[in] data           Data to be transmitted from LE.
+ * @param[in] dataLen        Length of the Data being transmitted.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen);
+
+/**
+ * Push the data from CA layer to the Sender processor queue.
+ *
+ * @param[in] remoteEndpoint Remote endpoint information of the
+ *                           server.
+ * @param[in] data           Data to be transmitted from LE.
+ * @param[in] dataLen        Length of the Data being transmitted.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen);
+
 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback reqRespCallback,
                           CANetworkChangeCallback netCallback,
-                          CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
+                          CAErrorHandleCallback errorCallback,
+                          ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1307,16 +1666,20 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
 
     g_errorHandler = errorCallback;
 
-    CAConnectivityHandler_t connHandler;
-    connHandler.startAdapter = CAStartLE;
-    connHandler.stopAdapter = CAStopLE;
-    connHandler.startListenServer = CAStartLEListeningServer;
-    connHandler.startDiscoveryServer = CAStartLEDiscoveryServer;
-    connHandler.sendData = CASendLEUnicastData;
-    connHandler.sendDataToAll = CASendLEMulticastData;
-    connHandler.GetnetInfo = CAGetLEInterfaceInformation;
-    connHandler.readData = CAReadLEData;
-    connHandler.terminate = CATerminateLE;
+    static const CAConnectivityHandler_t connHandler =
+        {
+            .startAdapter = CAStartLE,
+            .stopAdapter = CAStopLE,
+            .startListenServer = CAStartLEListeningServer,
+            .stopListenServer = CAStopLEListeningServer,
+            .startDiscoveryServer = CAStartLEDiscoveryServer,
+            .sendData = CASendLEUnicastData,
+            .sendDataToAll = CASendLEMulticastData,
+            .GetnetInfo = CAGetLEInterfaceInformation,
+            .readData = CAReadLEData,
+            .terminate = CATerminateLE
+        };
+
     registerCallback(connHandler, CA_ADAPTER_GATT_BTLE);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
@@ -1324,15 +1687,14 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
     return CA_STATUS_OK;
 }
 
-CAResult_t CAStartLE()
+static CAResult_t CAStartLE()
 {
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE, not implemented");
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE");
+
+    return CAStartLEAdapter();
 }
 
-CAResult_t CAStopLE()
+static CAResult_t CAStopLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 #ifndef SINGLE_THREAD
@@ -1355,7 +1717,7 @@ CAResult_t CAStopLE()
     return CA_STATUS_OK;
 }
 
-void CATerminateLE()
+static void CATerminateLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1384,9 +1746,10 @@ void CATerminateLE()
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-CAResult_t CAStartLEListeningServer()
+static CAResult_t CAStartLEListeningServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+#ifndef ROUTING_GATEWAY
     CAResult_t result = CA_STATUS_OK;
 #ifndef SINGLE_THREAD
     result = CAInitLEServerQueues();
@@ -1419,9 +1782,20 @@ CAResult_t CAStartLEListeningServer()
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
+#else
+    // Routing Gateway only supports BLE client mode.
+    OIC_LOG(ERROR, CALEADAPTER_TAG, "LE server not supported in Routing Gateway");
+    return CA_NOT_SUPPORTED;
+#endif
+}
+
+static CAResult_t CAStopLEListeningServer()
+{
+    OIC_LOG(ERROR, CALEADAPTER_TAG, "Listen server stop not supported.");
+    return CA_NOT_SUPPORTED;
 }
 
-CAResult_t CAStartLEDiscoveryServer()
+static CAResult_t CAStartLEDiscoveryServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
     CAResult_t result = CA_STATUS_OK;
@@ -1457,24 +1831,7 @@ CAResult_t CAStartLEDiscoveryServer()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAStartLENotifyServer()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
-                              uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return 0;
-}
-
-CAResult_t CAReadLEData()
+static CAResult_t CAReadLEData()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 #ifdef SINGLE_THREAD
@@ -1484,7 +1841,9 @@ CAResult_t CAReadLEData()
     return CA_STATUS_OK;
 }
 
-int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+static int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint,
+                                   const void *data,
+                                   uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1503,7 +1862,7 @@ int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Send unicast data failed\n");
             if (g_errorHandler)
             {
-                g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
+                g_errorHandler(endpoint, data, dataLen, result);
             }
             ca_mutex_unlock(g_bleIsServerMutex);
             return -1;
@@ -1529,7 +1888,9 @@ int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint
     return dataLen;
 }
 
-int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+static int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint,
+                                     const void *data,
+                                     uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1580,7 +1941,7 @@ int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, ui
     return dataLen;
 }
 
-CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
+static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1634,7 +1995,7 @@ CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     return CA_STATUS_OK;
 }
 
-CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1663,15 +2024,17 @@ CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
     return res;
 }
 
-void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
+static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL_VOID(g_localBLEAddress, CALEADAPTER_TAG, "g_localBLEAddress is null");
-    CAEndpoint_t localEndpoint = {};
+    CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
 
     ca_mutex_lock(g_bleLocalAddressMutex);
-    OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), g_localBLEAddress);
+    OICStrcpy(localEndpoint.addr,
+              sizeof(localEndpoint.addr),
+              g_localBLEAddress);
     ca_mutex_unlock(g_bleLocalAddressMutex);
 
     g_bleAdapterState = adapter_state;
@@ -1702,9 +2065,9 @@ void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
-                                     const void *data,
-                                     uint32_t dataLen)
+static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1720,7 +2083,7 @@ CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
     VERIFY_NON_NULL_RET(g_bleClientSendQueueHandle, CALEADAPTER_TAG, "g_bleClientSendQueueHandle",
                         CA_STATUS_FAILED);
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
+    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%u]", dataLen);
 
     CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
@@ -1737,63 +2100,67 @@ CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
     return CA_STATUS_OK;
 }
 
-
-CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
-                                     const void *data,
-                                     uint32_t dataLen)
+static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
 
 #ifdef SINGLE_THREAD
-    char header[CA_HEADER_LENGTH] = {0};
+    uint8_t header[CA_HEADER_LENGTH] = { 0 };
 
-    CAResult_t result = CAGenerateHeader(header, dataLen);
+    CAResult_t result =
+        CAGenerateHeader(header, CA_HEADER_LENGTH, dataLen);
 
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
     if (!CAIsLEConnected())
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "le not conn");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
     result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
-    int32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
-    for (int32_t iter = 0; iter < dataLimit; iter++)
+    const uint32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
+    for (uint32_t iter = 0; iter < dataLimit; iter++)
     {
-        result = CAUpdateCharacteristicsToAllGattClients((data +
-                                                         (iter * CA_SUPPORTED_BLE_MTU_SIZE)),
-                                                         CA_SUPPORTED_BLE_MTU_SIZE);
+        result =
+            CAUpdateCharacteristicsToAllGattClients(
+                data + (iter * CA_SUPPORTED_BLE_MTU_SIZE),
+                CA_SUPPORTED_BLE_MTU_SIZE);
+
         if (CA_STATUS_OK != result)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return -1;
+            return CA_STATUS_FAILED;
         }
+
         CALEDoEvents();
     }
 
-    uint8_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
-    if(remainingLen)
+    const uint32_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
+    if (remainingLen)
     {
-        result = CAUpdateCharacteristicsToAllGattClients((data +
-                                                         (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE)),
-                                                         remainingLen);
+        result =
+            CAUpdateCharacteristicsToAllGattClients(
+                data + (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE),
+                remainingLen);
         if (CA_STATUS_OK != result)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return -1;
+            return CA_STATUS_FAILED;
         }
         CALEDoEvents();
     }
@@ -1810,47 +2177,60 @@ CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
 
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
 
-    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
+    CALEData_t * const bleData =
+        CACreateLEData(remoteEndpoint, data, dataLen);
+
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
         return CA_MEMORY_ALLOC_FAILED;
     }
+
     // Add message to send queue
     ca_mutex_lock(g_bleServerSendDataMutex);
-    CAQueueingThreadAddData(g_bleServerSendQueueHandle, bleData, sizeof(CALEData_t));
+    CAQueueingThreadAddData(g_bleServerSendQueueHandle,
+                            bleData,
+                            sizeof(CALEData_t));
     ca_mutex_unlock(g_bleServerSendDataMutex);
 #endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                         const void *data, uint32_t dataLength,
-                                         uint32_t *sentLength)
+static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
+                                                const uint8_t *data,
+                                                uint32_t dataLength,
+                                                uint32_t *sentLength)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     //Input validation
-    VERIFY_NON_NULL(serviceUUID, CALEADAPTER_TAG, "service UUID is null");
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
 
 #ifdef SINGLE_THREAD
     if(g_networkPacketReceivedCallback)
     {
-        CAEndpoint_t endPoint = { 0 };   // will be filled by upper layer
-        endPoint.adapter = CA_ADAPTER_GATT_BTLE;
-        g_networkPacketReceivedCallback(&endPoint, data, dataLength);
+        // will be filled by upper layer
+        const CASecureEndpoint_t endpoint =
+            { .endpoint = { .adapter = CA_ADAPTER_GATT_BTLE } };
+
+
+        g_networkPacketReceivedCallback(&endpoint, data, dataLength);
     }
 #else
-    VERIFY_NON_NULL_RET(g_bleServerReceiverQueue, CALEADAPTER_TAG, "g_bleServerReceiverQueue",
+    VERIFY_NON_NULL_RET(g_bleReceiverQueue,
+                        CALEADAPTER_TAG,
+                        "g_bleReceiverQueue",
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
-                                                          CA_ADAPTER_GATT_BTLE,
-                                                          remoteAddress, 0);
+    CAEndpoint_t * const remoteEndpoint =
+        CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                               CA_ADAPTER_GATT_BTLE,
+                               remoteAddress,
+                               0);
+
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
@@ -1858,9 +2238,14 @@ CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress, const char *
     }
 
     // Create bleData to add to queue
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
+    OIC_LOG_V(DEBUG,
+              CALEADAPTER_TAG,
+              "Data received from LE layer [%d]",
+              dataLength);
+
+    CALEData_t * const bleData =
+        CACreateLEData(remoteEndpoint, data, dataLength);
 
-    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -1869,8 +2254,8 @@ CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress, const char *
     }
 
     CAFreeEndpoint(remoteEndpoint);
-    // Add message to send queue
-    CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
+    // Add message to receiver queue
+    CAQueueingThreadAddData(g_bleReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
 #endif
@@ -1878,18 +2263,18 @@ CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress, const char *
     return CA_STATUS_OK;
 }
 
-CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                         const void *data, uint32_t dataLength,
-                                         uint32_t *sentLength)
+static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
+                                                const uint8_t *data,
+                                                uint32_t dataLength,
+                                                uint32_t *sentLength)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     //Input validation
-    VERIFY_NON_NULL(serviceUUID, CALEADAPTER_TAG, "service UUID is null");
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
 #ifndef SINGLE_THREAD
-    VERIFY_NON_NULL_RET(g_bleClientReceiverQueue, CALEADAPTER_TAG, "g_bleClientReceiverQueue",
+    VERIFY_NON_NULL_RET(g_bleReceiverQueue, CALEADAPTER_TAG, "g_bleReceiverQueue",
                         CA_STATUS_FAILED);
 
     //Add message to data queue
@@ -1902,7 +2287,7 @@ CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress, const char *
         return CA_STATUS_FAILED;
     }
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
+    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%u]", dataLength);
 
     // Create bleData to add to queue
     CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
@@ -1914,8 +2299,8 @@ CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress, const char *
     }
 
     CAFreeEndpoint(remoteEndpoint);
-    // Add message to send queue
-    CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
+    // Add message to receiver queue
+    CAQueueingThreadAddData(g_bleReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
 #endif
@@ -1923,18 +2308,18 @@ CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress, const char *
     return CA_STATUS_OK;
 }
 
-void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle)
+static void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
     g_bleAdapterThreadPool = handle;
     ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
+static void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1947,17 +2332,24 @@ void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CALEErrorHandler(const char *remoteAddress, const void *data, uint32_t dataLen,
-                      CAResult_t result)
+static void CALEErrorHandler(const char *remoteAddress,
+                             const uint8_t *data,
+                             uint32_t dataLen,
+                             CAResult_t result)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler IN");
 
     VERIFY_NON_NULL_VOID(data, CALEADAPTER_TAG, "Data is null");
-    CAEndpoint_t *rep = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
-                                               remoteAddress, 0);
-    //if required, will be used to build remote end point
+
+    CAEndpoint_t *rep = CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                                               CA_ADAPTER_GATT_BTLE,
+                                               remoteAddress,
+                                               0);
+
+    // if required, will be used to build remote endpoint
     g_errorHandler(rep, data, dataLen, result);
 
     CAFreeEndpoint(rep);
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT");
 }