Integrated singlethread and multithread files of BLE adapter.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / caleadapter.c
index 32165fa..37f14ba 100644 (file)
  ******************************************************************/
 #include "caleadapter.h"
 
-#ifdef __TIZEN__
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <unistd.h>
-#include <pthread.h>
-#endif //#ifdef __TIZEN__
 #include <stdio.h>
 #include <stdlib.h>
 
-#ifdef __TIZEN__
-#include "cableserver.h"
-#include "cableclient.h"
+#include "caleinterface.h"
 #include "cacommon.h"
-#include "umutex.h"
+#include "camutex.h"
 #include "caadapterutils.h"
-#else // __ARDUINO__
-#include "BLEAdapterArduino.h"
-#include "caadapterutils.h"
-#endif //#ifdef __TIZEN__
+#ifndef SINGLE_THREAD
 #include "caqueueingthread.h"
-#include "camsgparser.h"
-
-
-#define CALEADAPTER_TAG "CA_BLE_ADAPTER"
-
-static CANetworkChangeCallback gNetworkCallback = NULL;
+#endif
+#include "cafragmentation.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "caremotehandler.h"
 
-static char gLocalBLEAddress[16] = { 0, };
+/**
+ * @var CALEADAPTER_TAG
+ * @brief Logging tag for module name.
+ */
+#define CALEADAPTER_TAG "LAD"
 
-static CABool_t gIsServer = CA_FALSE;
+/**
+ * @var g_networkCallback
+ * @brief Callback to provide the status of the network change to CA layer.
+ */
+static CANetworkChangeCallback g_networkCallback = NULL;
 
-static u_mutex gBleIsServerMutex = NULL;
+/**
+ * @var g_localBLEAddress
+ * @brief bleAddress of the local adapter. Value will be initialized to zero, and will
+ *        be updated later.
+ */
+static char g_localBLEAddress[18] = {0};
 
-static u_mutex gBleNetworkCbMutex = NULL;
+/**
+ * @var g_isServer
+ * @brief Variable to differentiate btw GattServer and GattClient.
+ */
+static bool g_isServer = false;
 
-static u_mutex gBleLocalAddressMutex = NULL;
+/**
+ * @var g_bleIsServerMutex
+ * @brief Mutex to synchronize the task to be executed on the GattServer function calls.
+ */
+static ca_mutex g_bleIsServerMutex = NULL;
 
 /**
- * @var gBleClientThreadPool
- * @brief reference to threadpool
+ * @var g_bleNetworkCbMutex
+ * @brief Mutex to synchronize the callback to be called for the network changes.
  */
-static u_thread_pool_t gBleAdapterThreadPool = NULL;
+static ca_mutex g_bleNetworkCbMutex = NULL;
 
 /**
- * @var gBleAdapterThreadPoolMutex
- * @brief Mutex to synchronize the task to be pushed to thread pool.
+ * @var g_bleLocalAddressMutex
+ * @brief Mutex to synchronize the updation of the local LE address of the adapter.
  */
-static u_mutex gBleAdapterThreadPoolMutex = NULL;
+static ca_mutex g_bleLocalAddressMutex = NULL;
 
 /**
- * @var gBLEClientSendQueueHandle
- * @brief Queue to process the outgoing packets from GATTClient.
+ * @var g_bleAdapterThreadPool
+ * @brief reference to threadpool
  */
-static CAQueueingThread_t *gBLEClientSendQueueHandle = NULL;
+static ca_thread_pool_t g_bleAdapterThreadPool = NULL;
 
 /**
- * @var gCABleClientReceiverQueue
- * @brief Queue to process the incoming packets to GATT Client.
+ * @var g_bleAdapterThreadPoolMutex
+ * @brief Mutex to synchronize the task to be pushed to thread pool.
  */
-static CAQueueingThread_t *gCABleClientReceiverQueue = NULL;
+static ca_mutex g_bleAdapterThreadPoolMutex = NULL;
 
 /**
- * @var gBleClientSendDataMutex
+ * @var g_bleClientSendDataMutex
  * @brief Mutex to synchronize the queing of the data from SenderQueue.
  */
-static u_mutex gBleClientSendDataMutex = NULL;
-
+static ca_mutex g_bleClientSendDataMutex = NULL;
 
 /**
- * @var gBleClientReceiveDataMutex
+ * @var g_bleClientReceiveDataMutex
  * @brief Mutex to synchronize the queing of the data from ReceiverQueue.
  */
-static u_mutex gBleClientReceiveDataMutex = NULL;
+static ca_mutex g_bleClientReceiveDataMutex = NULL;
+
 
 /**
- * @var gDataReceiverHandlerState
- * @brief Stop condition of redvhandler.
+ * @var g_bleServerSendDataMutex
+ * @brief Mutex to synchronize the queing of the data from SenderQueue.
  */
-static bool gDataReceiverHandlerState = false;
+static ca_mutex g_bleServerSendDataMutex = NULL;
 
 /**
- * @var gSendQueueHandle
- * @brief Queue to process the outgoing packets from GATTServer.
+ * @var g_bleServerReceiveDataMutex
+ * @brief Mutex to synchronize the queing of the data from ReceiverQueue.
  */
-static CAQueueingThread_t *gSendQueueHandle = NULL;
+static ca_mutex g_bleServerReceiveDataMutex = NULL;
 
 /**
- * @var gCABleServerReceiverQueue
- * @brief Queue to process the incoming packets to GATTServer
+ * @var g_bleAdapterReqRespCbMutex
+ * @brief Mutex to synchronize the callback to be called for the adapterReqResponse.
  */
-static CAQueueingThread_t *gCABleServerReceiverQueue = NULL;
+static ca_mutex g_bleAdapterReqRespCbMutex = NULL;
 
 /**
- * @var gBleServerSendDataMutex
- * @brief Mutex to synchronize the queing of the data from SenderQueue.
+ * @var g_networkPacketReceivedCallback
+ * @brief Callback to be called when network packet recieved from either GattServer or GattClient.
  */
-static u_mutex gBleServerSendDataMutex = NULL;
+static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
 
 /**
- * @var gBleServerReceiveDataMutex
- * @brief Mutex to synchronize the queing of the data from ReceiverQueue.
+ * @var g_errorHandler
+ * @brief Callback to notify error from the BLE adapter
  */
-static u_mutex gBleServerReceiveDataMutex = NULL;
+static CAErrorHandleCallback g_errorHandler = NULL;
 
-static u_mutex gBleAdapterReqRespCbMutex = NULL;
+/**
+ * @var g_bleAdapterState
+ * @brief Storing Adapter state information
+ */
+static CAAdapterState_t g_bleAdapterState = CA_ADAPTER_DISABLED;
 
-static CANetworkPacketReceivedCallback gNetworkPacketReceivedCallback = NULL;
 /**
  * @ENUM CALeServerStatus
  * @brief status of BLE Server Status
- *
  *  This ENUM provides information of LE Adapter Server status
  */
 typedef enum
@@ -141,1419 +150,1806 @@ typedef enum
     CA_DISCOVERY_SERVER
 } CALeServerStatus;
 
+/**
+ * @var gLeServerStatus
+ * @brief structure to maintain the status of the server.
+ */
 static CALeServerStatus gLeServerStatus = CA_SERVER_NOTSTARTED;
 
-int32_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
-
-void CASetBleAdapterThreadPoolHandle(u_thread_pool_t handle);
-
-#ifdef __TIZEN__
-void CALEDeviceStateChangedCb(int32_t result, bt_adapter_state_e adapter_state,
-                              void *user_data);
-CAResult_t CAInitBleAdapterMutex();
-CAResult_t CATermiateBleAdapterMutex();
-
-#endif //#ifdef __TIZEN__
-
-CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
-                          CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback,
-                          u_thread_pool_t handle)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    //Input validation
-    VERIFY_NON_NULL(registerCallback, NULL, "RegisterConnectivity callback is null");
-    VERIFY_NON_NULL(reqRespCallback, NULL, "PacketReceived Callback is null");
-    VERIFY_NON_NULL(netCallback, NULL, "NetworkChange Callback is null");
+/**
+* @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);
 
-    CAResult_t result = CAInitBleAdapterMutex();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleAdapterMutex failed!");
-        return CA_STATUS_FAILED;
-    }
+/**
+* @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);
 
-#ifdef __TIZEN__
+/**
+* @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);
 
-    bt_initialize();
+/**
+* @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();
 
-#endif //#ifdef __TIZEN__
+/**
+* @fn  CATerminateBleAdapterMutex
+* @brief  Used to terminate all required mutex variable for LE adapter implementation.
+*
+* @return  void
+*/
+void CATerminateLEAdapterMutex();
 
-    CASetBleServerThreadPoolHandle(handle);
-    CASetBleClientThreadPoolHandle(handle);
-    CASetBleAdapterThreadPoolHandle(handle);
-    CASetBLEReqRespServerCallback(CABLEServerReceivedData);
-    CASetBLEReqRespClientCallback(CABLEClientReceivedData);
-    CASetBLEReqRespAdapterCallback(reqRespCallback);
+/**
+* @fn  CALEErrorHandler
+* @brief  prepares and notify error through error callback
+*
+* @return  void
+*/
+static void CALEErrorHandler(const char *remoteAddress, const void *data, uint32_t dataLen,
+                             CAResult_t result);
+
+#ifndef SINGLE_THREAD
+/**
+ * @var g_dataReceiverHandlerState
+ * @brief Stop condition of recvhandler.
+ */
+static bool g_dataReceiverHandlerState = false;
 
-    CALERegisterNetworkNotifications(netCallback);
+/**
+ * @var g_bleClientSendQueueHandle
+ * @brief Queue to process the outgoing packets from GATTClient.
+ */
+static CAQueueingThread_t *g_bleClientSendQueueHandle = NULL;
 
-    CAConnectivityHandler_t connHandler;
-    connHandler.startAdapter = NULL;
-    connHandler.stopAdapter = NULL;
-    connHandler.startListenServer = CAStartLEListeningServer;
-    connHandler.startDiscoverServer = CAStartLEDiscoveryServer;
-    connHandler.sendData = CASendLEUnicastData;
-    connHandler.sendDataToAll = CASendLEMulticastData;
-    connHandler.GetnetInfo = CAGetLEInterfaceInformation;
-    connHandler.readData = CAReadLEData;
-    connHandler.terminate = CATerminateLE;
-    registerCallback(connHandler, CA_LE);
+/**
+ * @var g_bleClientReceiverQueue
+ * @brief Queue to process the incoming packets to GATT Client.
+ */
+static CAQueueingThread_t *g_bleClientReceiverQueue = NULL;
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+/**
+ * @var g_bleServerSendQueueHandle
+ * @brief Queue to process the outgoing packets from GATTServer.
+ */
+static CAQueueingThread_t *g_bleServerSendQueueHandle = NULL;
 
-    return CA_STATUS_OK;
-}
+/**
+ * @var g_bleServerReceiverQueue
+ * @brief Queue to process the incoming packets to GATTServer
+ */
+static CAQueueingThread_t *g_bleServerReceiverQueue = NULL;
 
-void CATerminateLE()
+/**
+* @fn  CALEDataDestroyer
+* @brief  Used to free data
+*
+* @return  void
+*/
+static void CALEDataDestroyer(void *data, uint32_t size);
+
+void CAInitLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CASetBLEReqRespServerCallback(NULL);
-    CASetBLEReqRespClientCallback(NULL);
-    CALERegisterNetworkNotifications(NULL);
-
-    u_mutex_lock(gBleIsServerMutex);
-    if (CA_TRUE == gIsServer)
+    CAResult_t result = CAInitLEServerQueues();
+    if (CA_STATUS_OK != result)
     {
-        CAStopBleGattServer();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerQueues failed");
+        return;
     }
-    else
+
+    result = CAInitLEClientQueues();
+    if (CA_STATUS_OK != result)
     {
-        CAStopBLEGattClient();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
+        return;
     }
-    u_mutex_unlock(gBleIsServerMutex);
-
-    CATerminateBleQueues();
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return;
 }
 
-CAResult_t CAStartLEListeningServer()
+CAResult_t CAInitLEServerQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    bt_error_e err = BT_ERROR_NONE;
-    bt_adapter_state_e adapterState;
+    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
 
-    CAResult_t result = CAInitBleServerQueues();
+    CAResult_t result = CAInitLEServerSenderQueue();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerSenderQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
         return CA_STATUS_FAILED;
     }
 
-    //Get Bluetooth adapter state
-    if (BT_ERROR_NONE != (err = bt_adapter_get_state(&adapterState)))
+    result = CAInitLEServerReceiverQueue();
+    if (CA_STATUS_OK != result)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!, error num [%x]",
-                  err);
-
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerReceiverQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
         return CA_STATUS_FAILED;
     }
 
-    if (BT_ADAPTER_ENABLED != adapterState)
-    {
-        gLeServerStatus = CA_LISTENING_SERVER;
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
-        return CA_STATUS_OK;
-    }
+    g_dataReceiverHandlerState = true;
 
-    CAStartBleGattServer();
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    u_mutex_lock(gBleIsServerMutex);
-    gIsServer = CA_TRUE;
-    u_mutex_unlock(gBleIsServerMutex);
     return CA_STATUS_OK;
 }
 
-CAResult_t CAStartLEDiscoveryServer()
+CAResult_t CAInitLEClientQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    bt_error_e err = BT_ERROR_NONE;
-    bt_adapter_state_e adapterState;
+    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
 
-    CAResult_t result = CAInitBleClientQueues();
+    CAResult_t result = CAInitLEClientSenderQueue();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientSenderQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
         return CA_STATUS_FAILED;
     }
 
-    //Get Bluetooth adapter state
-    if (BT_ERROR_NONE != (err = bt_adapter_get_state(&adapterState)))
+    result = CAInitLEClientReceiverQueue();
+    if (CA_STATUS_OK != result)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!, error num [%x]",
-                  err);
-
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientReceiverQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
         return CA_STATUS_FAILED;
     }
 
-    if (BT_ADAPTER_ENABLED != adapterState)
-    {
-        gLeServerStatus = CA_DISCOVERY_SERVER;
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Disc Server will be started once BT Adapter is enabled");
-        return CA_STATUS_OK;
-    }
-
-    CAStartBLEGattClient();
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    u_mutex_lock(gBleIsServerMutex);
-    gIsServer = CA_FALSE;
-    u_mutex_unlock(gBleIsServerMutex);
-    return CA_STATUS_OK;
-}
+    g_dataReceiverHandlerState = true;
 
-CAResult_t CAStartLENotifyServer()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-
     return CA_STATUS_OK;
 }
 
-uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen)
+CAResult_t CAInitLEServerSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    // Check if the message queue is already initialized
+    if (g_bleServerSendQueueHandle)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Queue is already initialized!");
+        return CA_STATUS_OK;
+    }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    // Create send message queue
+    g_bleServerSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleServerSendQueueHandle)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
 
-    return CA_STATUS_OK;
-}
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerSendQueueHandle,
+                                                   g_bleAdapterThreadPool,
+                                                   CALEServerSendDataThread, CALEDataDestroyer))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleServerSendQueueHandle);
+        g_bleServerSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
+    }
 
-CAResult_t CAReadLEData()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerSendQueueHandle))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleServerSendQueueHandle);
+        g_bleServerSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
+    }
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-
     return CA_STATUS_OK;
 }
 
-uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen)
+CAResult_t CAInitLEClientSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    //Input validation
-    VERIFY_NON_NULL(endpoint, NULL, "Remote endpoint is null");
-    VERIFY_NON_NULL(data, NULL, "Data is null");
-
-    CAResult_t result = CA_STATUS_FAILED;
-
-#ifdef __TIZEN__
-    u_mutex_lock(gBleIsServerMutex);
-    if (CA_TRUE  == gIsServer)
-    {
-        result = CABLEServerSendData(endpoint, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEUnicastData] CABleServerSenderQueueEnqueueMessage failed \n");
-            u_mutex_unlock(gBleIsServerMutex);
-            return 0;
-        }
-    }
-    else
+    if (g_bleClientSendQueueHandle)
     {
-        result = CABLEClientSendData(endpoint, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEUnicastData] CABleClientSenderQueueEnqueueMessage failed \n");
-            u_mutex_unlock(gBleIsServerMutex);
-            return 0;
-        }
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
+        return CA_STATUS_OK;
     }
-    u_mutex_unlock(gBleIsServerMutex);
-#else
-    char *tempPath = "temp_path";
-    updateCharacteristicsInGattServer(tempPath, (char *) data, dataLen);
-#endif //#ifdef __TIZEN__
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-
-    return dataLen;
-}
-
-uint32_t CASendLEMulticastData(void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    //Input validation
-    VERIFY_NON_NULL(data, NULL, "Data is null");
 
-    if (0 >= dataLen)
+    // Create send message queue
+    g_bleClientSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleClientSendQueueHandle)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Invalid Parameter");
-        return 0;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
     }
 
-    CAResult_t result = CA_STATUS_FAILED;
-#ifdef __TIZEN__
-    u_mutex_lock(gBleIsServerMutex);
-    if (CA_TRUE  == gIsServer)
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientSendQueueHandle,
+                                                   g_bleAdapterThreadPool,
+                                                   CALEClientSendDataThread, CALEDataDestroyer))
     {
-        result = CABLEServerSendData(NULL, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEMulticastDataToAll] CABleServerSenderQueueEnqueueMessage failed" );
-            u_mutex_unlock(gBleIsServerMutex);
-            return 0;
-        }
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
     }
-    else
+
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientSendQueueHandle))
     {
-        result = CABLEClientSendData(NULL, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEMulticastDataToAll] CABleClientSenderQueueEnqueueMessage failed" );
-            u_mutex_unlock(gBleIsServerMutex);
-            return 0;
-        }
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
     }
-    u_mutex_unlock(gBleIsServerMutex);
-#else
-    char *tempPath = "temp_path";
-    updateCharacteristicsInGattServer(tempPath, (char *) data, dataLen);
-#endif //#ifdef __TIZEN__
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return dataLen;
+    return CA_STATUS_OK;
 }
 
-CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAInitLEServerReceiverQueue()
 {
     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;
+    }
 
-    VERIFY_NON_NULL(info, NULL, "CALocalConnectivity info is null");
-
-#if __TIZEN__
-
-    char *local_address = NULL;
+    // Create send message queue
+    g_bleServerReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleServerReceiverQueue)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        OICFree(g_bleServerSendQueueHandle);
+        return CA_MEMORY_ALLOC_FAILED;
+    }
 
-    bt_adapter_get_address(&local_address);
-    if (NULL == local_address)
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerReceiverQueue, g_bleAdapterThreadPool,
+            CALEServerDataReceiverHandler, CALEDataDestroyer))
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Get local bt adapter address failed");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleServerReceiverQueue);
+        g_bleServerReceiverQueue = NULL;
         return CA_STATUS_FAILED;
     }
 
-#endif //#if ARDUINODUE
-    *size = 0;
-    (*info) = (CALocalConnectivity_t *) OICMalloc(sizeof(CALocalConnectivity_t));
-    if (NULL == (*info))
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerReceiverQueue))
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failure!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleServerReceiverQueue);
+        g_bleServerReceiverQueue = NULL;
         return CA_STATUS_FAILED;
     }
-    memset((*info), 0x0, sizeof(CALocalConnectivity_t));
-
-    strncpy((*info)->addressInfo.BT.btMacAddress, local_address, strlen(local_address));
-    u_mutex_lock(gBleLocalAddressMutex);
-    strncpy(gLocalBLEAddress, local_address, sizeof(gLocalBLEAddress));
-    u_mutex_unlock(gBleLocalAddressMutex);
-
-    (*info)->type = CA_LE;
-    *size = 1;
-    OICFree(local_address);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-int32_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+CAResult_t CAInitLEClientReceiverQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_lock(gBleNetworkCbMutex);
-    gNetworkCallback = netCallback;
-    u_mutex_unlock(gBleNetworkCbMutex);
-    int32_t ret = 0;
-#ifdef __TIZEN__
-    if (netCallback)
+    // Check if the message queue is already initialized
+    if (g_bleClientReceiverQueue)
     {
-        ret = bt_adapter_set_state_changed_cb(CALEDeviceStateChangedCb, NULL);
-        if (ret != 0)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "bt_adapter_set_state_changed_cb failed!");
-        }
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
     }
     else
     {
-        ret = bt_adapter_unset_state_changed_cb();
-        if (ret != 0)
+        // 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;
+        }
+
+        if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientReceiverQueue,
+                                                       g_bleAdapterThreadPool,
+                                                       CALEClientDataReceiverHandler, NULL))
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "bt_adapter_set_state_changed_cb failed!");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+            OICFree(g_bleClientSendQueueHandle);
+            OICFree(g_bleClientReceiverQueue);
+            g_bleClientReceiverQueue = NULL;
+            return CA_STATUS_FAILED;
         }
     }
-#endif //#ifdef __TIZEN__
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientReceiverQueue))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleClientReceiverQueue);
+        g_bleClientReceiverQueue = NULL;
+        return CA_STATUS_FAILED;
+    }
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-#ifdef __TIZEN__
-
-void CALEDeviceStateChangedCb(int32_t result, bt_adapter_state_e adapter_state, void *user_data)
+void CAStopLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CALocalConnectivity_t localEndpoint;
-
-    u_mutex_lock(gBleLocalAddressMutex);
-    strncpy(localEndpoint.addressInfo.BT.btMacAddress, gLocalBLEAddress, strlen(gLocalBLEAddress));
-    u_mutex_unlock(gBleLocalAddressMutex);
-
-    // Start a GattServer/Client if gLeServerStatus is SET
-    if (CA_LISTENING_SERVER == gLeServerStatus)
+    ca_mutex_lock(g_bleClientSendDataMutex);
+    if (NULL != g_bleClientSendQueueHandle)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattServer");
-        CAStartBleGattServer();
+        CAQueueingThreadStop(g_bleClientSendQueueHandle);
     }
-    else if (CA_DISCOVERY_SERVER == gLeServerStatus)
+    ca_mutex_unlock(g_bleClientSendDataMutex);
+
+    ca_mutex_lock(g_bleClientReceiveDataMutex);
+    if (NULL != g_bleClientReceiverQueue)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattClient");
-        CAStartBLEGattClient();
+        CAQueueingThreadStop(g_bleClientReceiverQueue);
     }
-    gLeServerStatus = CA_SERVER_NOTSTARTED;
+    ca_mutex_unlock(g_bleClientReceiveDataMutex);
 
-    u_mutex_lock(gBleNetworkCbMutex);
-    if (NULL != gNetworkCallback)
+    ca_mutex_lock(g_bleServerSendDataMutex);
+    if (NULL != g_bleServerSendQueueHandle)
     {
-        gNetworkCallback(&localEndpoint, adapter_state);
+        CAQueueingThreadStop(g_bleServerSendQueueHandle);
     }
-    else
+    ca_mutex_unlock(g_bleServerSendDataMutex);
+
+    ca_mutex_lock(g_bleServerReceiveDataMutex);
+    if (NULL != g_bleServerReceiverQueue)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "gNetworkCallback is NULL");
+        CAQueueingThreadStop(g_bleServerReceiverQueue);
     }
-    u_mutex_unlock(gBleNetworkCbMutex);
+    ca_mutex_unlock(g_bleServerReceiveDataMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-CAResult_t CAInitBleAdapterMutex()
+void CATerminateLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_init();
-    if (NULL == gBleIsServerMutex)
-    {
-        gBleIsServerMutex = u_mutex_new();
-        if (NULL == gBleIsServerMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+    CAQueueingThreadDestroy(g_bleClientSendQueueHandle);
+    OICFree(g_bleClientSendQueueHandle);
+    g_bleClientSendQueueHandle = NULL;
 
-    if (NULL == gBleNetworkCbMutex)
-    {
-        gBleNetworkCbMutex = u_mutex_new();
-        if (NULL == gBleNetworkCbMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
 
-    if (NULL == gBleLocalAddressMutex)
-    {
-        gBleLocalAddressMutex = u_mutex_new();
-        if (NULL == gBleLocalAddressMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+    CAQueueingThreadDestroy(g_bleClientReceiverQueue);
+    OICFree(g_bleClientReceiverQueue);
+    g_bleClientReceiverQueue = NULL;
 
-    if (NULL == gBleAdapterThreadPoolMutex)
+
+    CAQueueingThreadDestroy(g_bleServerSendQueueHandle);
+    OICFree(g_bleServerSendQueueHandle);
+    g_bleServerSendQueueHandle = NULL;
+
+
+    CAQueueingThreadDestroy(g_bleServerReceiverQueue);
+    OICFree(g_bleServerReceiverQueue);
+    g_bleServerReceiverQueue = NULL;
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+}
+
+void CALEServerDataReceiverHandler(void *threadData)
+{
+    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)
+        {
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bleData!");
+            return;
+        }
+
+        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)
+        {
+            ca_mutex_lock(g_bleAdapterReqRespCbMutex);
+            if (NULL == g_networkPacketReceivedCallback)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
+                ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
+                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");
+            recvDataLen = 0;
+            totalDataLen = 0;
+            isHeaderAvailable = false;
+            OICFree(defragData);
+            CAFreeEndpoint(remoteEndpoint);
+            ca_mutex_unlock(g_bleServerReceiveDataMutex);
+            return;
+        }
+    }
+    ca_mutex_unlock(g_bleServerReceiveDataMutex);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+}
+
+void CALEClientDataReceiverHandler(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);
+
+    if (g_dataReceiverHandlerState)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
+
+        CALEData_t *bleData = (CALEData_t *) threadData;
+        if (!bleData)
+        {
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid wifidata!");
+            return;
+        }
+
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
+
+        if (!isHeaderAvailable)
+        {
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
+
+            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);
+
+            defragData = (char *) OICMalloc(sizeof(char) * totalDataLen);
+            if (NULL == defragData)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
+                return;
+            }
+
+            remoteAddress = bleData->remoteEndpoint->addr;
+
+            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
+                                                    remoteAddress, 0);
+
+            memcpy(defragData, 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)
+        {
+            ca_mutex_lock(g_bleAdapterReqRespCbMutex);
+            if (NULL == g_networkPacketReceivedCallback)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
+                ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
+                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;
+        }
+    }
+    ca_mutex_unlock(g_bleClientReceiveDataMutex);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+}
+
+void CALEServerSendDataThread(void *threadData)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    CALEData_t *bleData = (CALEData_t *) threadData;
+    if (!bleData)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
+        return;
+    }
+
+    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
+
+    int32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+
+    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");
+        OICFree(header);
+        return;
+    }
+
+    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    if (CA_STATUS_OK != result )
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
+        OICFree(header);
+        OICFree(dataSegment);
+        return ;
+    }
+
+    memcpy(dataSegment, header, CA_HEADER_LENGTH);
+    OICFree(header);
+
+    int32_t length = 0;
+    if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
+    {
+        length = totalLength;
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+    }
+    else
+    {
+        length =  CA_SUPPORTED_BLE_MTU_SIZE;
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
+               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
+    }
+
+    int32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    int32_t index = 0;
+    // Send the first segment with the header.
+     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);
+            OICFree(dataSegment);
+            return;
+        }
+
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", 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);
+            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);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]",
+                                               CA_SUPPORTED_BLE_MTU_SIZE);
+        }
+
+        int32_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)
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
+            result = CAUpdateCharacteristicsToGattClient(
+                         bleData->remoteEndpoint->addr,
+                         bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                         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);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", remainingLen);
+        }
+     }
+    else
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Server Sending Multicast data");
+        result = CAUpdateCharacteristicsToAllGattClients(dataSegment, length);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
+                      result);
+            CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+            OICFree(dataSegment);
+            return;
+        }
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", length);
+        for (index = 1; index < iter; index++)
+        {
+            // Send the remaining header.
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
+            result = CAUpdateCharacteristicsToAllGattClients(
+                         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, "Update characteristics failed, result [%d]",
+                          result);
+                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", CA_SUPPORTED_BLE_MTU_SIZE);
+        }
+
+        int32_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)
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
+            result = CAUpdateCharacteristicsToAllGattClients(
+                         bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                         remainingLen);
+            if (CA_STATUS_OK != result)
+            {
+                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
+                          result);
+                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", remainingLen);
+        }
+    }
+    OICFree(dataSegment);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+}
+
+void CALEClientSendDataThread(void *threadData)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    CALEData_t *bleData = (CALEData_t *) threadData;
+    if (!bleData)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
+        return;
+    }
+
+    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    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));
+    if (NULL == dataSegment)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
+        OICFree(header);
+        return;
+    }
+
+    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    if (CA_STATUS_OK != result )
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
+        OICFree(header);
+        OICFree(dataSegment);
+        return ;
+    }
+    memcpy(dataSegment, header, CA_HEADER_LENGTH);
+    OICFree(header);
+
+    uint32_t length = 0;
+    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);
+    }
+    else
+    {
+        length = CA_SUPPORTED_BLE_MTU_SIZE;
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length  [%d]", length);
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
+               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
+    }
+
+    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);
+
+        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);
+            OICFree(dataSegment);
+            return ;
+        }
+
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
+        for (index = 1; index < iter; index++)
+        {
+            // Send the remaining header.
+            result = CAUpdateCharacteristicsToGattServer(
+                     bleData->remoteEndpoint->addr,
+                     bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                     CA_SUPPORTED_BLE_MTU_SIZE,
+                     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);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]",
+                                               CA_SUPPORTED_BLE_MTU_SIZE);
+        }
+
+        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)
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
+            result = CAUpdateCharacteristicsToGattServer(
+                     bleData->remoteEndpoint->addr,
+                     bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                     remainingLen,
+                     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);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", remainingLen);
+        }
+    }
+    else
+    {
+        //Sending Mulitcast Data
+        // Send the first segment with the header.
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Multicast Data");
+        result = CAUpdateCharacteristicsToAllGattServers(dataSegment, length);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG_V(ERROR, CALEADAPTER_TAG,
+                      "Update characteristics (all) failed, result [%d]", result);
+            CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+            OICFree(dataSegment);
+            return ;
+        }
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
+        // Send the remaining header.
+        for (index = 1; index < iter; index++)
+        {
+            result = CAUpdateCharacteristicsToAllGattServers(
+                         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, "Update characteristics (all) failed, result [%d]",
+                          result);
+                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]",
+                      CA_SUPPORTED_BLE_MTU_SIZE);
+        }
+
+        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)
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
+            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,
+                          "Update characteristics (all) failed, result [%d]", result);
+                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
+                OICFree(dataSegment);
+                return;
+            }
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", remainingLen);
+        }
+
+    }
+
+    OICFree(dataSegment);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT - CABLEClientSendDataThread");
+}
+
+CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
+                           uint32_t dataLength)
+{
+    CALEData_t *bleData = (CALEData_t *) OICMalloc(sizeof(CALEData_t));
+    if (!bleData)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return NULL;
+    }
+
+    bleData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
+    bleData->data = (void *)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)
+{
+    VERIFY_NON_NULL_VOID(bleData, NULL, "Param bleData is NULL");
+
+    CAFreeEndpoint(bleData->remoteEndpoint);
+    OICFree(bleData->data);
+    OICFree(bleData);
+}
+
+void CALEDataDestroyer(void *data, uint32_t size)
+{
+    CALEData_t *ledata = (CALEData_t *) data;
+
+    CAFreeLEData(ledata);
+}
+#endif
+
+CAResult_t CAInitLEAdapterMutex()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    if (NULL == g_bleIsServerMutex)
+    {
+        g_bleIsServerMutex = ca_mutex_new();
+        if (NULL == g_bleIsServerMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (NULL == g_bleNetworkCbMutex)
     {
-        gBleAdapterThreadPoolMutex = u_mutex_new();
-        if (NULL == gBleAdapterThreadPoolMutex)
+        g_bleNetworkCbMutex = ca_mutex_new();
+        if (NULL == g_bleNetworkCbMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    if (NULL == gBleClientSendDataMutex)
+    if (NULL == g_bleLocalAddressMutex)
     {
-        gBleClientSendDataMutex = u_mutex_new();
-        if (NULL == gBleClientSendDataMutex)
+        g_bleLocalAddressMutex = ca_mutex_new();
+        if (NULL == g_bleLocalAddressMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    if (NULL == gBleClientReceiveDataMutex)
+    if (NULL == g_bleAdapterThreadPoolMutex)
     {
-        gBleClientReceiveDataMutex = u_mutex_new();
-        if (NULL == gBleClientReceiveDataMutex)
+        g_bleAdapterThreadPoolMutex = ca_mutex_new();
+        if (NULL == g_bleAdapterThreadPoolMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    if (NULL == gBleServerSendDataMutex)
+    if (NULL == g_bleClientSendDataMutex)
     {
-        gBleServerSendDataMutex = u_mutex_new();
-        if (NULL == gBleServerSendDataMutex)
+        g_bleClientSendDataMutex = ca_mutex_new();
+        if (NULL == g_bleClientSendDataMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    if (NULL == gBleServerReceiveDataMutex)
+    if (NULL == g_bleClientReceiveDataMutex)
     {
-        gBleServerReceiveDataMutex = u_mutex_new();
-        if (NULL == gBleServerReceiveDataMutex)
+        g_bleClientReceiveDataMutex = ca_mutex_new();
+        if (NULL == g_bleClientReceiveDataMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    if (NULL == gBleAdapterReqRespCbMutex)
+    if (NULL == g_bleServerSendDataMutex)
     {
-        gBleAdapterReqRespCbMutex = u_mutex_new();
-        if (NULL == gBleAdapterReqRespCbMutex)
+        g_bleServerSendDataMutex = ca_mutex_new();
+        if (NULL == g_bleServerSendDataMutex)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "u_mutex_new failed");
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
             return CA_STATUS_FAILED;
         }
     }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    if (NULL == g_bleServerReceiveDataMutex)
+    {
+        g_bleServerReceiveDataMutex = ca_mutex_new();
+        if (NULL == g_bleServerReceiveDataMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (NULL == g_bleAdapterReqRespCbMutex)
+    {
+        g_bleAdapterReqRespCbMutex = ca_mutex_new();
+        if (NULL == g_bleAdapterReqRespCbMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
-CAResult_t CATermiateBleAdapterMutex()
+
+void CATerminateLEAdapterMutex()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_free(gBleIsServerMutex);
-    gBleIsServerMutex = NULL;
-
-    u_mutex_free(gBleNetworkCbMutex);
-    gBleNetworkCbMutex = NULL;
-
-    u_mutex_free(gBleLocalAddressMutex);
-    gBleLocalAddressMutex = NULL;
+    ca_mutex_free(g_bleIsServerMutex);
+    g_bleIsServerMutex = NULL;
 
-    u_mutex_free(gBleAdapterThreadPoolMutex);
-    gBleAdapterThreadPoolMutex = NULL;
+    ca_mutex_free(g_bleNetworkCbMutex);
+    g_bleNetworkCbMutex = NULL;
 
-    u_mutex_free(gBleClientSendDataMutex);
-    gBleClientSendDataMutex = NULL;
+    ca_mutex_free(g_bleLocalAddressMutex);
+    g_bleLocalAddressMutex = NULL;
 
-    u_mutex_free(gBleClientReceiveDataMutex);
-    gBleClientReceiveDataMutex = NULL;
+    ca_mutex_free(g_bleAdapterThreadPoolMutex);
+    g_bleAdapterThreadPoolMutex = NULL;
 
-    u_mutex_free(gBleServerSendDataMutex);
-    gBleServerSendDataMutex = NULL;
+    ca_mutex_free(g_bleClientSendDataMutex);
+    g_bleClientSendDataMutex = NULL;
 
-    u_mutex_free(gBleServerReceiveDataMutex);
-    gBleServerReceiveDataMutex = NULL;
-
-    u_mutex_free(gBleAdapterReqRespCbMutex);
-    gBleAdapterReqRespCbMutex = NULL;
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
+    ca_mutex_free(g_bleClientReceiveDataMutex);
+    g_bleClientReceiveDataMutex = NULL;
 
-void CAInitBleQueues()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    ca_mutex_free(g_bleServerSendDataMutex);
+    g_bleServerSendDataMutex = NULL;
 
-    CAResult_t result = CAInitBleServerQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return;
-    }
+    ca_mutex_free(g_bleServerReceiveDataMutex);
+    g_bleServerReceiveDataMutex = NULL;
 
-    result = CAInitBleClientQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return;
-    }
+    ca_mutex_free(g_bleAdapterReqRespCbMutex);
+    g_bleAdapterReqRespCbMutex = NULL;
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return;
-
 }
 
-CAResult_t CAInitBleServerQueues()
+CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
+                          CANetworkPacketReceivedCallback reqRespCallback,
+                          CANetworkChangeCallback netCallback,
+                          CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_lock(gBleAdapterThreadPoolMutex);
+    //Input validation
+    VERIFY_NON_NULL(registerCallback, NULL, "RegisterConnectivity callback is null");
+    VERIFY_NON_NULL(reqRespCallback, NULL, "PacketReceived Callback is null");
+    VERIFY_NON_NULL(netCallback, NULL, "NetworkChange Callback is null");
 
-    CAResult_t result = CAInitBleServerSenderQueue();
+    CAResult_t result = CA_STATUS_OK;
+    result = CAInitLEAdapterMutex();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        u_mutex_unlock(gBleAdapterThreadPoolMutex);
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleAdapterMutex failed!");
         return CA_STATUS_FAILED;
     }
-
-    result = CAInitBleServerReceiverQueue();
+    result = CAInitializeLENetworkMonitor();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        u_mutex_unlock(gBleAdapterThreadPoolMutex);
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitializeLENetworkMonitor() failed");
         return CA_STATUS_FAILED;
     }
 
-    gDataReceiverHandlerState = true;
+    CAInitializeLEAdapter();
+
+    CASetLEClientThreadPoolHandle(handle);
+    CASetLEReqRespClientCallback(CALEAdapterClientReceivedData);
+    CASetLEServerThreadPoolHandle(handle);
+    CASetLEAdapterThreadPoolHandle(handle);
+    CASetLEReqRespServerCallback(CALEAdapterServerReceivedData);
+    CASetLEReqRespAdapterCallback(reqRespCallback);
+
+    CASetBLEClientErrorHandleCallback(CALEErrorHandler);
+    CASetBLEServerErrorHandleCallback(CALEErrorHandler);
+    CALERegisterNetworkNotifications(netCallback);
+
+    g_errorHandler = errorCallback;
 
-    u_mutex_unlock(gBleAdapterThreadPoolMutex);
+    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;
+    registerCallback(connHandler, CA_ADAPTER_GATT_BTLE);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleClientQueues()
+CAResult_t CAStartLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    u_mutex_lock(gBleAdapterThreadPoolMutex);
-
-    CAResult_t result = CAInitBleClientSenderQueue();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        u_mutex_unlock(gBleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
-    }
-
-    result = CAInitBleClientReceiverQueue();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        u_mutex_unlock(gBleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
-    }
-
-    gDataReceiverHandlerState = true;
-
-    u_mutex_unlock(gBleAdapterThreadPoolMutex);
-
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE, not implemented");
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleServerSenderQueue()
+CAResult_t CAStopLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    // Check if the message queue is already initialized
-    if (gSendQueueHandle)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
-    }
-
-    // Create send message queue
-    gSendQueueHandle = OICMalloc(sizeof(CAQueueingThread_t));
-    if (!gSendQueueHandle)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return CA_MEMORY_ALLOC_FAILED;
-    }
+#ifndef SINGLE_THREAD
+    CAStopLEQueues();
+#endif
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(gSendQueueHandle, gBleAdapterThreadPool,
-            CABLEServerSendDataThread))
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true == g_isServer)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(gSendQueueHandle);
-        gSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
+        CAStopLEGattServer();
     }
-
-    if (CA_STATUS_OK != CAQueueingThreadStart(gSendQueueHandle))
+    else
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "u_thread_pool_add_task failed ");
-        OICFree(gSendQueueHandle);
-        gSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
+        CAStopLEGattClient();
     }
-
+    ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
 
+    return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleClientSenderQueue()
+void CATerminateLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    if (gBLEClientSendQueueHandle)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
-    }
+    CASetLEReqRespServerCallback(NULL);
+    CASetLEReqRespClientCallback(NULL);
+    CALERegisterNetworkNotifications(NULL);
+    CASetLEReqRespAdapterCallback(NULL);
+    CATerminateLENetworkMonitor();
 
-    // Create send message queue
-    gBLEClientSendQueueHandle = OICMalloc(sizeof(CAQueueingThread_t));
-    if (!gBLEClientSendQueueHandle)
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true == g_isServer)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return CA_MEMORY_ALLOC_FAILED;
+        CATerminateLEGattServer();
     }
-
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(gBLEClientSendQueueHandle, gBleAdapterThreadPool,
-            CABLEClientSendDataThread))
+    else
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(gBLEClientSendQueueHandle);
-        gBLEClientSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
+        CATerminateLEGattClient();
     }
+    ca_mutex_unlock(g_bleIsServerMutex);
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(gBLEClientSendQueueHandle))
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "u_thread_pool_add_task failed ");
-        OICFree(gBLEClientSendQueueHandle);
-        gBLEClientSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
-    }
+#ifndef SINGLE_THREAD
+    CATerminateLEQueues();
+#endif
+    CATerminateLEAdapterMutex();
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleServerReceiverQueue()
+CAResult_t CAStartLEListeningServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    // Check if the message queue is already initialized
-    if (gCABleServerReceiverQueue)
+    CAResult_t result = CA_STATUS_OK;
+#ifndef SINGLE_THREAD
+    result = CAInitLEServerQueues();
+    if (CA_STATUS_OK != result)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEServerQueues failed");
+        return CA_STATUS_FAILED;
     }
+#endif
 
-    // Create send message queue
-    gCABleServerReceiverQueue = OICMalloc(sizeof(CAQueueingThread_t));
-    if (!gCABleServerReceiverQueue)
+    result = CAGetLEAdapterState();
+    if (CA_ADAPTER_NOT_ENABLED == result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        OICFree(gSendQueueHandle);
-        return CA_MEMORY_ALLOC_FAILED;
+        gLeServerStatus = CA_LISTENING_SERVER;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
+        return CA_STATUS_OK;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(gCABleServerReceiverQueue, gBleAdapterThreadPool,
-            CABLEServerDataReceiverHandler))
+    if (CA_STATUS_FAILED == result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(gCABleServerReceiverQueue);
-        gCABleServerReceiverQueue = NULL;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
         return CA_STATUS_FAILED;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(gCABleServerReceiverQueue))
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "u_thread_pool_add_task failed ");
-        OICFree(gCABleServerReceiverQueue);
-        gCABleServerReceiverQueue = NULL;
-        return CA_STATUS_FAILED;
-    }
+    CAStartLEGattServer();
+
+    ca_mutex_lock(g_bleIsServerMutex);
+    g_isServer = true;
+    ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleClientReceiverQueue()
+CAResult_t CAStartLEDiscoveryServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    // Check if the message queue is already initialized
-    if (gCABleClientReceiverQueue)
+    CAResult_t result = CA_STATUS_OK;
+#ifndef SINGLE_THREAD
+    result = CAInitLEClientQueues();
+    if (CA_STATUS_OK != result)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEClientQueues failed");
+        return CA_STATUS_FAILED;
     }
-    else
+#endif
+    result = CAGetLEAdapterState();
+    if (CA_ADAPTER_NOT_ENABLED == result)
     {
-        // Create send message queue
-        gCABleClientReceiverQueue = OICMalloc(sizeof(CAQueueingThread_t));
-        if (!gCABleClientReceiverQueue)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-            OICFree(gBLEClientSendQueueHandle);
-            return CA_MEMORY_ALLOC_FAILED;
-        }
-
-        if (CA_STATUS_OK != CAQueueingThreadInitialize(gCABleClientReceiverQueue, gBleAdapterThreadPool,
-                CABLEClientDataReceiverHandler))
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-            OICFree(gBLEClientSendQueueHandle);
-            OICFree(gCABleClientReceiverQueue);
-            gCABleClientReceiverQueue = NULL;
-            return CA_STATUS_FAILED;
-        }
+        gLeServerStatus = CA_DISCOVERY_SERVER;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
+        return CA_STATUS_OK;
     }
-    //gClientUp = CA_TRUE; //AMOGH
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(gCABleClientReceiverQueue))
+    if (CA_STATUS_FAILED == result)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "u_thread_pool_add_task failed ");
-        OICFree(gCABleClientReceiverQueue);
-        gCABleClientReceiverQueue = NULL;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
         return CA_STATUS_FAILED;
     }
 
+    CAStartLEGattClient();
+
+    ca_mutex_lock(g_bleIsServerMutex);
+    g_isServer = false;
+    ca_mutex_unlock(g_bleIsServerMutex);
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-void CATerminateBleQueues()
+CAResult_t CAStartLENotifyServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_lock(gBleClientSendDataMutex);
-    if (NULL != gBLEClientSendQueueHandle)
-    {
-        CAQueueingThreadStop(gBLEClientSendQueueHandle);
-        gBLEClientSendQueueHandle = NULL;
-    }
-    u_mutex_unlock(gBleClientSendDataMutex);
-
-    u_mutex_lock(gBleClientReceiveDataMutex);
-    if (NULL != gCABleClientReceiverQueue)
-    {
-        CAQueueingThreadStop(gCABleClientReceiverQueue);
-        gCABleClientReceiverQueue = NULL;
-    }
-    u_mutex_unlock(gBleClientReceiveDataMutex);
-
-    u_mutex_lock(gBleServerSendDataMutex);
-    if (NULL != gBLEClientSendQueueHandle)
-    {
-        CAQueueingThreadStop(gBLEClientSendQueueHandle);
-        gBLEClientSendQueueHandle = NULL;
-    }
-    u_mutex_unlock(gBleServerSendDataMutex);
-
-    u_mutex_lock(gBleServerReceiveDataMutex);
-    if (NULL != gCABleServerReceiverQueue)
-    {
-        CAQueueingThreadStop(gCABleServerReceiverQueue);
-        gCABleServerReceiverQueue = NULL;
-    }
-    u_mutex_unlock(gBleServerReceiveDataMutex);
-
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-void CABLEServerDataReceiverHandler(void *threadData)
+uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
+                              uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "IN");
-
-    // CAAdapterMessage_t *message = NULL;
-    static const char *remoteAddress = NULL;
-    static const char *serviceUUID = NULL;
-    static uint32_t recvDataLen = 0;
-    static uint32_t totalDataLen = 0;
-    static char *defragData = NULL;
-    static bool isHeaderAvailable = false;
-    static CARemoteEndpoint_t *remoteEndpoint = NULL;
-
-    u_mutex_lock(gBleClientReceiveDataMutex);
-
-    if (gDataReceiverHandlerState)
-    {
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        CABLEData *bleData = (CABLEData *) threadData;
-        if (!bleData)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid wifidata!");
-            return;
-        }
-
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        if (!isHeaderAvailable)
-        {
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-            char *header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
-            VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "header is NULL");
-
-            memcpy(header, bleData->data, CA_HEADER_LENGTH);
-            totalDataLen = CAParseHeader(header);
-            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 *) OICMalloc(sizeof(char) * totalDataLen);
-            if (NULL == defragData)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-                OICFree(header);
-                return;
-            }
-
-            OICFree(header);
-
-            remoteAddress = bleData->remoteEndpoint->addressInfo.LE.leMacAddress;
-            serviceUUID = bleData->remoteEndpoint->resourceUri;
-
-            remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
-                             serviceUUID);
-
-            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);
-        }
-        CAFreeBLEData(bleData);
-        if (totalDataLen == recvDataLen)
-        {
-            u_mutex_lock(gBleAdapterReqRespCbMutex);
-            if (NULL == gNetworkPacketReceivedCallback)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
-                u_mutex_unlock(gBleAdapterReqRespCbMutex);
-                return;
-            }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending data up !");
-            gNetworkPacketReceivedCallback(remoteEndpoint, defragData, recvDataLen);
-            recvDataLen = 0;
-            totalDataLen = 0;
-            isHeaderAvailable = false;
-            u_mutex_unlock(gBleAdapterReqRespCbMutex);
-        }
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-        if (false == gDataReceiverHandlerState)
-        {
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "GATTClient is terminating. Cleaning up");
-            OICFree(defragData);
-            OICFree(remoteEndpoint);
-            u_mutex_unlock(gBleClientReceiveDataMutex);
-            return;
-        }
-    }
-    u_mutex_unlock(gBleClientReceiveDataMutex);
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "OUT");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return 0;
 }
 
-void CABLEClientDataReceiverHandler(void *threadData)
-{
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "IN");
-
-    // CAAdapterMessage_t *message = NULL;
-    static const char *remoteAddress = NULL;
-    static const char *serviceUUID = NULL;
-    static uint32_t recvDataLen = 0;
-    static uint32_t totalDataLen = 0;
-    static char *defragData = NULL;
-    static bool isHeaderAvailable = false;
-    static CARemoteEndpoint_t *remoteEndpoint = NULL;
-
-    u_mutex_lock(gBleClientReceiveDataMutex);
-
-    if (gDataReceiverHandlerState)
-    {
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        CABLEData *bleData = (CABLEData *) threadData;
-        if (!bleData)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid wifidata!");
-            return;
-        }
-
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
-
-        if (!isHeaderAvailable)
-        {
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-            char *header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
-            VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "header is NULL");
-
-            memcpy(header, bleData->data, CA_HEADER_LENGTH);
-            totalDataLen = CAParseHeader(header);
-            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 *) OICMalloc(sizeof(char) * totalDataLen);
-            if (NULL == defragData)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-                OICFree(header);
-                return;
-            }
+CAResult_t CAReadLEData()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+#ifdef SINGLE_THREAD
+    CACheckLEData();
+#endif
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
+}
 
-            OICFree(header);
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-            remoteAddress = bleData->remoteEndpoint->addressInfo.LE.leMacAddress;
-            serviceUUID = bleData->remoteEndpoint->resourceUri;
+    //Input validation
+    VERIFY_NON_NULL_RET(endpoint, NULL, "Remote endpoint is null", -1);
+    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
 
-            remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
-                             serviceUUID);
+    CAResult_t result = CA_STATUS_FAILED;
 
-            memcpy(defragData , 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);
-        }
-        CAFreeBLEData(bleData);
-        if (totalDataLen == recvDataLen)
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true  == g_isServer)
+    {
+        result = CALEAdapterServerSendData(endpoint, data, dataLen);
+        if (CA_STATUS_OK != result)
         {
-            u_mutex_lock(gBleAdapterReqRespCbMutex);
-            if (NULL == gNetworkPacketReceivedCallback)
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Send unicast data failed\n");
+            if (g_errorHandler)
             {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "gReqRespCallback is NULL!");
-                u_mutex_unlock(gBleAdapterReqRespCbMutex);
-                return;
+                g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending data up !");
-            gNetworkPacketReceivedCallback(remoteEndpoint, defragData, recvDataLen);
-            recvDataLen = 0;
-            totalDataLen = 0;
-            isHeaderAvailable = false;
-            u_mutex_unlock(gBleAdapterReqRespCbMutex);
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
         }
-
-        if (false == gDataReceiverHandlerState)
+    }
+    else
+    {
+        result = CALEAdapterClientSendData(endpoint, data, dataLen);
+        if (CA_STATUS_OK != result)
         {
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "GATTClient is terminating. Cleaning up");
-            OICFree(defragData);
-            OICFree(remoteEndpoint);
-            u_mutex_unlock(gBleClientReceiveDataMutex);
-            return;
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Send unicast data failed \n");
+            if (g_errorHandler)
+            {
+                g_errorHandler(endpoint, data, dataLen, result);
+            }
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
         }
     }
-    u_mutex_unlock(gBleClientReceiveDataMutex);
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "OUT");
+    ca_mutex_unlock(g_bleIsServerMutex);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return dataLen;
 }
 
-void CABLEServerSendDataThread(void *threadData)
+int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CABLEData *bleData = (CABLEData *) threadData;
-    if (!bleData)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
-        return;
-    }
-    char *header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
-    VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
+    //Input validation
+    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
 
-    char *dataSegment = (char *) OICMalloc(sizeof(char) * bleData->dataLen + CA_HEADER_LENGTH);
-    if (NULL == dataSegment)
+    if (0 >= dataLen)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
-        OICFree(header);
-        return;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Invalid Parameter");
+        return -1;
     }
 
-    memset(header, 0x0, sizeof(char) * CA_HEADER_LENGTH );
-    memset(dataSegment, 0x0, sizeof(char) * bleData->dataLen );
+    CAResult_t result = CA_STATUS_FAILED;
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
-    if (CA_STATUS_OK != result )
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true  == g_isServer)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
-        OICFree(header);
-        OICFree(dataSegment);
-        return ;
-    }
+        result = CALEAdapterServerSendData(NULL, data, dataLen);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Send multicast data failed" );
 
-    memcpy(dataSegment, header, CA_HEADER_LENGTH);
-    OICFree(header);
-    int32_t length = 0;
-    if (CA_SUPPORTED_BLE_MTU_SIZE >= bleData->dataLen)
-    {
-        length = bleData->dataLen + CA_HEADER_LENGTH;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+            ca_mutex_unlock(g_bleIsServerMutex);
+            if (g_errorHandler)
+            {
+                g_errorHandler(endpoint, data, dataLen, result);
+            }
+            return -1;
+        }
     }
     else
     {
-        length =  CA_SUPPORTED_BLE_MTU_SIZE;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
-               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
-    }
-
-    int32_t iter = bleData->dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
-    int32_t index = 0;
-    u_mutex_lock(gBleServerSendDataMutex);
-    // Send the first segment with the header.
-    result = CAUpdateCharacteristicsInGattServer(dataSegment, length);
-    for (index = 1; index < iter; index++)
-    {
-        // Send the remaining header.
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
-        result = CAUpdateCharacteristicsInGattServer(
-                     bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
-                     CA_SUPPORTED_BLE_MTU_SIZE);
-    }
-    if (bleData->dataLen / CA_SUPPORTED_BLE_MTU_SIZE)
-    {
-        // 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 = CAUpdateCharacteristicsInGattServer(
-                     bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                     bleData->dataLen % CA_SUPPORTED_BLE_MTU_SIZE + CA_HEADER_LENGTH);
+        result = CALEAdapterClientSendData(NULL, data, dataLen);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Send Multicast data failed" );
+            if (g_errorHandler)
+            {
+                g_errorHandler(endpoint, data, dataLen, result);
+            }
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
+        }
     }
-
-    OICFree(bleData->remoteEndpoint);
-    OICFree(bleData);
-    u_mutex_unlock(gBleServerSendDataMutex); // AMOGH is this mutex required  ?
+    ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return;
-
+    return dataLen;
 }
 
-void CABLEClientSendDataThread(void *threadData)
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CABLEData *bleData = (CABLEData *) threadData;
-    if (!bleData)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
-        return;
-    }
-    char *header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
-    VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
+    VERIFY_NON_NULL(info, NULL, "CALocalConnectivity info is null");
 
-    char *dataSegment = (char *) OICMalloc(sizeof(char) * bleData->dataLen + CA_HEADER_LENGTH);
-    if (NULL == dataSegment)
+    char *local_address = NULL;
+
+    CAResult_t res = CAGetLEAddress(&local_address);
+    if (CA_STATUS_OK != res)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
-        OICFree(header);
-        return;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAGetLEAddress has failed");
+        return res;
     }
 
-    memset(header, 0x0, sizeof(char) * CA_HEADER_LENGTH );
-    memset(dataSegment, 0x0, sizeof(char) * bleData->dataLen );
-
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
-    if (CA_STATUS_OK != result )
+    if (NULL == local_address)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
-        OICFree(header);
-        OICFree(dataSegment);
-        return ;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is NULL");
+        return CA_STATUS_FAILED;
     }
-    memcpy(dataSegment, header, CA_HEADER_LENGTH);
-    OICFree(header);
-    int32_t length = 0;
-    if (CA_SUPPORTED_BLE_MTU_SIZE >= bleData->dataLen)
+
+    *size = 0;
+    (*info) = (CAEndpoint_t *) OICCalloc(1, sizeof(CAEndpoint_t));
+    if (NULL == (*info))
     {
-        length = bleData->dataLen + CA_HEADER_LENGTH;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failure!");
+        OICFree(local_address);
+        return CA_STATUS_FAILED;
     }
-    else
+
+    size_t local_address_len = strlen(local_address);
+
+    if(local_address_len >= sizeof(g_localBLEAddress) ||
+            local_address_len >= MAX_ADDR_STR_SIZE_CA - 1)
     {
-        length = CA_SUPPORTED_BLE_MTU_SIZE;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
-               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is too long");
+        OICFree(*info);
+        OICFree(local_address);
+        return CA_STATUS_FAILED;
     }
 
-    int32_t iter = bleData->dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
-    int32_t index = 0;
-    u_mutex_lock(gBleClientSendDataMutex);
-    if (NULL != bleData->remoteEndpoint)
+    OICStrcpy((*info)->addr, sizeof((*info)->addr), local_address);
+    ca_mutex_lock(g_bleLocalAddressMutex);
+    OICStrcpy(g_localBLEAddress, sizeof(g_localBLEAddress), local_address);
+    ca_mutex_unlock(g_bleLocalAddressMutex);
+
+    (*info)->adapter = CA_ADAPTER_GATT_BTLE;
+    *size = 1;
+    OICFree(local_address);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
+CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    ca_mutex_lock(g_bleNetworkCbMutex);
+    g_networkCallback = netCallback;
+    ca_mutex_unlock(g_bleNetworkCbMutex);
+    CAResult_t res = CA_STATUS_OK;
+    if (netCallback)
     {
-        // Send the first segment with the header.
-        result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
-                 dataSegment,
-                 length,
-                 UNICAST, 0);
-        for (index = 1; index < iter; index++)
-        {
-            // Send the remaining header.
-            result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
-                     bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                     CA_SUPPORTED_BLE_MTU_SIZE,
-                     UNICAST, 0);
-        }
-        if (bleData->dataLen / CA_SUPPORTED_BLE_MTU_SIZE)
+        res = CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCb);
+        if (CA_STATUS_OK != res)
         {
-            // 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->addressInfo.LE.leMacAddress,
-                     bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                     bleData->dataLen % CA_SUPPORTED_BLE_MTU_SIZE + CA_HEADER_LENGTH,
-                     UNICAST, 0);
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
         }
     }
     else
     {
-        // Send the first segment with the header.
-        result = CAUpdateCharacteristicsToAllGattServers(dataSegment + (index * length),
-                 length);
-        // Send the remaining header.
-        for (index = 1; index <= iter; index++)
-        {
-            result = CAUpdateCharacteristicsToAllGattServers(
-                         bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                         CA_SUPPORTED_BLE_MTU_SIZE);
-        }
-        if (bleData->dataLen / CA_SUPPORTED_BLE_MTU_SIZE)
+        res = CAUnSetLEAdapterStateChangedCb();
+        if (CA_STATUS_OK != res)
         {
-            // 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,
-                         bleData->dataLen % CA_SUPPORTED_BLE_MTU_SIZE + CA_HEADER_LENGTH);
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
         }
     }
 
-    OICFree(bleData->remoteEndpoint);
-    OICFree(bleData);
-    u_mutex_unlock(gBleClientSendDataMutex);
-
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return;
-
+    return res;
 }
 
-CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
-                           uint32_t dataLength)
+void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
 {
-    CABLEData *bleData = (CABLEData *) OICMalloc(sizeof(CABLEData));
-    if (!bleData)
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    VERIFY_NON_NULL_VOID(g_localBLEAddress, NULL, "g_localBLEAddress is null");
+    CAEndpoint_t localEndpoint = {};
+
+    ca_mutex_lock(g_bleLocalAddressMutex);
+    OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), g_localBLEAddress);
+    ca_mutex_unlock(g_bleLocalAddressMutex);
+
+    g_bleAdapterState = adapter_state;
+    // Start a GattServer/Client if gLeServerStatus is SET
+    if (CA_LISTENING_SERVER == gLeServerStatus)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return NULL;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartLEGattServer");
+        CAStartLEGattServer();
     }
-
-    bleData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
-    bleData->data = (void *)OICMalloc(dataLength);
-    if (NULL == bleData->data)
+    else if (CA_DISCOVERY_SERVER == gLeServerStatus)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        CAFreeBLEData(bleData);
-        return NULL;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattClient");
+        CAStartLEGattClient();
     }
-    memcpy(bleData->data, data, dataLength);
-    bleData->dataLen = dataLength;
-
-    return bleData;
-}
+    gLeServerStatus = CA_SERVER_NOTSTARTED;
 
-void CAFreeBLEData(CABLEData *bleData)
-{
-    if (!bleData)
-        return;
+    ca_mutex_lock(g_bleNetworkCbMutex);
+    if (NULL != g_networkCallback)
+    {
+        g_networkCallback(&localEndpoint, adapter_state);
+    }
+    else
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "g_networkCallback is NULL");
+    }
+    ca_mutex_unlock(g_bleNetworkCbMutex);
 
-    CAAdapterFreeRemoteEndpoint(bleData->remoteEndpoint);
-    OICFree(bleData->data);
-    OICFree(bleData);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
-                               void *data,
-                               uint32_t dataLen)
+CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data,
+                                     uint32_t dataLen)
 {
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN ");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, NULL, "Param data is NULL");
-
-    VERIFY_NON_NULL_RET(gBLEClientSendQueueHandle, CALEADAPTER_TAG,
-                        "gBLEClientSendQueueHandle is  NULL",
+#ifndef SINGLE_THREAD
+    VERIFY_NON_NULL_RET(g_bleClientSendQueueHandle, CALEADAPTER_TAG,
+                        "g_bleClientSendQueueHandle is  NULL",
                         CA_STATUS_FAILED);
-    VERIFY_NON_NULL_RET(gBleClientSendDataMutex, CALEADAPTER_TAG,
-                        "gBleClientSendDataMutex is NULL",
+    VERIFY_NON_NULL_RET(g_bleClientSendDataMutex, CALEADAPTER_TAG,
+                        "g_bleClientSendDataMutex is NULL",
                         CA_STATUS_FAILED);
 
-    VERIFY_NON_NULL_RET(gBLEClientSendQueueHandle, CALEADAPTER_TAG, "gBLEClientSendQueueHandle",
+    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);
 
-    CABLEData *bleData = CACreateBLEData(remoteEndpoint, data, dataLen);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
         return CA_MEMORY_ALLOC_FAILED;
     }
     // Add message to send queue
-    u_mutex_lock(gBleClientSendDataMutex);
-    CAQueueingThreadAddData(gBLEClientSendQueueHandle, bleData, sizeof(CABLEData));
-    u_mutex_unlock(gBleClientSendDataMutex);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT ");
+    ca_mutex_lock(g_bleClientSendDataMutex);
+    CAQueueingThreadAddData(g_bleClientSendQueueHandle, bleData, sizeof(CALEData_t));
+    ca_mutex_unlock(g_bleClientSendDataMutex);
+#endif
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
 
-CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
-                               void *data,
-                               uint32_t dataLen)
+CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data,
+                                     uint32_t dataLen)
 {
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN ");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, NULL, "Param data is NULL");
 
-    VERIFY_NON_NULL_RET(gSendQueueHandle, CALEADAPTER_TAG,
-                        "BleClientReceiverQueue is  NULL",
+#ifdef SINGLE_THREAD
+    char header[CA_HEADER_LENGTH] = {0};
+
+    CAResult_t result = CAGenerateHeader(header, dataLen);
+
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
+        return -1;
+    }
+
+    if (!CAIsLEConnected())
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "le not conn");
+        return -1;
+    }
+
+    result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
+        return -1;
+    }
+
+    int32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
+    for (int32_t iter = 0; iter < dataLimit; iter++)
+    {
+        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;
+        }
+        CALEDoEvents();
+    }
+
+    uint8_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
+    if(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;
+        }
+        CALEDoEvents();
+    }
+#else
+    VERIFY_NON_NULL_RET(g_bleServerSendQueueHandle, CALEADAPTER_TAG,
+                        "BleClientReceiverQueue is NULL",
                         CA_STATUS_FAILED);
-    VERIFY_NON_NULL_RET(gBleClientSendDataMutex, CALEADAPTER_TAG,
+    VERIFY_NON_NULL_RET(g_bleServerSendDataMutex, CALEADAPTER_TAG,
                         "BleClientSendDataMutex is NULL",
                         CA_STATUS_FAILED);
 
-    VERIFY_NON_NULL_RET(gSendQueueHandle, CALEADAPTER_TAG, "sendQueueHandle",
+    VERIFY_NON_NULL_RET(g_bleServerSendQueueHandle, CALEADAPTER_TAG, "sendQueueHandle",
                         CA_STATUS_FAILED);
 
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
 
-    CABLEData *bleData = CACreateBLEData(remoteEndpoint, data, dataLen);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
         return CA_MEMORY_ALLOC_FAILED;
     }
     // Add message to send queue
-    u_mutex_lock(gBleServerSendDataMutex);
-    CAQueueingThreadAddData(gSendQueueHandle, bleData, sizeof(CABLEData));
-    u_mutex_unlock(gBleServerSendDataMutex);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT ");
+    ca_mutex_lock(g_bleServerSendDataMutex);
+    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 CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   void *data, uint32_t dataLength, uint32_t *sentLength)
+CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress, const char *serviceUUID,
+                                         const void *data, uint32_t dataLength,
+                                         uint32_t *sentLength)
 {
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "IN");
+    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");
-    VERIFY_NON_NULL_RET(gCABleServerReceiverQueue, CALEADAPTER_TAG, "gCABleServerReceiverQueue",
+
+#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);
+    }
+#else
+    VERIFY_NON_NULL_RET(g_bleServerReceiverQueue, CALEADAPTER_TAG, "g_bleServerReceiverQueue",
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                                         serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                                                          CA_ADAPTER_GATT_BTLE,
+                                                          remoteAddress, 0);
     if (NULL == remoteEndpoint)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
         return CA_STATUS_FAILED;
     }
 
     // Create bleData to add to queue
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
 
-    CABLEData *bleData = CACreateBLEData(remoteEndpoint, data, dataLength);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        CAFreeEndpoint(remoteEndpoint);
         return CA_MEMORY_ALLOC_FAILED;
     }
 
+    CAFreeEndpoint(remoteEndpoint);
     // Add message to send queue
-    CAQueueingThreadAddData(gCABleServerReceiverQueue, bleData, sizeof(CABLEData));
+    CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-
-    OICFree(data);
-    data = NULL;
-
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "OUT");
+#endif
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   void *data, uint32_t dataLength, uint32_t *sentLength)
+CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress, const char *serviceUUID,
+                                         const void *data, uint32_t dataLength,
+                                         uint32_t *sentLength)
 {
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "IN");
+    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");
-    VERIFY_NON_NULL_RET(gCABleClientReceiverQueue, CALEADAPTER_TAG, "gCABleClientReceiverQueue",
+#ifndef SINGLE_THREAD
+    VERIFY_NON_NULL_RET(g_bleClientReceiverQueue, CALEADAPTER_TAG, "g_bleClientReceiverQueue",
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                                         serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                                                          CA_ADAPTER_GATT_BTLE,
+                                                          remoteAddress, 0);
     if (NULL == remoteEndpoint)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
         return CA_STATUS_FAILED;
     }
 
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
 
     // Create bleData to add to queue
-    CABLEData *bleData = CACreateBLEData(remoteEndpoint, data, dataLength);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
+        CAFreeEndpoint(remoteEndpoint);
         return CA_MEMORY_ALLOC_FAILED;
     }
 
+    CAFreeEndpoint(remoteEndpoint);
     // Add message to send queue
-    CAQueueingThreadAddData(gCABleClientReceiverQueue, bleData, sizeof(CABLEData));
+    CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-
-    OICFree(data);
-    data = NULL;
-
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "OUT");
+#endif
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-void CASetBleAdapterThreadPoolHandle(u_thread_pool_t handle)
+void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_unlock(gBleAdapterThreadPoolMutex);
-    gBleAdapterThreadPool = handle;
-    u_mutex_unlock(gBleAdapterThreadPoolMutex);
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+    g_bleAdapterThreadPool = handle;
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
+void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    u_mutex_lock(gBleAdapterReqRespCbMutex);
+    ca_mutex_lock(g_bleAdapterReqRespCbMutex);
 
-    gNetworkPacketReceivedCallback = callback;
+    g_networkPacketReceivedCallback = callback;
 
-    u_mutex_unlock(gBleAdapterReqRespCbMutex);
+    ca_mutex_unlock(g_bleAdapterReqRespCbMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
+void CALEErrorHandler(const char *remoteAddress, const void *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
+    g_errorHandler(rep, data, dataLen, result);
 
-#endif //#ifdef OIC_TIZEN
+    CAFreeEndpoint(rep);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT");
+}