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;
* @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);
/**
* @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
* @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);
/**
* @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
/**
* 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_ */
-
******************************************************************/
/**
+ * @file
+ *
* This file provides APIs for BLE modules.
*/
* @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);
* 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
* @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.
* @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);
* @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);
/**
* @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);
/**
#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;
}
-
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);
/**
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,
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)
{
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");
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");
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");
}
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)
}
-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");
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");
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");
}
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)
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");
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");
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);
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)
{
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");
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);
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);
* @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.
* @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);
/**
* @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.
* @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);
/**
* @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);
/**
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");
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)
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");
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");
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);
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;
}
CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
- const char *charValue,
+ const uint8_t *charValue,
uint32_t charValueLen)
{
CAResult_t result = CA_SEND_FAILED;
return result;
}
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *charValue,
uint32_t charValueLen)
{
OIC_LOG(DEBUG, TAG, "IN");
* @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.
* @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).
* @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).
* @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);
/**
* @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.
#define MAX_EVENT_COUNT 20
static bool g_serverRunning = false;
-static char *g_coapBuffer = NULL;
+static uint8_t *g_coapBuffer = NULL;
/**
* @var g_receivedDataLen
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)
{
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");
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,
{
return ble_connected();
}
-char CALEReadData()
+
+uint8_t CALEReadData()
{
- return (char)ble_read();
+ return (uint8_t)ble_read();
}
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
* API to read data from BLE shield.
* @return - Data read.
*/
-char CALEReadData();
+uint8_t CALEReadData();
/**
* API to perform BLE events.
*/
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;
/**
{
uint32_t recvDataLen;
uint32_t totalDataLen;
- char *defragData;
+ uint8_t *defragData;
CAEndpoint_t *remoteEndpoint;
} CABLESenderInfo_t;
* @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
/**
* 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);
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.
*
*
*/
static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
- const void *data,
+ const uint8_t *data,
uint32_t dataLength,
uint32_t *sentLength);
* @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.
*
* @retval ::CA_STATUS_FAILED Operation failed.
*/
static CALEData_t *CACreateLEData(const CAEndpoint_t *remoteEndpoint,
- const void *data,
+ const uint8_t *data,
uint32_t dataLength);
/**
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);
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");
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!!!");
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)
{
{
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");
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;
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,
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,
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;
}
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)
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");
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");
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.
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;
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,
}
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,
}
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!");
}
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;
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;
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;
}
static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
- const void *data,
+ const uint8_t *data,
uint32_t dataLen)
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
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)
}
static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
- const void *data,
+ const uint8_t *data,
uint32_t dataLen)
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
#ifdef SINGLE_THREAD
- char header[CA_HEADER_LENGTH] = {0};
+ uint8_t header[CA_HEADER_LENGTH] = { 0 };
- CAResult_t result = CAGenerateHeader(header, dataLen);
+ CAResult_t result =
+ CAGenerateHeader(header, CA_HEADER_LENGTH, dataLen);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "Generate header failed");
- return -1;
+ return CA_STATUS_FAILED;
}
if (!CAIsLEConnected())
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "le not conn");
- return -1;
+ return CA_STATUS_FAILED;
}
result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
- return -1;
+ return CA_STATUS_FAILED;
}
- int32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
- for (int32_t iter = 0; iter < dataLimit; iter++)
+ const uint32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
+ for (uint32_t iter = 0; iter < dataLimit; iter++)
{
- result = CAUpdateCharacteristicsToAllGattClients((data +
- (iter * CA_SUPPORTED_BLE_MTU_SIZE)),
- CA_SUPPORTED_BLE_MTU_SIZE);
+ result =
+ CAUpdateCharacteristicsToAllGattClients(
+ data + (iter * CA_SUPPORTED_BLE_MTU_SIZE),
+ CA_SUPPORTED_BLE_MTU_SIZE);
+
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
- return -1;
+ return CA_STATUS_FAILED;
}
+
CALEDoEvents();
}
- uint8_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
- if(remainingLen)
+ const uint32_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
+ if (remainingLen)
{
- result = CAUpdateCharacteristicsToAllGattClients((data +
- (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE)),
- remainingLen);
+ result =
+ CAUpdateCharacteristicsToAllGattClients(
+ data + (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE),
+ remainingLen);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
- return -1;
+ return CA_STATUS_FAILED;
}
CALEDoEvents();
}
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");
}
static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
- const void *data,
+ const uint8_t *data,
uint32_t dataLength,
uint32_t *sentLength)
{
#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 !");
}
// 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!");
}
static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
- const void *data,
+ const uint8_t *data,
uint32_t dataLength,
uint32_t *sentLength)
{
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);
}
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");
}
}
if (iter != NULL)
+ {
g_variant_iter_free(iter);
+ }
}
static void CALEOnPropertiesChanged(GDBusConnection * connection,
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)
{
// Only stop if we were previously started.
if (!CALECheckStarted())
+ {
return result;
+ }
// Stop the event loop thread regardless of previous errors.
CALEStopEventLoop(&g_context);
// 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
&g_context);
if (result != CA_STATUS_OK)
+ {
return result;
+ }
/*
Wait until initialization completes before continuing, basically
}
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
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
CAResult_t CAUpdateCharacteristicsToGattServer(
char const * remoteAddress,
- char const * data,
+ uint8_t const * data,
uint32_t dataLen,
CALETransferType_t type,
int32_t position)
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");
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;
*/
static bool CAGattClientSendRequestData(GDBusProxy * characteristic,
CALEContext * context,
- char const * data,
+ uint8_t const * data,
size_t length)
{
assert(context != NULL);
}
CAResult_t CAGattClientSendData(void const * method_info,
- void const * data,
+ uint8_t const * data,
size_t length)
{
assert(method_info != NULL);
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);
result = CAGattClientSendRequestData(characteristic,
info->context,
- (char const *) data,
+ data,
length);
}
* @see @c CAGattSendMethod() for further details.
*/
bool CAGattSendRequest(void const * method_info,
- void const * data,
+ uint8_t const * data,
size_t length);
// ---------------------------------------------------------------
* @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);
*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;
* @return @c true on success, @c false otherwise.
*/
bool CAGattRecv(CAGattRecvInfo * info,
- char const * data,
+ uint8_t const * data,
uint32_t length);
#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;
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");
}
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");
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)
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");
* @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.
*
*/
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.
}
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");
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)
* @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);
/**
* @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.
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");