Integrated singlethread and multithread files of BLE adapter.
authorvimala.v <vimala.v@samsung.com>
Fri, 3 Jul 2015 05:22:36 +0000 (10:52 +0530)
committerErich Keane <erich.keane@intel.com>
Fri, 3 Jul 2015 15:17:15 +0000 (15:17 +0000)
Removed all "_singlethread" files related to BLE adapter.

Change-Id: Idad8e8a488d7b2d742f7082116f9bd4895175d8f
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1035
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
17 files changed:
resource/csdk/connectivity/inc/caleadapter.h
resource/csdk/connectivity/inc/caleadapter_singlethread.h [deleted file]
resource/csdk/connectivity/inc/caleinterface.h
resource/csdk/connectivity/inc/caleinterface_singlethread.h [deleted file]
resource/csdk/connectivity/src/bt_le_adapter/SConscript
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c
resource/csdk/connectivity/src/bt_le_adapter/arduino/SConscript
resource/csdk/connectivity/src/bt_le_adapter/arduino/cableclient.cpp [new file with mode: 0644]
resource/csdk/connectivity/src/bt_le_adapter/arduino/cablenwmonitor.cpp
resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp
resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.h
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/bt_le_adapter/caleadapter_singlethread.c [deleted file]
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c
resource/csdk/connectivity/src/cainterfacecontroller_singlethread.c

index 64feca3..284db86 100644 (file)
@@ -174,8 +174,9 @@ void CATerminateLE();
  * @retval #CA_STATUS_FAILED Operation failed
  *
  */
-CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const 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);
 
 /**
  * @brief  This function will receive the data from the GattClient and add the data into the
@@ -190,8 +191,9 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const 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);
 
 /**
  * @brief  This function is used to set the NetworkPacket received callback to CA layer from
@@ -199,7 +201,7 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
  * @param  callback [IN] callback handle sent from the upper layer.
  * @return NONE
  */
-void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
+void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
 
 /**
  * @brief  This function will push the data from CA layer to the Sender processor queue.
@@ -213,8 +215,8 @@ void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
-                               const void *data, uint32_t dataLen);
+CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data, uint32_t dataLen);
 
 /**
  * @brief  This function will push the data from CA layer to the Sender processor queue.
@@ -228,8 +230,8 @@ CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
-                               const void *data,  uint32_t dataLen);
+CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data,  uint32_t dataLen);
 
 /**
  * @brief  This function will be associated with the sender queue for GattServer.This function will
@@ -241,7 +243,7 @@ CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
  *
  * @return  NONE
  */
-void CABLEServerSendDataThread(void *threadData);
+void CALEServerSendDataThread(void *threadData);
 
 /**
  * @brief  This function will be associated with the sender queue for GattClient.This function will
@@ -253,7 +255,7 @@ void CABLEServerSendDataThread(void *threadData);
  *
  * @return NONE
  */
-void CABLEClientSendDataThread(void *threadData);
+void CALEClientSendDataThread(void *threadData);
 
 /**
  * @brief  This function will be associated with the receiver queue of GattServer. This function
@@ -266,7 +268,7 @@ void CABLEClientSendDataThread(void *threadData);
  *
  * @return  NONE
  */
-void CABLEServerDataReceiverHandler(void *threadData);
+void CALEServerDataReceiverHandler(void *threadData);
 
 /**
  * @brief  This function will be associated with the receiver queue of GattClient. This function
@@ -278,28 +280,28 @@ void CABLEServerDataReceiverHandler(void *threadData);
  *                         and Data.
  * @return NONE
  */
-void CABLEClientDataReceiverHandler(void *threadData);
+void CALEClientDataReceiverHandler(void *threadData);
 
 /**
  * @brief  This function is used to Initalize both GattServer and GattClient queues. All four
  *         queues will be initialized with this function invocations.
  * @return  NONE
  */
-void CAInitBleQueues();
+void CAInitLEQueues();
 
 /**
  * @brief  This function will stop all queues created for GattServer and GattClient. All
  *         four queues will be be stopped with this function invocations.
  * @return  NONE
  */
-void CAStopBleQueues();
+void CAStopLEQueues();
 
 /**
  * @brief  This function will terminate all queues created for GattServer and GattClient. All
  *         four queues will be be terminated with this function invocations.
  * @return  NONE
  */
-void CATerminateBleQueues();
+void CATerminateLEQueues();
 
 /**
  * @brief  This function will initalize the Receiver and Sender queues for GattServer. This
@@ -310,7 +312,7 @@ void CATerminateBleQueues();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAInitBleServerQueues();
+CAResult_t CAInitLEServerQueues();
 
 /**
  * @brief  This function will initalize the Receiver and Sender queues for GattClient. This
@@ -323,7 +325,7 @@ CAResult_t CAInitBleServerQueues();
  * @retval #CA_STATUS_FAILED Operation failed
  *
  */
-CAResult_t CAInitBleClientQueues();
+CAResult_t CAInitLEClientQueues();
 
 /**
  * @brief  This function will initalize the Receiver queue for GattServer. This will initialize
@@ -335,7 +337,7 @@ CAResult_t CAInitBleClientQueues();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAInitBleServerSenderQueue();
+CAResult_t CAInitLEServerSenderQueue();
 
 /**
  * @brief  This function will initalize the Receiver queue for GattClient. This will initialize
@@ -347,7 +349,7 @@ CAResult_t CAInitBleServerSenderQueue();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAInitBleClientSenderQueue();
+CAResult_t CAInitLEClientSenderQueue();
 
 /**
  * @brief  This function will initalize the Receiver queue for GattServer. This will initialize
@@ -360,7 +362,7 @@ CAResult_t CAInitBleClientSenderQueue();
  * @retval #CA_STATUS_FAILED Operation failed
  *
  */
-CAResult_t CAInitBleServerReceiverQueue();
+CAResult_t CAInitLEServerReceiverQueue();
 
 /**
  * @brief  This function will initalize the Receiver queue for GattClient. This will initialize
@@ -372,7 +374,7 @@ CAResult_t CAInitBleServerReceiverQueue();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAInitBleClientReceiverQueue();
+CAResult_t CAInitLEClientReceiverQueue();
 
 /**
  * @brief  This function will create the Data required to send it in the queue.
@@ -386,7 +388,7 @@ CAResult_t CAInitBleClientReceiverQueue();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
+CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
                            uint32_t dataLength);
 
 /**
@@ -394,7 +396,7 @@ CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data
  * @param bleData [IN] Structure contains the information of a particular data segment.
  * @return NONE
  */
-void CAFreeBLEData(CALEData_t *bleData);
+void CAFreeLEData(CALEData_t *bleData);
 
 /**
  * @brief This will be used to notify device status changes to the LE adapter layer
diff --git a/resource/csdk/connectivity/inc/caleadapter_singlethread.h b/resource/csdk/connectivity/inc/caleadapter_singlethread.h
deleted file mode 100644 (file)
index 5e8134d..0000000
+++ /dev/null
@@ -1,426 +0,0 @@
-/* ****************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-/**
- * @file
- *
- * This file contains the APIs for LE adapters to be implemented.
- */
-
-#ifndef CA_LEADAPTER_SINGLETHREAD_H_
-#define CA_LEADAPTER_SINGLETHREAD_H_
-
-#include "cacommon.h"
-#include "caadapterinterface.h"
-
-/**
- * BLE Interface APIs.
- */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @struct CALEData_t
- * @brief Stores the information of the Data to be sent from the queues.
- *        This structure will be pushed to the sender/receiver queue for processing.
- */
-typedef struct
-{
-    CAEndpoint_t *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */
-    void *data;         /**< Data to be transmitted over LE tranport */
-    uint32_t dataLen;   /**< Length of the data being transmitted */
-} CALEData_t;
-
-/**
- * @brief Initialize LE connectivity interface.
- * @param registerCallback [IN] Callback to register LE interfaces to Connectivity Abstraction Layer
- * @param reqRespCallback  [IN] Callback to notify request and response messages from server(s)
- *                              started at Connectivity Abstraction Layer.
- * @param netCallback      [IN] Callback to notify the network additions to Connectivity
- *                              Abstraction Layer.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
-                          CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback);
-
-/**
- * @brief Starting LE connectivity adapters.
- *        As its peer to peer it doesnot require to start any servers
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartLE();
-
-/**
- * @brief Starting listening server for receiving multicast search requests
- * Transport Specific Behavior:
- *   LE  Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartLEListeningServer();
-
-/**
- * @brief for starting discovery servers for receiving multicast advertisements
- * Transport Specific Behavior:
- *   LE  Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartLEDiscoveryServer();
-
-/**
- * @brief Sends data to the endpoint using the adapter connectivity.
- * @param  endpoint  [IN]  Remote Endpoint information (like ipaddress , port, reference uri
- *                         and connectivity type) to which the unicast data has to be sent.
- * @param  data      [IN]  Data which required to be sent.
- * @param  dataLen   [IN]  Size of data to be sent.
- * @return  The number of bytes sent on the network. Returns -1 on error.
- * @remarks dataLen must be > 0.
- */
-int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data,
-                             uint32_t dataLen);
-
-/**
- * @brief Sends Multicast data to the endpoint using the LE connectivity.
- * @param   data        [IN]    Data which required to be sent.
- * @param   dataLen     [IN]    Size of data to be sent.
- * @return  The number of bytes sent on the network. Returns -1 on error.
- * @remarks  dataLen must be > 0.
- */
-int32_t CASendLEMulticastData(const void *data, uint32_t dataLen);
-
-/**
- * @brief Starts notification server on EDR adapters.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartLENotifyServer();
-
-/**
- * @brief Send notification information.
- * @param   endpoint  [IN]    Remote Endpoint information (like ipaddress , port, reference uri
- *                            and connectivity type) to which the unicast data has to be sent.
- * @param   data      [IN]    Data which required to be sent.
- * @param   dataLen   [IN]    Size of data to be sent.
- * @return  The number of bytes sent on the network. Returns 0 on error.
- * @remarks dataLen must be > 0.
- */
-uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
-                              uint32_t dataLen);
-
-/**
- * @brief   Get LE Connectivity network information
- * @param   info        [OUT]   Local connectivity information structures
- * @param   size        [OUT]   Number of local connectivity structures.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
-
-/**
- * @brief Read Synchronous API callback.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAReadLEData();
-
-/**
- * @brief Stopping the adapters and close socket connections
- *   LE Stops all GATT servers and close sockets.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStopLE();
-
-/**
- * @brief Terminate the LE connectivity adapter.
- * Configuration information will be deleted from further use
- */
-void CATerminateLE();
-
-/**
- * @brief  This function will receive the data from the GattServer and add the data to
- *         the Server receiver queue.
- * @param  remoteAddress [IN] Remote address of the device from where data is received.
- * @param  serviceUUID   [IN] Uuid of the OIC service running on the remote device
- * @param  data          [IN] Actual data recevied from the remote device.
- * @param  dataLength    [IN] Length of the data received from the remote device.
- * @param  sentLength    [IN] Length of the data sent from the remote device.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const void *data, uint32_t dataLength, uint32_t *sentLength);
-
-/**
- * @brief  This function will receive the data from the GattClient and add the data into the
- *         Client receiver queue.
- * @param  remoteAddress [IN] Remote address of the device from where data is received.
- * @param  serviceUUID   [IN] Uuid of the OIC service running on the remote device
- * @param  data          [IN] Actual data recevied from the remote device.
- * @param  dataLength    [IN] Length of the data received from the remote device.
- * @param  sentLength    [IN] Length of the data sent from the remote device.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const void *data, uint32_t dataLength, uint32_t *sentLength);
-
-/**
- * @brief  This function is used to set the NetworkPacket received callback to CA layer from
- *         adapter layer.
- * @param  callback [IN] callback handle sent from the upper layer.
- * @return NONE
- */
-void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
-
-/**
- * @brief  This function will push the data from CA layer to the Sender processor queue.
- *
- * @param  remoteEndpoint [IN] Remote endpoint information of the server.
- * @param  data           [IN] Data to be transmitted from LE.
- * @param  dataLen        [IN] length of the Data being transmitted.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
-                               const void *data, uint32_t dataLen);
-
-/**
- * @brief  This function will push the data from CA layer to the Sender processor queue.
- *
- * @param  remoteEndpoint [IN] Remote endpoint information of the server.
- * @param  data           [IN] Data to be transmitted from LE.
- * @param  dataLen        [IN] length of the Data being transmitted.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
-                               const void *data, uint32_t dataLen);
-
-/**
- * @brief  This function will be associated with the sender queue for GattClient.This function will
- *         fragment the data to the MTU of the transport and send the data in fragments to the
- *         adapters. The function will be blocked untill all data is sent out from the adapter.
- *
- * @param  threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
- *                         and Data.
- *
- * @return NONE
- */
-void CABLEClientSendDataThread(void *threadData);
-
-/**
- * @brief  This function will be associated with the receiver queue of GattClient. This function
- *         will defragment the data received and will send the data UP to the CA layer only after
- *         it collects all the data from the adapter layer. Adapter Header will provide the length
- *         of the data sent from the server.
- *
- * @param  threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
- *                         and Data.
- * @return NONE
- */
-void CABLEClientDataReceiverHandler(void *threadData);
-
-/**
- * @brief  This function will terminate all queues created for GattServer and GattClient. All
- *         four queues will be be terminated with this function invocations.
- * @return  NONE
- */
-void CATerminateBleQueues();
-
-/**
- * @brief  This function will initalize the Receiver queue for GattClient. This will initialize
- *         the queue to process the function CABLEClientDataReceiverHandler() when ever the task
- *         is added to this queue.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAInitBleClientReceiverQueue();
-
-/**
- * @brief  This function will initalize the Receiver queue for GattServer. This will initialize
- *         the queue to process the function CABLEServerDataReceiverHandler() when ever the task
- *         is added to this queue.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- *
- */
-CAResult_t CAInitBleServerReceiverQueue();
-
-/**
- * @brief  This function is used to Initalize both GattServer and GattClient queues. All four
- *         queues will be initialized with this function invocations.
- * @return  NONE
- */
-void CAInitBleQueues();
-
-/**
- * @brief  This function will initalize the Receiver and Sender queues for GattServer. This
- *         function will inturn call the functions CAInitBleServerReceiverQueue() and
- *         CAInitBleServerSenderQueue() to initialize the queues.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAInitBleServerQueues();
-
-/**
- * @brief  This function will initalize the Receiver and Sender queues for GattClient. This
- *         function will inturn call the functions CAInitBleClientReceiverQueue() and
- *         CAInitBleClientSenderQueue() to initialize the queues.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- *
- */
-CAResult_t CAInitBleClientQueues();
-
-/**
- * @brief  This function will initalize the Receiver queue for GattServer. This will initialize
- *         the queue to process the function CABLEServerSendDataThread() when ever the task is
- *         added to this queue.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAInitBleServerSenderQueue();
-
-/**
- * @brief  This function will initalize the Receiver queue for GattClient. This will initialize
- *         the queue to process the function CABLEClientSendDataThread() when ever the task is
- *         added to this queue.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAInitBleClientSenderQueue();
-
-/**
- * @brief  This function will be associated with the receiver queue of GattServer. This function
- *         will defragment the data received and will send the data UP to the CA layer only after
- *         it collects all the data from the adapter layer. Adapter Header will provide the
- *         length of the data sent from the server.
- *
- * @param  context [IN] Data pushed to the queue which contains the info about RemoteEndpoint
- *                      and Data.
- *
- * @return  NONE
- */
-void CABLEServerDataReceiverHandler(void *context);
-
-/**
- * @brief  This function will be associated with the sender queue for GattServer.This function will
- *         fragment the data to the MTU of the transport and send the data in fragments to the
- *         adapters. The function will be blocked untill all data is sent out from the adapter.
- *
- * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
- *                        and Data.
- *
- * @return  NONE
- */
-void CABLEServerSendDataThread(void *threadData);
-
-/**
- * @brief  This function will create the Data required to send it in the queue.
- *
- * @param  remoteEndpoint [IN] Remote endpoint information of the server.
- * @param  data           [IN] Data to be transmitted from LE.
- * @param  dataLength     [IN] length of the Data being transmitted.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
-                            uint32_t dataLength);
-
-/**
- * @brief Used to free the BLE information stored in the sender/receiver queues.
- * @param bleData [IN] Structure contains the information of a particular data segment.
- * @return NONE
- */
-void CAFreeBLEData(CALEData_t *bleData);
-
-/**
- * @brief This will be used to notify the device status changes to the LE adapter layer
- * @param  adapter_state [IN] State of the adapter
- * @return NONE
- */
-typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
-
-/**
- * @brief This will be used to notify that network packet recieved from GATTClient to adapter layer.
- * @param  remoteAddress  [IN] Remote endpoint Address
- * @param  serviceUUID    [IN] Service UUID
- * @param  data           [IN] Data received
- * @param  dataLength     [IN] Length of the data received
- * @param  sentLength     [IN] Length of the data sent
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress,
-                    const char *serviceUUID, const void *data, uint32_t dataLength,
-                    uint32_t *sentLength);
-
-/**
- * @brief This will be used to notify that network packet recieved from GATTServer to adapter layer.
- * @param  remoteAddress  [IN] Remote endpoint Address
- * @param  serviceUUID    [IN] Service UUID
- * @param  data           [IN] Data received
- * @param  dataLength     [IN] Length of the data received
- * @param  sentLength     [IN] Length of the data sent
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress,
-        const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* CA_LEADAPTER_SINGLETHREAD_H_ */
-
index 6879214..5f83e51 100644 (file)
@@ -135,7 +135,7 @@ CAResult_t CAGetLEAddress(char **local_address);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAStartBleGattServer();
+CAResult_t CAStartLEGattServer();
 
 /**
  * @brief  Used to stop BLE Gatt Service.
@@ -145,13 +145,13 @@ CAResult_t CAStartBleGattServer();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAStopBleGattServer();
+CAResult_t CAStopLEGattServer();
 
 /**
  * @brief  Used to stop Gatt Server thread and remove service registration, stop advertising.
  * @return NONE
  */
-void CATerminateBleGattServer();
+void CATerminateLEGattServer();
 
 /**
  * @brief  Used to store upper layer callback locally which will be used to send the data to
@@ -159,7 +159,7 @@ void CATerminateBleGattServer();
  * @param  callback [IN] Callback function to pass the data to CA layer.
  * @return NONE
  */
-void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
+void CASetLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
 
 /**
  * @brief  Used to update characteristics(Read/Write) value that we want to send to particular
@@ -189,7 +189,7 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *
  * @retval #CA_STATUS_FAILED Operation failed
  */
 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
-                                                   const uint32_t charValueLen);
+                                                   uint32_t charValueLen);
 
 /**
  * @brief  Used to start CAStartBleGattClientThread for initializing Gatt Client
@@ -199,7 +199,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAStartBLEGattClient();
+CAResult_t CAStartLEGattClient();
 
 /**
  * @brief  Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
@@ -209,13 +209,19 @@ CAResult_t CAStartBLEGattClient();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-void CAStopBLEGattClient();
+void CAStopLEGattClient();
 
 /**
  * @brief  Used to unset all the callbacks and stop service discovery
  * @return NONE
  */
-void CATerminateBLEGattClient();
+void CATerminateLEGattClient();
+
+/**
+ * @brief API to read the data from characteristics and invoke notifyCallback.
+ * @return - NONE
+ */
+void CACheckLEData();
 
 /**
  * @brief  Sets the value of characteristic and update the value to GATTServer(unicast).
@@ -255,7 +261,7 @@ CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data, uint32_t
  *
  * @return  void
  */
-void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
+void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
 
 /**
  * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
@@ -267,7 +273,7 @@ void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle);
+void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
 * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
@@ -275,7 +281,7 @@ void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle);
 *                    task.
 * @return NONE
 */
-void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle);
+void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
  * @brief  Used to unset the callback of adapter connection state change.
diff --git a/resource/csdk/connectivity/inc/caleinterface_singlethread.h b/resource/csdk/connectivity/inc/caleinterface_singlethread.h
deleted file mode 100644 (file)
index 6cc639b..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-/* ****************************************************************
-*
-* Copyright 2014 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-
-/**
- * @file
- *
- * This file provides APIs for BLE modules.
- */
-
-#ifndef CA_LE_INTERFACE_SINGLETHREAD_H_
-#define CA_LE_INTERFACE_SINGLETHREAD_H_
-
-#include <stdbool.h>
-
-#include "cacommon.h"
-#include "caleadapter_singlethread.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @enum CALETransferType_t
- * @brief Provide information about different mode of data transfer
- *        This enum is used to differentiate between unicast and multicast data transfer.
- */
-typedef enum
-{
-    LE_MULTICAST,    /**< When this enum is selected, data will be updated to all OIC servers. */
-    LE_UNICAST       /**< When this enum is selected, data will be updated to desired OIC Server. */
-} CALETransferType_t;
-
-
-/**
- * @brief  Used to get the current state of the LE adapter.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_ADAPTER_NOT_ENABLED  adapter not enabled
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAGetLEAdapterState();
-
-/**
- * @brief  Used to initialize the network monitor layer of the LE adapter.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CALEInitializeNetworkMonitor();
-
-/**
- * @brief  Used to terminate the network monitor layer of the LE adapter.
- * @return NONE
- */
-void CALETerminateNetworkMonitor();
-
-/**
- * @brief  This function is used to set the callback for the Device state changes in the adapter.
- *
- * @param  callback  [IN]  Callback to notify the Device state change to the CA Layer
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
-
-/**
- * @brief  Provides the BD address of the local adapter.
- * @param  local_address [OUT] pointer to the location where bd address needs to be stored.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAGetLEAddress(char **local_address);
-
-/**
- * @brief  Used to start Gatt Server thread for service creation and advertise ble service.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAStartBleGattServer();
-
-/**
- * @brief  Used to stop BLE Gatt Service.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAStopBleGattServer();
-
-/**
- * @brief  Used to store upper layer callback locally which will be used to send the data to
- *         application
- * @param  callback [IN] Callback function to pass the data to CA layer.
- * @return NONE
- */
-void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
-
-/**
- * @brief  Used to update characteristics(Read/Write) value that we want to send to particular
- *         client. Both unicast and multicast will use the same api. In mulicast, we will be
- *         sending in loop to all clients.
- *
- * @param  charValue     [IN] Data that we want to send to client(unicast)/clients(multicast)
- * @param  charValueLen  [IN] Length of the data.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
-                                                   uint8_t charValueLen);
-
-/**
- * @brief  Used to start CAStartBleGattClientThread for initializing Gatt Client
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAStartBLEGattClient();
-
-/**
- * @brief  Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
- *         function.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-void CAStopBLEGattClient();
-
-/**
- * @brief  Used to unset all the callbacks and stop service discovery
- * @return NONE
- */
-void CATerminateBLEGattClient();
-
-/**
- * @brief  Sets the value of characteristic and update the value to GATTServer(unicast).
- *
- * @param  remoteAddress [IN] The address of the remote device
- * @param  data          [IN] The value of characteristic (byte array)
- * @param  dataLen       [IN] The length of value
- * @param  type          [IN] Type of the transfer(#CALETransferType_t)
- * @param  position      [IN] The unique index of each ble server. Used for multicast feature.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char  *data,
-                                                const uint32_t dataLen, CALETransferType_t type,
-                                                const int32_t position);
-
-/**
- * @brief  Sets the value of characteristic and update the value to all registered
- *         GATTServer -> Multicast
- * @param  data     [IN] The value of characteristic (byte array)
- * @param  dataLen  [IN] The length of value
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
- */
-CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data, uint32_t dataLen);
-
-/**
- * @brief  Used to store upper layer callback locally which will be used to send the data to
- *         application
- * @param  callback  [IN] Callback function to pass the data to CA layer.
- *
- * @return  void
- */
-void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CA_LE_INTERFACE_SINGLETHREAD_H_ */
-
index d6cfe61..c5468a1 100644 (file)
@@ -13,12 +13,9 @@ src_dir = os.path.join(os.curdir, 'bt_le_adapter')
 
 # Source files to build common for all platforms.
 common_files = None
-if target_os != 'arduino':
-        common_files = [ os.path.join(src_dir,
+common_files = [ os.path.join(src_dir,
                                       'caleadapter.c') ]
-else:
-        common_files = [ os.path.join(src_dir,
-                                      'caleadapter_singlethread.c') ]
+
 
 # Get list of target-specific source file base names, i.e. no parent
 # directories prepended to the path.
index 190459b..e2986e9 100644 (file)
@@ -3161,7 +3161,7 @@ void CALEClientSetTheSendRequestFlag(bool flag)
  * adapter common
  */
 
-CAResult_t CAStartBLEGattClient()
+CAResult_t CAStartLEGattClient()
 {
     CAResult_t res = CALEClientStartMulticastServer();
     if (CA_STATUS_OK != res)
@@ -3176,7 +3176,7 @@ CAResult_t CAStartBLEGattClient()
     return res;
 }
 
-void CAStopBLEGattClient()
+void CAStopLEGattClient()
 {
     OIC_LOG(DEBUG, TAG, "CAStopBLEGattClient");
 
@@ -3225,7 +3225,7 @@ void CAStopBLEGattClient()
 
 }
 
-void CATerminateBLEGattClient()
+void CATerminateLEGattClient()
 {
     OIC_LOG(DEBUG, TAG, "Terminate GATT Client");
     CALEClientTerminate();
@@ -3250,7 +3250,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, uint32_t da
     return CALEClientSendMulticastMessage(data, dataLen);
 }
 
-void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
+void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -3261,7 +3261,7 @@ void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle)
+void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
index 9f812a6..2964b5a 100644 (file)
@@ -2286,7 +2286,7 @@ Java_org_iotivity_ca_CaLeServerInterface_caLeAdvertiseStartFailureCallback(JNIEn
  * adapter common
  */
 
-CAResult_t CAStartBleGattServer()
+CAResult_t CAStartLEGattServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -2313,7 +2313,7 @@ CAResult_t CAStartBleGattServer()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAStopBleGattServer()
+CAResult_t CAStopLEGattServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -2321,7 +2321,7 @@ CAResult_t CAStopBleGattServer()
     return CA_STATUS_OK;
 }
 
-void CATerminateBleGattServer()
+void CATerminateLEGattServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -2331,7 +2331,7 @@ void CATerminateBleGattServer()
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback)
+void CASetLEReqRespServerCallback(CABLEServerDataReceivedCallback callback)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -2367,7 +2367,7 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *
 }
 
 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
-                                                   const uint32_t charValueLen)
+                                                   uint32_t charValueLen)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(charValue, TAG, "device is null");
@@ -2379,7 +2379,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
     return result;
 }
 
-void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle)
+void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
index b1ef61e..9de983f 100644 (file)
@@ -8,6 +8,7 @@ import os.path
 env.PrependUnique(CPPPATH = [ os.path.join(src_dir, 'arduino') ])
 
 src_files = [ 'cableserver.cpp',
-              'cablenwmonitor.cpp']
+              'cablenwmonitor.cpp',
+              'cableclient.cpp']
 
 Return('src_files')
diff --git a/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableclient.cpp b/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableclient.cpp
new file mode 100644 (file)
index 0000000..6ea6967
--- /dev/null
@@ -0,0 +1,61 @@
+/******************************************************************
+*
+* Copyright 2014 Samsung Electronics All Rights Reserved.
+*
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+******************************************************************/
+
+
+//logger.h included first to avoid conflict with RBL library PROGMEM attribute
+#include "logger.h"
+#include "caleinterface.h"
+
+#define TAG "LEC"
+
+void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
+void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+CAResult_t CAStartLEGattClient()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+void CAStopLEGattClient()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+void CATerminateLEGattClient()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
index a61c483..2740a70 100644 (file)
 //logger.h included first to avoid conflict with RBL library PROGMEM attribute
 #include "logger.h"
 
-#include "caleinterface_singlethread.h"
+#include "caleinterface.h"
 
 #include <Arduino.h>
 #include <SPI.h>
 #include <boards.h>
 #include <RBL_nRF8001.h>
 
-#include "caleadapter_singlethread.h"
+#include "caleadapter.h"
 #include "caadapterutils.h"
 #include "oic_malloc.h"
 
@@ -50,19 +50,26 @@ static CALEDeviceStateChangedCallback g_caLEDeviceStateChangedCallback = NULL;
  */
 static unsigned char *g_leAddress = NULL;
 
-CAResult_t CALEInitializeNetworkMonitor()
+CAResult_t CAInitializeLENetworkMonitor()
 {
     OIC_LOG(DEBUG, TAG, "IN");
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-void CALETerminateNetworkMonitor()
+void CATerminateLENetworkMonitor()
 {
     OIC_LOG(DEBUG, TAG, "IN");
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
+CAResult_t CAInitializeLEAdapter()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
 CAResult_t CAGetLEAdapterState()
 {
     OIC_LOG(DEBUG, TAG, "IN");
index 1ad39b3..57fcc84 100644 (file)
 #include <boards.h>
 #include <RBL_nRF8001.h>
 
-#include "caleinterface_singlethread.h"
+#include "caleinterface.h"
 #include "oic_malloc.h"
 #include "caadapterutils.h"
+#include "cafragmentation.h"
 
 #define TAG "LES"
 
-CAResult_t CAInitializeBle()
+/**
+ * @var    g_bleServerDataReceivedCallback
+ * @brief  Maintains the callback to be notified on receival of network packets from other
+ *           BLE devices
+ */
+static CABLEServerDataReceivedCallback g_bleServerDataReceivedCallback = NULL;
+
+/**
+ * @def MAX_EVENT_COUNT
+ * @brief Maximum number of tries to get the event on BLE Shield address.
+ */
+#define MAX_EVENT_COUNT 20
+
+static bool g_serverRunning = false;
+static char *g_coapBuffer = NULL;
+
+/**
+ * @var g_receivedDataLen
+ * @brief Actual length of data received.
+ */
+static uint32_t g_receivedDataLen = 0;
+
+/**
+ * @var g_packetDataLen
+ * @brief Total Length of data that is being fragmented.
+ */
+static uint32_t g_packetDataLen = 0;
+
+void CACheckLEDataInternal()
+{
+    CALEDoEvents();
+
+    if (CAIsLEDataAvailable())
+    {
+        // Allocate Memory for COAP Buffer and do ParseHeader
+        if (NULL == g_coapBuffer)
+        {
+            OIC_LOG(DEBUG, TAG, "IN");
+            char headerArray[CA_HEADER_LENGTH] = "";
+            while (CAIsLEDataAvailable() && g_receivedDataLen < CA_HEADER_LENGTH)
+            {
+                headerArray[g_receivedDataLen++] = CALEReadData();
+            }
+
+            g_packetDataLen = CAParseHeader(headerArray);
+
+            if (g_packetDataLen > COAP_MAX_PDU_SIZE)
+            {
+                OIC_LOG(ERROR, TAG, "len > pdu_size");
+                return;
+            }
+
+            g_coapBuffer = (char *)OICCalloc((size_t)g_packetDataLen, sizeof(char));
+            if (NULL == g_coapBuffer)
+            {
+                OIC_LOG(ERROR, TAG, "malloc");
+                return;
+            }
+
+            OIC_LOG(DEBUG, TAG, "OUT");
+            g_receivedDataLen = 0;
+        }
+
+        OIC_LOG(DEBUG, TAG, "IN");
+        while (CAIsLEDataAvailable())
+        {
+            OIC_LOG(DEBUG, TAG, "In While loop");
+            g_coapBuffer[g_receivedDataLen++] = CALEReadData();
+            if (g_receivedDataLen == g_packetDataLen)
+            {
+                OIC_LOG(DEBUG, TAG, "Read Comp BLE Pckt");
+                g_coapBuffer[g_receivedDataLen] = '\0';
+                if (g_receivedDataLen > 0)
+                {
+                    OIC_LOG_V(DEBUG, TAG, "recv dataLen=%d", g_receivedDataLen);
+                    //CANotifyCallback((void *)g_coapBuffer, g_dataLen, "", 0);
+                    uint32_t sentLength = 0;
+                    g_bleServerDataReceivedCallback("", "", g_coapBuffer,
+                                                    g_receivedDataLen, &sentLength);
+                }
+                g_receivedDataLen = 0;
+                OICFree(g_coapBuffer);
+                g_coapBuffer = NULL;
+                break;
+            }
+        }
+        OIC_LOG(DEBUG, TAG, "OUT");
+    }
+    else
+    {
+        OIC_LOG(DEBUG, TAG, "NoData");
+    }
+    return;
+}
+
+CAResult_t CALEInitialize()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -50,37 +146,40 @@ CAResult_t CAInitializeBle()
     return CA_STATUS_OK;
 }
 
-CAResult_t CATerminateBle()
+void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    ble_radio_reset();
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
+}
 
+void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-unsigned char CAIsBleDataAvailable()
+unsigned char CAIsLEDataAvailable()
 {
     return ble_available();
 }
 
-unsigned char CAIsBleConnected()
+unsigned char CAIsLEConnected()
 {
     return ble_connected();
 }
-char CAReadBleData()
+char CALEReadData()
 {
     return (char)ble_read();
 }
 
-CAResult_t CABleDoEvents()
+CAResult_t CALEDoEvents()
 {
     ble_do_events();
     return CA_STATUS_OK;
 }
 
 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *char_value,
-                                                   uint8_t valueLength)
+                                                   uint32_t valueLength)
 {
     // ble_write_bytes() api can send only max of 255 bytes at a time
     // This function shall never be called to send more than 255 bytes by the fragmentation logic.
@@ -89,4 +188,59 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *char_value,
     return CA_STATUS_OK;
 }
 
+void CASetLEReqRespServerCallback(CABLEServerDataReceivedCallback callback)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    g_bleServerDataReceivedCallback = callback;
+    OIC_LOG(DEBUG, TAG, "OUT");
+}
 
+CAResult_t CAStartLEGattServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t result = CALEInitialize();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, TAG, "ble init fail: %d", result);
+        return CA_STATUS_FAILED;
+    }
+    /**
+     * Below for loop is to process the BLE Events received from BLE Shield.
+     * BLE Events includes BLE Shield Address Added as a patch to RBL Library.
+     */
+    for (int iter = 0; iter < MAX_EVENT_COUNT; iter++)
+    {
+        CACheckLEDataInternal();
+    }
+
+    g_serverRunning = true;
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
+CAResult_t CAStopLEGattServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    // There is no server running to stop.
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
+void CATerminateLEGattServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    ble_radio_reset();
+    g_serverRunning = false;
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return;
+}
+
+void CACheckLEData()
+{
+    if (false == g_serverRunning)
+    {
+        OIC_LOG(ERROR, TAG, "Server is not running");
+        return;
+    }
+    CACheckLEDataInternal();
+}
index 60e19b2..df0750a 100644 (file)
@@ -42,48 +42,31 @@ extern "C"
  * @brief API to initialize Arduino BLE module and advertise the service
  * @return #CA_STATUS_OK or Appropriate error code
  */
-CAResult_t CAInitializeBle();
-
-/**
- * @brief API to Terminate Arduino BLE module and advertise the service
- * @return #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CATerminateBle();
-
-/**
- * @brief Send the received data to Connectivity Abstraction layer.
- * @param data       [IN] Data received from BLE characteristics
- * @param dataLen    [IN] Received data Length
- * @param senderAdrs [IN] Sender Address.
- * @param senderPort [IN] Sender port
- * @return #CA_STATUS_OK or Appropriate error code
- */
-void CANotifyCallback(const void *data, int32_t dataLen, const char *senderAdrs,
-                      int32_t senderPort);
+CAResult_t CALEInitialize();
 
 /**
  * @brief API to check whether data is available in BLE shield
  * @return - Received buffer length
  */
-unsigned char CAIsBleDataAvailable();
+unsigned char CAIsLEDataAvailable();
 
 /**
  * @brief API to check whether client is connected with BLE Shield
  * @return - Connection state
  */
-unsigned char CAIsBleConnected();
+unsigned char CAIsLEConnected();
 
 /**
  * @brief API to read data from BLE shield
  * @return - Data read
  */
-char CAReadBleData();
+char CALEReadData();
 
 /**
  * @brief API to perform BLE events
  * @return #CA_STATUS_OK or Appropriate error code
  */
-CAResult_t CABleDoEvents();
+CAResult_t CALEDoEvents();
 
 #ifdef __cplusplus
 } /* extern "C" */
index 22381d9..37f14ba 100644 (file)
@@ -26,7 +26,9 @@
 #include "cacommon.h"
 #include "camutex.h"
 #include "caadapterutils.h"
+#ifndef SINGLE_THREAD
 #include "caqueueingthread.h"
+#endif
 #include "cafragmentation.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
@@ -36,7 +38,7 @@
  * @var CALEADAPTER_TAG
  * @brief Logging tag for module name.
  */
-#define CALEADAPTER_TAG "CA_BLE_ADAPTER"
+#define CALEADAPTER_TAG "LAD"
 
 /**
  * @var g_networkCallback
@@ -46,7 +48,8 @@ static CANetworkChangeCallback g_networkCallback = NULL;
 
 /**
  * @var g_localBLEAddress
- * @brief bleAddress of the local adapter. Value will be initialized to zero, and will be updated later.
+ * @brief bleAddress of the local adapter. Value will be initialized to zero, and will
+ *        be updated later.
  */
 static char g_localBLEAddress[18] = {0};
 
@@ -87,18 +90,6 @@ static ca_thread_pool_t g_bleAdapterThreadPool = NULL;
 static ca_mutex g_bleAdapterThreadPoolMutex = NULL;
 
 /**
- * @var g_bleClientSendQueueHandle
- * @brief Queue to process the outgoing packets from GATTClient.
- */
-static CAQueueingThread_t *g_bleClientSendQueueHandle = NULL;
-
-/**
- * @var g_bleClientReceiverQueue
- * @brief Queue to process the incoming packets to GATT Client.
- */
-static CAQueueingThread_t *g_bleClientReceiverQueue = NULL;
-
-/**
  * @var g_bleClientSendDataMutex
  * @brief Mutex to synchronize the queing of the data from SenderQueue.
  */
@@ -110,23 +101,6 @@ static ca_mutex g_bleClientSendDataMutex = NULL;
  */
 static ca_mutex g_bleClientReceiveDataMutex = NULL;
 
-/**
- * @var g_dataReceiverHandlerState
- * @brief Stop condition of recvhandler.
- */
-static bool g_dataReceiverHandlerState = false;
-
-/**
- * @var g_sendQueueHandle
- * @brief Queue to process the outgoing packets from GATTServer.
- */
-static CAQueueingThread_t *g_sendQueueHandle = NULL;
-
-/**
- * @var g_bleServerReceiverQueue
- * @brief Queue to process the incoming packets to GATTServer
- */
-static CAQueueingThread_t *g_bleServerReceiverQueue = NULL;
 
 /**
  * @var g_bleServerSendDataMutex
@@ -200,12 +174,13 @@ CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
 * @fn  CASetBleAdapterThreadPoolHandle
 * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
 *
-* @param[in] handle - Thread pool handle which is given by above layer for using thread creation task.
+* @param[in] handle - Thread pool handle which is given by above layer for using thread
+*                     creation task.
 *
 * @return  void
 *
 */
-void CASetBleAdapterThreadPoolHandle(ca_thread_pool_t handle);
+void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
 * @fn  CALEDeviceStateChangedCb
@@ -229,7 +204,7 @@ void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state);
 * @retval  CA_STATUS_FAILED Operation failed
 *
 */
-CAResult_t CAInitBleAdapterMutex();
+CAResult_t CAInitLEAdapterMutex();
 
 /**
 * @fn  CATerminateBleAdapterMutex
@@ -237,15 +212,7 @@ CAResult_t CAInitBleAdapterMutex();
 *
 * @return  void
 */
-void CATerminateBleAdapterMutex();
-
-/**
-* @fn  CALEDataDestroyer
-* @brief  Used to free data
-*
-* @return  void
-*/
-static void CALEDataDestroyer(void *data, uint32_t size);
+void CATerminateLEAdapterMutex();
 
 /**
 * @fn  CALEErrorHandler
@@ -256,1426 +223,1485 @@ static void CALEDataDestroyer(void *data, uint32_t size);
 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;
 
-CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
-                          CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback,
-                          CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
+/**
+ * @var g_bleClientSendQueueHandle
+ * @brief Queue to process the outgoing packets from GATTClient.
+ */
+static CAQueueingThread_t *g_bleClientSendQueueHandle = NULL;
+
+/**
+ * @var g_bleClientReceiverQueue
+ * @brief Queue to process the incoming packets to GATT Client.
+ */
+static CAQueueingThread_t *g_bleClientReceiverQueue = NULL;
+
+/**
+ * @var g_bleServerSendQueueHandle
+ * @brief Queue to process the outgoing packets from GATTServer.
+ */
+static CAQueueingThread_t *g_bleServerSendQueueHandle = NULL;
+
+/**
+ * @var g_bleServerReceiverQueue
+ * @brief Queue to process the incoming packets to GATTServer
+ */
+static CAQueueingThread_t *g_bleServerReceiverQueue = NULL;
+
+/**
+* @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");
 
-    //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 = CAInitBleAdapterMutex();
+    CAResult_t result = CAInitLEServerQueues();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleAdapterMutex failed!");
-        return CA_STATUS_FAILED;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerQueues failed");
+        return;
     }
 
-    result = CAInitializeLENetworkMonitor();
+    result = CAInitLEClientQueues();
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitializeLENetworkMonitor() failed");
-        return CA_STATUS_FAILED;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
+        return;
     }
 
-    CAInitializeLEAdapter();
-
-    CASetBleClientThreadPoolHandle(handle);
-    CASetBleServerThreadPoolHandle(handle);
-    CASetBleAdapterThreadPoolHandle(handle);
-    CASetBLEReqRespServerCallback(CABLEServerReceivedData);
-    CASetBLEReqRespClientCallback(CABLEClientReceivedData);
-    CASetBLEReqRespAdapterCallback(reqRespCallback);
-
-    CASetBLEClientErrorHandleCallback(CALEErrorHandler);
-    CASetBLEServerErrorHandleCallback(CALEErrorHandler);
-    CALERegisterNetworkNotifications(netCallback);
-
-    g_errorHandler = errorCallback;
-
-    CAConnectivityHandler_t connHandler;
-    connHandler.startAdapter = CAStartLE;
-    connHandler.stopAdapter = CAStopLE;
-    connHandler.startListenServer = CAStartLEListeningServer;
-    connHandler.startDiscoveryServer = CAStartLEDiscoveryServer;
-    connHandler.sendData = CASendLEUnicastData;
-    connHandler.sendDataToAll = CASendLEMulticastData;
-    connHandler.GetnetInfo = CAGetLEInterfaceInformation;
-    connHandler.readData = CAReadLEData;
-    connHandler.terminate = CATerminateLE;
-    registerCallback(connHandler, CA_ADAPTER_GATT_BTLE);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartLE()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE, not implemented");
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
-CAResult_t CAStopLE()
+CAResult_t CAInitLEServerQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CAStopBleQueues();
+    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
 
-    ca_mutex_lock(g_bleIsServerMutex);
-    if (true == g_isServer)
+    CAResult_t result = CAInitLEServerSenderQueue();
+    if (CA_STATUS_OK != result)
     {
-        CAStopBleGattServer();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerSenderQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+        return CA_STATUS_FAILED;
     }
-    else
+
+    result = CAInitLEServerReceiverQueue();
+    if (CA_STATUS_OK != result)
     {
-        CAStopBLEGattClient();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerReceiverQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+        return CA_STATUS_FAILED;
     }
-    ca_mutex_unlock(g_bleIsServerMutex);
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    g_dataReceiverHandlerState = true;
 
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-void CATerminateLE()
+CAResult_t CAInitLEClientQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CASetBLEReqRespServerCallback(NULL);
-    CASetBLEReqRespClientCallback(NULL);
-    CALERegisterNetworkNotifications(NULL);
-    CASetBLEReqRespAdapterCallback(NULL);
-    CATerminateLENetworkMonitor();
+    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
 
-    ca_mutex_lock(g_bleIsServerMutex);
-    if (true == g_isServer)
+    CAResult_t result = CAInitLEClientSenderQueue();
+    if (CA_STATUS_OK != result)
     {
-        CATerminateBleGattServer();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientSenderQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+        return CA_STATUS_FAILED;
     }
-    else
+
+    result = CAInitLEClientReceiverQueue();
+    if (CA_STATUS_OK != result)
     {
-        CATerminateBLEGattClient();
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientReceiverQueue failed");
+        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
+        return CA_STATUS_FAILED;
     }
-    ca_mutex_unlock(g_bleIsServerMutex);
 
-    CATerminateBleQueues();
+    g_dataReceiverHandlerState = true;
 
-    CATerminateBleAdapterMutex();
+    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-CAResult_t CAStartLEListeningServer()
+CAResult_t CAInitLEServerSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    CAResult_t result = CAInitBleServerQueues();
-    if (CA_STATUS_OK != result)
+    // Check if the message queue is already initialized
+    if (g_bleServerSendQueueHandle)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return CA_STATUS_FAILED;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Queue is already initialized!");
+        return CA_STATUS_OK;
     }
 
-    result = CAGetLEAdapterState();
-    if (CA_ADAPTER_NOT_ENABLED == result)
+    // Create send message queue
+    g_bleServerSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleServerSendQueueHandle)
     {
-        gLeServerStatus = CA_LISTENING_SERVER;
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
-        return CA_STATUS_OK;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
     }
 
-    if (CA_STATUS_FAILED == result)
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerSendQueueHandle,
+                                                   g_bleAdapterThreadPool,
+                                                   CALEServerSendDataThread, CALEDataDestroyer))
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleServerSendQueueHandle);
+        g_bleServerSendQueueHandle = NULL;
         return CA_STATUS_FAILED;
     }
 
-    CAStartBleGattServer();
-
-    ca_mutex_lock(g_bleIsServerMutex);
-    g_isServer = true;
-    ca_mutex_unlock(g_bleIsServerMutex);
+    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;
 }
 
-CAResult_t CAStartLEDiscoveryServer()
+CAResult_t CAInitLEClientSenderQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CAResult_t result = CAInitBleClientQueues();
-    if (CA_STATUS_OK != result)
+    if (g_bleClientSendQueueHandle)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return CA_STATUS_FAILED;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
+        return CA_STATUS_OK;
     }
 
-    result = CAGetLEAdapterState();
-    if (CA_ADAPTER_NOT_ENABLED == result)
+    // Create send message queue
+    g_bleClientSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+    if (!g_bleClientSendQueueHandle)
     {
-        gLeServerStatus = CA_DISCOVERY_SERVER;
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
-        return CA_STATUS_OK;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
     }
 
-    if (CA_STATUS_FAILED == result)
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientSendQueueHandle,
+                                                   g_bleAdapterThreadPool,
+                                                   CALEClientSendDataThread, CALEDataDestroyer))
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
         return CA_STATUS_FAILED;
     }
 
-    CAStartBLEGattClient();
-
-    ca_mutex_lock(g_bleIsServerMutex);
-    g_isServer = false;
-    ca_mutex_unlock(g_bleIsServerMutex);
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientSendQueueHandle))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleClientSendQueueHandle);
+        g_bleClientSendQueueHandle = NULL;
+        return CA_STATUS_FAILED;
+    }
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CAStartLENotifyServer()
+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;
+    }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
+    // 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;
+    }
 
-uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerReceiverQueue, g_bleAdapterThreadPool,
+            CALEServerDataReceiverHandler, CALEDataDestroyer))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+        OICFree(g_bleServerReceiverQueue);
+        g_bleServerReceiverQueue = NULL;
+        return CA_STATUS_FAILED;
+    }
+
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerReceiverQueue))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleServerReceiverQueue);
+        g_bleServerReceiverQueue = NULL;
+        return CA_STATUS_FAILED;
+    }
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return 0;
+    return CA_STATUS_OK;
 }
 
-CAResult_t CAReadLEData()
+CAResult_t CAInitLEClientReceiverQueue()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    //Input validation
-    VERIFY_NON_NULL_RET(endpoint, NULL, "Remote endpoint is null", -1);
-    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
-
-    CAResult_t result = CA_STATUS_FAILED;
-
-    ca_mutex_lock(g_bleIsServerMutex);
-    if (true  == g_isServer)
+    // Check if the message queue is already initialized
+    if (g_bleClientReceiverQueue)
     {
-        result = CABLEServerSendData(endpoint, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEUnicastData] CABleServerSenderQueueEnqueueMessage failed \n");
-            g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
-            ca_mutex_unlock(g_bleIsServerMutex);
-            return -1;
-        }
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
     }
     else
     {
-        result = CABLEClientSendData(endpoint, data, dataLen);
-        if (CA_STATUS_OK != result)
+        // Create send message queue
+        g_bleClientReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
+        if (!g_bleClientReceiverQueue)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEUnicastData] CABleClientSenderQueueEnqueueMessage failed \n");
-            g_errorHandler(endpoint, data, dataLen, result);
-            ca_mutex_unlock(g_bleIsServerMutex);
-            return -1;
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
+            OICFree(g_bleClientSendQueueHandle);
+            return CA_MEMORY_ALLOC_FAILED;
         }
-    }
-    ca_mutex_unlock(g_bleIsServerMutex);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return dataLen;
-}
-
-int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    //Input validation
-    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
-
-    if (0 >= dataLen)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Invalid Parameter");
-        return -1;
-    }
 
-    CAResult_t result = CA_STATUS_FAILED;
-
-    ca_mutex_lock(g_bleIsServerMutex);
-    if (true  == g_isServer)
-    {
-        result = CABLEServerSendData(NULL, data, dataLen);
-        if (CA_STATUS_OK != result)
+        if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientReceiverQueue,
+                                                       g_bleAdapterThreadPool,
+                                                       CALEClientDataReceiverHandler, NULL))
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEMulticastDataToAll] CABleServerSenderQueueEnqueueMessage failed" );
-            ca_mutex_unlock(g_bleIsServerMutex);
-            g_errorHandler(endpoint, data, dataLen, result);
-            return -1;
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
+            OICFree(g_bleClientSendQueueHandle);
+            OICFree(g_bleClientReceiverQueue);
+            g_bleClientReceiverQueue = NULL;
+            return CA_STATUS_FAILED;
         }
     }
-    else
+    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientReceiverQueue))
     {
-        result = CABLEClientSendData(NULL, data, dataLen);
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "[SendLEMulticastDataToAll] CABleClientSenderQueueEnqueueMessage failed" );
-            g_errorHandler(endpoint, data, dataLen, result);
-            ca_mutex_unlock(g_bleIsServerMutex);
-            return -1;
-        }
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
+        OICFree(g_bleClientReceiverQueue);
+        g_bleClientReceiverQueue = NULL;
+        return CA_STATUS_FAILED;
     }
-    ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return dataLen;
+    return CA_STATUS_OK;
 }
 
-CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
+void CAStopLEQueues()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    VERIFY_NON_NULL(info, NULL, "CALocalConnectivity info is null");
-
-    char *local_address = NULL;
-
-    CAResult_t res = CAGetLEAddress(&local_address);
-    if (CA_STATUS_OK != res)
+    ca_mutex_lock(g_bleClientSendDataMutex);
+    if (NULL != g_bleClientSendQueueHandle)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAGetLEAddress has failed");
-        return res;
+        CAQueueingThreadStop(g_bleClientSendQueueHandle);
     }
+    ca_mutex_unlock(g_bleClientSendDataMutex);
 
-    if (NULL == local_address)
+    ca_mutex_lock(g_bleClientReceiveDataMutex);
+    if (NULL != g_bleClientReceiverQueue)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is NULL");
-        return CA_STATUS_FAILED;
+        CAQueueingThreadStop(g_bleClientReceiverQueue);
     }
+    ca_mutex_unlock(g_bleClientReceiveDataMutex);
 
-    *size = 0;
-    (*info) = (CAEndpoint_t *) OICCalloc(1, sizeof (CAEndpoint_t));
-    if (NULL == (*info))
+    ca_mutex_lock(g_bleServerSendDataMutex);
+    if (NULL != g_bleServerSendQueueHandle)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failure!");
-        OICFree(local_address);
-        return CA_STATUS_FAILED;
+        CAQueueingThreadStop(g_bleServerSendQueueHandle);
     }
+    ca_mutex_unlock(g_bleServerSendDataMutex);
 
-    size_t local_address_len = strlen(local_address);
-
-    if(local_address_len >= sizeof(g_localBLEAddress) ||
-            local_address_len >= MAX_ADDR_STR_SIZE_CA - 1)
+    ca_mutex_lock(g_bleServerReceiveDataMutex);
+    if (NULL != g_bleServerReceiverQueue)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is too long");
-        OICFree(*info);
-        OICFree(local_address);
-        return CA_STATUS_FAILED;
+        CAQueueingThreadStop(g_bleServerReceiverQueue);
     }
-
-    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);
+    ca_mutex_unlock(g_bleServerReceiveDataMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
-CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+void CATerminateLEQueues()
 {
     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)
-    {
-        res = CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCb);
-        if (CA_STATUS_OK != res)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
-        }
-    }
-    else
-    {
-        res = CAUnSetLEAdapterStateChangedCb();
-        if (CA_STATUS_OK != res)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
-        }
-    }
+    CAQueueingThreadDestroy(g_bleClientSendQueueHandle);
+    OICFree(g_bleClientSendQueueHandle);
+    g_bleClientSendQueueHandle = NULL;
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return res;
-}
 
-void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    CAQueueingThreadDestroy(g_bleClientReceiverQueue);
+    OICFree(g_bleClientReceiverQueue);
+    g_bleClientReceiverQueue = NULL;
 
-    VERIFY_NON_NULL_VOID(g_localBLEAddress, NULL, "g_localBLEAddress is null");
-    CAEndpoint_t localEndpoint = {};
-    localEndpoint.adapter = CA_ADAPTER_GATT_BTLE;
-    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(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattServer");
-        CAStartBleGattServer();
-    }
-    else if (CA_DISCOVERY_SERVER == gLeServerStatus)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattClient");
-        CAStartBLEGattClient();
-    }
-    gLeServerStatus = CA_SERVER_NOTSTARTED;
+    CAQueueingThreadDestroy(g_bleServerSendQueueHandle);
+    OICFree(g_bleServerSendQueueHandle);
+    g_bleServerSendQueueHandle = NULL;
 
-    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);
+
+    CAQueueingThreadDestroy(g_bleServerReceiverQueue);
+    OICFree(g_bleServerReceiverQueue);
+    g_bleServerReceiverQueue = NULL;
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-CAResult_t CAInitBleAdapterMutex()
+void CALEServerDataReceiverHandler(void *threadData)
 {
     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;
-        }
-    }
+    static uint32_t recvDataLen = 0;
+    static uint32_t totalDataLen = 0;
+    static char *defragData = NULL;
+    static bool isHeaderAvailable = false;
+    static CAEndpoint_t *remoteEndpoint = NULL;
 
-    if (NULL == g_bleNetworkCbMutex)
-    {
-        g_bleNetworkCbMutex = ca_mutex_new();
-        if (NULL == g_bleNetworkCbMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+    ca_mutex_lock(g_bleServerReceiveDataMutex);
 
-    if (NULL == g_bleLocalAddressMutex)
+    if (g_dataReceiverHandlerState)
     {
-        g_bleLocalAddressMutex = ca_mutex_new();
-        if (NULL == g_bleLocalAddressMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
 
-    if (NULL == g_bleAdapterThreadPoolMutex)
-    {
-        g_bleAdapterThreadPoolMutex = ca_mutex_new();
-        if (NULL == g_bleAdapterThreadPoolMutex)
+        CALEData_t *bleData = (CALEData_t *) threadData;
+        if (!bleData)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bleData!");
+            return;
         }
-    }
 
-    if (NULL == g_bleClientSendDataMutex)
-    {
-        g_bleClientSendDataMutex = ca_mutex_new();
-        if (NULL == g_bleClientSendDataMutex)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
 
-    if (NULL == g_bleClientReceiveDataMutex)
-    {
-        g_bleClientReceiveDataMutex = ca_mutex_new();
-        if (NULL == g_bleClientReceiveDataMutex)
+        if (!isHeaderAvailable)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
-        }
-    }
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
+            totalDataLen = CAParseHeader((char*)bleData->data);
 
-    if (NULL == g_bleServerSendDataMutex)
-    {
-        g_bleServerSendDataMutex = ca_mutex_new();
-        if (NULL == g_bleServerSendDataMutex)
+            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(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
+            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 (NULL == g_bleServerReceiveDataMutex)
-    {
-        g_bleServerReceiveDataMutex = ca_mutex_new();
-        if (NULL == g_bleServerReceiveDataMutex)
+        if (totalDataLen == recvDataLen)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
+            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 (NULL == g_bleAdapterReqRespCbMutex)
-    {
-        g_bleAdapterReqRespCbMutex = ca_mutex_new();
-        if (NULL == g_bleAdapterReqRespCbMutex)
+        if (false == g_dataReceiverHandlerState)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
-            return CA_STATUS_FAILED;
+            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;
         }
     }
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    return CA_STATUS_OK;
+    ca_mutex_unlock(g_bleServerReceiveDataMutex);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CATerminateBleAdapterMutex()
+void CALEClientDataReceiverHandler(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    ca_mutex_free(g_bleIsServerMutex);
-    g_bleIsServerMutex = NULL;
-
-    ca_mutex_free(g_bleNetworkCbMutex);
-    g_bleNetworkCbMutex = NULL;
+    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_free(g_bleLocalAddressMutex);
-    g_bleLocalAddressMutex = NULL;
+    ca_mutex_lock(g_bleClientReceiveDataMutex);
 
-    ca_mutex_free(g_bleAdapterThreadPoolMutex);
-    g_bleAdapterThreadPoolMutex = NULL;
+    if (g_dataReceiverHandlerState)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
 
-    ca_mutex_free(g_bleClientSendDataMutex);
-    g_bleClientSendDataMutex = NULL;
+        CALEData_t *bleData = (CALEData_t *) threadData;
+        if (!bleData)
+        {
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid wifidata!");
+            return;
+        }
 
-    ca_mutex_free(g_bleClientReceiveDataMutex);
-    g_bleClientReceiveDataMutex = NULL;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
 
-    ca_mutex_free(g_bleServerSendDataMutex);
-    g_bleServerSendDataMutex = NULL;
+        if (!isHeaderAvailable)
+        {
+            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
 
-    ca_mutex_free(g_bleServerReceiveDataMutex);
-    g_bleServerReceiveDataMutex = NULL;
+            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);
 
-    ca_mutex_free(g_bleAdapterReqRespCbMutex);
-    g_bleAdapterReqRespCbMutex = NULL;
+            defragData = (char *) OICMalloc(sizeof(char) * totalDataLen);
+            if (NULL == defragData)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
+                return;
+            }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-}
+            remoteAddress = bleData->remoteEndpoint->addr;
 
-void CAInitBleQueues()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
+                                                    remoteAddress, 0);
 
-    CAResult_t result = CAInitBleServerQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerQueues failed");
-        return;
-    }
+            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);
+        }
 
-    result = CAInitBleClientQueues();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientQueues failed");
-        return;
+        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");
 }
 
-CAResult_t CAInitBleServerQueues()
+void CALEServerSendDataThread(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
-
-    CAResult_t result = CAInitBleServerSenderQueue();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerSenderQueue failed");
-        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
-    }
-
-    result = CAInitBleServerReceiverQueue();
-    if (CA_STATUS_OK != result)
+    CALEData_t *bleData = (CALEData_t *) threadData;
+    if (!bleData)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerReceiverQueue failed");
-        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
+        return;
     }
 
-    g_dataReceiverHandlerState = true;
-
-    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAInitBleClientQueues()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    ca_mutex_lock(g_bleAdapterThreadPoolMutex);
+    int32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
 
-    CAResult_t result = CAInitBleClientSenderQueue();
-    if (CA_STATUS_OK != result)
+    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, "CAInitBleClientSenderQueue failed");
-        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
+        OICFree(header);
+        return;
     }
 
-    result = CAInitBleClientReceiverQueue();
-    if (CA_STATUS_OK != result)
+    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    if (CA_STATUS_OK != result )
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleClientReceiverQueue failed");
-        ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-        return CA_STATUS_FAILED;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
+        OICFree(header);
+        OICFree(dataSegment);
+        return ;
     }
 
-    g_dataReceiverHandlerState = true;
-
-    ca_mutex_unlock(g_bleAdapterThreadPoolMutex);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
+    memcpy(dataSegment, header, CA_HEADER_LENGTH);
+    OICFree(header);
 
-CAResult_t CAInitBleServerSenderQueue()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    // Check if the message queue is already initialized
-    if (g_sendQueueHandle)
+    int32_t length = 0;
+    if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Queue is already initialized!");
-        return CA_STATUS_OK;
+        length = totalLength;
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
     }
-
-    // Create send message queue
-    g_sendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_sendQueueHandle)
+    else
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return CA_MEMORY_ALLOC_FAILED;
+        length =  CA_SUPPORTED_BLE_MTU_SIZE;
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
+               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_bleAdapterThreadPool,
-            CABLEServerSendDataThread, CALEDataDestroyer))
+    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(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_sendQueueHandle);
-        g_sendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
-    }
+        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);
+        }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
+        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(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_sendQueueHandle);
-        g_sendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
+        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");
-    return CA_STATUS_OK;
 }
 
-CAResult_t CAInitBleClientSenderQueue()
+void CALEClientSendDataThread(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    if (g_bleClientSendQueueHandle)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
-    }
-
-    // Create send message queue
-    g_bleClientSendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_bleClientSendQueueHandle)
+    CALEData_t *bleData = (CALEData_t *) threadData;
+    if (!bleData)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return CA_MEMORY_ALLOC_FAILED;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
+        return;
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientSendQueueHandle, g_bleAdapterThreadPool,
-            CABLEClientSendDataThread, CALEDataDestroyer))
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_bleClientSendQueueHandle);
-        g_bleClientSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
-    }
+    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleClientSendQueueHandle))
+    uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+    char *dataSegment = (char *) OICCalloc(totalLength + 1, sizeof(char));
+    if (NULL == dataSegment)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleClientSendQueueHandle);
-        g_bleClientSendQueueHandle = NULL;
-        return CA_STATUS_FAILED;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
+        OICFree(header);
+        return;
     }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAInitBleServerReceiverQueue()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-    // Check if the message queue is already initialized
-    if (g_bleServerReceiverQueue)
+    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    if (CA_STATUS_OK != result )
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-        return CA_STATUS_OK;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
+        OICFree(header);
+        OICFree(dataSegment);
+        return ;
     }
+    memcpy(dataSegment, header, CA_HEADER_LENGTH);
+    OICFree(header);
 
-    // Create send message queue
-    g_bleServerReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-    if (!g_bleServerReceiverQueue)
+    uint32_t length = 0;
+    if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        OICFree(g_sendQueueHandle);
-        return CA_MEMORY_ALLOC_FAILED;
+        length = totalLength;
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
+        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
     }
-
-    if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleServerReceiverQueue, g_bleAdapterThreadPool,
-            CABLEServerDataReceiverHandler, CALEDataDestroyer))
+    else
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-        OICFree(g_bleServerReceiverQueue);
-        g_bleServerReceiverQueue = NULL;
-        return CA_STATUS_FAILED;
+        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);
     }
 
-    if (CA_STATUS_OK != CAQueueingThreadStart(g_bleServerReceiverQueue))
+    uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    uint32_t index = 0;
+    if (NULL != bleData->remoteEndpoint) //Sending Unicast Data
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_thread_pool_add_task failed ");
-        OICFree(g_bleServerReceiverQueue);
-        g_bleServerReceiverQueue = NULL;
-        return CA_STATUS_FAILED;
-    }
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAInitBleClientReceiverQueue()
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+        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);
 
-    // Check if the message queue is already initialized
-    if (g_bleClientReceiverQueue)
-    {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Already queue is initialized!");
-    }
-    else
-    {
-        // Create send message queue
-        g_bleClientReceiverQueue = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t));
-        if (!g_bleClientReceiverQueue)
+        if (CA_STATUS_OK != result)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-            OICFree(g_bleClientSendQueueHandle);
-            return CA_MEMORY_ALLOC_FAILED;
+            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
+            g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+            OICFree(dataSegment);
+            return ;
         }
 
-        if (CA_STATUS_OK != CAQueueingThreadInitialize(g_bleClientReceiverQueue, g_bleAdapterThreadPool,
-                CABLEClientDataReceiverHandler, NULL))
+        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
+        for (index = 1; index < iter; index++)
         {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to Initialize send queue thread");
-            OICFree(g_bleClientSendQueueHandle);
-            OICFree(g_bleClientReceiverQueue);
-            g_bleClientReceiverQueue = NULL;
-            return CA_STATUS_FAILED;
+            // 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);
         }
     }
-    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;
-    }
+    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);
+        }
 
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
+        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 CAStopBleQueues()
+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");
 
-    ca_mutex_lock(g_bleClientSendDataMutex);
-    if (NULL != g_bleClientSendQueueHandle)
+    if (NULL == g_bleIsServerMutex)
     {
-        CAQueueingThreadStop(g_bleClientSendQueueHandle);
+        g_bleIsServerMutex = ca_mutex_new();
+        if (NULL == g_bleIsServerMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
     }
-    ca_mutex_unlock(g_bleClientSendDataMutex);
 
-    ca_mutex_lock(g_bleClientReceiveDataMutex);
-    if (NULL != g_bleClientReceiverQueue)
+    if (NULL == g_bleNetworkCbMutex)
     {
-        CAQueueingThreadStop(g_bleClientReceiverQueue);
+        g_bleNetworkCbMutex = ca_mutex_new();
+        if (NULL == g_bleNetworkCbMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
     }
-    ca_mutex_unlock(g_bleClientReceiveDataMutex);
 
-    ca_mutex_lock(g_bleServerSendDataMutex);
-    if (NULL != g_sendQueueHandle)
+    if (NULL == g_bleLocalAddressMutex)
     {
-        CAQueueingThreadStop(g_sendQueueHandle);
+        g_bleLocalAddressMutex = ca_mutex_new();
+        if (NULL == g_bleLocalAddressMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
     }
-    ca_mutex_unlock(g_bleServerSendDataMutex);
 
-    ca_mutex_lock(g_bleServerReceiveDataMutex);
-    if (NULL != g_bleServerReceiverQueue)
+    if (NULL == g_bleAdapterThreadPoolMutex)
     {
-        CAQueueingThreadStop(g_bleServerReceiverQueue);
+        g_bleAdapterThreadPoolMutex = ca_mutex_new();
+        if (NULL == g_bleAdapterThreadPoolMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (NULL == g_bleClientSendDataMutex)
+    {
+        g_bleClientSendDataMutex = ca_mutex_new();
+        if (NULL == g_bleClientSendDataMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (NULL == g_bleClientReceiveDataMutex)
+    {
+        g_bleClientReceiveDataMutex = ca_mutex_new();
+        if (NULL == g_bleClientReceiveDataMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (NULL == g_bleServerSendDataMutex)
+    {
+        g_bleServerSendDataMutex = ca_mutex_new();
+        if (NULL == g_bleServerSendDataMutex)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    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;
+        }
     }
-    ca_mutex_unlock(g_bleServerReceiveDataMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-void CATerminateBleQueues()
+void CATerminateLEAdapterMutex()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CAQueueingThreadDestroy(g_bleClientSendQueueHandle);
-    OICFree(g_bleClientSendQueueHandle);
-    g_bleClientSendQueueHandle = NULL;
+    ca_mutex_free(g_bleIsServerMutex);
+    g_bleIsServerMutex = NULL;
 
+    ca_mutex_free(g_bleNetworkCbMutex);
+    g_bleNetworkCbMutex = NULL;
 
-    CAQueueingThreadDestroy(g_bleClientReceiverQueue);
-    OICFree(g_bleClientReceiverQueue);
-    g_bleClientReceiverQueue = NULL;
+    ca_mutex_free(g_bleLocalAddressMutex);
+    g_bleLocalAddressMutex = NULL;
+
+    ca_mutex_free(g_bleAdapterThreadPoolMutex);
+    g_bleAdapterThreadPoolMutex = NULL;
+
+    ca_mutex_free(g_bleClientSendDataMutex);
+    g_bleClientSendDataMutex = NULL;
 
+    ca_mutex_free(g_bleClientReceiveDataMutex);
+    g_bleClientReceiveDataMutex = NULL;
 
-    CAQueueingThreadDestroy(g_sendQueueHandle);
-    OICFree(g_sendQueueHandle);
-    g_sendQueueHandle = NULL;
+    ca_mutex_free(g_bleServerSendDataMutex);
+    g_bleServerSendDataMutex = NULL;
 
+    ca_mutex_free(g_bleServerReceiveDataMutex);
+    g_bleServerReceiveDataMutex = NULL;
 
-    CAQueueingThreadDestroy(g_bleServerReceiverQueue);
-    OICFree(g_bleServerReceiverQueue);
-    g_bleServerReceiverQueue = NULL;
+    ca_mutex_free(g_bleAdapterReqRespCbMutex);
+    g_bleAdapterReqRespCbMutex = NULL;
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
-void CABLEServerDataReceiverHandler(void *threadData)
+
+CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
+                          CANetworkPacketReceivedCallback reqRespCallback,
+                          CANetworkChangeCallback netCallback,
+                          CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     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);
+    //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");
 
-    if (g_dataReceiverHandlerState)
+    CAResult_t result = CA_STATUS_OK;
+    result = CAInitLEAdapterMutex();
+    if (CA_STATUS_OK != result)
     {
-        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(ERROR, CALEADAPTER_TAG, "CAInitBleAdapterMutex failed!");
+        return CA_STATUS_FAILED;
+    }
+    result = CAInitializeLENetworkMonitor();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitializeLENetworkMonitor() failed");
+        return CA_STATUS_FAILED;
+    }
 
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
+    CAInitializeLEAdapter();
 
-        if (!isHeaderAvailable)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-            totalDataLen = CAParseHeader((char*)bleData->data);
+    CASetLEClientThreadPoolHandle(handle);
+    CASetLEReqRespClientCallback(CALEAdapterClientReceivedData);
+    CASetLEServerThreadPoolHandle(handle);
+    CASetLEAdapterThreadPoolHandle(handle);
+    CASetLEReqRespServerCallback(CALEAdapterServerReceivedData);
+    CASetLEReqRespAdapterCallback(reqRespCallback);
 
-            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);
+    CASetBLEClientErrorHandleCallback(CALEErrorHandler);
+    CASetBLEServerErrorHandleCallback(CALEErrorHandler);
+    CALERegisterNetworkNotifications(netCallback);
 
-            defragData = (char *) OICCalloc(totalDataLen + 1, sizeof(char));
-            if (NULL == defragData)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-                return;
-            }
+    g_errorHandler = errorCallback;
 
-            const char *remoteAddress = bleData->remoteEndpoint->addr;
+    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);
 
-            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
-                                                    remoteAddress, 0);
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 
-            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);
-        }
+    return CA_STATUS_OK;
+}
 
-        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);
+CAResult_t CAStartLE()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE, not implemented");
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-void CABLEClientDataReceiverHandler(void *threadData)
+CAResult_t CAStopLE()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+#ifndef SINGLE_THREAD
+    CAStopLEQueues();
+#endif
 
-    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)
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true == g_isServer)
     {
-        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;
-        }
+        CAStopLEGattServer();
+    }
+    else
+    {
+        CAStopLEGattClient();
+    }
+    ca_mutex_unlock(g_bleIsServerMutex);
 
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "checking for DE Fragmentation");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 
-        if (!isHeaderAvailable)
-        {
-            OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
+    return CA_STATUS_OK;
+}
 
-            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);
+void CATerminateLE()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-            defragData = (char *) OICMalloc(sizeof(char) * totalDataLen);
-            if (NULL == defragData)
-            {
-                OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-                return;
-            }
+    CASetLEReqRespServerCallback(NULL);
+    CASetLEReqRespClientCallback(NULL);
+    CALERegisterNetworkNotifications(NULL);
+    CASetLEReqRespAdapterCallback(NULL);
+    CATerminateLENetworkMonitor();
 
-            remoteAddress = bleData->remoteEndpoint->addr;
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true == g_isServer)
+    {
+        CATerminateLEGattServer();
+    }
+    else
+    {
+        CATerminateLEGattClient();
+    }
+    ca_mutex_unlock(g_bleIsServerMutex);
 
-            remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_GATT_BTLE,
-                                                    remoteAddress, 0);
+#ifndef SINGLE_THREAD
+    CATerminateLEQueues();
+#endif
+    CATerminateLEAdapterMutex();
 
-            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 CABLEServerSendDataThread(void *threadData)
+CAResult_t CAStartLEListeningServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    CALEData_t *bleData = (CALEData_t *) threadData;
-    if (!bleData)
+    CAResult_t result = CA_STATUS_OK;
+#ifndef SINGLE_THREAD
+    result = CAInitLEServerQueues();
+    if (CA_STATUS_OK != result)
     {
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
-        return;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEServerQueues failed");
+        return CA_STATUS_FAILED;
     }
+#endif
 
-    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)
+    result = CAGetLEAdapterState();
+    if (CA_ADAPTER_NOT_ENABLED == result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
-        OICFree(header);
-        return;
+        gLeServerStatus = CA_LISTENING_SERVER;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
+        return CA_STATUS_OK;
     }
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
-    if (CA_STATUS_OK != result )
+    if (CA_STATUS_FAILED == result)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
-        OICFree(header);
-        OICFree(dataSegment);
-        return ;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
+        return CA_STATUS_FAILED;
     }
 
-    memcpy(dataSegment, header, CA_HEADER_LENGTH);
-    OICFree(header);
+    CAStartLEGattServer();
 
-    int32_t length = 0;
-    if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
+    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 CAStartLEDiscoveryServer()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+    CAResult_t result = CA_STATUS_OK;
+#ifndef SINGLE_THREAD
+    result = CAInitLEClientQueues();
+    if (CA_STATUS_OK != result)
     {
-        length = totalLength;
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEClientQueues failed");
+        return CA_STATUS_FAILED;
     }
-    else
+#endif
+    result = CAGetLEAdapterState();
+    if (CA_ADAPTER_NOT_ENABLED == result)
     {
-        length =  CA_SUPPORTED_BLE_MTU_SIZE;
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
-               CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
+        gLeServerStatus = CA_DISCOVERY_SERVER;
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Listen Server will be started once BT Adapter is enabled");
+        return CA_STATUS_OK;
     }
 
-    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
+    if (CA_STATUS_FAILED == result)
     {
-        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(ERROR, CALEADAPTER_TAG, "Bluetooth get state failed!");
+        return CA_STATUS_FAILED;
+    }
 
-        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);
-        }
+    CAStartLEGattClient();
 
-        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);
+    ca_mutex_lock(g_bleIsServerMutex);
+    g_isServer = false;
+    ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-void CABLEClientSendDataThread(void *threadData)
+CAResult_t CAStartLENotifyServer()
 {
     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;
-    }
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
+}
 
-    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 CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
+                              uint32_t dataLen)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    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);
-    }
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return 0;
+}
 
-    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);
+CAResult_t CAReadLEData()
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+#ifdef SINGLE_THREAD
+    CACheckLEData();
+#endif
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return CA_STATUS_OK;
+}
 
-        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 ;
-        }
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-        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);
-        }
+    //Input validation
+    VERIFY_NON_NULL_RET(endpoint, NULL, "Remote endpoint is null", -1);
+    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
 
-        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);
+    CAResult_t result = CA_STATUS_FAILED;
 
-            if (CA_STATUS_OK != result)
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true  == g_isServer)
+    {
+        result = CALEAdapterServerSendData(endpoint, data, dataLen);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "Send unicast data failed\n");
+            if (g_errorHandler)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                                                   result);
-                g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
-                OICFree(dataSegment);
-                return;
+                g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", remainingLen);
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
         }
     }
     else
     {
-        //Sending Mulitcast Data
-        // Send the first segment with the header.
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Multicast Data");
-        result = CAUpdateCharacteristicsToAllGattServers(dataSegment, length);
+        result = CALEAdapterClientSendData(endpoint, data, dataLen);
         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(ERROR, CALEADAPTER_TAG, "Send unicast data failed \n");
+            if (g_errorHandler)
+            {
+                g_errorHandler(endpoint, data, dataLen, result);
+            }
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
         }
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
-        // Send the remaining header.
-        for (index = 1; index < iter; index++)
+    }
+    ca_mutex_unlock(g_bleIsServerMutex);
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return dataLen;
+}
+
+int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    //Input validation
+    VERIFY_NON_NULL_RET(data, NULL, "Data is null", -1);
+
+    if (0 >= dataLen)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Invalid Parameter");
+        return -1;
+    }
+
+    CAResult_t result = CA_STATUS_FAILED;
+
+    ca_mutex_lock(g_bleIsServerMutex);
+    if (true  == g_isServer)
+    {
+        result = CALEAdapterServerSendData(NULL, data, dataLen);
+        if (CA_STATUS_OK != result)
         {
-            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(ERROR, CALEADAPTER_TAG, "Send multicast data failed" );
+
+            ca_mutex_unlock(g_bleIsServerMutex);
+            if (g_errorHandler)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics (all) failed, result [%d]",
-                          result);
-                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
-                OICFree(dataSegment);
-                return;
+                g_errorHandler(endpoint, data, dataLen, result);
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]",
-                      CA_SUPPORTED_BLE_MTU_SIZE);
+            return -1;
         }
-
-        uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
-        if ( remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
+    }
+    else
+    {
+        result = CALEAdapterClientSendData(NULL, data, dataLen);
+        if (CA_STATUS_OK != result)
         {
-            // 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(ERROR, CALEADAPTER_TAG, "Send Multicast data failed" );
+            if (g_errorHandler)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                          "Update characteristics (all) failed, result [%d]", result);
-                CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
-                OICFree(dataSegment);
-                return;
+                g_errorHandler(endpoint, data, dataLen, result);
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", remainingLen);
+            ca_mutex_unlock(g_bleIsServerMutex);
+            return -1;
         }
-
     }
+    ca_mutex_unlock(g_bleIsServerMutex);
 
-    OICFree(dataSegment);
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT - CABLEClientSendDataThread");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return dataLen;
 }
 
-CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
-                           uint32_t dataLength)
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
-    CALEData_t *bleData = (CALEData_t *) OICMalloc(sizeof(CALEData_t));
-    if (!bleData)
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
+
+    VERIFY_NON_NULL(info, NULL, "CALocalConnectivity info is null");
+
+    char *local_address = NULL;
+
+    CAResult_t res = CAGetLEAddress(&local_address);
+    if (CA_STATUS_OK != res)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        return NULL;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "CAGetLEAddress has failed");
+        return res;
     }
 
-    bleData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
-    bleData->data = (void *)OICCalloc(dataLength + 1, 1);
-    if (NULL == bleData->data)
+    if (NULL == local_address)
     {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
-        CAFreeBLEData(bleData);
-        return NULL;
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is NULL");
+        return CA_STATUS_FAILED;
     }
-    memcpy(bleData->data, data, dataLength);
-    bleData->dataLen = dataLength;
 
-    return bleData;
+    *size = 0;
+    (*info) = (CAEndpoint_t *) OICCalloc(1, sizeof(CAEndpoint_t));
+    if (NULL == (*info))
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failure!");
+        OICFree(local_address);
+        return CA_STATUS_FAILED;
+    }
+
+    size_t local_address_len = strlen(local_address);
+
+    if(local_address_len >= sizeof(g_localBLEAddress) ||
+            local_address_len >= MAX_ADDR_STR_SIZE_CA - 1)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is too long");
+        OICFree(*info);
+        OICFree(local_address);
+        return CA_STATUS_FAILED;
+    }
+
+    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;
 }
 
-void CAFreeBLEData(CALEData_t *bleData)
+CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
 {
-    VERIFY_NON_NULL_VOID(bleData, NULL, "Param bleData is NULL");
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CAFreeEndpoint(bleData->remoteEndpoint);
-    OICFree(bleData->data);
-    OICFree(bleData);
+    ca_mutex_lock(g_bleNetworkCbMutex);
+    g_networkCallback = netCallback;
+    ca_mutex_unlock(g_bleNetworkCbMutex);
+    CAResult_t res = CA_STATUS_OK;
+    if (netCallback)
+    {
+        res = CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCb);
+        if (CA_STATUS_OK != res)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
+        }
+    }
+    else
+    {
+        res = CAUnSetLEAdapterStateChangedCb();
+        if (CA_STATUS_OK != res)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
+        }
+    }
+
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+    return res;
 }
 
-void CALEDataDestroyer(void *data, uint32_t size)
+void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
 {
-    CALEData_t *ledata = (CALEData_t *) data;
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CAFreeBLEData(ledata);
-}
+    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(DEBUG, CALEADAPTER_TAG, "Before CAStartLEGattServer");
+        CAStartLEGattServer();
+    }
+    else if (CA_DISCOVERY_SERVER == gLeServerStatus)
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Before CAStartBleGattClient");
+        CAStartLEGattClient();
+    }
+    gLeServerStatus = CA_SERVER_NOTSTARTED;
+
+    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);
 
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
+}
 
-CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
-                               const void *data,
-                               uint32_t dataLen)
+CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data,
+                                     uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, NULL, "Param data is NULL");
-
+#ifndef SINGLE_THREAD
     VERIFY_NON_NULL_RET(g_bleClientSendQueueHandle, CALEADAPTER_TAG,
                         "g_bleClientSendQueueHandle is  NULL",
                         CA_STATUS_FAILED);
@@ -1688,7 +1714,7 @@ CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
 
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
 
-    CALEData_t *bleData = CACreateBLEData(remoteEndpoint, data, dataLen);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -1698,33 +1724,85 @@ CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
     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 CAEndpoint_t *remoteEndpoint,
-                               const void *data,
-                               uint32_t dataLen)
+CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                     const void *data,
+                                     uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, NULL, "Param data is NULL");
 
-    VERIFY_NON_NULL_RET(g_sendQueueHandle, CALEADAPTER_TAG,
+#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(g_bleServerSendDataMutex, CALEADAPTER_TAG,
                         "BleClientSendDataMutex is NULL",
                         CA_STATUS_FAILED);
 
-    VERIFY_NON_NULL_RET(g_sendQueueHandle, 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);
 
-    CALEData_t *bleData = CACreateBLEData(remoteEndpoint, data, dataLen);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -1732,15 +1810,16 @@ CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
     }
     // Add message to send queue
     ca_mutex_lock(g_bleServerSendDataMutex);
-    CAQueueingThreadAddData(g_sendQueueHandle, bleData, sizeof(CALEData_t));
+    CAQueueingThreadAddData(g_bleServerSendQueueHandle, bleData, sizeof(CALEData_t));
     ca_mutex_unlock(g_bleServerSendDataMutex);
-
+#endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const 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(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1748,6 +1827,15 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
     VERIFY_NON_NULL(serviceUUID, CALEADAPTER_TAG, "service UUID is null");
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
+
+#ifdef SINGLE_THREAD
+    if(g_networkPacketReceivedCallback)
+    {
+        CAEndpoint_t endPoint = { 0 };   // will be filled by upper layer
+        endPoint.adapter = CA_ADAPTER_GATT_BTLE;
+        g_networkPacketReceivedCallback(&endPoint, data, dataLength);
+    }
+#else
     VERIFY_NON_NULL_RET(g_bleServerReceiverQueue, CALEADAPTER_TAG, "g_bleServerReceiverQueue",
                         CA_STATUS_FAILED);
 
@@ -1764,7 +1852,7 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
     // Create bleData to add to queue
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
 
-    CALEData_t *bleData = CACreateBLEData(remoteEndpoint, data, dataLength);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -1777,13 +1865,14 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
     CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-
+#endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
-                                   const 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(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1791,6 +1880,7 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
     VERIFY_NON_NULL(serviceUUID, CALEADAPTER_TAG, "service UUID is null");
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
+#ifndef SINGLE_THREAD
     VERIFY_NON_NULL_RET(g_bleClientReceiverQueue, CALEADAPTER_TAG, "g_bleClientReceiverQueue",
                         CA_STATUS_FAILED);
 
@@ -1807,7 +1897,7 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
 
     // Create bleData to add to queue
-    CALEData_t *bleData = CACreateBLEData(remoteEndpoint, data, dataLength);
+    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -1820,12 +1910,12 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
     CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-
+#endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-void CASetBleAdapterThreadPoolHandle(ca_thread_pool_t handle)
+void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -1836,7 +1926,7 @@ void CASetBleAdapterThreadPoolHandle(ca_thread_pool_t handle)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
+void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
diff --git a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter_singlethread.c b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter_singlethread.c
deleted file mode 100644 (file)
index e5d5974..0000000
+++ /dev/null
@@ -1,430 +0,0 @@
-/******************************************************************
-*
-* Copyright 2014 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-#include "caleadapter_singlethread.h"
-
-#include "caleinterface_singlethread.h"
-#include "cableserver.h"
-#include "logger.h"
-#include "caadapterutils.h"
-#include "cafragmentation.h"
-#include "caremotehandler.h"
-
-#define TAG "LAD"
-
-/**
- * @def MAX_EVENT_COUNT
- * @brief Maximum number of tries to get the event on BLE Shield address.
- */
-#define MAX_EVENT_COUNT 20
-
-static CANetworkChangeCallback g_networkCallback = NULL;
-static bool g_serverRunning = false;
-static CANetworkPacketReceivedCallback g_respCallback;
-static char *g_coapBuffer = NULL;
-static uint32_t g_dataLen = 0;
-static uint32_t g_packetDataLen = 0;
-
-/**
- * @brief API to register for BLE network notification.
- * @param net_callback - network notification callback.
- * @return - Error Code
- */
-CAResult_t LERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
-
-/**
- * @brief API to send received data to upper layer.
- * @param[in] data - data received from BLE characteristics.
- * @param[in] dataLen - received data Length.
- * @param[in] senderAdrs - sender Address.
- * @param[in] senderPort - sender port.
- * @return - Error Code
- */
-void CANotifyCallback(const void *data, int32_t dataLen, const char *senderAdrs,
-                      int32_t senderPort);
-
-/**
- * @brief API to read the data from characteristics and invoke notifyCallback.
- * @return - void
- */
-void CACheckData();
-
-/**
- * @brief API to Send the data.
- * @return - Number of bytes sent. -1 on error.
- */
-int32_t CASendLEData(const void *data, uint32_t dataLen);
-
-CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
-                          CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    if (NULL == registerCallback || NULL == reqRespCallback || NULL == netCallback)
-    {
-        OIC_LOG(ERROR, TAG, "i/p null");
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    CAResult_t result = CALEInitializeNetworkMonitor();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, TAG, "n/w init fail: %d", result);
-        return CA_STATUS_FAILED;
-    }
-
-    g_respCallback = reqRespCallback;
-    LERegisterNetworkNotifications(netCallback);
-    CAConnectivityHandler_t connHandler;
-    connHandler.startAdapter = CAStartLE;
-    connHandler.startListenServer = CAStartLEListeningServer;
-    connHandler.startDiscoveryServer = CAStartLEDiscoveryServer;
-    connHandler.sendData = CASendLEUnicastData;
-    connHandler.sendDataToAll = CASendLEMulticastData;
-    connHandler.GetnetInfo = CAGetLEInterfaceInformation;
-    connHandler.readData = CAReadLEData;
-    connHandler.stopAdapter = CAStopLE;
-    connHandler.terminate = CATerminateLE;
-    registerCallback(connHandler, CA_ADAPTER_GATT_BTLE);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartLE()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartLEListeningServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    CAResult_t result = CAInitializeBle();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, TAG, "ble init fail: %d", result);
-        return CA_STATUS_FAILED;
-    }
-    /**
-     * Below for loop is to process the BLE Events received from BLE Shield.
-     * BLE Events includes BLE Shield Address Added as a patch to RBL Library.
-     */
-    for (int iter = 0; iter < MAX_EVENT_COUNT; iter++)
-    {
-        CACheckData();
-    }
-
-    g_serverRunning = true;
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartLEDiscoveryServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartLENotifyServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
-                              uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return 1;
-}
-
-int32_t CASendLEUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
-                            uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    if (NULL == remoteEndpoint || NULL == data || dataLen == 0)
-    {
-        OIC_LOG(ERROR, TAG, "i/p null");
-        return -1;
-    }
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CASendLEData(data, dataLen);
-}
-
-int32_t CASendLEMulticastData(const void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    if (NULL == data || 0 == dataLen)
-    {
-        OIC_LOG(ERROR, TAG, "i/p null");
-        return -1;
-    }
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CASendLEData(data, dataLen);
-}
-
-CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    if (NULL == info || NULL == size)
-    {
-        OIC_LOG(ERROR, TAG, "i/p null");
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    char *leAddress = NULL;
-    CAResult_t res = CAGetLEAddress(&leAddress);
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "CAGetLEAddress has failed");
-        return res;
-    }
-
-    if (NULL == leAddress)
-    {
-        OIC_LOG(ERROR, TAG, "Failed to get Le addr");
-        return CA_STATUS_FAILED;
-    }
-
-    OIC_LOG_V(DEBUG, TAG, "leAddress = %s", leAddress);
-
-    /**
-     * Create local endpoint using util function
-     */
-    (*info) = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_RFCOMM_BTEDR, leAddress, 0);
-    if (NULL == (*info))
-    {
-        OIC_LOG(ERROR, TAG, "malloc fail");
-        return CA_MEMORY_ALLOC_FAILED;
-    }
-
-    (*size) = 1;
-    if (*leAddress)
-    {
-        OICFree(leAddress);
-    }
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAReadLEData()
-{
-    if (true == g_serverRunning)
-    {
-        CACheckData();
-    }
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStopLE()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    CAStopBleGattServer();
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-void CATerminateLE()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    g_respCallback = NULL;
-    LERegisterNetworkNotifications(NULL);
-    CAResult_t result = CATerminateBle();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, TAG, "ble terminate fail");
-        return;
-    }
-
-    CALETerminateNetworkMonitor();
-    g_serverRunning = false;
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return;
-}
-
-CAResult_t LERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    g_networkCallback = netCallback;
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartBleGattServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    // Done at time of setup i.e. in initializeBle api
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStopBleGattServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    // There is no server running to stop.
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-void CANotifyCallback(const void *data, int32_t dataLen, const char *senderAdrs, int32_t senderPort)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    if (g_respCallback)
-    {
-
-        /* Cannot get Address as of now */
-        CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
-                                                             CA_ADAPTER_GATT_BTLE,
-                                                             senderAdrs, senderPort);
-
-        g_respCallback(localEndpoint, data, dataLen);
-    }
-    OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CACheckData()
-{
-    CABleDoEvents();
-
-    if (CAIsBleDataAvailable())
-    {
-        // Allocate Memory for COAP Buffer and do ParseHeader
-        if (NULL == g_coapBuffer)
-        {
-            OIC_LOG(DEBUG, TAG, "IN");
-            char headerArray[CA_HEADER_LENGTH] = "";
-            while (CAIsBleDataAvailable() && g_dataLen < CA_HEADER_LENGTH)
-            {
-                headerArray[g_dataLen++] = CAReadBleData();
-            }
-
-            g_packetDataLen = CAParseHeader(headerArray);
-
-            if (g_packetDataLen > COAP_MAX_PDU_SIZE)
-            {
-                OIC_LOG(ERROR, TAG, "len > pdu_size");
-                return;
-            }
-
-            g_coapBuffer = (char *)OICCalloc((size_t)g_packetDataLen, sizeof(char));
-            if (NULL == g_coapBuffer)
-            {
-                OIC_LOG(ERROR, TAG, "malloc");
-                return;
-            }
-
-            OIC_LOG(DEBUG, TAG, "OUT");
-            g_dataLen = 0;
-        }
-
-        OIC_LOG(DEBUG, TAG, "IN");
-        while (CAIsBleDataAvailable())
-        {
-            OIC_LOG(DEBUG, TAG, "In While loop");
-            g_coapBuffer[g_dataLen++] = CAReadBleData();
-            if (g_dataLen == g_packetDataLen)
-            {
-                OIC_LOG(DEBUG, TAG, "Read Comp BLE Pckt");
-                g_coapBuffer[g_dataLen] = '\0';
-                if (g_dataLen > 0)
-                {
-                    OIC_LOG_V(DEBUG, TAG, "recv dataLen=%d", g_dataLen);
-                    CANotifyCallback((void *)g_coapBuffer, g_dataLen, "", 0);
-                }
-                g_dataLen = 0;
-                OICFree(g_coapBuffer);
-                g_coapBuffer = NULL;
-                break;
-            }
-        }
-        OIC_LOG(DEBUG, TAG, "OUT");
-    }
-    else
-    {
-        OIC_LOG(DEBUG, TAG, "NoData");
-    }
-    return;
-}
-
-int32_t CASendLEData(const void *data, uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    char header[CA_HEADER_LENGTH] = {0};
-
-    CAResult_t result = CAGenerateHeader(header, dataLen);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, TAG, "Generate header failed");
-        return -1;
-    }
-
-    if (!CAIsBleConnected())
-    {
-        OIC_LOG(ERROR, TAG, "le not conn");
-        return -1;
-    }
-
-    result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, 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, TAG, "Update characteristics failed");
-            return -1;
-        }
-        CABleDoEvents();
-    }
-
-    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, TAG, "Update characteristics failed");
-            return -1;
-        }
-        CABleDoEvents();
-    }
-
-    OIC_LOG(DEBUG, TAG, "writebytes done");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    // Arduino BLEWrite doesnot return value. So, Return the received DataLength
-    return dataLen;
-}
-
index 54c3e69..be9cd39 100644 (file)
@@ -634,7 +634,7 @@ void CAPrintDiscoveryInformation(const bt_adapter_le_device_discovery_info_s *di
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
 }
 
-void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle)
+void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -645,7 +645,7 @@ void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle)
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
 }
 
-void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
+void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -664,7 +664,7 @@ void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback)
     g_clientErrorCallback = callback;
 }
 
-CAResult_t CAStartBLEGattClient()
+CAResult_t CAStartLEGattClient()
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -719,7 +719,7 @@ void CAStartBleGattClientThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleSetScanParameter Failed");
         ca_mutex_unlock(g_bleClientStateMutex);
-        CATerminateBLEGattClient();
+        CATerminateLEGattClient();
         return;
     }
 
@@ -728,7 +728,7 @@ void CAStartBleGattClientThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleGattSetCallbacks Failed");
         ca_mutex_unlock(g_bleClientStateMutex);
-        CATerminateBLEGattClient();
+        CATerminateLEGattClient();
         return;
     }
 
@@ -739,7 +739,7 @@ void CAStartBleGattClientThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_start_device_discovery Failed");
         ca_mutex_unlock(g_bleClientStateMutex);
-        CATerminateBLEGattClient();
+        CATerminateLEGattClient();
         return;
     }
 
@@ -760,7 +760,7 @@ void CAStartBleGattClientThread(void *data)
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
 }
 
-void CAStopBLEGattClient()
+void CAStopLEGattClient()
 {
     OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "IN");
 
@@ -805,7 +805,7 @@ void CAStopBLEGattClient()
     OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "OUT");
 }
 
-void CATerminateBLEGattClient()
+void CATerminateLEGattClient()
 {
     OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "IN");
     ca_mutex_lock(g_bleClientStateMutex);
index d800fc5..9bcb6dc 100644 (file)
@@ -150,7 +150,7 @@ void CABleGattServerConnectionStateChangedCb(int result, bool connected,
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
 }
 
-CAResult_t CAStartBleGattServer()
+CAResult_t CAStartLEGattServer()
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
@@ -192,7 +192,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "Gatt Server is already running");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -201,7 +201,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "_bt_gatt_init_service failed");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -214,7 +214,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "CAAddNewBleServiceInGattServer failed");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -227,7 +227,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "CAAddNewCharacteristicsToGattServer failed");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -241,7 +241,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "CAAddNewCharacteristicsToGattServer failed");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -250,7 +250,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "CARegisterBleServicewithGattServer failed");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -269,7 +269,7 @@ void CAStartBleGattServerThread(void *data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_hAdvertiser is NULL");
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -279,7 +279,7 @@ void CAStartBleGattServerThread(void *data)
         OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "bt_adapter_le_start_advertising failed with ret [%d] ",
                   res);
         ca_mutex_unlock(g_bleServerStateMutex);
-        CATerminateBleGattServer();
+        CATerminateLEGattServer();
         return;
     }
 
@@ -303,7 +303,7 @@ void CAStartBleGattServerThread(void *data)
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
 }
 
-CAResult_t CAStopBleGattServer()
+CAResult_t CAStopLEGattServer()
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
@@ -375,7 +375,7 @@ CAResult_t CAStopBleGattServer()
     return CA_STATUS_OK;
 }
 
-void CATerminateBleGattServer()
+void CATerminateLEGattServer()
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
@@ -496,7 +496,7 @@ CAResult_t CADeInitBleGattService()
     return CA_STATUS_OK;
 }
 
-void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle)
+void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
     ca_mutex_lock(g_bleServerThreadPoolMutex);
@@ -755,8 +755,7 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *
     return CA_STATUS_OK;
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
-        const uint32_t charValueLen)
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue, uint32_t charValueLen)
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
@@ -801,7 +800,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
     return CA_STATUS_OK;
 }
 
-void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback)
+void CASetLEReqRespServerCallback(CABLEServerDataReceivedCallback callback)
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
index 6e4c265..4d08fa8 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "caipadapter.h"
 #include "caedradapter_singlethread.h"
-#include "caleadapter_singlethread.h"
+#include "caleadapter.h"
 #include "caadapterutils.h"
 
 #include "canetworkconfigurator.h"
@@ -146,7 +146,8 @@ void CAInitializeAdapters()
 #endif /* EDR_ADAPTER */
 
 #ifdef LE_ADAPTER
-    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback);
+    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+                   NULL, NULL);
 #endif /* LE_ADAPTER */
 
     OIC_LOG(DEBUG, TAG, "OUT");