******************************************************************/
/**
+ * @file
+ *
* This file provides APIs for BLE modules.
*/
#include "cacommon.h"
#include "cathreadpool.h"
+#include "uarraylist.h"
#ifdef __cplusplus
extern "C"
} CALETransferType_t;
/**
+ * Stores the information of the Data to be sent from the queues.
+ *
+ * This structure will be pushed to the sender/receiver queue for
+ * processing.
+ */
+typedef struct
+{
+ /// 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;
+
+ /// Sender information list
+ u_arraylist_t * senderInfo;
+} CALEData_t;
+
+/**
+ * The MTU supported for BLE adapter
+ */
+#ifdef __APPLE__
+#define CA_DEFAULT_BLE_MTU_SIZE 152
+#else
+#define CA_DEFAULT_BLE_MTU_SIZE 20
+#endif
+/**
+ * The MTU supported for BLE spec
+ */
+#define CA_SUPPORTED_BLE_MTU_SIZE 517
+
+/**
+ * The Header of the MTU supported for BLE spec
+ */
+#define CA_BLE_MTU_HEADER_SIZE 5
+
+/**
* This will be used to notify device status changes to the LE adapter layer.
* @param[in] adapter_state State of the adapter.
*/
typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
/**
+ * This will be used to notify device connection state changes to the LE adapter layer.
+ * @param[in] adapter Transport type information.
+ * @param[in] remoteAddress Endpoint object from which the connection status is changed.
+ * @param[in] connected State of connection.
+ */
+typedef void (*CALEConnectionStateChangedCallback)(CATransportAdapter_t adapter,
+ const char *remoteAddress, bool connected);
+
+/**
* Notify the adapter layer that a packet was received from the GATT
* peer.
*
* @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);
* Initialize the LE adapter layer. This will be invoked from the CA
* layer.
*
+ * @param[in] threadPool Thread pool handle
* @return ::CA_STATUS_OK or Appropriate error code
* @retval ::CA_STATUS_OK Successful
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
CAResult_t CAStartLEAdapter();
/**
+ * Stop the LE adapter layer.
+ *
+ * This function will be invoked from the CA layer when the LE
+ * "network" is unselected via @c CAUnselectNetwork(). It gives an
+ * opportunity for LE adapter implementations to perform operations
+ * after stopping a GATT client or server. Most LE adapter
+ * implementations will simply implement this function as no-op.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ */
+CAResult_t CAStopLEAdapter();
+
+/**
* Used to get the current state of the LE adapter.
*
* @return ::CA_STATUS_OK or Appropriate error code
CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
/**
- * Initialize all the mutex variables required to operate the LE
- * network monitor layer.
+ * Set the callback for the device connection state changes.
+ *
+ * @param[in] callback Callback to notify the Device connection state change to
+ * the CA Layer
*
* @return ::CA_STATUS_OK or Appropriate error code
* @retval ::CA_STATUS_OK Successful
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
* @retval ::CA_STATUS_FAILED Operation failed
*/
-CAResult_t CAInitLENetworkMonitorMutexVariables();
-
-/**
- * Used to terminate all the mutex variables required to operate the LE
- * network monitor layer.
- */
-void CATerminateLENetworkMonitorMutexVariables();
+CAResult_t CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCallback callback);
/**
* Provides the MAC address of the local Bluetooth adapter.
CAResult_t CAStopLEGattServer();
/**
+ * initialize gatt server
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ * @retval ::CA_STATUS_OK Successful
+ * @retval ::CA_STATUS_FAILED Operation failed
+ */
+CAResult_t CAInitializeLEGattServer();
+
+/**
* Stop Gatt Server thread and remove service registration, stop
* advertising.
*/
* 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.
void CAStopLEGattClient();
/**
+ * initialize Client
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code
+ * @retval ::CA_STATUS_OK Successful
+ * @retval ::CA_STATUS_FAILED Operation failed
+ */
+CAResult_t CAInitializeLEGattClient();
+
+/**
* Unset all the callbacks and stop service discovery
*/
void CATerminateLEGattClient();
* @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);
/**
void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
/**
- * Unset the callback of adapter connection state change.
+ * Unset the callback of adapter state change.
*
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
CAResult_t CAUnSetLEAdapterStateChangedCb();
/**
+ * Unset the callback of adapter connection state change.
+ *
+ * @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 CAUnSetLENWConnectionStateChangedCb();
+
+/**
* This will be used to notify errors in BLE adapter.
*
* @param[in] remoteAddress Remote endpoint Address
* @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);
/**
*/
void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
+/**
+ * This is the callback which will be called whenever there is change in gatt connection
+ * with Client(Connected/Disconnected).
+ *
+ * @param[in] connected State of connection.
+ * @param[in] remoteAddress Mac address of the remote device in which we made connection.
+ */
+void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress);
+
+/**
+ * This is the callback which will be called whenever there is change in gatt connection
+ * with server(Connected/Disconnected)
+ *
+ * @param[in] connected State of connection
+ * @param[in] remoteAddress Mac address of the remote device in which we made connection.
+ */
+void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress);
+
#ifdef __cplusplus
}
#endif