Corrected pointer arithmetic on void* variables.
authorOssama Othman <ossama.othman@intel.com>
Fri, 31 Jul 2015 23:12:40 +0000 (16:12 -0700)
committerJon A. Cruz <jonc@osg.samsung.com>
Tue, 11 Aug 2015 00:18:15 +0000 (00:18 +0000)
Octet arrays were represented by void* and char* typed variables in
several areas of the CA layer.  Use uint8_t* where appropriate to
address undefined pointer arithemetic on pointers to void.  Code that
treated the octet arrays as strings (e.g. performed strcpy() on them)
was corrected as well.  This addresses several major issues flagged by
SonarQube.

Change-Id: I8d5c57eafa0b0e394e0ee202df1bb7b67c7a59b1
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2034
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
24 files changed:
resource/csdk/connectivity/inc/caedrinterface.h
resource/csdk/connectivity/inc/cafragmentation.h
resource/csdk/connectivity/inc/caleinterface.h
resource/csdk/connectivity/src/adapter_util/cafragmentation.c
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.h
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/linux/caleinterface.c
resource/csdk/connectivity/src/bt_le_adapter/linux/characteristic.c
resource/csdk/connectivity/src/bt_le_adapter/linux/client.c
resource/csdk/connectivity/src/bt_le_adapter/linux/client.h
resource/csdk/connectivity/src/bt_le_adapter/linux/recv.c
resource/csdk/connectivity/src/bt_le_adapter/linux/recv.h
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.h
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.h
resource/csdk/connectivity/src/cablockwisetransfer.c

index b6f0034..6944270 100644 (file)
@@ -67,7 +67,7 @@ typedef enum
 typedef struct
 {
     CAEndpoint_t *remoteEndpoint;       /**< Remote Endpoint. */
-    void *data;                         /**< Data to be sent. */
+    uint8_t *data;                      /**< Data to be sent. */
     uint32_t dataLen;                   /**< Length of the data to be sent. */
 } CAEDRData;
 
@@ -88,7 +88,7 @@ typedef struct
  * @param[out] sentLength    Length of the sent data.
  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
  */
-typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const void *data,
+typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const uint8_t *data,
                                           uint32_t dataLength, uint32_t *sentLength);
 
 /**
@@ -105,8 +105,10 @@ typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
  * @param[in]  result          error code as defined in ::CAResult_t.
  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
  */
-typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress, const void *data,
-        uint32_t dataLength, CAResult_t result);
+typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress,
+                                         const uint8_t *data,
+                                         uint32_t dataLength,
+                                         CAResult_t result);
 
 /**
  * Initialize the network monitor module
@@ -263,7 +265,8 @@ CAResult_t CAEDRGetAdapterEnableState(bool *state);
  * @param[in]  dataLength      Length of the data to be sent.
  * @return ::CA_STATUS_OK or Appropriate error code.
  */
-CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const void *data,
+CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
+                                      const uint8_t *data,
                                       uint32_t dataLength);
 
 /**
@@ -272,7 +275,8 @@ CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const void *dat
  * @param[in]  dataLength      Length of the data to be sent.
  * @return ::CA_STATUS_OK or Appropriate error code.
  */
-CAResult_t CAEDRClientSendMulticastData(const void *data, uint32_t dataLength);
+CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
+                                        uint32_t dataLength);
 
 /**
  * This function gets bonded bluetooth device list
index a10f9f2..253fbd4 100644 (file)
@@ -123,43 +123,47 @@ extern "C"
 
 /**
  * This function is used to generate the CA specific header to
- * maintain the fragmentation logic. The header structure
- * explained above will be formed and returned to the caller.
+ * maintain the fragmentation logic. The header structure explained
+ * above will be formed and returned to the caller.
  *
- * @param[in,out] header Pointer to the octet array that will contain
- *                       the generated header.
- * @param[in]     length The total length of the data.  The length will
- *                       be embedded in bits 5-16 of the header,
- *                       meaning the maximum overall length of the
- *                       data to be fragmented can be no more than 4096
- *                       (2^12).
+ * @param[in,out] header       Pointer to the octet array that will
+ *                             contain the generated header.
+ * @param[in]     headerLength Length of the @a header octet array.
+ * @param[in]     dataLength   The total length of the data.  The
+ *                             length will be embedded in bits 5-16 of
+ *                             the header, meaning the maximum overall
+ *                             length of the data to be fragmented can
+ *                             be no more than 4096 (2^12).
  *
- * @return ::CA_STATUS_OK on success. One of the ::CA_STATUS_FAILED or
- *           other error values on error.
- * @retval ::CA_STATUS_OK             Successful
- * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments
- * @retval ::CA_STATUS_FAILED         Operation failed
-*/
-CAResult_t CAGenerateHeader(char *header, uint32_t length);
-
-/**
- * This function is used to parse the header in the receiver
- * end. This function will provide the information of the total
- * length of the data which has been fragmented.
+ * @return @c CA_STATUS_OK on success. One of the @c CA_STATUS_FAILED
+ *         or other error values on error.
+ * @retval @c CA_STATUS_OK             Successful
+ * @retval @c CA_STATUS_INVALID_PARAM  Invalid input arguments
+ * @retval @c CA_STATUS_FAILED         Operation failed
+ */
+CAResult_t CAGenerateHeader(uint8_t *header,
+                            size_t headerLength,
+                            size_t datalength);
+
+/**
+ * This function is used to parse the header in the receiver end. This
+ * function will provide the information of the total length of the
+ * data which has been fragmented.
  *
- * @param[in] header Pointer to the octet array data which contains the
- *                   header information.  Note that pointer should
+ * @param[in] header Pointer to the octet array data which contains
+ *                   the header information.  Note that pointer should
  *                   point to two bytes of data header which needs to
  *                   be parsed.
+ * @param[in] length Length of the @a octet array containing the
+ *                   header.
  *
  * @return Overall length of the data to be reassembled, or 0 on
  *         failure.
  */
-uint32_t CAParseHeader(const char *header);
+uint32_t CAParseHeader(const uint8_t *header, size_t length);
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
 #endif  /* CA_FRAGMENTATION_H_ */
-
index 589d146..5436b33 100644 (file)
@@ -19,6 +19,8 @@
 ******************************************************************/
 
 /**
+ * @file
+ *
  * This file provides APIs for BLE modules.
  */
 
@@ -68,7 +70,7 @@ typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
  * @retval ::CA_STATUS_FAILED Operation failed.
  */
 typedef CAResult_t (*CABLEDataReceivedCallback)(const char *remoteAddress,
-                                                const void *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLength,
                                                 uint32_t *sentLength);
 
@@ -207,9 +209,9 @@ void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback);
  * Update characteristics(Read/Write) value that we want to send to
  * particular client.
  *
- * @param[in] address      BD address of Gatt client
- * @param[in] charValue    Data that we want to send to client(unicast)
- * @param[in] charValueLen Length of the data.
+ * @param[in] address  BD address of Gatt client
+ * @param[in] value    Data that we want to send to client(unicast)
+ * @param[in] valueLen Length of the data.
  *
  * @return ::CA_STATUS_OK or Appropriate error code
  * @retval ::CA_STATUS_OK  Successful
@@ -217,23 +219,23 @@ void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback);
  * @retval ::CA_STATUS_FAILED Operation failed
  */
 CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
-                                               const char *charValue,
-                                               uint32_t charValueLen);
+                                               const uint8_t *value,
+                                               uint32_t valueLen);
 
 /**
  * Update characteristics(Read/Write) value that we want to multicast
  * to all clients.
  *
- * @param[in] charValue    Data that we want to send to clients(multicast)
- * @param[in] charValueLen Length of the data.
+ * @param[in] value    Data that we want to send to clients(multicast)
+ * @param[in] valueLen Length of the data.
  *
  * @return ::CA_STATUS_OK or Appropriate error code
  * @retval ::CA_STATUS_OK  Successful
  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments
  * @retval ::CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
-                                                   uint32_t charValueLen);
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *value,
+                                                   uint32_t valueLen);
 
 /**
  * Start @c CAStartBleGattClientThread for initializing Gatt Client.
@@ -283,7 +285,7 @@ void CACheckLEData();
  * @retval ::CA_STATUS_FAILED Operation failed
  */
 CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
-                                                const char  *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLen,
                                                 CALETransferType_t type,
                                                 int32_t position);
@@ -300,7 +302,7 @@ CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments
  * @retval ::CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data,
+CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data,
                                                    uint32_t dataLen);
 
 /**
@@ -353,7 +355,7 @@ CAResult_t CAUnSetLEAdapterStateChangedCb();
  * @param[in] result        error code as per CAResult_t
  */
 typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress,
-                                         const void *data,
+                                         const uint8_t *data,
                                          uint32_t dataLength,
                                          CAResult_t result);
 /**
index eacbbec..6831046 100644 (file)
 #include "cafragmentation.h"
 
 /**
- * @var CA_FRAGMENTATION_TAG
- * @brief debugging tag for fragmentation module
+ * Debugging tag for fragmentation module.
  */
 #define CA_FRAGMENTATION_TAG "CA_FRAGMENTATION"
 
-CAResult_t CAGenerateHeader(char *header, uint32_t length)
+CAResult_t CAGenerateHeader(uint8_t *header,
+                            size_t headerLength,
+                            size_t dataLength)
 {
     OIC_LOG(DEBUG, CA_FRAGMENTATION_TAG, "IN");
 
     VERIFY_NON_NULL(header, CA_FRAGMENTATION_TAG, "header is NULL");
-    memset(header, 0x0, sizeof(char) * CA_HEADER_LENGTH);
 
-    if(length > MAX_DATA_LENGTH_SUPPORTED)
+    if (headerLength < CA_HEADER_LENGTH)
     {
-        OIC_LOG(DEBUG, CA_FRAGMENTATION_TAG,
-                "Given length is more than 4095.It will be truncated");
+        return CA_STATUS_FAILED;
     }
-    //if length is more than 4095 then it will be truncated.
-    header[1] = length & 0xFF;
-    length >>= 8;
-    header[0] = length & 0x0F;
-    header[0] = header[0] | 0x40; // Adding version 0100.(Not used. Future use)
+
+    if (dataLength > MAX_DATA_LENGTH_SUPPORTED)
+    {
+        OIC_LOG_V(WARNING,
+                  CA_FRAGMENTATION_TAG,
+                  "Given length is more than %d.  It will be truncated.",
+                  MAX_DATA_LENGTH_SUPPORTED);
+    }
+
+    // Only bother initializing the header section of the buffer.  It
+    // is up to the caller to handle the data section.
+    memset(header, 0, CA_HEADER_LENGTH);
+
+    // If length is more than 4095 then it will be truncated.
+    header[1] = dataLength & 0xFF;
+    dataLength >>= 8;
+    header[0] = dataLength & 0x0F;
+    header[0] = header[0] | 0x40; // Adding version 0100.
+                                  // (Not used. Future use)
 
     OIC_LOG(DEBUG, CA_FRAGMENTATION_TAG, "OUT");
 
     return CA_STATUS_OK;
 }
 
-uint32_t CAParseHeader(const char *header)
+uint32_t CAParseHeader(const uint8_t *header, size_t length)
 {
     OIC_LOG(DEBUG, CA_FRAGMENTATION_TAG, "IN");
 
     VERIFY_NON_NULL_RET(header, CA_FRAGMENTATION_TAG, "header is NULL", 0);
 
-    uint32_t dataLen = ((header[0] & 0x0F) << 8) | (header[1] & 0xFF);
+    uint32_t dataLen = 0;
+
+    if (length >= CA_HEADER_LENGTH)
+    {
+        dataLen = ((header[0] & 0x0F) << 8) | (header[1] & 0xFF);
+    }
 
     OIC_LOG(DEBUG, CA_FRAGMENTATION_TAG, "OUT");
+
     return dataLen;
 }
-
index 3cb4449..d1bf5b4 100644 (file)
@@ -102,21 +102,24 @@ void CAAdapterTerminateQueues();
 void CAAdapterDataSendHandler(void *context);
 void CAAdapterDataReceiverHandler(void *context);
 CAResult_t CAAdapterStopQueue();
-void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dataLength,
+void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
                        uint32_t *sentLength);
 void CAEDRNotifyNetworkStatus(CANetworkStatus_t status);
 void CAEDROnNetworkStatusChanged(void *context);
-CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const void *data,
+CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const uint8_t *data,
                              uint32_t dataLength, uint32_t *sentLength);
 CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity,
                                            CANetworkStatus_t status);
-CAResult_t CAEDRClientSendData(const char *remoteAddress, const void *data,
+
+CAResult_t CAEDRClientSendData(const char *remoteAddress,
+                               const uint8_t *data,
                                uint32_t dataLength);
+
 /**
  * @fn CACreateEDRData
  * @brief Helper function to create CAEDRData
  */
-static CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, const void *data,
+static CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, const uint8_t *data,
                                   uint32_t dataLength);
 
 /**
@@ -133,7 +136,7 @@ void CAEDRFreeNetworkEvent(CAEDRNetworkEvent *event);
 
 static void CAEDRDataDestroyer(void *data, uint32_t size);
 
-static void CAEDRErrorHandler(const char *remoteAddress, const void *data,
+static void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
                               uint32_t dataLength, CAResult_t result);
 
 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
@@ -549,7 +552,8 @@ void CAAdapterDataSendHandler(void *context)
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
 
-CAResult_t CAEDRClientSendData(const char *remoteAddress, const void *data,
+CAResult_t CAEDRClientSendData(const char *remoteAddress,
+                               const uint8_t *data,
                                uint32_t dataLength)
 {
 
@@ -641,7 +645,7 @@ CAResult_t CAAdapterStopQueue()
     return CA_STATUS_OK;
 }
 
-void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dataLength,
+void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
                        uint32_t *sentLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
@@ -678,7 +682,7 @@ void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dat
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
 
-void CAEDRErrorHandler(const char *remoteAddress, const void *data,
+void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
                        uint32_t dataLength, CAResult_t result)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
@@ -703,7 +707,7 @@ void CAEDRErrorHandler(const char *remoteAddress, const void *data,
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
 
-CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const void *data,
+CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const uint8_t *data,
                              uint32_t dataLength, uint32_t *sentLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CAAdapterSendData");
@@ -857,7 +861,7 @@ void CAEDRFreeNetworkEvent(CAEDRNetworkEvent *event)
 }
 
 CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint,
-                                        const void *data, uint32_t dataLength)
+                                        const uint8_t *data, uint32_t dataLength)
 {
     CAEDRData *edrData = (CAEDRData *)OICMalloc(sizeof (CAEDRData));
     if (!edrData)
index 48f4ac9..fcfb279 100644 (file)
@@ -583,7 +583,8 @@ void CAEDRClientDisconnectAll(void)
 }
 
 
-CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const void *data,
+CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
+                                      const uint8_t *data,
                                       uint32_t dataLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
@@ -681,7 +682,8 @@ CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const void *dat
     return CA_STATUS_OK;
 }
 
-CAResult_t CAEDRClientSendMulticastData(const void *data, uint32_t dataLength)
+CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
+                                        uint32_t dataLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
 
@@ -846,8 +848,10 @@ void CAEDRDataRecvCallback(bt_socket_received_data_s *data, void *userData)
 
     uint32_t sentLength = 0;
 
-    g_edrPacketReceivedCallback(device->remoteAddress, data->data,
-                                (uint32_t)data->data_size, &sentLength);
+    g_edrPacketReceivedCallback(device->remoteAddress,
+                                (uint8_t *) data->data,
+                                (uint32_t) data->data_size,
+                                &sentLength);
 
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
index 86058b5..38ae49a 100644 (file)
@@ -348,19 +348,21 @@ void CALEClientSendFinish(JNIEnv *env, jobject gatt)
     CALEClientUpdateSendCnt(env);
 }
 
-CAResult_t CALEClientSendUnicastMessage(const char* address, const char* data,
+CAResult_t CALEClientSendUnicastMessage(const char* address,
+                                        const uint8_t* data,
                                         const uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessage(%s, %s)", address, data);
+    OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessage(%s, %p)", address, data);
     VERIFY_NON_NULL(address, TAG, "address is null");
     VERIFY_NON_NULL(data, TAG, "data is null");
 
     return CALEClientSendUnicastMessageImpl(address, data, dataLen);
 }
 
-CAResult_t CALEClientSendMulticastMessage(const char* data, const uint32_t dataLen)
+CAResult_t CALEClientSendMulticastMessage(const uint8_t* data,
+                                          const uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "CALEClientSendMulticastMessage(%s)", data);
+    OIC_LOG_V(DEBUG, TAG, "CALEClientSendMulticastMessage(%p)", data);
     VERIFY_NON_NULL(data, TAG, "data is null");
 
     if (!g_jvm)
@@ -480,10 +482,10 @@ void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback)
     g_clientErrorCallback = callback;
 }
 
-CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const char* data,
+CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t* data,
                                       const uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessageImpl, address: %s, data: %s", address,
+    OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessageImpl, address: %s, data: %p", address,
               data);
     VERIFY_NON_NULL(address, TAG, "address is null");
     VERIFY_NON_NULL(data, TAG, "data is null");
@@ -619,10 +621,10 @@ error_exit:
     return CA_SEND_FAILED;
 }
 
-CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const char* data,
+CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
                                               const uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "CASendMulticastMessageImpl, send to, data: %s, %d", data, dataLen);
+    OIC_LOG_V(DEBUG, TAG, "CASendMulticastMessageImpl, send to, data: %p, %u", data, dataLen);
     VERIFY_NON_NULL(data, TAG, "data is null");
     VERIFY_NON_NULL(env, TAG, "env is null");
 
@@ -673,7 +675,7 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const char* data,
         res = CALEClientSendData(env, jarrayObj);
         if (res != CA_STATUS_OK)
         {
-            OIC_LOG(ERROR, TAG, "BT device[%d] - send has failed");
+            OIC_LOG(ERROR, TAG, "BT device - send has failed");
         }
 
         jstring jni_address = CALEGetAddressFromBTDevice(env, jarrayObj);
@@ -3121,7 +3123,7 @@ void CATerminateLEGattClient()
     CALEClientTerminate();
 }
 
-CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char  *data,
+CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const uint8_t  *data,
                                                 uint32_t dataLen, CALETransferType_t type,
                                                 int32_t position)
 {
@@ -3138,7 +3140,7 @@ CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const
     return CALEClientSendUnicastMessage(remoteAddress, data, dataLen);
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, uint32_t dataLen)
+CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "call CALEClientSendMulticastMessage");
     VERIFY_NON_NULL(data, TAG, "data is null");
@@ -3521,24 +3523,23 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicChangedCallback(
     VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
     VERIFY_NON_NULL_VOID(data, TAG, "data is null");
 
-    // get Byte Array and covert to char*
+    // get Byte Array and convert to uint8_t*
     jint length = (*env)->GetArrayLength(env, data);
 
     jboolean isCopy;
     jbyte *jni_byte_responseData = (jbyte*) (*env)->GetByteArrayElements(env, data, &isCopy);
 
-    OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - raw data received : %s",
+    OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - raw data received : %p",
             jni_byte_responseData);
 
-    char* receivedData = (char*) OICMalloc(sizeof(char) * length + 1);
+    uint8_t* receivedData = OICMalloc(length);
     if (!receivedData)
     {
-        OIC_LOG(ERROR, TAG, "recevicedData is null");
+        OIC_LOG(ERROR, TAG, "receivedData is null");
         return;
     }
 
-    memcpy(receivedData, (const char*) jni_byte_responseData, length);
-    receivedData[length] = '\0';
+    memcpy(receivedData, jni_byte_responseData, length);
     (*env)->ReleaseByteArrayElements(env, data, jni_byte_responseData, JNI_ABORT);
 
     jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
@@ -3557,7 +3558,7 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicChangedCallback(
         return;
     }
 
-    OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - data. : %s, %d",
+    OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - data. : %p, %d",
               receivedData, length);
 
     ca_mutex_lock(g_bleServerBDAddressMutex);
index 4022d8d..1b04609 100644 (file)
@@ -60,7 +60,7 @@ typedef struct le_state_info
  * @param[in]  data                   Data received from remote device.
  * @pre  Callback must be registered using CALESetCallback(CAPacketReceiveCallback callback)
  */
-typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
+typedef void (*CAPacketReceiveCallback)(const char *address, const uint8_t *data);
 
 /**
  * initialize JNI object.
@@ -104,7 +104,7 @@ void CALEClientSendFinish(JNIEnv *env, jobject gatt);
  * @param[in]   dataLen               data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEClientSendUnicastMessage(const char *address, const char *data,
+CAResult_t CALEClientSendUnicastMessage(const char *address, const uint8_t *data,
                                         const uint32_t dataLen);
 
 /**
@@ -113,7 +113,7 @@ CAResult_t CALEClientSendUnicastMessage(const char *address, const char *data,
  * @param[in]   dataLen               data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEClientSendMulticastMessage(const char *data, const uint32_t dataLen);
+CAResult_t CALEClientSendMulticastMessage(const uint8_t *data, const uint32_t dataLen);
 
 /**
  * start unicast server.
@@ -152,7 +152,7 @@ void CALEClientSetCallback(CAPacketReceiveCallback callback);
  * @param[in]   dataLen               data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEClientSendUnicastMessageImpl(const char *address, const char *data,
+CAResult_t CALEClientSendUnicastMessageImpl(const char *address, const uint8_t *data,
                                             const uint32_t dataLen);
 
 /**
@@ -162,7 +162,7 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char *address, const char *dat
  * @param[in]   dataLen               data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const char *data,
+CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data,
                                               const uint32_t dataLen);
 
 /**
index dfa9c15..db04fac 100644 (file)
@@ -1506,9 +1506,9 @@ void CALEServerTerminate()
     OIC_LOG(DEBUG, TAG, "OUT - CALEServerTerminate");
 }
 
-CAResult_t CALEServerSendUnicastMessage(const char* address, const char* data, uint32_t dataLen)
+CAResult_t CALEServerSendUnicastMessage(const char* address, const uint8_t* data, uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendUnicastMessage(%s, %s)", address, data);
+    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendUnicastMessage(%s, %p)", address, data);
     VERIFY_NON_NULL(address, TAG, "address is null");
     VERIFY_NON_NULL(data, TAG, "data is null");
 
@@ -1549,9 +1549,9 @@ CAResult_t CALEServerSendUnicastMessage(const char* address, const char* data, u
     return ret;
 }
 
-CAResult_t CALEServerSendMulticastMessage(const char* data, uint32_t dataLen)
+CAResult_t CALEServerSendMulticastMessage(const uint8_t* data, uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendMulticastMessage(%s)", data);
+    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendMulticastMessage(%p)", data);
     VERIFY_NON_NULL(data, TAG, "data is null");
 
     if (!g_jvm)
@@ -1710,10 +1710,10 @@ void CALEServerSetCallback(CAPacketReceiveCallback callback)
     g_packetReceiveCallback = callback;
 }
 
-CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char* address, const char* data,
+CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char* address, const uint8_t* data,
                                             uint32_t dataLen)
 {
-    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendUnicastMessageImpl, address: %s, data: %s",
+    OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendUnicastMessageImpl, address: %s, data: %p",
             address, data);
     VERIFY_NON_NULL(env, TAG, "env is null");
     VERIFY_NON_NULL(address, TAG, "address is null");
@@ -1785,7 +1785,7 @@ CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char* address, co
     return CA_STATUS_OK;
 }
 
-CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen)
+CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data, uint32_t dataLen)
 {
     OIC_LOG_V(DEBUG, TAG, "IN - CALEServerSendMulticastMessageImpl, send to, data: %s", data);
     VERIFY_NON_NULL(env, TAG, "env is null");
@@ -2210,22 +2210,21 @@ Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerCharacteristicWriteReques
     VERIFY_NON_NULL_VOID(device, TAG, "device");
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
-    // get Byte Array and covert to char*
+    // get Byte Array and covert to uint8_t*
     jint length = (*env)->GetArrayLength(env, data);
 
     jboolean isCopy;
     jbyte *jni_byte_requestData = (jbyte *) (*env)->GetByteArrayElements(env, data, &isCopy);
 
-    char* requestData = NULL;
-    requestData = (char*) OICMalloc(sizeof(char) * length + 1);
+    uint8_t* requestData = NULL;
+    requestData = OICMalloc(length);
     if (!requestData)
     {
         OIC_LOG(ERROR, TAG, "requestData is null");
         return;
     }
 
-    memcpy(requestData, (const char*) jni_byte_requestData, length);
-    requestData[length] = '\0';
+    memcpy(requestData, jni_byte_requestData, length);
     (*env)->ReleaseByteArrayElements(env, data, jni_byte_requestData, JNI_ABORT);
 
     jstring jni_address = CALEGetAddressFromBTDevice(env, device);
@@ -2244,7 +2243,7 @@ Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerCharacteristicWriteReques
         return;
     }
 
-    OIC_LOG_V(DEBUG, TAG, "remote device address : %s, %s, %d", address, requestData, length);
+    OIC_LOG_V(DEBUG, TAG, "remote device address : %s, %p, %d", address, requestData, length);
 
     ca_mutex_lock(g_bleClientBDAddressMutex);
     uint32_t sentLength = 0;
@@ -2359,7 +2358,7 @@ void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback)
 }
 
 CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
-                                               const char *charValue,
+                                               const uint8_t *charValue,
                                                uint32_t charValueLen)
 {
     CAResult_t result = CA_SEND_FAILED;
@@ -2378,7 +2377,7 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
     return result;
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *charValue,
                                                    uint32_t charValueLen)
 {
     OIC_LOG(DEBUG, TAG, "IN");
index 6d1dc74..1b7a862 100644 (file)
@@ -41,7 +41,7 @@ extern "C"
  * @param[in]  data              Data received from remote device.
  * @pre  Callback must be registered using CALEServerSetCallback(CAPacketReceiveCallback callback).
  */
-typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
+typedef void (*CAPacketReceiveCallback)(const char *address, const uint8_t *data);
 
 /**
  * initialize server for BLE.
@@ -62,7 +62,7 @@ void CALEServerTerminate();
  * @param[in]   dataLen          data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEServerSendUnicastMessage(const char *address, const char *data, uint32_t dataLen);
+CAResult_t CALEServerSendUnicastMessage(const char *address, const uint8_t *data, uint32_t dataLen);
 
 /**
  * send data for multicast (interface).
@@ -70,7 +70,7 @@ CAResult_t CALEServerSendUnicastMessage(const char *address, const char *data, u
  * @param[in]   dataLen          data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEServerSendMulticastMessage(const char *data, uint32_t dataLen);
+CAResult_t CALEServerSendMulticastMessage(const uint8_t *data, uint32_t dataLen);
 
 /**
  * start multicast server (start advertise).
@@ -99,7 +99,7 @@ void CALEServerSetCallback(CAPacketReceiveCallback callback);
  * @param[in]   dataLen          data length.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, const char *data,
+CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, const uint8_t *data,
                                             uint32_t dataLen);
 
 /**
@@ -109,7 +109,7 @@ CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, co
  * @param[in]   dataLen          data length
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen);
+CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data, uint32_t dataLen);
 
 /**
  * set context of application.
index 09b4e20..9e80c02 100644 (file)
@@ -50,7 +50,7 @@ static CABLEDataReceivedCallback g_bleServerDataReceivedCallback = NULL;
 #define MAX_EVENT_COUNT 20
 
 static bool g_serverRunning = false;
-static char *g_coapBuffer = NULL;
+static uint8_t *g_coapBuffer = NULL;
 
 /**
  * @var g_receivedDataLen
@@ -74,13 +74,13 @@ void CACheckLEDataInternal()
         if (NULL == g_coapBuffer)
         {
             OIC_LOG(DEBUG, TAG, "IN");
-            char headerArray[CA_HEADER_LENGTH] = "";
+            uint8_t headerArray[CA_HEADER_LENGTH];
             while (CAIsLEDataAvailable() && g_receivedDataLen < CA_HEADER_LENGTH)
             {
                 headerArray[g_receivedDataLen++] = CALEReadData();
             }
 
-            g_packetDataLen = CAParseHeader(headerArray);
+            g_packetDataLen = CAParseHeader(headerArray, CA_HEADER_LENGTH);
 
             if (g_packetDataLen > COAP_MAX_PDU_SIZE)
             {
@@ -88,7 +88,7 @@ void CACheckLEDataInternal()
                 return;
             }
 
-            g_coapBuffer = (char *)OICCalloc((size_t)g_packetDataLen, sizeof(char));
+            g_coapBuffer = (uint8_t *)OICCalloc((size_t)g_packetDataLen, 1);
             if (NULL == g_coapBuffer)
             {
                 OIC_LOG(ERROR, TAG, "malloc");
@@ -107,10 +107,9 @@ void CACheckLEDataInternal()
             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);
+                    OIC_LOG_V(DEBUG, TAG, "recv dataLen=%u", g_receivedDataLen);
                     uint32_t sentLength = 0;
                     // g_coapBuffer getting freed by CAMesssageHandler
                     g_bleServerDataReceivedCallback("", g_coapBuffer,
@@ -167,9 +166,10 @@ unsigned char CAIsLEConnected()
 {
     return ble_connected();
 }
-char CALEReadData()
+
+uint8_t CALEReadData()
 {
-    return (char)ble_read();
+    return (uint8_t)ble_read();
 }
 
 CAResult_t CALEDoEvents()
@@ -178,7 +178,7 @@ CAResult_t CALEDoEvents()
     return CA_STATUS_OK;
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *char_value,
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *char_value,
                                                    uint32_t valueLength)
 {
     // ble_write_bytes() api can send only max of 255 bytes at a time
index 490513f..f95fcbe 100644 (file)
@@ -60,7 +60,7 @@ unsigned char CAIsLEConnected();
  * API to read data from BLE shield.
  * @return - Data read.
  */
-char CALEReadData();
+uint8_t CALEReadData();
 
 /**
  * API to perform BLE events.
index d44c3f6..9a46051 100644 (file)
  */
 typedef struct
 {
-    CAEndpoint_t *remoteEndpoint;   /**< Remote endpoint contains the
-                                       information of remote device. */
-    void *data;        /**< Data to be transmitted over LE transport. */
-    uint32_t dataLen;  /**< Length of the data being transmitted. */
+    /// Remote endpoint contains the information of remote device.
+    CAEndpoint_t *remoteEndpoint;
+
+    /// Data to be transmitted over LE transport.
+    uint8_t *data;
+
+    /// Length of the data being transmitted.
+    uint32_t dataLen;
 } CALEData_t;
 
 /**
@@ -64,7 +68,7 @@ typedef struct
 {
     uint32_t recvDataLen;
     uint32_t totalDataLen;
-    char *defragData;
+    uint8_t *defragData;
     CAEndpoint_t *remoteEndpoint;
  } CABLESenderInfo_t;
 
@@ -198,7 +202,7 @@ static void CASetLEAdapterThreadPoolHandle(ca_thread_pool_t handle);
  * @param[in] adapter_state New state of the adapter to be notified to
  *                          the upper layer.
  */
-static void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state);
+static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state);
 
 /**
  * Used to initialize all required mutex variable for LE Adapter
@@ -220,10 +224,9 @@ static void CATerminateLEAdapterMutex();
 
 /**
  * Prepares and notify error through error callback.
- *
  */
 static void CALEErrorHandler(const char *remoteAddress,
-                             const void *data,
+                             const uint8_t *data,
                              uint32_t dataLen,
                              CAResult_t result);
 
@@ -352,6 +355,48 @@ static CAResult_t CAStopLE();
 static void CATerminateLE();
 
 /**
+ * Set the NetworkPacket received callback to CA layer from adapter
+ * layer.
+ *
+ * @param[in] callback Callback handle sent from the upper layer.
+ */
+static void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
+
+/**
+ * Push the data from CA layer to the Sender processor queue.
+ *
+ * @param[in] remoteEndpoint Remote endpoint information of the
+ *                           server.
+ * @param[in] data           Data to be transmitted from LE.
+ * @param[in] dataLen        Length of the Data being transmitted.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen);
+
+/**
+ * Push the data from CA layer to the Sender processor queue.
+ *
+ * @param[in] remoteEndpoint Remote endpoint information of the
+ *                           server.
+ * @param[in] data           Data to be transmitted from LE.
+ * @param[in] dataLen        Length of the Data being transmitted.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK  Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
+                                            const uint8_t *data,
+                                            uint32_t dataLen);
+
+/**
  * This function will receive the data from the GattServer and add the
  * data to the Server receiver queue.
  *
@@ -371,7 +416,7 @@ static void CATerminateLE();
  *
  */
 static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
-                                                const void *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLength,
                                                 uint32_t *sentLength);
 
@@ -394,53 +439,11 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
  * @retval ::CA_STATUS_FAILED Operation failed.
  */
 static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
-                                                const void *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLength,
                                                 uint32_t *sentLength);
 
 /**
- * Set the NetworkPacket received callback to CA layer from adapter
- * layer.
- *
- * @param[in] callback Callback handle sent from the upper layer.
- */
-static void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
-
-/**
- * Push the data from CA layer to the Sender processor queue.
- *
- * @param[in] remoteEndpoint Remote endpoint information of the
- *                           server.
- * @param[in] data           Data to be transmitted from LE.
- * @param[in] dataLen        Length of the Data being transmitted.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK  Successful.
- * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- */
-static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
-                                            const void *data,
-                                            uint32_t dataLen);
-
-/**
- * Push the data from CA layer to the Sender processor queue.
- *
- * @param[in] remoteEndpoint Remote endpoint information of the
- *                           server.
- * @param[in] data           Data to be transmitted from LE.
- * @param[in] dataLen        Length of the Data being transmitted.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK  Successful.
- * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- */
-static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
-                                            const void *data,
-                                            uint32_t dataLen);
-
-/**
  * This function will be associated with the sender queue for
  * GattServer.
  *
@@ -574,7 +577,7 @@ static CAResult_t CAInitLEReceiverQueue();
  * @retval ::CA_STATUS_FAILED Operation failed.
  */
 static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
-                                  const void *data,
+                                  const uint8_t *data,
                                   uint32_t dataLength);
 
 /**
@@ -851,15 +854,21 @@ static void CATerminateLEQueues()
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
-static CAResult_t CALEGetSenderInfo(char *leAddress,
+static CAResult_t CALEGetSenderInfo(const char *leAddress,
                                     CABLESenderInfo_t **senderInfo,
                                     uint32_t *senderIndex)
 {
-    VERIFY_NON_NULL_RET(leAddress, CALEADAPTER_TAG, "Ble-Address in-param NULL", CA_STATUS_FAILED);
-    VERIFY_NON_NULL_RET(senderIndex, CALEADAPTER_TAG, "Index in-param NULL", CA_STATUS_FAILED);
-
-    uint32_t listLength = u_arraylist_length(g_senderInfo);
-    uint32_t addrLength = strlen(leAddress);
+    VERIFY_NON_NULL_RET(leAddress,
+                        CALEADAPTER_TAG,
+                        "NULL BLE address argument",
+                        CA_STATUS_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(senderIndex,
+                        CALEADAPTER_TAG,
+                        "NULL index argument",
+                        CA_STATUS_INVALID_PARAM);
+
+    const uint32_t listLength = u_arraylist_length(g_senderInfo);
+    const uint32_t addrLength = strlen(leAddress);
     for (uint32_t index = 0; index < listLength; index++)
     {
         CABLESenderInfo_t *info = (CABLESenderInfo_t *) u_arraylist_get(g_senderInfo, index);
@@ -919,7 +928,7 @@ static void CALEDataReceiverHandler(void *threadData)
 
         if(!senderInfo)
         {
-            CABLESenderInfo_t *newSender = (CABLESenderInfo_t*)OICMalloc(sizeof(CABLESenderInfo_t));
+            CABLESenderInfo_t *newSender = OICMalloc(sizeof(CABLESenderInfo_t));
             if(!newSender)
             {
                 OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed for new sender");
@@ -932,7 +941,8 @@ static void CALEDataReceiverHandler(void *threadData)
             newSender->remoteEndpoint = NULL;
 
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-            newSender->totalDataLen = CAParseHeader((char*)bleData->data);
+            newSender->totalDataLen = CAParseHeader(bleData->data,
+                                                    bleData->dataLen);
             if(!(newSender->totalDataLen))
             {
                 OIC_LOG(ERROR, CALEADAPTER_TAG, "Total Data Length is parsed as 0!!!");
@@ -946,7 +956,8 @@ static void CALEDataReceiverHandler(void *threadData)
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "data received in the first packet [%u] bytes",
                                                 bleData->dataLen);
 
-            newSender->defragData = (char *) OICCalloc(newSender->totalDataLen + 1, sizeof(char));
+            newSender->defragData = OICCalloc(newSender->totalDataLen + 1,
+                                              sizeof(*newSender->defragData));
 
             if (NULL == newSender->defragData)
             {
@@ -1038,20 +1049,25 @@ static void CALEServerSendDataThread(void *threadData)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
-    CALEData_t *bleData = (CALEData_t *) threadData;
+    CALEData_t * const bleData = (CALEData_t *) threadData;
     if (!bleData)
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Invalid bledata!");
         return;
     }
 
-    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1);
     VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    int32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+    const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+
+    OIC_LOG_V(DEBUG,
+              CALEADAPTER_TAG,
+              "Server total Data length with header is [%u]",
+              totalLength);
+
+    uint8_t * const dataSegment = OICCalloc(totalLength, 1);
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server total Data length with header is [%d]", totalLength);
-    char *dataSegment = (char *) OICCalloc(totalLength + 1, sizeof(char));
     if (NULL == dataSegment)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
@@ -1059,19 +1075,21 @@ static void CALEServerSendDataThread(void *threadData)
         return;
     }
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    CAResult_t result = CAGenerateHeader(header,
+                                         CA_HEADER_LENGTH,
+                                         bleData->dataLen);
     if (CA_STATUS_OK != result )
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
         OICFree(header);
         OICFree(dataSegment);
-        return ;
+        return;
     }
 
     memcpy(dataSegment, header, CA_HEADER_LENGTH);
     OICFree(header);
 
-    int32_t length = 0;
+    uint32_t length = 0;
     if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
         length = totalLength;
@@ -1084,31 +1102,49 @@ static void CALEServerSendDataThread(void *threadData)
                CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
     }
 
-    int32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
-    int32_t index = 0;
+    uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    uint32_t index = 0;
+
     // Send the first segment with the header.
-     if (NULL != bleData->remoteEndpoint) //Sending Unicast Data
+    if (NULL != bleData->remoteEndpoint) // Sending Unicast Data
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Server Sending Unicast Data");
+
         result = CAUpdateCharacteristicsToGattClient(
                     bleData->remoteEndpoint->addr, dataSegment, length);
+
         if (CA_STATUS_OK != result)
         {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
-            g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+            OIC_LOG_V(ERROR,
+                      CALEADAPTER_TAG,
+                      "Update characteristics failed, result [%d]",
+                      result);
+
+            g_errorHandler(bleData->remoteEndpoint,
+                           bleData->data,
+                           bleData->dataLen,
+                           result);
             OICFree(dataSegment);
             return;
         }
 
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", length);
+        OIC_LOG_V(DEBUG,
+                  CALEADAPTER_TAG,
+                  "Server Sent data length [%u]",
+                  length);
         for (index = 1; index < iter; index++)
         {
             // Send the remaining header.
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
-            result = CAUpdateCharacteristicsToGattClient(
-                         bleData->remoteEndpoint->addr,
-                         bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
-                         CA_SUPPORTED_BLE_MTU_SIZE);
+            OIC_LOG_V(DEBUG,
+                      CALEADAPTER_TAG,
+                      "Sending the chunk number [%u]",
+                      index);
+
+            result =
+                CAUpdateCharacteristicsToGattClient(
+                    bleData->remoteEndpoint->addr,
+                    bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
+                    CA_SUPPORTED_BLE_MTU_SIZE);
             if (CA_STATUS_OK != result)
             {
                 OIC_LOG_V(ERROR, CALEADAPTER_TAG,
@@ -1121,10 +1157,13 @@ static void CALEServerSendDataThread(void *threadData)
                                                CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        int32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen =
+            totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattClient(
                          bleData->remoteEndpoint->addr,
@@ -1132,9 +1171,14 @@ static void CALEServerSendDataThread(void *threadData)
                          remainingLen);
             if (CA_STATUS_OK != result)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                                                   result);
-                g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+                OIC_LOG_V(ERROR,
+                          CALEADAPTER_TAG,
+                          "Update characteristics failed, result [%d]",
+                          result);
+                g_errorHandler(bleData->remoteEndpoint,
+                               bleData->data,
+                               bleData->dataLen,
+                               result);
                 OICFree(dataSegment);
                 return;
             }
@@ -1169,10 +1213,10 @@ static void CALEServerSendDataThread(void *threadData)
                 OICFree(dataSegment);
                 return;
             }
-            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", CA_SUPPORTED_BLE_MTU_SIZE);
+            OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%u]", CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        int32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
             // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
@@ -1207,11 +1251,11 @@ static void CALEClientSendDataThread(void *threadData)
         return;
     }
 
-    char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
+    uint8_t * const header = OICCalloc(CA_HEADER_LENGTH, 1);
     VERIFY_NON_NULL_VOID(header, CALEADAPTER_TAG, "Malloc failed");
 
-    uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
-    char *dataSegment = (char *) OICCalloc(totalLength + 1, sizeof(char));
+    const uint32_t totalLength = bleData->dataLen + CA_HEADER_LENGTH;
+    uint8_t *dataSegment = OICCalloc(totalLength, 1);
     if (NULL == dataSegment)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failed");
@@ -1219,7 +1263,9 @@ static void CALEClientSendDataThread(void *threadData)
         return;
     }
 
-    CAResult_t result = CAGenerateHeader(header, bleData->dataLen);
+    CAResult_t result = CAGenerateHeader(header,
+                                         CA_HEADER_LENGTH,
+                                         bleData->dataLen);
     if (CA_STATUS_OK != result )
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
@@ -1234,37 +1280,51 @@ static void CALEClientSendDataThread(void *threadData)
     if (CA_SUPPORTED_BLE_MTU_SIZE > totalLength)
     {
         length = totalLength;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data, bleData->dataLen);
+        memcpy(dataSegment + CA_HEADER_LENGTH,
+               bleData->data,
+               bleData->dataLen);
     }
     else
     {
         length = CA_SUPPORTED_BLE_MTU_SIZE;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "length  [%d]", length);
-        memcpy(dataSegment + CA_HEADER_LENGTH, bleData->data,
+        memcpy(dataSegment + CA_HEADER_LENGTH,
+               bleData->data,
                CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
     }
 
-    uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
+    const uint32_t iter = totalLength / CA_SUPPORTED_BLE_MTU_SIZE;
     uint32_t index = 0;
     if (NULL != bleData->remoteEndpoint) //Sending Unicast Data
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Unicast Data");
         // Send the first segment with the header.
-        result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addr,
-                 dataSegment,
-                 length,
-                 LE_UNICAST, 0);
+        result =
+            CAUpdateCharacteristicsToGattServer(
+                bleData->remoteEndpoint->addr,
+                dataSegment,
+                length,
+                LE_UNICAST,
+                0);
 
         if (CA_STATUS_OK != result)
         {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
-            g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
+            OIC_LOG_V(ERROR,
+                      CALEADAPTER_TAG,
+                      "Update characteristics failed, result [%d]",
+                      result);
+            g_errorHandler(bleData->remoteEndpoint,
+                           bleData->data,
+                           bleData->dataLen,
+                           result);
             OICFree(dataSegment);
-            return ;
+            return;
         }
 
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length  is [%d]", length);
+        OIC_LOG_V(DEBUG,
+                  CALEADAPTER_TAG,
+                  "Client Sent Data length  is [%u]",
+                  length);
+
         for (index = 1; index < iter; index++)
         {
             // Send the remaining header.
@@ -1275,8 +1335,10 @@ static void CALEClientSendDataThread(void *threadData)
                      LE_UNICAST, 0);
             if (CA_STATUS_OK != result)
             {
-                OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                                                   result);
+                OIC_LOG_V(ERROR,
+                          CALEADAPTER_TAG,
+                          "Update characteristics failed, result [%d]",
+                          result);
                 g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
                 OICFree(dataSegment);
                 return;
@@ -1285,10 +1347,11 @@ static void CALEClientSendDataThread(void *threadData)
                                                CA_SUPPORTED_BLE_MTU_SIZE);
         }
 
-        uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
+        const uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
         if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattServer(
                      bleData->remoteEndpoint->addr,
@@ -1341,13 +1404,15 @@ static void CALEClientSendDataThread(void *threadData)
         }
 
         uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
-        if ( remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
+        if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
         {
-            // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
+            // send the last segment of the data (Ex: 22 bytes of 622
+            // bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
-            result = CAUpdateCharacteristicsToAllGattServers(
-                         bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
-                          remainingLen);
+            result =
+                CAUpdateCharacteristicsToAllGattServers(
+                    bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
+                    remainingLen);
             if (CA_STATUS_OK != result)
             {
                 OIC_LOG_V(ERROR, CALEADAPTER_TAG,
@@ -1367,10 +1432,11 @@ static void CALEClientSendDataThread(void *threadData)
 }
 
 static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
-                                  const void *data,
+                                  const uint8_t *data,
                                   uint32_t dataLength)
 {
-    CALEData_t *bleData = (CALEData_t *) OICMalloc(sizeof(CALEData_t));
+    CALEData_t * const bleData = OICMalloc(sizeof(CALEData_t));
+
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
@@ -1378,13 +1444,15 @@ static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
     }
 
     bleData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
-    bleData->data = (void *)OICCalloc(dataLength + 1, 1);
+    bleData->data = OICCalloc(dataLength + 1, 1);
+
     if (NULL == bleData->data)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed!");
         CAFreeLEData(bleData);
         return NULL;
     }
+
     memcpy(bleData->data, data, dataLength);
     bleData->dataLen = dataLength;
 
@@ -1763,7 +1831,7 @@ static int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint,
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Send unicast data failed\n");
             if (g_errorHandler)
             {
-                g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
+                g_errorHandler(endpoint, data, dataLen, result);
             }
             ca_mutex_unlock(g_bleIsServerMutex);
             return -1;
@@ -1925,15 +1993,17 @@ static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCa
     return res;
 }
 
-static void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
+static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL_VOID(g_localBLEAddress, CALEADAPTER_TAG, "g_localBLEAddress is null");
-    CAEndpoint_t localEndpoint = {.adapter = CA_DEFAULT_ADAPTER};
+    CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
 
     ca_mutex_lock(g_bleLocalAddressMutex);
-    OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), g_localBLEAddress);
+    OICStrcpy(localEndpoint.addr,
+              sizeof(localEndpoint.addr),
+              g_localBLEAddress);
     ca_mutex_unlock(g_bleLocalAddressMutex);
 
     g_bleAdapterState = adapter_state;
@@ -1965,7 +2035,7 @@ static void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
 }
 
 static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
-                                            const void *data,
+                                            const uint8_t *data,
                                             uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
@@ -1982,7 +2052,7 @@ static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
     VERIFY_NON_NULL_RET(g_bleClientSendQueueHandle, CALEADAPTER_TAG, "g_bleClientSendQueueHandle",
                         CA_STATUS_FAILED);
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
+    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%u]", dataLen);
 
     CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
     if (!bleData)
@@ -2000,7 +2070,7 @@ static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
 }
 
 static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
-                                            const void *data,
+                                            const uint8_t *data,
                                             uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
@@ -2008,53 +2078,58 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
 
 #ifdef SINGLE_THREAD
-    char header[CA_HEADER_LENGTH] = {0};
+    uint8_t header[CA_HEADER_LENGTH] = { 0 };
 
-    CAResult_t result = CAGenerateHeader(header, dataLen);
+    CAResult_t result =
+        CAGenerateHeader(header, CA_HEADER_LENGTH, dataLen);
 
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
     if (!CAIsLEConnected())
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "le not conn");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
     result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-        return -1;
+        return CA_STATUS_FAILED;
     }
 
-    int32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
-    for (int32_t iter = 0; iter < dataLimit; iter++)
+    const uint32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
+    for (uint32_t iter = 0; iter < dataLimit; iter++)
     {
-        result = CAUpdateCharacteristicsToAllGattClients((data +
-                                                         (iter * CA_SUPPORTED_BLE_MTU_SIZE)),
-                                                         CA_SUPPORTED_BLE_MTU_SIZE);
+        result =
+            CAUpdateCharacteristicsToAllGattClients(
+                data + (iter * CA_SUPPORTED_BLE_MTU_SIZE),
+                CA_SUPPORTED_BLE_MTU_SIZE);
+
         if (CA_STATUS_OK != result)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return -1;
+            return CA_STATUS_FAILED;
         }
+
         CALEDoEvents();
     }
 
-    uint8_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
-    if(remainingLen)
+    const uint32_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
+    if (remainingLen)
     {
-        result = CAUpdateCharacteristicsToAllGattClients((data +
-                                                         (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE)),
-                                                         remainingLen);
+        result =
+            CAUpdateCharacteristicsToAllGattClients(
+                data + (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE),
+                remainingLen);
         if (CA_STATUS_OK != result)
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return -1;
+            return CA_STATUS_FAILED;
         }
         CALEDoEvents();
     }
@@ -2071,15 +2146,20 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
 
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data Sending to LE layer [%d]", dataLen);
 
-    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLen);
+    CALEData_t * const bleData =
+        CACreateLEData(remoteEndpoint, data, dataLen);
+
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
         return CA_MEMORY_ALLOC_FAILED;
     }
+
     // Add message to send queue
     ca_mutex_lock(g_bleServerSendDataMutex);
-    CAQueueingThreadAddData(g_bleServerSendQueueHandle, bleData, sizeof(CALEData_t));
+    CAQueueingThreadAddData(g_bleServerSendQueueHandle,
+                            bleData,
+                            sizeof(CALEData_t));
     ca_mutex_unlock(g_bleServerSendDataMutex);
 #endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
@@ -2087,7 +2167,7 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
 }
 
 static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
-                                                const void *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLength,
                                                 uint32_t *sentLength)
 {
@@ -2100,18 +2180,25 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
 #ifdef SINGLE_THREAD
     if(g_networkPacketReceivedCallback)
     {
-        CAEndpoint_t endPoint = { 0 };   // will be filled by upper layer
-        endPoint.adapter = CA_ADAPTER_GATT_BTLE;
+        CAEndpoint_t endPoint =
+            { .adapter = CA_ADAPTER_GATT_BTLE };  // will be filled by
+                                                  // upper layer
+
         g_networkPacketReceivedCallback(&endPoint, data, dataLength);
     }
 #else
-    VERIFY_NON_NULL_RET(g_bleReceiverQueue, CALEADAPTER_TAG, "g_bleReceiverQueue",
+    VERIFY_NON_NULL_RET(g_bleReceiverQueue,
+                        CALEADAPTER_TAG,
+                        "g_bleReceiverQueue",
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
-                                                          CA_ADAPTER_GATT_BTLE,
-                                                          remoteAddress, 0);
+    CAEndpoint_t * const remoteEndpoint =
+        CACreateEndpointObject(CA_DEFAULT_FLAGS,
+                               CA_ADAPTER_GATT_BTLE,
+                               remoteAddress,
+                               0);
+
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
@@ -2119,9 +2206,14 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
     }
 
     // Create bleData to add to queue
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
+    OIC_LOG_V(DEBUG,
+              CALEADAPTER_TAG,
+              "Data received from LE layer [%d]",
+              dataLength);
+
+    CALEData_t * const bleData =
+        CACreateLEData(remoteEndpoint, data, dataLength);
 
-    CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
@@ -2140,7 +2232,7 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
 }
 
 static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
-                                                const void *data,
+                                                const uint8_t *data,
                                                 uint32_t dataLength,
                                                 uint32_t *sentLength)
 {
@@ -2163,7 +2255,7 @@ static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
         return CA_STATUS_FAILED;
     }
 
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%d]", dataLength);
+    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Data received from LE layer [%u]", dataLength);
 
     // Create bleData to add to queue
     CALEData_t *bleData = CACreateLEData(remoteEndpoint, data, dataLength);
@@ -2209,20 +2301,23 @@ static void CASetLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callba
 }
 
 static void CALEErrorHandler(const char *remoteAddress,
-                             const void *data,
+                             const uint8_t *data,
                              uint32_t dataLen,
                              CAResult_t result)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler IN");
 
     VERIFY_NON_NULL_VOID(data, CALEADAPTER_TAG, "Data is null");
+
     CAEndpoint_t *rep = CACreateEndpointObject(CA_DEFAULT_FLAGS,
                                                CA_ADAPTER_GATT_BTLE,
                                                remoteAddress,
                                                0);
-    //if required, will be used to build remote end point
+
+    // if required, will be used to build remote endpoint
     g_errorHandler(rep, data, dataLen, result);
 
     CAFreeEndpoint(rep);
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT");
 }
index 0ed2715..632240a 100644 (file)
@@ -361,7 +361,9 @@ static void CALEOnInterfacesRemoved(GDBusConnection * connection,
     }
 
     if (iter != NULL)
+    {
         g_variant_iter_free(iter);
+    }
 }
 
 static void CALEOnPropertiesChanged(GDBusConnection * connection,
@@ -652,13 +654,12 @@ static bool CALEDeviceFilter(GDBusProxy * device)
     gsize length = 0;
     char const ** const UUIDs = g_variant_get_strv(prop, &length);
 
-    /**
-     * @note It would have been nice to use @c g_strv_contains() here,
-     *       but we would need to run it twice: once for the uppercase
-     *       form of the UUID and once for for the lowercase form.
-     *       Just run the loop manually, and use @c strcasecmp()
-     *       instead.
-     */
+    /*
+      It would have been nice to use g_strv_contains() here, but we
+      would need to run it twice: once for the uppercase form of the
+      UUID and once for for the lowercase form.  Just run the loop
+      manually, and use strcasecmp() instead.
+    */
     char const * const * const end = UUIDs + length;
     for (char const * const * u = UUIDs; u != end; ++u)
     {
@@ -840,7 +841,9 @@ static CAResult_t CALEStop()
 
     // Only stop if we were previously started.
     if (!CALECheckStarted())
+    {
         return result;
+    }
 
     // Stop the event loop thread regardless of previous errors.
     CALEStopEventLoop(&g_context);
@@ -907,7 +910,9 @@ CAResult_t CAStartLEAdapter()
 
     // Only start if we were previously stopped.
     if (CALECheckStarted())
+    {
       return result;
+    }
 
     /**
      * Spawn a thread to run the GLib event loop that will drive D-Bus
@@ -930,7 +935,9 @@ CAResult_t CAStartLEAdapter()
                                      &g_context);
 
     if (result != CA_STATUS_OK)
+    {
         return result;
+    }
 
     /*
       Wait until initialization completes before continuing, basically
@@ -1140,12 +1147,12 @@ void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback)
 }
 
 CAResult_t CAUpdateCharacteristicsToGattClient(char const * address,
-                                               char const * charValue,
-                                               uint32_t charValueLen)
+                                               uint8_t const * value,
+                                               uint32_t valueLen)
 {
     (void)address;
-    (void)charValue;
-    (void)charValueLen;
+    (void)value;
+    (void)valueLen;
     /**
      * @todo To be implemented shortly as part of the effort to
      *       address a critical code review that stated this BLE
@@ -1155,11 +1162,11 @@ CAResult_t CAUpdateCharacteristicsToGattClient(char const * address,
     return CA_NOT_SUPPORTED;
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattClients(char const * charValue,
-                                                   uint32_t charValueLen)
+CAResult_t CAUpdateCharacteristicsToAllGattClients(uint8_t const * value,
+                                                   uint32_t valueLen)
 {
-    (void)charValue;
-    (void)charValueLen;
+    (void)value;
+    (void)valueLen;
     /**
      * @todo To be implemented shortly as part of the effort to
      *       address a critical code review that stated this BLE
@@ -1196,7 +1203,7 @@ void CACheckLEData()
 
 CAResult_t CAUpdateCharacteristicsToGattServer(
     char const * remoteAddress,
-    char const * data,
+    uint8_t const * data,
     uint32_t dataLen,
     CALETransferType_t type,
     int32_t position)
@@ -1215,7 +1222,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(
     return CA_NOT_SUPPORTED;
 }
 
-CAResult_t CAUpdateCharacteristicsToAllGattServers(char const * data,
+CAResult_t CAUpdateCharacteristicsToAllGattServers(uint8_t const * data,
                                                    uint32_t length)
 {
     OIC_LOG(DEBUG, TAG, "Send data to all");
index 1b05ed9..3cf4c1b 100644 (file)
@@ -76,11 +76,10 @@ static gboolean CAGattCharacteristicHandleWriteValue(
       the server, and the server is handling that write request.
     */
 
+    // GLib maps an octet to a guchar, which is of size 1.
     gsize len = 0;
     gconstpointer const data =
-        g_variant_get_fixed_array(value,
-                                  &len,
-                                  1);  // sizeof(guchar) == 1
+        g_variant_get_fixed_array(value, &len, 1);
 
     CAGattCharacteristic * const c = user_data;
 
index 4ca2224..373ee50 100644 (file)
@@ -144,7 +144,7 @@ bool CAGattClientsDestroy(CALEContext * context)
  */
 static bool CAGattClientSendRequestData(GDBusProxy * characteristic,
                                         CALEContext * context,
-                                        char const * data,
+                                        uint8_t const * data,
                                         size_t length)
 {
     assert(context != NULL);
@@ -201,7 +201,7 @@ static bool CAGattClientSendRequestData(GDBusProxy * characteristic,
 }
 
 CAResult_t CAGattClientSendData(void const * method_info,
-                                void const * data,
+                                uint8_t const * data,
                                 size_t length)
 {
     assert(method_info != NULL);
@@ -213,12 +213,12 @@ CAResult_t CAGattClientSendData(void const * method_info,
 
     return CAGattClientSendRequestData(characteristic,
                                        info->context,
-                                       (char const *) data,
+                                       data,
                                        length);
 }
 
 CAResult_t CAGattClientSendDataToAll(void const * method_info,
-                                     void const * data,
+                                     uint8_t const * data,
                                      size_t length)
 {
     assert(method_info != NULL);
@@ -235,7 +235,7 @@ CAResult_t CAGattClientSendDataToAll(void const * method_info,
 
         result = CAGattClientSendRequestData(characteristic,
                                              info->context,
-                                             (char const *) data,
+                                             data,
                                              length);
     }
 
index 46d260c..4000405 100644 (file)
@@ -59,7 +59,7 @@ typedef struct _CAGattRequestInfo
  * @see @c CAGattSendMethod() for further details.
  */
 bool CAGattSendRequest(void const * method_info,
-                       void const * data,
+                       uint8_t const * data,
                        size_t length);
 
 // ---------------------------------------------------------------
@@ -84,7 +84,7 @@ bool CAGattSendRequest(void const * method_info,
  * @return @c CA_STATUS_OK on success, @c CA_STATUS_FAILED otherwise.
  */
 CAResult_t CAGattClientSendDataToAll(void const * method_info,
-                                     void const * data,
+                                     uint8_t const * data,
                                      size_t length);
 
 
index 9cadb89..99bfdd8 100644 (file)
@@ -46,7 +46,9 @@ void CAGattRecvInfoDestroy(CAGattRecvInfo * info)
     *info = g_null_info;
 }
 
-bool CAGattRecv(CAGattRecvInfo * info, char const * data, uint32_t length)
+bool CAGattRecv(CAGattRecvInfo * info,
+                uint8_t const * data,
+                uint32_t length)
 {
     uint32_t sent_length = 0;
 
index a017c5a..78c5af9 100644 (file)
@@ -91,7 +91,7 @@ void CAGattRecvInfoDestroy(CAGattRecvInfo * info);
  * @return @c true on success, @c false otherwise.
  */
 bool CAGattRecv(CAGattRecvInfo * info,
-                char const * data,
+                uint8_t const * data,
                 uint32_t length);
 
 
index ffebf4d..d7c505c 100644 (file)
@@ -45,8 +45,7 @@
 #define TZ_BLE_CLIENT_TAG "TZ_BLE_GATT_CLIENT"
 
 /**
- * @var g_bLEServiceList
- * @brief This contains the list of OIC services a client connect to.
+ * This contains the list of OIC services a client connect to.
  */
 static BLEServiceList *g_bLEServiceList = NULL;
 
@@ -131,7 +130,8 @@ 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");
 
@@ -1374,7 +1374,7 @@ CAResult_t CASetCharacteristicDescriptorValue(stGattCharDescriptor_t *stGattChar
 }
 
 CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
-        const char  *data, uint32_t dataLen,
+        const uint8_t *data, uint32_t dataLen,
         CALETransferType_t type, int32_t position)
 {
     OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
@@ -1412,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)
@@ -1436,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");
index b583296..d4a96fc 100644 (file)
@@ -55,7 +55,9 @@
  * @param[in]  userData       The user data passed from the request function.
  */
 void CABleGattCharacteristicChangedCb(bt_gatt_attribute_h characteristic,
-                            unsigned char *value, int valueLen, void *userData);
+                                      unsigned char *value,
+                                      int valueLen,
+                                      void *userData);
 /**
  * This is the callback which will be called after the characteristics changed.
  *
@@ -374,7 +376,7 @@ CAResult_t CASetCharacteristicDescriptorValue
  */
 CAResult_t CABleClientSenderQueueEnqueueMessage
                             (const CAEndpoint_t *remoteEndpoint,
-                                                const void *data, uint32_t dataLen);
+                                                const uint8_t *data, uint32_t dataLen);
 
 /**
  * This is the thread which will be used for processing sender queue.
index 88e365a..a971465 100644 (file)
@@ -577,8 +577,10 @@ CAResult_t CARemoveAllBleServicesFromGattServer()
 }
 
 void CABleGattRemoteCharacteristicWriteCb(char *charPath,
-        unsigned char *charValue,
-        int charValueLen, const char *remoteAddress, void *userData)
+                                          unsigned char *charValue,
+                                          int charValueLen,
+                                          const char *remoteAddress,
+                                          void *userData)
 {
     OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
 
@@ -588,17 +590,21 @@ void CABleGattRemoteCharacteristicWriteCb(char *charPath,
         return;
     }
 
-    OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "charPath = [%s] charValue = [%s] len [%d]", charPath,
-              charValue, charValueLen);
+    OIC_LOG_V(DEBUG,
+              TZ_BLE_SERVER_TAG,
+              "charPath = [%s] charValue = [%x] len [%d]",
+              charPath,
+              charValue,
+              charValueLen);
 
-    char *data = (char *)OICMalloc(sizeof(char) * charValueLen + 1);
+    uint8_t *data = OICMalloc(charValueLen);
     if (NULL == data)
     {
         OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "Malloc failed!");
         return;
     }
 
-    OICStrcpy(data, charValueLen + 1, charValue);
+    memcpy(data, charValue, charValueLen);
 
     ca_mutex_lock(g_bleReqRespCbMutex);
     if (NULL == g_bleServerDataReceivedCallback)
index dcf6a0a..f8bd414 100644 (file)
@@ -140,7 +140,7 @@ CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
  * @return  ::CA_STATUS_OK or Appropriate error code.
  */
 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
-                                               const char *charValue, int charValueLen,
+                                               const uint8_t *charValue, int charValueLen,
                                                bool read);
 
 /**
@@ -208,7 +208,7 @@ CAResult_t CALEReadDataFromLEServer();
  * @retval  ::CA_STATUS_FAILED Operation failed.
  */
 CAResult_t CABleServerSenderQueueEnqueueMessage
-                (const CAEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLen);
+                (const CAEndpoint_t *remoteEndpoint, const uint8_t *data, uint32_t dataLen);
 
 /**
  * This is the thread which will be used for processing receiver queue.
index f5026c1..c016654 100644 (file)
@@ -1913,7 +1913,7 @@ CAResult_t CAUpdatePayloadData(CABlockData_t *currData, const CAData_t *received
             OIC_LOG(DEBUG, TAG, "allocate memory for the received block payload");
 
             size_t totalPayloadLen = prePayloadLen + blockPayloadLen + 1;
-            void *newPayload = realloc(currData->payload, totalPayloadLen);
+            CAPayload_t newPayload = OICRealloc(currData->payload, totalPayloadLen);
             if (NULL == newPayload)
             {
                 OIC_LOG(ERROR, TAG, "out of memory");