Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / cableclient.c
index 1fba87b..d7c505c 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* ****************************************************************
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 #include "caqueueingthread.h"
 #include "caadapterutils.h"
 #include "cafragmentation.h"
+#include "cagattservice.h"
 #include "oic_string.h"
 #include "oic_malloc.h"
 
 /**
- * @def TZ_BLE_CLIENT_TAG
- * @brief Logging tag for module name
+ * Logging tag for module name.
  */
 #define TZ_BLE_CLIENT_TAG "TZ_BLE_GATT_CLIENT"
 
 /**
- * @var BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG
- * @brief Its the constant value for characteristic descriptor from spec.
- */
-#define BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG "2902"
-
-/**
- * @var g_bLEServiceList
- * @brief This contains the list of OIC services a client connect tot.
+ * This contains the list of OIC services a client connect to.
  */
 static BLEServiceList *g_bLEServiceList = NULL;
 
 /**
- * @var g_isBleGattClientStarted
- * @brief Boolean variable to keep the state of the GATT Client.
+ * Boolean variable to keep the state of the GATT Client.
  */
 static bool g_isBleGattClientStarted = false;
 
 /**
- * @var g_bleServiceListMutex
- * @brief Mutex to synchronize access to BleServiceList.
+ * Mutex to synchronize access to BleServiceList.
  */
 static ca_mutex g_bleServiceListMutex = NULL;
 
 /**
- * @var g_bleReqRespClientCbMutex
- * @brief Mutex to synchronize access to the requestResponse callback to be called
- *           when the data needs to be sent from GATTClient.
+ * Mutex to synchronize access to the requestResponse callback to be called
+ *    when the data needs to be sent from GATTClient.
  */
 static ca_mutex g_bleReqRespClientCbMutex = NULL;
 
 /**
- * @var g_bleReqRespClientCbMutex
- * @brief Mutex to synchronize access to the requestResponse callback to be called
- *           when the data needs to be sent from GATTClient.
+ * Mutex to synchronize access to the requestResponse callback to be called
+ *    when the data needs to be sent from GATTClient.
  */
 static ca_mutex g_bleClientConnectMutex = NULL;
 
 
 /**
- * @var g_bleClientStateMutex
- * @brief Mutex to synchronize the calls to be done to the platform from GATTClient
- *           interfaces from different threads.
+ * Mutex to synchronize the calls to be done to the platform from GATTClient
+ *    interfaces from different threads.
  */
 static ca_mutex g_bleClientStateMutex = NULL;
 
 /**
- * @var g_bleServerBDAddressMutex
- * @brief Mutex to synchronize the Server BD Address update on client side.
+ * Mutex to synchronize the Server BD Address update on client side.
  */
 static ca_mutex g_bleServerBDAddressMutex = NULL;
 
 /**
- * @var g_bleClientSendCondWait
- * @brief Condition used for notifying handler the presence of data in send queue.
+ * Condition used for notifying handler the presence of data in send queue.
  */
 static ca_cond g_bleClientSendCondWait = NULL;
 
 /**
- * @var g_bleClientThreadPoolMutex
- * @brief Mutex to synchronize the task to be pushed to thread pool.
+ * Mutex to synchronize the task to be pushed to thread pool.
  */
 static ca_mutex g_bleClientThreadPoolMutex = NULL;
 
 /**
- * @var gNetworkPacketReceivedClientCallback
- * @brief Maintains the callback to be notified on receival of network packets from other
- *           BLE devices
+ * Maintains the callback to be notified on receival of network packets
+ *    from other BLE devices
  */
-static CABLEClientDataReceivedCallback g_bleClientDataReceivedCallback = NULL;
+static CABLEDataReceivedCallback g_bleClientDataReceivedCallback = NULL;
 
 /**
- * @var g_clientErrorCallback
- * @brief callback to update the error to le adapter
+ * callback to update the error to le adapter
  */
 static CABLEErrorHandleCallback g_clientErrorCallback;
 
 /**
- * @var g_eventLoop
- * @brief gmainLoop to manage the threads to receive the callback from the platfrom.
+ * gmainLoop to manage the threads to receive the callback from the platfrom.
  */
 static GMainLoop *g_eventLoop = NULL;
 
 /**
- * @var g_bleClientThreadPool
- * @brief reference to threadpool
+ * reference to threadpool.
  */
 static ca_thread_pool_t g_bleClientThreadPool = NULL;
 
 /**
- * @struct stGattServiceInfo_t
- * @brief structure to map the service attribute to BD Address.
+ * structure to map the service attribute to BD Address.
  */
 typedef struct gattService
 {
@@ -144,14 +124,14 @@ typedef struct gattService
 } stGattServiceInfo_t;
 
 /**
- * @var g_remoteAddress
- * @brief Remote address of Gatt Server
+ * Remote address of Gatt Server.
  */
 static char *g_remoteAddress = NULL;
 
 void CABleGattCharacteristicChangedCb(bt_gatt_attribute_h characteristic,
                                       unsigned char *value,
-                                      int valueLen, void *userData)
+                                      int valueLen,
+                                      void *userData)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -169,8 +149,8 @@ void CABleGattCharacteristicChangedCb(bt_gatt_attribute_h characteristic,
 
     ca_mutex_lock(g_bleServerBDAddressMutex);
     uint32_t sentLength = 0;
-    g_bleClientDataReceivedCallback(g_remoteAddress, OIC_BLE_SERVICE_ID,
-                                     value, valueLen, &sentLength);
+    g_bleClientDataReceivedCallback(g_remoteAddress, value, valueLen,
+                                    &sentLength);
 
     OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Sent data Length is %d", sentLength);
     ca_mutex_unlock(g_bleServerBDAddressMutex);
@@ -279,7 +259,7 @@ bool CABleGattCharacteristicsDiscoveredCb(int result,
     OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "New Characteristics[%s] of uuid[%s] is obtained",
               (char *)characteristic, uuid);
 
-    if(0 == strcasecmp(uuid, CA_BLE_READ_CHAR_UUID)) // Server will read on this characterisctics
+    if(0 == strcasecmp(uuid, CA_GATT_RESPONSE_CHRC_UUID)) // Server will read on this characterisctics
     {
         OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Read characteristics is obtained");
         OICFree(uuid);
@@ -331,7 +311,7 @@ bool CABleGattCharacteristicsDiscoveredCb(int result,
         }
         ca_mutex_unlock(g_bleClientThreadPoolMutex);
     }
-    else if (0 == strcasecmp(uuid, CA_BLE_WRITE_CHAR_UUID)) // Server will write on this characteristics.
+    else if (0 == strcasecmp(uuid, CA_GATT_REQUEST_CHRC_UUID)) // Server will write on this characteristics.
     {
         OICFree(uuid);
         OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Write characteristics is obtained");
@@ -651,7 +631,7 @@ void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
 }
 
-void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback)
+void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -1369,9 +1349,9 @@ CAResult_t CASetCharacteristicDescriptorValue(stGattCharDescriptor_t *stGattChar
     OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "desc x3 [%x]", stGattCharDescInfo->desc[3]);
 
 
-    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG strUUID is [%s]",
+    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "CA_GATT_CONFIGURATION_DESC_UUID strUUID is [%s]",
               strUUID);
-    //if (!strncmp(strUUID, BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG, 2))
+    //if (!strncmp(strUUID, CA_GATT_CONFIGURATION_DESC_UUID, 2))
     {
         OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "setting notification/indication for descriptor");
 
@@ -1394,8 +1374,8 @@ CAResult_t CASetCharacteristicDescriptorValue(stGattCharDescriptor_t *stGattChar
 }
 
 CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
-        const char  *data, const uint32_t dataLen,
-        CALETransferType_t type, const int32_t position)
+        const uint8_t *data, uint32_t dataLen,
+        CALETransferType_t type, int32_t position)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
 
@@ -1432,16 +1412,12 @@ CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
 
     VERIFY_NON_NULL(bleServiceInfo, TZ_BLE_CLIENT_TAG, "bleServiceInfo is NULL");
 
-    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating the data of length [%d] to [%s] ", dataLen,
+    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating the data of length [%u] to [%s] ", dataLen,
               bleServiceInfo->bdAddress);
 
     OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating to write char [%s]",
               bleServiceInfo->read_char);
 
-    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG,
-              "Updating the data of length [%d] to [%s]", dataLen,
-              bleServiceInfo->bdAddress);
-
     int result = bt_gatt_set_characteristic_value(bleServiceInfo->write_char, (unsigned char *)data,
                      dataLen);
     if (BT_ERROR_NONE != result)
@@ -1456,7 +1432,7 @@ CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
     return CA_STATUS_OK;
 }
 
-CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data,
+CAResult_t  CAUpdateCharacteristicsToAllGattServers(const uint8_t *data,
             uint32_t dataLen)
 {
     OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "IN");
@@ -1490,5 +1466,3 @@ CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data,
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT ");
     return CA_STATUS_OK;
 }
-
-