Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caleinterface.h
index ff1ab29..0ac0028 100644 (file)
@@ -30,7 +30,8 @@
 #include <stdbool.h>
 
 #include "cacommon.h"
-#include "caleadapter.h"
+#include "cathreadpool.h"
+#include "uarraylist.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -38,9 +39,10 @@ extern "C"
 #endif
 
 /**
- * @enum CALETransferType_t
- * @brief Provide info about different mode of data transfer
- *        This enum is used to differentiate between unicast and multicast data transfer.
+ * Provide info about different mode of data transfer.
+ *
+ * This enum is used to differentiate between unicast and multicast
+ * data transfer.
  */
 typedef enum
 {
@@ -48,247 +50,401 @@ typedef enum
     LE_UNICAST       /**< When this enum is selected, data will be updated to desired OIC Server. */
 } 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;
+
+/**
+ * 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.
+ *
+ * @param[in]  remoteAddress  Remote endpoint Address.
+ * @param[in]  data           Data received.
+ * @param[in]  dataLength     Length of the data received.
+ * @param[in]  sentLength     Length of the data sent.
+ *
+ * @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.
+ */
+typedef CAResult_t (*CABLEDataReceivedCallback)(const char *remoteAddress,
+                                                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
+ * @retval ::CA_STATUS_FAILED Operation failed
+ */
+CAResult_t CAInitializeLEAdapter(const ca_thread_pool_t threadPool);
+
+/**
+ * Start the LE adapter layer.
+ *
+ * This function will be invoked from the CA layer when the LE
+ * "network" is selected via @c CASelectNetwork().  It gives an
+ * opportunity for LE adapter implementations to perform operations
+ * before starting 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 CAStartLEAdapter();
 
 /**
- * @brief  Initialize the LE adapter layer. This will be invoked from the CA layer.
+ * Stop the LE adapter layer.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * 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 CAInitializeLEAdapter();
+CAResult_t CAStopLEAdapter();
 
 /**
- * @brief  Used to get the current state of the LE adapter.
+ * Used to get the current state of the LE adapter.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_ADAPTER_NOT_ENABLED  adapter not enabled
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return ::CA_STATUS_OK or Appropriate error code
+ * @retval ::CA_STATUS_OK  Successful
+ * @retval ::CA_ADAPTER_NOT_ENABLED  adapter not enabled
+ * @retval ::CA_STATUS_FAILED Operation failed
  */
 CAResult_t CAGetLEAdapterState();
 
 /**
- * @brief  Used to initialize the network monitor layer of the LE adapter. Mutex variables required
- *         to operate in this layer and other paramters can be initialized in this function.
+ * Initialize the network monitor layer of the LE adapter.  Mutex
+ * variables required to operate in this layer and other parameters
+ * can be initialized in this function.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 CAInitializeLENetworkMonitor();
 
 /**
- * @brief  Used to terminate the network monitor layer of the LE adapter. The variables intialized
- *         in CAInitializeLEAdapterController() must be cleared in this function.
- * @return NONE
+ * Terminate the network monitor layer of the LE adapter. The
+ * variables initialized in @c CAInitializeLENetworkMonitor() must be
+ * cleared in this function.
  */
 void CATerminateLENetworkMonitor();
 
 /**
- * @brief  This function is used to set the callback for the Device state changes in the adapter.
+ * Set the callback for the device state changes in the adapter.
  *
- * @param  callback  [IN] Callback to notify the Device state change to the CA Layer
+ * @param[in] callback Callback to notify the Device 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 argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
 
 /**
- * @brief  Used to initilaze all the mutex variables required to operate the LE network monitor
- *         layer.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * 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();
+CAResult_t CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCallback callback);
 
 /**
- * @brief  Used to terminate all the mutex variables required to operate the LE network monitor
- *         layer.
- * @return NONE
+ * Provides the MAC address of the local Bluetooth adapter.
+ *
+ * @param[out] local_address Pointer to the location where bd address
+ *                           needs to be stored.
+ *
+ * @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
  */
-void CATerminateLENetworkMonitorMutexVariables();
+CAResult_t CAGetLEAddress(char **local_address);
 
 /**
- * @brief  Provides the BD address of the local adapter.
- * @param  local_address [OUT] pointer to the location where bd address needs to be stored.
+ * Start Gatt Server thread for service creation and advertise BLE
+ * service.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 CAGetLEAddress(char **local_address);
+CAResult_t CAStartLEGattServer();
 
 /**
- * @brief  Used to start Gatt Server thread for service creation and advertise ble service.
+ * Stop BLE Gatt Service.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 CAStartBleGattServer();
+CAResult_t CAStopLEGattServer();
 
 /**
- * @brief  Used to stop BLE Gatt Service.
+ * initialize gatt server
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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.
  */
-CAResult_t CAStopBleGattServer();
+void CATerminateLEGattServer();
 
 /**
- * @brief  Used to stop Gatt Server thread and remove service registration, stop advertising.
- * @return NONE
+ * Used to store upper layer callback locally which will be used to
+ * send the data to application.
+ *
+ * @param[in] callback Callback function to pass the data to CA layer.
  */
-void CATerminateBleGattServer();
+void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback);
 
 /**
- * @brief  Used to store upper layer callback locally which will be used to send the data to
- *         application
- * @param  callback [IN] Callback function to pass the data to CA layer.
- * @return NONE
+ * Update characteristics(Read/Write) value that we want to send to
+ * particular client.
+ *
+ * @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_INVALID_PARAM  Invalid input arguments
+ * @retval ::CA_STATUS_FAILED Operation failed
  */
-void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
+CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
+                                               const uint8_t *value,
+                                               uint32_t valueLen);
 
 /**
- * @brief  Used to update characteristics(Read/Write) value that we want to send to particular
- *         client.
+ * Update characteristics(Read/Write) value that we want to multicast
+ * to all clients.
  *
- * @param  address     [IN] BD address of Gatt client
- * @param  charValue     [IN] Data that we want to send to client(unicast)
- * @param  charValueLen  [IN] 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 argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 CAUpdateCharacteristicsToGattClient(const char* address, const char *charValue,
-                                               const uint32_t charValueLen);
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *value,
+                                                   uint32_t valueLen);
 
 /**
- * @brief  Used to update characteristics(Read/Write) value that we want to multicast to all clients
+ * Start @c CAStartBleGattClientThread for initializing Gatt Client.
  *
- * @param  charValue     [IN] Data that we want to send to clients(multicast)
- * @param  charValueLen  [IN] 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 CAStartLEGattClient();
+
+/**
+ * Stop Gatt client gracefully.  In turn it will call the
+ * @c CATerminateBLEGattClient function.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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,
-                                                   const uint32_t charValueLen);
+void CAStopLEGattClient();
 
 /**
- * @brief  Used to start CAStartBleGattClientThread for initializing Gatt Client
+ * initialize Client
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return ::CA_STATUS_OK or Appropriate error code
+ * @retval ::CA_STATUS_OK  Successful
+ * @retval ::CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAStartBLEGattClient();
+CAResult_t CAInitializeLEGattClient();
 
 /**
- * @brief  Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
- *         function.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * Unset all the callbacks and stop service discovery
  */
-void CAStopBLEGattClient();
+void CATerminateLEGattClient();
 
 /**
- * @brief  Used to unset all the callbacks and stop service discovery
- * @return NONE
+ * Read the data from characteristics and invoke notify callback.
  */
-void CATerminateBLEGattClient();
+void CACheckLEData();
 
 /**
- * @brief  Sets the value of characteristic and update the value to GATTServer(unicast).
+ * Set the value of characteristic and update the value to
+ * GATTServer (unicast).
  *
- * @param  remoteAddress [IN] The address of the remote device
- * @param  data          [IN] The value of characteristic (byte array)
- * @param  dataLen       [IN] The length of value
- * @param  type          [IN] Type of the transfer(#CALETransferType_t)
- * @param  position      [IN] The unique index of each ble server. Used for multicast feature.
+ * @param[in] remoteAddress The address of the remote device
+ * @param[in] data          The value of characteristic (byte array)
+ * @param[in] dataLen       The length of value
+ * @param[in] type          Type of the transfer(::CALETransferType_t)
+ * @param[in] position      The unique index of each ble server. Used
+ *                          for multicast feature.
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char  *data,
-                                                const uint32_t dataLen, CALETransferType_t type,
-                                                const int32_t position);
+CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
+                                                const uint8_t *data,
+                                                uint32_t dataLen,
+                                                CALETransferType_t type,
+                                                int32_t position);
 
 /**
- * @brief  Sets the value of characteristic and update the value to all registered
- *         GATTServer -> Multicast
- * @param  data     [IN] The value of characteristic (byte array)
- * @param  dataLen  [IN] The length of value
+ * Set the value of characteristic and update the value to all
+ * registered GATTServer (multicast).
  *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @param[in]  data    The value of characteristic (byte array)
+ * @param[in]  dataLen The length of value
+ *
+ * @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  CAUpdateCharacteristicsToAllGattServers(const char  *data, uint32_t dataLen);
+CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data,
+                                                   uint32_t dataLen);
 
 /**
- * @brief  Used to store upper layer callback locally which will be used to send the data to
- *         application
- * @param  callback  [IN] Callback function to pass the data to CA layer.
+ * Store upper layer callback locally which will be used to send the
+ * data to application.
  *
- * @return  void
+ * @param[in] callback Callback function to pass the data to CA layer.
  */
-void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
+void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback);
 
 /**
- * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
+ * Set the server thread pool handle which is required for spawning
+ * new thread.
+ *
+ * @param[in] handle Thread pool handle which is given by above layer
+ *                   for using thread creation task.
  *
- * @param handle [IN] Thread pool handle which is given by above layer for using thread
- *                    creation task.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK  Successful
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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
  */
-void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle);
+void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
-* @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
-* @param handle [IN] Thread pool handle which is given by above layer for using thread creation
-*                    task.
-* @return NONE
+* Set the client thread pool handle which is required for spawning new
+* thread.
+*
+* @param[in] handle Thread pool handle which is given by above layer
+*                   for using thread creation task.
 */
-void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle);
+void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
 
 /**
- * @brief  Used to 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
- * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
- * @retval #CA_STATUS_FAILED Operation failed
+ * @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 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] data          Data received
+ * @param[in] dataLength    Length of the data received
+ * @param[in] result        error code as per CAResult_t
+ */
+typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress,
+                                         const uint8_t *data,
+                                         uint32_t dataLength,
+                                         CAResult_t result);
+/**
+ * Set the client error handler callback.
+ *
+ * @param[in] callback Callback function to update error to the
+ *                     adapter.
+ */
+void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback);
+
+
+/**
+ * Set the server error handler callback.
+ *
+ * @param[in] callback Callback function to update error to the
+ *                     adapter.
+ */
+void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* CA_LE_INTERFACE_H_ */
-