X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Finc%2Fcaleinterface.h;h=c354ee3ed65f23e5c70693d04d8105eceeda6f7e;hb=refs%2Ftags%2Ftizen_4.0.m2_release;hp=ff1ab2929b9570896065aae97dbc9d349a5fd700;hpb=0734f2d4a926a266e8f5a988834e4c25c2d8d11d;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/inc/caleinterface.h b/resource/csdk/connectivity/inc/caleinterface.h index ff1ab29..c354ee3 100644 --- a/resource/csdk/connectivity/inc/caleinterface.h +++ b/resource/csdk/connectivity/inc/caleinterface.h @@ -30,7 +30,8 @@ #include #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,438 @@ 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; + +/** + * The MTU supported for BLE adapter + */ +#ifdef __APPLE__ +#define CA_DEFAULT_BLE_MTU_SIZE 152 +#else +#define CA_DEFAULT_BLE_MTU_SIZE 20 +#endif /** - * @brief Initialize the LE adapter layer. This will be invoked from the CA layer. + * 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. + * + * @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. * - * @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] 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(); /** - * @brief Used to get the current state of the LE adapter. + * 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(); + +/** + * 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 - * @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 CAStopBleGattServer(); +CAResult_t CAInitializeLEGattServer(); /** - * @brief Used to stop Gatt Server thread and remove service registration, stop advertising. - * @return NONE + * Stop Gatt Server thread and remove service registration, stop + * advertising. */ -void CATerminateBleGattServer(); +void CATerminateLEGattServer(); /** - * @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 + * 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 CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback); +void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback); /** - * @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 send to + * particular client. * - * @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] 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 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 CAUpdateCharacteristicsToGattClient(const char *address, + const uint8_t *value, + uint32_t valueLen); /** - * @brief Used to update characteristics(Read/Write) value that we want to multicast to all clients + * Update characteristics(Read/Write) value that we want to multicast + * to all clients. * - * @param charValue [IN] Data that we want to send to clients(multicast) - * @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 CAUpdateCharacteristicsToAllGattClients(const char *charValue, - const uint32_t charValueLen); +CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *value, + uint32_t valueLen); /** - * @brief Used to start CAStartBleGattClientThread for initializing Gatt Client + * Start @c CAStartBleGattClientThread for initializing Gatt 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_INVALID_PARAM Invalid input arguments + * @retval ::CA_STATUS_FAILED Operation failed */ -CAResult_t CAStartBLEGattClient(); +CAResult_t CAStartLEGattClient(); /** - * @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 + * 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 arguments + * @retval ::CA_STATUS_FAILED Operation failed */ -void CAStopBLEGattClient(); +void CAStopLEGattClient(); /** - * @brief Used to unset all the callbacks and stop service discovery - * @return NONE + * initialize Client + * + * @return ::CA_STATUS_OK or Appropriate error code + * @retval ::CA_STATUS_OK Successful + * @retval ::CA_STATUS_FAILED Operation failed */ -void CATerminateBLEGattClient(); +CAResult_t CAInitializeLEGattClient(); /** - * @brief Sets the value of characteristic and update the value to GATTServer(unicast). + * Unset all the callbacks and stop service discovery + */ +void CATerminateLEGattClient(); + +/** + * Read the data from characteristics and invoke notify callback. + */ +void CACheckLEData(); + +/** + * 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). + * + * @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 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 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); + +/** + * 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 #endif /* CA_LE_INTERFACE_H_ */ -