static CAQueueingThread_t *g_bleServerSendQueueHandle = NULL;
/**
- * Starting LE connectivity adapters.
- *
- * As its peer to peer it does not require to start any servers.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- */
-static CAResult_t CAStartLE();
-
-/**
- * Start listening server for receiving multicast search requests.
- *
- * Transport Specific Behavior:
- * LE Starts GATT Server with prefixed UUID and Characteristics
- * per OIC Specification.
- * @return ::CA_STATUS_OK or Appropriate error code.
- */
-static CAResult_t CAStartLEListeningServer();
-
-/**
- * Sarting discovery of servers for receiving multicast
- * advertisements.
- *
- * Transport Specific Behavior:
- * LE Starts GATT Server with prefixed UUID and Characteristics
- * per OIC Specification.
- *
- * @return ::CA_STATUS_OK or Appropriate error code
- */
-static CAResult_t CAStartLEDiscoveryServer();
-
-/**
- * Send data to the endpoint using the adapter connectivity.
- *
- * @param[in] endpoint Remote Endpoint information (like MAC address,
- * reference URI and connectivity type) to which
- * the unicast data has to be sent.
- * @param[in] data Data which required to be sent.
- * @param[in] dataLen Size of data to be sent.
- *
- * @note dataLen must be > 0.
- *
- * @return The number of bytes sent on the network, or -1 on error.
- */
-static int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint,
- const void *data,
- uint32_t dataLen);
-
-/**
- * Send multicast data to the endpoint using the LE connectivity.
- *
- * @param[in] endpoint Remote Endpoint information to which the
- * multicast data has to be sent.
- * @param[in] data Data which required to be sent.
- * @param[in] dataLen Size of data to be sent.
- *
- * @note dataLen must be > 0.
- *
- * @return The number of bytes sent on the network, or -1 on error.
- */
-static int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint,
- const void *data,
- uint32_t dataLen);
-
-/**
- * Get LE Connectivity network information.
- *
- * @param[out] info Local connectivity information structures.
- * @param[out] size Number of local connectivity structures.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- */
-static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info,
- uint32_t *size);
-
-/**
- * Read Synchronous API callback.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- */
-static CAResult_t CAReadLEData();
-
-/**
- * Stopping the adapters and close socket connections.
- *
- * LE Stops all GATT servers and GATT Clients.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- */
-static CAResult_t CAStopLE();
-
-/**
- * Terminate the LE connectivity adapter.
- *
- * Configuration information will be deleted from further use.
- */
-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.
- *
- * @param[in] remoteAddress Remote address of the device from where
- * data is received.
- * @param[in] data Actual data recevied from the remote
- * device.
- * @param[in] dataLength Length of the data received from the
- * remote device.
- * @param[in] sentLength Length of the data sent from the remote
- * device.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK Successful.
- * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- *
- */
-static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
- const uint8_t *data,
- uint32_t dataLength,
- uint32_t *sentLength);
-
-/**
- * This function will receive the data from the GattClient and add the
- * data into the Client receiver queue.
- *
- * @param[in] remoteAddress Remote address of the device from where
- * data is received.
- * @param[in] data Actual data recevied from the remote
- * device.
- * @param[in] dataLength Length of the data received from the
- * remote device.
- * @param[in] sentLength Length of the data sent from the remote
- * device.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK Successful.
- * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- */
-static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
- const uint8_t *data,
- uint32_t dataLength,
- uint32_t *sentLength);
-
-/**
* This function will be associated with the sender queue for
* GattServer.
*
OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
}
+/**
+ * Starting LE connectivity adapters.
+ *
+ * As its peer to peer it does not require to start any servers.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStartLE();
+
+/**
+ * Start listening server for receiving multicast search requests.
+ *
+ * Transport Specific Behavior:
+ * LE Starts GATT Server with prefixed UUID and Characteristics
+ * per OIC Specification.
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStartLEListeningServer();
+
+/**
+ * Sarting discovery of servers for receiving multicast
+ * advertisements.
+ *
+ * Transport Specific Behavior:
+ * LE Starts GATT Server with prefixed UUID and Characteristics
+ * per OIC Specification.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ */
+static CAResult_t CAStartLEDiscoveryServer();
+
+/**
+ * Send data to the endpoint using the adapter connectivity.
+ *
+ * @param[in] endpoint Remote Endpoint information (like MAC address,
+ * reference URI and connectivity type) to which
+ * the unicast data has to be sent.
+ * @param[in] data Data which required to be sent.
+ * @param[in] dataLen Size of data to be sent.
+ *
+ * @note dataLen must be > 0.
+ *
+ * @return The number of bytes sent on the network, or -1 on error.
+ */
+static int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint,
+ const void *data,
+ uint32_t dataLen);
+
+/**
+ * Send multicast data to the endpoint using the LE connectivity.
+ *
+ * @param[in] endpoint Remote Endpoint information to which the
+ * multicast data has to be sent.
+ * @param[in] data Data which required to be sent.
+ * @param[in] dataLen Size of data to be sent.
+ *
+ * @note dataLen must be > 0.
+ *
+ * @return The number of bytes sent on the network, or -1 on error.
+ */
+static int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint,
+ const void *data,
+ uint32_t dataLen);
+
+/**
+ * Get LE Connectivity network information.
+ *
+ * @param[out] info Local connectivity information structures.
+ * @param[out] size Number of local connectivity structures.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info,
+ uint32_t *size);
+
+/**
+ * Read Synchronous API callback.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAReadLEData();
+
+/**
+ * Stopping the adapters and close socket connections.
+ *
+ * LE Stops all GATT servers and GATT Clients.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStopLE();
+
+/**
+ * Terminate the LE connectivity adapter.
+ *
+ * Configuration information will be deleted from further use.
+ */
+static void CATerminateLE();
+
+/**
+ * This function will receive the data from the GattServer and add the
+ * data to the Server receiver queue.
+ *
+ * @param[in] remoteAddress Remote address of the device from where
+ * data is received.
+ * @param[in] data Actual data recevied from the remote
+ * device.
+ * @param[in] dataLength Length of the data received from the
+ * remote device.
+ * @param[in] sentLength Length of the data sent from the remote
+ * device.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ *
+ */
+static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
+ const uint8_t *data,
+ uint32_t dataLength,
+ uint32_t *sentLength);
+
+/**
+ * This function will receive the data from the GattClient and add the
+ * data into the Client receiver queue.
+ *
+ * @param[in] remoteAddress Remote address of the device from where
+ * data is received.
+ * @param[in] data Actual data recevied from the remote
+ * device.
+ * @param[in] dataLength Length of the data received from the
+ * remote device.
+ * @param[in] sentLength Length of the data sent from the remote
+ * device.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
+ 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 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);
+
CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback reqRespCallback,
CANetworkChangeCallback netCallback,
static CAResult_t CAStartLE()
{
- OIC_LOG(DEBUG, CALEADAPTER_TAG, __func__);
+ OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE");
return CAStartLEAdapter();
}
return;
}
- char *charReadUUID = CA_GATT_RESPONSE_CHRC_UUID;
- char charReadValue[] = {33, 44, 55, 66}; // These are initial random values
+ static const char charReadUUID[] = CA_GATT_RESPONSE_CHRC_UUID;
+ uint8_t charReadValue[] = {33, 44, 55, 66}; // These are initial random values
ret = CAAddNewCharacteristicsToGattServer(g_gattSvcPath, charReadUUID, charReadValue,
CA_BLE_INITIAL_BUF_SIZE, true); // For Read Characteristics.
return;
}
- char *charWriteUUID = CA_GATT_REQUEST_CHRC_UUID;
- char charWriteValue[] = {33, 44, 55, 66}; // These are initial random values
+ static const char charWriteUUID[] = CA_GATT_REQUEST_CHRC_UUID;
+ uint8_t charWriteValue[] = {33, 44, 55, 66}; // These are initial random values
ret = CAAddNewCharacteristicsToGattServer(g_gattSvcPath, charWriteUUID, charWriteValue,
OIC_LOG_V(DEBUG,
TZ_BLE_SERVER_TAG,
- "charPath = [%s] charValue = [%x] len [%d]",
+ "charPath = [%s] charValue = [%p] len [%d]",
charPath,
charValue,
charValueLen);
}
CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
- const char *charValue, int charValueLen, bool read)
+ const uint8_t *charValue, int charValueLen, bool read)
{
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
- char *charFlags[1];
+ const char *charFlags[1];
if(read)
{
charFlags[0] = "notify";
size_t flagLen = sizeof(charFlags) / sizeof(charFlags[0]);
char *charPath = NULL;
- int ret = bt_gatt_add_characteristic(charUUID, charValue, charValueLen, charFlags, flagLen,
- svcPath, &charPath);
+ int ret =
+ bt_gatt_add_characteristic(charUUID,
+ (const char *) charValue,
+ charValueLen,
+ charFlags,
+ flagLen,
+ svcPath,
+ &charPath);
if (0 != ret || NULL == charPath)
{
}
CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
- const char *charValue,
+ const uint8_t *charValue,
uint32_t charValueLen)
{
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
return CA_STATUS_FAILED;
}
- char *data = (char *) OICCalloc(sizeof(char), (charValueLen + 1));
+ char *data = OICCalloc(charValueLen, 1);
if (NULL == data)
{
OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "malloc failed!");
return CA_STATUS_FAILED;
}
- OICStrcpy(data, charValueLen + 1, charValue);
+ memcpy(data, charValue, charValueLen); // Binary data
- OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
+ OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%p] dataLen [%u]",
(const char *)g_gattReadCharPath, data, charValueLen);
- int ret = bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, address);
+ int ret =
+ bt_gatt_update_characteristic(g_gattReadCharPath,
+ data,
+ charValueLen,
+ address);
if (0 != ret)
{
OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG,
return CA_STATUS_OK;
}
-CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue, uint32_t charValueLen)
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *charValue, uint32_t charValueLen)
{
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
return CA_STATUS_FAILED;
}
- char *data = (char *) OICMalloc(sizeof(char) * (charValueLen + 1));
+ char *data = OICMalloc(charValueLen);
if (NULL == data)
{
OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "malloc failed!");
return CA_STATUS_FAILED;
}
- OICStrcpy(data, charValueLen + 1, charValue);
+ memcpy(data, charValue, charValueLen); // Binary data
- OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
+ OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%p] dataLen [%u]",
(const char *)g_gattReadCharPath, data, charValueLen);
- int ret = bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, NULL);
+ int ret =
+ bt_gatt_update_characteristic(g_gattReadCharPath,
+ data,
+ charValueLen,
+ NULL);
if (0 != ret)
{
OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG,