From: DoHyun Pyun Date: Thu, 4 Jun 2015 12:05:05 +0000 (+0900) Subject: Merge Tizen 2.4's API headers for Web TCT / UTC build X-Git-Tag: submit/tizen_mobile/20150604.234646^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d2b962543a59a9964e00d05dc1e848695e3f5a1;p=platform%2Fcore%2Fapi%2Fbluetooth.git Merge Tizen 2.4's API headers for Web TCT / UTC build Change-Id: Ib32b4795e0d44e7ac4092a078b6567719205c34b Signed-off-by: DoHyun Pyun --- diff --git a/doc/bluetooth_doc.h b/doc/bluetooth_doc.h old mode 100755 new mode 100644 index 1dfd984..6f318c0 --- a/doc/bluetooth_doc.h +++ b/doc/bluetooth_doc.h @@ -161,9 +161,10 @@ * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_HEADER Required Header * \#include * - * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_OVERVIEW Overview + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_OVERVIEW Overview + * Bluetooth stack architecture has been changed. Thus, GATT APIs defined in Tizen 2.3 are deprecated and new GATT client APIs are defined. * - * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_MODULE_FEATURE Related Features + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_FEATURE Related Features * This API is related with the following features:\n * - http://tizen.org/feature/network.bluetooth\n * - http://tizen.org/feature/network.bluetooth.le\n @@ -198,7 +199,6 @@ * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_FEATURE Related Features * This API is related with the following features:\n * - http://tizen.org/feature/network.bluetooth\n - * - http://tizen.org/feature/network.bluetooth.le\n * * It is recommended to design feature related codes in your application for reliability.\n * @@ -676,7 +676,8 @@ * Two roles are defined for devices that implement GATT. * The @a Server is the device that accepts incoming commands and requests from the client and sends responses, indications and notifications to a client. * The @a Client is the device that initiates commands and requests towards the server and can receive responses, indications and notifications sent by the server. - * This API supports the @a Client role in GATT. + * This API supports the @a Client role in GATT. \n + * Bluetooth stack architecture has been changed. Thus, GATT APIs defined in Tizen 2.3 are deprecated and new GATT client APIs are defined. * * @section CAPI_NETWORK_BLUETOOTH_GATT_MODULE_FEATURE Related Features * This API is related with the following features:\n diff --git a/include/bluetooth.h b/include/bluetooth.h old mode 100755 new mode 100644 index 853934f..e5cf694 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -25,7 +25,7 @@ #include "bluetooth_type.h" #include "bluetooth_internal.h" -#include "bluetooth_extention.h" +#include "bluetooth_extension.h" #ifdef __cplusplus extern "C" @@ -667,8 +667,9 @@ int bt_adapter_set_remote_oob_data(const char *remote_address, int bt_adapter_remove_remote_oob_data(const char *remote_address); /** + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Starts the LE device discovery for a BT_ADAPTER_DEVICE_DISCOVERY_LE type. + * @brief Starts the LE device discovery. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth @@ -690,7 +691,6 @@ int bt_adapter_remove_remote_oob_data(const char *remote_address); * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * or must be #BT_ADAPTER_LE_ENABLED. * @post This function invokes bt_adapter_le_device_discovery_state_changed_cb(). * * @see bt_adapter_le_is_discovering() @@ -701,6 +701,7 @@ int bt_adapter_remove_remote_oob_data(const char *remote_address); int bt_adapter_le_start_device_discovery(void); /** + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Stops the LE device discovery, asynchronously. * @since_tizen 2.3 @@ -728,6 +729,7 @@ int bt_adapter_le_start_device_discovery(void); int bt_adapter_le_stop_device_discovery(void); /** + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Checks for the LE device discovery is in progress or not. * @since_tizen 2.3 @@ -747,7 +749,6 @@ int bt_adapter_le_stop_device_discovery(void); * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * or must be #BT_ADAPTER_LE_ENABLED. * * @see bt_adapter_le_start_device_discovery() * @see bt_adapter_le_stop_device_discovery() @@ -755,6 +756,7 @@ int bt_adapter_le_stop_device_discovery(void); int bt_adapter_le_is_discovering(bool *is_discovering); /** + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Registers a callback function to be invoked when the LE device discovery state changes. * @since_tizen 2.3 @@ -778,6 +780,7 @@ int bt_adapter_le_is_discovering(bool *is_discovering); int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data); /** + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Unregisters the callback function. * @since_tizen 2.3 @@ -796,836 +799,945 @@ int bt_adapter_le_unset_device_discovery_state_changed_cb(void); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Create advertiser to advertise device's existence or respond to LE scanning reqeust. - * @since_tizen 2.3 + * @brief Starts the LE scan to find LE advertisement. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth * - * @param[out] advertiser The handle of advertiser + * @details If a LE advertisement is found, bt_adapter_le_scan_result_cb() will be invoked. + * + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_le_scan_result_cb(). * - * @see bt_adapter_le_destroy_advertiser() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser); +int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Destroy advertiser. - * @since_tizen 2.3 - * - * @param[out] advertiser The handle of advertiser + * @brief Stops the LE scan. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). + * @pre The LE scan must be in progress with bt_adapter_le_start_scan(). * - * @see bt_adapter_le_create_advertiser() + * @see bt_adapter_le_start_scan() */ -int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser); +int bt_adapter_le_stop_scan(void); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Set the data to be advertised or responded to scan request from LE scanning device. - * The maximum advertised or responded data size is 31 bytes - * including data type and system wide data. - * @since_tizen 2.3 + * @brief Gets the service UUID list from the scan result information + * @since_tizen 2.3.1 * - * @param[in] advertiser The handle of advertiser + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service UUID or 128-bit service UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] info The scan result information * @param[in] pkt_type The packet type - * @param[in] data_type The data type that is included in packet - * @param[in] data The data to be advertised or be responded to scan request from LE scanning device - * @param[in] data_size The size of data to be set. + * @param[out] uuids The list of string of the service uuid + * @param[out] count The count of the service UUIDs * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_le_remove_advertising_data() - * @see bt_adapter_le_clear_advertising_data() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, - bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, - void *data, unsigned int data_size); +int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Unset the data to be advertised or responded to scan request from LE scanning device. - * @since_tizen 2.3 + * @brief Gets the device name from the scan result information + * @since_tizen 2.3.1 * - * @param[in] advertiser The handle of advertiser + * @remarks The @a name must be released with free() by you. + * + * @param[in] info The scan result information * @param[in] pkt_type The packet type - * @param[in] data_type The data type to be removed from selected packet + * @param[out] name The device name * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_le_add_advertising_data() - * @see bt_adapter_le_clear_advertising_data() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, - bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type); +int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char **name); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Clear all data to be advertised or responded to scan request from LE scanning device. - * @since_tizen 2.3 + * @brief Gets the transmission power level from the scan result information + * @since_tizen 2.3.1 * - * @param[in] advertiser The handle of advertiser - * @param[in] pkt_type The packet type to be cleared + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] power_level The transmission power level in dBm * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_le_add_advertising_data() - * @see bt_adapter_le_remove_advertising_data() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); +int bt_adapter_le_get_scan_result_tx_power_level(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *power_level); /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Start advertising with passed advertiser and advertising parameters. - * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth + * @brief Gets the service solicitation UUID list from the scan result information + * @since_tizen 2.3.1 * - * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported - * devices can know this device's existence. And one of them can make a connection reqeust, - * if it is allowed. + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service solicitation UUID or 128-bit service solicitaion UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) * - * @param[in] advertiser The handle of advertiser - * @param[in] adv_params The parameters of advertising \n - * If NULL is passed, default values which are defined in driver / controller are used. - * @param[in] cb The callback to report the result of this function - * @param[in] user_data The user data to be passed when callback is called + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] uuids The list of string of the service solicitation uuid + * @param[out] count The count of the service UUIDs * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). * - * @see bt_adapter_le_stop_advertising() - * @see bt_adapter_le_advertising_state_changed_cb() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, bt_adapter_le_advertising_params_s *adv_params, - bt_adapter_le_advertising_state_changed_cb cb, void *user_data); +int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE - * @brief Stops the advertising. - * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth + * @brief Gets the service data list from the scan result information + * @since_tizen 2.3.1 * - * @param[in] advertiser The handle of advertiser + * @remarks The @a data_list must be released with bt_adapter_le_free_service_data_list() by you . + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] data_list The list of the service data + * @param[out] count The count of the service data list * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The advertising must be going on with bt_adapter_le_start_advertising(). - * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_le_start_advertising() - * @see bt_adapter_le_advertising_state_changed_cb() + * @see bt_adapter_le_scan_result_cb() */ -int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser); +int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_service_data_s **data_list, int *count); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Creates a bond with a remote Bluetooth device, asynchronously. - * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees service data list. + * @since_tizen 2.3.1 * - * @remarks A bond can be destroyed by bt_device_destroy_bond().\n - * The bonding request can be cancelled by bt_device_cancel_bonding(). + * @param[in] data_list The list of the service data + * @param[in] count The count of the service data list * - * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_adapter_le_get_scan_result_service_data_list() + */ +int bt_adapter_le_free_service_data_list(bt_adapter_le_service_data_s *data_list, int count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the appearance from the scan result information + * @since_tizen 2.3.1 + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] appearance The appearance * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @post This function invokes bt_device_bond_created_cb(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_start_device_discovery() - * @see bt_device_bond_created_cb() - * @see bt_device_cancel_bonding() - * @see bt_device_destroy_bond() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() + * @see bt_adapter_le_scan_result_cb() */ -int bt_device_create_bond(const char *remote_address); +int bt_adapter_le_get_scan_result_appearance(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *appearance); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Cancels the bonding process. - * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the manufacturer data from the scan result information + * @since_tizen 2.3.1 * - * @remarks Use this function when the remote Bluetooth device is not responding to the - * bond request or you wish to cancel the bonding request. + * @remarks The @a manufacturer_data must be released with free() by you. + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] manufacturer_id The manufacturer ID + * @param[out] manufacturer_data The manufacturer data (byte array) + * @param[out] manufacturer_data_len The length of manufacturer data * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The creating a bond must be in progress by bt_device_create_bond(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_device_create_bond() - * @see bt_device_bond_created_cb() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() + * @see bt_adapter_le_scan_result_cb() */ -int bt_device_cancel_bonding(void); +int bt_adapter_le_get_scan_result_manufacturer_data(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *manufacturer_id, char **manufacturer_data, int *manufacturer_data_len); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Destroys the bond, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Create advertiser to advertise device's existence or respond to LE scanning reqeust. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth * - * @param[in] remote_address The address of the remote Bluetooth device to remove bonding + * @param[out] advertiser The handle of advertiser * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_device_bond_destroyed_cb(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_device_create_bond() - * @see bt_device_bond_destroyed_cb() - * @see bt_device_set_bond_destroyed_cb() - * @see bt_device_unset_bond_destroyed_cb() + * @see bt_adapter_le_destroy_advertiser() */ -int bt_device_destroy_bond(const char *remote_address); +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Sets an alias for the bonded device. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroy advertiser. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth * - * @param[in] remote_address The address of the remote Bluetooth device - * @param[in] alias The alias of the remote Bluetooth device + * @param[out] advertiser The handle of advertiser * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_device_create_bond() + * @see bt_adapter_le_create_advertiser() */ -int bt_device_set_alias(const char *remote_address, const char *alias); +int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Sets the authorization of a bonded device, asynchronously. + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set the data to be advertised or responded to scan request from LE scanning device. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth * - * @remarks Once a device is authorized, you don't need to receive a confirmation. + * @remarks In case the data_type is local name or tx power level, you don't need to input data + * because the data value is written automatically by system. * - * @param[in] remote_address The address of the remote Bluetooth device to authorize - * @param[in] authorization_state The Bluetooth authorization state + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type that is included in packet + * @param[in] data The data to be advertised or be responded to scan request from LE scanning device, no need in case of LOCAL_NAME or TX_POWER_LEVEL + * @param[in] data_size The size of data to be set. * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post bt_device_authorization_changed_cb() will be invoked. + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_device_create_bond() - * @see bt_device_authorization_changed_cb() - * @see bt_device_set_authorization_changed_cb() - * @see bt_device_unset_authorization_changed_cb() + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); +int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, + void *data, unsigned int data_size); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Starts the search for services supported by the specified device, asynchronously. - * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 * - * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, - * then you don't need to run this function.\n - * The service search takes a couple of seconds to complete normally. \n + * @remarks 16-bit UUID or 128-bit UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) * - * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service UUID. * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_device_service_searched_cb(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_adapter_start_device_discovery() - * @see bt_device_create_bond() - * @see bt_device_bond_created_cb() - * @see bt_device_service_searched_cb() - * @see bt_device_set_service_searched_cb() - * @see bt_device_unset_service_searched_cb() + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_start_service_search(const char *remote_address); +int bt_adapter_le_add_advertising_service_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Gets the connected profiles. - * @since_tizen 2.3 - * @param[in] remote_address The address of the remote device - * @param[in] callback The callback function to invoke - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service solicitation UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit service solicitation UUID or 128-bit service solicitation UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service solicitation UUID. * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @post bt_device_connected_profile() will be invoked. - * @see bt_device_connected_profile() - */ -int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Gets the profile connected status. - * @since_tizen 2.3 - * @param[in] remote_address The address of the remote device - * @param[in] bt_profile wish to know bt_profile - * @param[out] connected_status the connected status * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile, - bool *connected_status); +int bt_adapter_le_add_advertising_service_solicitation_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the bond creates. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add service data to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit UUID is supported. (e.g. 180F) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid 16-bit UUID of the service + * @param[in] service_data The service data + * @param[in] service_data_len The data length of service data + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_bond_created_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_bond_created_cb() - * @see bt_device_unset_bond_created_cb() + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); +int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid, + const char *service_data, int service_data_len); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the external appearance of this device to advertise or scan response data. + * Please refer to the adopted Bluetooth specification for the the appearance. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] appearance The external appearance of device + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_bond_created_cb() + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_unset_bond_created_cb(void); +int bt_adapter_le_set_advertising_appearance(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int appearance); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the bond destroys. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add manufacturer specific data to advertise or scan response data. + * Please refer to the Bluetooth Assigned Numbers provided by the Bluetooth SIG for a list of existing company identifiers. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] manufacturer_id Manufacturer identifier + * @param[in] manufacturer_data The manufacturer specific data + * @param[in] manufacturer_data_len The data length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_bond_destroyed_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_bond_destroyed_cb() - * @see bt_device_unset_bond_destroyed_cb() + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); +int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int manufacturer_id, const char *manufacturer_data, int manufacturer_data_len); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the device name should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_name Whether the device name should be included + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_bond_destroyed_cb() + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_unset_bond_destroyed_cb(void); +int bt_adapter_le_set_advertising_device_name(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_name); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the authorization of device changes. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the transmission power level should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_tx_power Whether the transmission power level should be included + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_authorization_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_authorization_changed_cb() - * @see bt_device_set_authorization_changed_cb() - * @see bt_device_unset_authorization_changed_cb() + * + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); +int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_tx_power); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unset the data to be advertised or responded to scan request from LE scanning device. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type to be removed from selected packet + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_authorization_changed_cb() + * + * @see bt_adapter_le_add_advertising_data() + * @see bt_adapter_le_clear_advertising_data() */ -int bt_device_unset_authorization_changed_cb(void); +int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the process of service search finishes. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Clear all data to be advertised or responded to scan request from LE scanning device. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type to be cleared + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_service_searched_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_service_searched_cb() - * @see bt_device_unset_service_searched_cb() + * + * @see bt_adapter_le_add_advertising_data() */ -int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. + * + * @param[in] advertiser The handle of advertiser + * @param[in] adv_params The parameters of advertising \n + * If NULL is passed, default values which are defined in driver / controller are used. + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_service_searched_cb() + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() */ -int bt_device_unset_service_searched_cb(void); +int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, bt_adapter_le_advertising_params_s *adv_params, + bt_adapter_le_advertising_state_changed_cb cb, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the connection state is changed. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the advertising. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_connection_state_changed_cb() - * @see bt_device_unset_connection_state_changed_cb() - */ -int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function to be invoked when the connection state is changed. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The advertising must be going on with bt_adapter_le_start_advertising_new(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_connection_state_changed_cb() + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_advertising_state_changed_cb() */ -int bt_device_unset_connection_state_changed_cb(void); +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Registers a rfcomm server socket with a specific UUID. - * @since_tizen 2.3 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. + * @since_tizen 2.3.1 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth * - * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. * - * @param[in] service_uuid The UUID of service to provide - * @param[out] socket_fd The file descriptor of socket to listen - * @return 0 on success, otherwise a negative error value. + * @param[in] advertiser The handle of advertiser + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). * - * @see bt_socket_listen_and_accept_rfcomm() - * @see bt_socket_destroy_rfcomm() + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() */ -int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); +int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, bt_adapter_le_advertising_state_changed_cb cb, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm(). - * @since_tizen 2.3 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising mode to control the advertising power and latency. + * @since_tizen 2.3.1 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, - * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. * - * @param[in] socket_fd The file descriptor of socket (which was created using bt_socket_create_rfcomm()) to destroy + * @param[in] advertiser The handle of advertiser + * @param[in] mode The mode of advertising + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, - * then bt_socket_connection_state_changed_cb() will be called. - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() */ -int bt_socket_destroy_rfcomm(int socket_fd); +int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, bt_adapter_le_advertising_mode_e mode); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Starts listening on passed rfcomm socket and accepts connection requests. - * @since_tizen 2.3 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the advertising type should be connectable or non-connectable + * @since_tizen 2.3.1 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @details Pop-up is shown automatically when a RFCOMM connection is requested. - * bt_socket_connection_state_changed_cb() will be called with - * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. - * @param[in] socket_fd The file descriptor of socket on which start to listen - * @param[in] max_pending_connections The maximum number of pending connections + * + * @param[in] advertiser The handle of advertiser + * @param[in] connectable The type of advertising + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post If callback function bt_socket_connection_state_changed_cb() is set, - * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() */ -int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); +int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth * - * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). * - * @param[in] remote_address The address of the remote Bluetooth device - * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_socket_connection_state_changed_cb(). + * @post This function invokes bt_device_bond_created_cb(). * - * @see bt_device_create_bond() * @see bt_adapter_start_device_discovery() - * @see bt_device_start_service_search() - * @see bt_socket_disconnect_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() */ -int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); +int bt_device_create_bond(const char *remote_address); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels the bonding process. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @param[in] socket_fd The file descriptor of socket to close which was received using bt_socket_connection_state_changed_cb(). + * + * @remarks Use this function when the remote Bluetooth device is not responding to the + * bond request or you wish to cancel the bonding request. + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The connection must be established. + * @pre The creating a bond must be in progress by bt_device_create_bond(). * - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() */ -int bt_socket_disconnect_rfcomm(int socket_fd); +int bt_device_cancel_bonding(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Sends data to the connected device. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Destroys the bond, asynchronously. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. * - * @param[in] socket_fd The file descriptor of connected socket which was received using bt_socket_connection_state_changed_cb() - * @param[in] data The data to be sent - * @param[in] length The length of data to be sent + * @param[in] remote_address The address of the remote Bluetooth device to remove bonding * - * @return the number of bytes written (zero indicates nothing was written). - * @retval On error, -1 is returned, and errno is set appropriately. See write 2 man page. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * @exception BT_ERROR_PERMISSION_DENIED Permission denied - * @exception BT_ERROR_AGAIN Resource temporarily unavailable + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The connection must be established. + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_bond_destroyed_cb(). * - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @see bt_device_create_bond() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() */ -int bt_socket_send_data(int socket_fd, const char *data, int length); +int bt_device_destroy_bond(const char *remote_address); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when you receive data. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets an alias for the bonded device. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] alias The alias of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_socket_data_received_cb() will be invoked. - * @see bt_initialize() - * @see bt_socket_data_received_cb() - * @see bt_socket_set_data_received_cb() - * @see bt_socket_unset_data_received_cb() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * + * @see bt_device_create_bond() */ -int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); +int bt_device_set_alias(const char *remote_address, const char *alias); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Unregisters the callback function. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets the authorization of a bonded device, asynchronously. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Once a device is authorized, you don't need to receive a confirmation. + * + * @param[in] remote_address The address of the remote Bluetooth device to authorize + * @param[in] authorization_state The Bluetooth authorization state + * + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_socket_data_received_cb() - * @see bt_socket_set_data_received_cb() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post bt_device_authorization_changed_cb() will be invoked. + * + * @see bt_device_create_bond() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() */ -int bt_socket_unset_data_received_cb(void); +int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Starts the search for services supported by the specified device, asynchronously. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, + * then you don't need to run this function.\n + * The service search takes a couple of seconds to complete normally. \n + * + * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post If you listen a socket by bt_socket_listen(), bt_socket_connection_requested_cb() will be invoked. - * @see bt_initialize() - * @see bt_socket_unset_connection_requested_cb() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_service_searched_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() */ -int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); +int bt_device_start_service_search(const char *remote_address); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Unregisters the callback function. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the connected profiles. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_socket_set_connection_requested_cb() - * @see bt_socket_connection_requested_cb() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_device_connected_profile() will be invoked. + * @see bt_device_connected_profile() */ -int bt_socket_unset_connection_requested_cb(void); +int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when the connection state changes. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the profile connected status. + * @since_tizen 2.3 + * @param[in] remote_address The address of the remote device + * @param[in] bt_profile wish to know bt_profile + * @param[out] connected_status the connected status + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile, + bool *connected_status); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond creates. * @since_tizen 2.3 * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function @@ -1633,461 +1745,420 @@ int bt_socket_unset_connection_requested_cb(void); * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_socket_connection_state_changed_cb() will be invoked. + * @post bt_device_bond_created_cb() will be invoked. * @see bt_initialize() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() + * @see bt_device_bond_created_cb() + * @see bt_device_unset_bond_created_cb() */ -int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); +int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE * @brief Unregisters the callback function. * @since_tizen 2.3 * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). * @see bt_initialize() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() + * @see bt_device_set_bond_created_cb() */ -int bt_socket_unset_connection_state_changed_cb(void); +int bt_device_unset_bond_created_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond destroys. * @since_tizen 2.3 - * @details No popup appears when an OPP connection is requested from a remote device. - * Instead, @a connection_requested_cb() will be called. - * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). - * @remarks This function must be called to start Bluetooth OPP server. \n - * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. - * @param[in] destination The destination path - * @param[in] connection_requested_cb The callback called when an OPP connection is requested + * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_connection_requested_cb() - * @see bt_opp_server_deinitialize() - * @see bt_opp_server_accept() - * @see bt_opp_server_reject() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_destroyed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() */ -int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); +int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Denitializes the Bluetooth OPP server. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_initialize() - * @see bt_opp_server_deinitialize() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_destroyed_cb() */ -int bt_opp_server_deinitialize(void); +int bt_device_unset_bond_destroyed_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Accepts the push request from the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the authorization of device changes. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. - * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. - * @param[in] progress_cb The callback called when a file is being transfered - * @param[in] finished_cb The callback called when a transfer is finished - * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). + * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function - * @param[out] transfer_id The ID of transfer - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_reject() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_authorization_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() */ -int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, - void *user_data, int *transfer_id); +int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Rejects the push request from the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_accept() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_authorization_changed_cb() */ -int bt_opp_server_reject(void); +int bt_device_unset_authorization_changed_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Cancels the transfer. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the process of service search finishes. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @param[in] transfer_id The ID of transfer - * @return 0 on success, otherwise a negative error value. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_accept() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_service_searched_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_service_searched_cb() + * @see bt_device_unset_service_searched_cb() */ -int bt_opp_server_cancel_transfer(int transfer_id); +int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Sets the destination path of file to be pushed. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @param[in] destination The destination path of file to be pushed - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_server_initialize() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_service_searched_cb() */ -int bt_opp_server_set_destination(const char *destination); +int bt_device_unset_service_searched_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Initializes the Bluetooth OPP client. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the connection state is changed. * @since_tizen 2.3 - * @remarks This function must be called before Bluetooth OPP client starts. \n - * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() - * if Bluetooth OPP service is no longer needed. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_client_deinitialize() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() */ -int bt_opp_client_initialize(void); +int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Denitializes the Bluetooth OPP client. + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function to be invoked when the connection state is changed. * @since_tizen 2.3 * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_client_initialize() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_connection_state_changed_cb() */ -int bt_opp_client_deinitialize(void); +int bt_device_unset_connection_state_changed_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Adds file to be pushed. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. * @since_tizen 2.3 - * @param[in] file The path of file to be pushed + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). + * + * @param[in] service_uuid The UUID of service to provide + * @param[out] socket_fd The file descriptor of socket to listen * @return 0 on success, otherwise a negative error value. + * * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_client_clear_files() - * @see bt_opp_client_push_files() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_destroy_rfcomm() */ -int bt_opp_client_add_file(const char *file); +int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Adds file to be pushed. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm(). * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] socket_fd The file descriptor of socket (which was created using bt_socket_create_rfcomm()) to destroy * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_client_add_file() - * @see bt_opp_client_push_files() + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_opp_client_clear_files(void); +int bt_socket_destroy_rfcomm(int socket_fd); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Pushes the file to the remote device, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. - * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. - * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. - * bt_opp_client_push_finished_cb() will be called when the push request is finished. - * @param[in] remote_address The remote address - * @param[in] responded_cb The callback called when OPP server responds to the push request - * @param[in] progress_cb The callback called when each file is being transfered - * @param[in] finished_cb The callback called when the push request is finished - * @param[in] user_data The user data to be passed to the callback function + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] socket_fd The file descriptor of socket on which start to listen + * @param[in] max_pending_connections The maximum number of pending connections * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_opp_client_initialize() - * @see bt_opp_client_cancel_push + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, - bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); +int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Cancels the push request in progress, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre bt_opp_client_push_files() must be called. - * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, - * which is a parameter of bt_opp_client_push_files(). - * @see bt_opp_client_initialize() - * @see bt_opp_client_push_files() + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_device_create_bond() + * @see bt_adapter_start_device_discovery() + * @see bt_device_start_service_search() + * @see bt_socket_disconnect_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_opp_client_cancel_push(void); +int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Initializes the Bluetooth HID(Human Interface Device) Host. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. * @since_tizen 2.3 - * @remarks This function must be called before Bluetooth HID Host starts. \n - * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() - * if Bluetooth HID Host service is no longer needed. - * @param[in] connection_cb The callback called when the connection state is changed - * @param[in] user_data The user data to be passed to the callback function + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] socket_fd The file descriptor of socket to close which was received using bt_socket_connection_state_changed_cb(). * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_hid_host_deinitialize() - */ -int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The connection must be established. * - * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). - * @see bt_hid_host_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_hid_host_deinitialize(void); +int bt_socket_disconnect_rfcomm(int socket_fd); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Sends data to the connected device. * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/bluetooth - * @param[in] remote_address The remote address - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * + * @param[in] socket_fd The file descriptor of connected socket which was received using bt_socket_connection_state_changed_cb() + * @param[in] data The data to be sent + * @param[in] length The length of data to be sent + * + * @return the number of bytes written (zero indicates nothing was written). + * @retval On error, -1 is returned, and errno is set appropriately. See write 2 man page. * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @exception BT_ERROR_PERMISSION_DENIED Permission denied + * @exception BT_ERROR_AGAIN Resource temporarily unavailable * - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). - * @post bt_hid_host_connection_state_changed_cb() will be invoked. - * @see bt_hid_host_disconnect() - * @see bt_hid_host_connection_state_changed_cb() + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_hid_host_connect(const char *remote_address); +int bt_socket_send_data(int socket_fd, const char *data, int length); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when you receive data. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @param[in] remote_address The remote address - * @return 0 on success, otherwise a negative error value. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected by bt_hid_host_connect(). - * @post bt_hid_host_connection_state_changed_cb() will be invoked. - * @see bt_hid_host_connect() - * @see bt_hid_host_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_data_received_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() */ -int bt_hid_host_disconnect(const char *remote_address); +int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Initializes the Bluetooth profiles related with audio. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @remarks This function must be called before Bluetooth profiles related with audio starts. \n - * You must free all resources of the this service by calling bt_audio_deinitialize() - * if Bluetooth profiles related with audio service is no longer needed. - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The Bluetooth service must be initialized with bt_initialize(). * @see bt_initialize() - * @see bt_audio_deinitialize() - */ -int bt_audio_initialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Deinitializes the Bluetooth profiles related with audio. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() */ -int bt_audio_deinitialize(void); +int bt_socket_unset_data_received_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Connects the remote device with the given audio profile, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice - * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. - * @param[in] remote_address The remote address - * @param[in] type The type of audio profile - * @return 0 on success, otherwise a negative error value. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @post bt_audio_connection_state_changed_cb() will be invoked. - * @see bt_audio_disconnect() - * @see bt_audio_connection_state_changed_cb() + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post If you listen a socket by bt_socket_listen(), bt_socket_connection_requested_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_unset_connection_requested_cb() */ -int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); +int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Disconnects the remote device with the given audio profile, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @privlevel public - * @privilege %http://tizen.org/privilege/bluetooth - * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice - * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. - * @param[in] remote_address The remote address - * @param[in] type The type of audio profile - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected by bt_audio_connect(). - * @post bt_audio_connection_state_changed_cb() will be invoked. - * @see bt_audio_connect() - * @see bt_audio_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_connection_requested_cb() */ -int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); +int bt_socket_unset_connection_requested_cb(void); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Registers a callback function that will be invoked when the connection state is changed. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when the connection state changes. * @since_tizen 2.3 * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function @@ -2095,382 +2166,487 @@ int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_audio_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() */ -int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); +int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); /** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_audio_connection_state_changed_cb() - * @see bt_audio_set_connection_state_changed_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() */ -int bt_audio_unset_connection_state_changed_cb(void); +int bt_socket_unset_connection_state_changed_cb(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). * @since_tizen 2.3 - * @remarks This function must be called before Bluetooth AVRCP service. \n - * You must free all resources of the this service by calling bt_avrcp_target_deinitialize() - * if Bluetooth AVRCP service is no longer needed. - * @param[in] callback The callback function called when the connection state is changed + * @details No popup appears when an OPP connection is requested from a remote device. + * Instead, @a connection_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. \n + * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] connection_requested_cb The callback called when an OPP connection is requested * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_target_deinitialize() + * @see bt_opp_server_connection_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() */ -int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data); +int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Denitializes the Bluetooth OPP server. * @since_tizen 2.3 * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_avrcp_target_initialize(). - * @see bt_avrcp_target_initialize() + * @see bt_opp_server_initialize() + * @see bt_opp_server_deinitialize() */ -int bt_avrcp_target_deinitialize(void); +int bt_opp_server_deinitialize(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the equalize state to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Accepts the push request from the remote device. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] state The state of equalizer - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. + * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. + * @param[in] progress_cb The callback called when a file is being transfered + * @param[in] finished_cb The callback called when a transfer is finished + * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). + * @param[in] user_data The user data to be passed to the callback function + * @param[out] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_server_reject() */ -int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state); +int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, + void *user_data, int *transfer_id); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the repeat mode to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Rejects the push request from the remote device. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] mode The repeat mode - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_server_accept() */ -int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode); +int bt_opp_server_reject(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the shuffle mode to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Cancels the transfer. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] mode The repeat mode - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_server_accept() */ -int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode); +int bt_opp_server_cancel_transfer(int transfer_id); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the scan mode to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Sets the destination path of file to be pushed. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] mode The scan mode - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] destination The destination path of file to be pushed + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_server_initialize() */ -int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode); +int bt_opp_server_set_destination(const char *destination); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the player state to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Initializes the Bluetooth OPP client. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] state The player state - * @return 0 on success, otherwise a negative error value. + * @remarks This function must be called before Bluetooth OPP client starts. \n + * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() + * if Bluetooth OPP service is no longer needed. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_client_deinitialize() */ -int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state); +int bt_opp_client_initialize(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the current position of song to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Denitializes the Bluetooth OPP client. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] position The current position in milliseconds - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_initialize() + */ +int bt_opp_client_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3 + * @param[in] file The path of file to be pushed + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_client_clear_files() + * @see bt_opp_client_push_files() */ -int bt_avrcp_target_notify_position(unsigned int position); +int bt_opp_client_add_file(const char *file); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notifies the track to the remote device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] title The title of track - * @param[in] artist The artist of track - * @param[in] album The album of track - * @param[in] genre The genre of track - * @param[in] track_num The track number - * @param[in] total_tracks The number of all tracks - * @param[in] duration The duration of track in milliseconds - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() + * @see bt_opp_client_add_file() + * @see bt_opp_client_push_files() */ -int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album, const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration); +int bt_opp_client_clear_files(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Registers a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Pushes the file to the remote device, asynchronously. * @since_tizen 2.3 - * @param[in] callback The callback function to register + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. + * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. + * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. + * bt_opp_client_push_finished_cb() will be called when the push request is finished. + * @param[in] remote_address The remote address + * @param[in] responded_cb The callback called when OPP server responds to the push request + * @param[in] progress_cb The callback called when each file is being transfered + * @param[in] finished_cb The callback called when the push request is finished * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_unset_equalizer_state_changed_cb() + * @see bt_opp_client_initialize() + * @see bt_opp_client_cancel_push */ -int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data); +int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, + bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Unregisters a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Cancels the push request in progress, asynchronously. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_set_equalizer_state_changed_cb() + * @pre bt_opp_client_push_files() must be called. + * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, + * which is a parameter of bt_opp_client_push_files(). + * @see bt_opp_client_initialize() + * @see bt_opp_client_push_files() */ -int bt_avrcp_unset_equalizer_state_changed_cb(void); +int bt_opp_client_cancel_push(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Registers a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Initializes the Bluetooth HID(Human Interface Device) Host. * @since_tizen 2.3 - * @param[in] callback The callback function to register + * @remarks This function must be called before Bluetooth HID Host starts. \n + * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() + * if Bluetooth HID Host service is no longer needed. + * @param[in] connection_cb The callback called when the connection state is changed * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * @see bt_initialize() - * @see bt_avrcp_unset_repeat_mode_changed_cb() + * @see bt_hid_host_deinitialize() */ -int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data); +int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Unregisters a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_set_repeat_mode_changed_cb() + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @see bt_hid_host_initialize() */ -int bt_avrcp_unset_repeat_mode_changed_cb(void); +int bt_hid_host_deinitialize(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Registers a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_unset_shuffle_mode_changed_cb() + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_disconnect() + * @see bt_hid_host_connection_state_changed_cb() */ -int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data); +int bt_hid_host_connect(const char *remote_address); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Unregisters a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_set_shuffle_mode_changed_cb() + * @pre The remote device must be connected by bt_hid_host_connect(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_connect() + * @see bt_hid_host_connection_state_changed_cb() */ -int bt_avrcp_unset_shuffle_mode_changed_cb(void); +int bt_hid_host_disconnect(const char *remote_address); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Registers a callback function that will be invoked when the scan mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Initializes the Bluetooth profiles related with audio. * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @remarks This function must be called before Bluetooth profiles related with audio starts. \n + * You must free all resources of the this service by calling bt_audio_deinitialize() + * if Bluetooth profiles related with audio service is no longer needed. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * @see bt_initialize() - * @see bt_avrcp_unset_scan_mode_changed_cb() + * @see bt_audio_deinitialize() */ -int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data); +int bt_audio_initialize(void); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Unregisters a callback function that will be invoked when the scan mode is changed by the remote control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Deinitializes the Bluetooth profiles related with audio. * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + */ +int bt_audio_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Connects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_disconnect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Disconnects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth service must be initialized by bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_set_scan_mode_changed_cb() + * @pre The remote device must be connected by bt_audio_connect(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_connect() + * @see bt_audio_connection_state_changed_cb() */ -int bt_avrcp_unset_scan_mode_changed_cb(void); +int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_audio_unset_connection_state_changed_cb(void); /** * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE @@ -2862,7 +3038,6 @@ int bt_hdp_unregister_sink_app(const char *app_id); * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied @@ -2992,6 +3167,7 @@ int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_dat int bt_hdp_unset_data_received_cb(void); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_foreach_services or bt_gatt_client_get_service instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Gets the primary services of GATT(Generic Attribute Profile). * @since_tizen 2.3 @@ -3006,7 +3182,7 @@ int bt_hdp_unset_data_received_cb(void); * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retva l #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. @@ -3016,6 +3192,7 @@ int bt_hdp_unset_data_received_cb(void); int bt_gatt_foreach_primary_services(const char *remote_address, bt_gatt_primary_service_cb callback, void *user_data); /** + * @deprecated Deprecated since 2.3.1. This function call is not required because characteristic discovery is happened automatically. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Discovers the characteristics in service, asynchronously. * @since_tizen 2.3 @@ -3039,6 +3216,7 @@ int bt_gatt_foreach_primary_services(const char *remote_address, bt_gatt_primary int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, bt_gatt_characteristics_discovered_cb callback, void *user_data); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_get_uuid instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Gets the UUID of service. * @since_tizen 2.3 @@ -3061,6 +3239,7 @@ int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, bt_gatt_charac int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_service_foreach_included_services or bt_gatt_service_get_included_service instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Gets the included services in service. * @since_tizen 2.3 @@ -3085,6 +3264,7 @@ int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid); int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, bt_gatt_included_service_cb callback, void *user_data); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_set_characteristic_value_changed_cb instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Registers a callback function that will be invoked when a characteristic value is changed. * @since_tizen 2.3 @@ -3102,6 +3282,7 @@ int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, bt_gatt_inclu int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb callback, void *user_data); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_unset_characteristic_value_changed_cb instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Unregisters a callback function that will be invoked when a characteristic is changed. * @since_tizen 2.3 @@ -3116,6 +3297,7 @@ int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb call int bt_gatt_unset_characteristic_changed_cb(void); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_set_characteristic_value_changed_cb instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Watches all the characteristic value changes of the service * @since_tizen 2.3 @@ -3135,6 +3317,7 @@ int bt_gatt_unset_characteristic_changed_cb(void); int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_unset_characteristic_value_changed_cb instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Remove watching of all the characteristic value changes of the service * @since_tizen 2.3 @@ -3153,8 +3336,8 @@ int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service); */ int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service); - /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_get_value or bt_gatt_get_uuid after bt_gatt_client_read_value instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Gets the characteristic declaration. * @since_tizen 2.3 @@ -3180,6 +3363,7 @@ int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service); int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, char **uuid, unsigned char **value, int *value_length); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_set_value and bt_gatt_client_write_value instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Sets the value of characteristic. * @since_tizen 2.3 @@ -3202,6 +3386,7 @@ int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, c int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, const unsigned char *value, int value_length); /** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_set_value and bt_gatt_client_write_value instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Sets the value of characteristic request. * @since_tizen 2.3 @@ -3210,13 +3395,13 @@ int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, const u * @param[in] characteristic The attribute handle of characteristic * @param[in] value The value of characteristic (byte array) * @param[in] value_length The length of value - * @param[in] callback The result callback + * @param[in] callback The result callback * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retva l #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. @@ -3226,6 +3411,7 @@ int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, int value_length, bt_gatt_characteristic_write_cb callback); /** +* @deprecated Deprecated since 2.3.1. GATT handle clone is not allowed. Instead, all handles for client role must be got from GATT client handle. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Clones the attribute handle. * @since_tizen 2.3 @@ -3243,6 +3429,7 @@ int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h* clone, bt_gatt_attribute_h origin); /** +* @deprecated Deprecated since 2.3.1. GATT handle clone and destroy are not allowed. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Destroys the attribute handle. * @since_tizen 2.3 @@ -3257,6 +3444,7 @@ int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h* clone, bt_gatt_attribute int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle); /** + * @deprecated Deprecated since 2.3.1. Use gatt_client_read_value instead. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Reads the value of characteristic from remote device * @since_tizen 2.3 @@ -3279,6 +3467,7 @@ int bt_gatt_read_characteristic_value(bt_gatt_attribute_h char_handle, bt_gatt_characteristic_read_cb callback); /** + * @deprecated Deprecated since 2.3.1. This function call is not required because descriptor discovery is happened automatically. * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Discovers the characteristic descriptors of a characteristic within its definition, asynchronously. * @since_tizen 2.3 @@ -3303,6 +3492,569 @@ int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristi bt_gatt_characteristic_descriptor_discovered_cb callback, void *user_data); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a value must be released using free(). \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] value The value of @a gatt_handle. It is a byte stream type. + * @param[out] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_value(bt_gatt_h gatt_handle, char **value, int *value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as an integer type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The integer type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int offset, int *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as a float type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The float type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int offset, float *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] value The value to be updated + * @param[in] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_value(bt_gatt_h gatt_handle, const char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a integer type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a value will be saved in @a gatt_handle as this type + * @param[in] value The integer type's value to be updated + * @param[in] offset The offset from where @a value will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int value, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a float type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a mantissa and @a exponent will be saved in @a gatt_handle as this type + * @param[in] mantissa The mantissa of float type's value to be updated + * @param[in] exponent The exponent of float type's value to be updated + * @param[in] offset The offset from where @a mantissa and @a exponent will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int mantissa, int exponent, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the UUID of a service, characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a uuid must be released using free(). \n + * 16-bit UUID or 128-bit UUID is supported. (e.g. 2A19, 00002A19-0000-1000-8000-00805F9B34FB) + * + * @param[in] gatt_handle The handle of a service, characteristic or descriptor + * @param[out] uuid The string of the UUID of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_uuid(bt_gatt_h gatt_handle, char **uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the type of GATT handle + * @since_tizen 2.3.1 + * + * @param[in] gatt_handle The GATT handle + * @param[out] gatt_type The type of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_type(bt_gatt_h gatt_handle, bt_gatt_type_e *gatt_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT client handle which the specified service belongs to + * @since_tizen 2.3.1 + * + * @remark This function doesn't allocate new memory for GATT client handle. + * The returned GATT client handle is the same one which was got from bt_gatt_client_create(). + * So if it is destroyed by bt_gatt_client_destroy(), all related GATT handles are freed also. + * + * @param[in] service The service's GATT handle + * @param[out] client The GATT client handle which @a service belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_service_get_client(bt_gatt_h service, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a characteristic's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple characteristics which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The characteristic's GATT handle which has this UUID will be returned if it exists + * @param[out] characteristic The characteristic's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_characteristic(bt_gatt_h service, const char *uuid, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each characteristic that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each characteristic + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_characteristics(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets an included service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple included services which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The included service's GATT handle which has this UUID will be returned if it exists + * @param[out] included_service The included service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_included_service(bt_gatt_h service, const char *uuid, + bt_gatt_h *included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each included service that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each included service + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_included_services(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the service's GATT handle which the specified characteristic belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] service The service's GATT handle which @a characteristic belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_service(bt_gatt_h characteristic, bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the properties which a characteristic's GATT handle has + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] properties The properties which a characteristic's GATT handle has + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_property_e + */ +int bt_gatt_characteristic_get_properties(bt_gatt_h characteristic, int *properties); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the write type of the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] write_type The write type of the specified characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_get_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e *write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the write type of the specified charateristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] write_type The write type to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_write_value() + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_set_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a descriptor's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple descriptors which have same UUID, only the first matched one will be returned. + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] uuid The descriptor's GATT handle which has this UUID will be returned if it exists + * @param[out] descriptor The descriptor's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_descriptor(bt_gatt_h characteristic, const char *uuid, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each descriptor that belongs to the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The function to be invoked on each descriptor + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_characteristic_foreach_descriptors(bt_gatt_h characteristic, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the characteristic's GATT handle which the specified descriptor belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] descriptor The descriptor's GATT handle + * @param[out] characteristic The characteristic's GATT handle which @a descriptor belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_descriptor_get_characteristic(bt_gatt_h descriptor, bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT client handle + * @since_tizen 2.3.1 + * + * @remark The GATT client handle must be freed by bt_gatt_client_destroy() after use + * + * @param[in] remote_address The address of the remote device + * @param[out] client The created GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_destroy() + */ +int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT client's handle + * @since_tizen 2.3.1 + * + * @remark All related service, characteristic and descriptor's GATT handles are freed also + * + * @param[in] client The GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_destroy(bt_gatt_client_h client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the address of remote device + * @since_tizen 2.3.1 + * + * @param[in] client The created GATT client's handle + * @param[out] remote_address The address of the remote device which is associated with @a client + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_get_remote_address(bt_gatt_client_h client, + char **remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Reads the value of a characteristic or descriptor from the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a read request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_read_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Writes the value of a characteristic or descriptor to the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a write request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_characteristic_set_write_type() + * @see bt_gatt_set_value() + * @see bt_gatt_set_int_value() + * @see bt_gatt_set_float_value() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_write_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The callback to be invoked when the value is changed and it is informed + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_characteristic_value_changed_cb() + * @see bt_gatt_client_unset_characteristic_value_change() + */ +int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_client_characteristic_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle, whose value change will not be informed + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_set_characteristic_value_changed_cb() + */ +int bt_gatt_client_unset_characteristic_value_changed_cb(bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] client The GATT client's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_client_get_service(bt_gatt_client_h client, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT client + * @since_tizen 2.3.1 + * + * @param[in] client The GATT client's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_client_foreach_services(bt_gatt_client_h client, + bt_gatt_foreach_cb callback, void *user_data); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE * @brief Connect to a specific LE based service on a remote bluetooth dievice address, asynchronously. diff --git a/include/bluetooth_extension.h b/include/bluetooth_extension.h new file mode 100644 index 0000000..724a4f8 --- /dev/null +++ b/include/bluetooth_extension.h @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_NETWORK_BLUETOOTH_EXTENSION_H__ +#define __TIZEN_NETWORK_BLUETOOTH_EXTENSION_H__ + +#include "bluetooth_type.h" +#include "bluetooth_type_extension.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_extension.h + */ + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Opens a SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_close_sco() + * @see bt_ag_sco_state_changed_cb() + * @see bt_audio_connect() + */ +int bt_ag_open_sco(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Closes an opened SCO(Synchronous Connection Oriented link), asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The SCO must be opened with bt_ag_open_sco(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_open_sco() + * @see bt_ag_sco_state_changed_cb() + */ +int bt_ag_close_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. + * @since_tizen 2.3 + * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +int bt_ag_is_sco_opened(bool *opened); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + */ +int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_set_sco_state_changed_cb() + */ +int bt_ag_unset_sco_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_voice_recognition_state(bool state); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_EXTENTION_H__ + diff --git a/include/bluetooth_extention.h b/include/bluetooth_extention.h deleted file mode 100644 index d0eb0bc..0000000 --- a/include/bluetooth_extention.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __TIZEN_NETWORK_BLUETOOTH_EXTENSION_H__ -#define __TIZEN_NETWORK_BLUETOOTH_EXTENSION_H__ - -#include "bluetooth_type.h" -#include "bluetooth_type_extention.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * @file bluetooth_extension.h - */ - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Opens a SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_ALREADY_DONE Operation is already done - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio device must be connected with bt_audio_connect(). - * @post bt_ag_sco_state_changed_cb() will be invoked. - * @see bt_ag_close_sco() - * @see bt_ag_sco_state_changed_cb() - * @see bt_audio_connect() - */ -int bt_ag_open_sco(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Closes an opened SCO(Synchronous Connection Oriented link), asynchronously. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The SCO must be opened with bt_ag_open_sco(). - * @post bt_ag_sco_state_changed_cb() will be invoked. - * @see bt_ag_open_sco() - * @see bt_ag_sco_state_changed_cb() - */ -int bt_ag_close_sco(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. - * @since_tizen 2.3 - * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_ag_open_sco() - * @see bt_ag_close_sco() - */ -int bt_ag_is_sco_opened(bool *opened); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_sco_state_changed_cb() - * @see bt_ag_unset_sco_state_changed_cb() - */ -int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_sco_state_changed_cb() - * @see bt_ag_set_sco_state_changed_cb() - */ -int bt_ag_unset_sco_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Notifies the state of voice recognition. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio device must be connected with bt_audio_connect(). - * @see bt_audio_connect() - */ -int bt_ag_notify_voice_recognition_state(bool state); - -/** - * @} - */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif // __TIZEN_NETWORK_BLUETOOTH_EXTENSION_H__ - diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 583ead2..885a692 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -14,6 +14,7 @@ * limitations under the License. */ + #ifndef __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ #define __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ @@ -41,9 +42,9 @@ extern "C" * @details This function enables Bluetooth protocol stack and hardware. * * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_ALREADY_DONE Already enabled * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported @@ -74,7 +75,7 @@ int bt_adapter_enable(void); * @remarks You should disable Bluetooth adapter, which is helpful for saving power. * * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress @@ -103,7 +104,7 @@ int bt_adapter_disable(void); * @details This function does recovery logic, disables Bluetooth protocol stack and hardware, then enables after a few seconds. * * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress @@ -132,7 +133,7 @@ int bt_adapter_recover(void); * @details This function resets Bluetooth protocol and values. * * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied @@ -327,6 +328,81 @@ int bt_adapter_get_connectable(bool *connectable); */ int bt_adapter_set_connectable(bool connectable); +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the manufacturer data of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] data The manufacturer specific data of the Bluetooth device. + * @param[in] len The length of @a data.Maximaum length is 240 bytes. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked + * if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_manufacturer_data_changed_cb + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data(char *data, int len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked + * when the manufacturer data of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_manufacturer_data_changed_cb() + */ +int bt_adapter_unset_manufacturer_data_changed_cb(void); + + /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE @@ -477,7 +553,7 @@ int bt_adapter_le_unset_state_changed_cb(void); * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. * - * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_start_advertising_new() * @see bt_adapter_le_stop_advertising() */ int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type); @@ -509,13 +585,14 @@ int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e a * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. * - * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_start_advertising_new() * @see bt_adapter_le_stop_advertising() */ int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_e address_type); /** * @internal + * @deprecated Deprecated since 2.3.1 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief clear address from the whitelist for not accepting scanning request. * @since_tizen 2.3 @@ -537,14 +614,14 @@ int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_ * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. * - * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_start_advertising_new() * @see bt_adapter_le_stop_advertising() */ int bt_adapter_le_clear_white_list(void); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Sets the Privacy feature state of local Bluetooth adapter. * @since_tizen 2.3 * @privlevel platform @@ -567,238 +644,1665 @@ int bt_adapter_le_clear_white_list(void); int bt_adapter_le_enable_privacy(bool enable_privacy); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set Bluetooth LE scan mode * @since_tizen 2.3 * @privlevel platform * @privilege %http://tizen.org/privilege/bluetooth.admin - * - * @remarks A bond can be destroyed by bt_device_destroy_bond().\n - * The bonding request can be cancelled by bt_device_cancel_bonding(). - * - * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created - * @param[in] conn_type The connection type(LE or BREDR) to create bond with remote device + * @param[in] scan_mode The scan mode * * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_INVALID_PARAM Parameter is invalid * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @post This function invokes bt_device_bond_created_cb(). - * - * @see bt_adapter_start_device_discovery() - * @see bt_device_create_bond() - * @see bt_device_bond_created_cb() - * @see bt_device_cancel_bonding() - * @see bt_device_destroy_bond() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() */ -int bt_device_create_bond_by_type(const char *remote_address, - bt_device_connection_link_type_e conn_type); +int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Cancels service search process. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Creates scan filter to find only LE advertisement which has specific data. + * @since_tizen 2.4 + * + * @param[out] scan_filter The handle of scan filter * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The service search must be in progress by bt_device_start_service_search(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_device_start_service_search() - * @see bt_device_service_searched_cb() - * @see bt_device_set_service_searched_cb() - * @see bt_device_unset_service_searched_cb() + * @see bt_adapter_le_destroy_scan_filter() */ -int bt_device_cancel_service_search(void); +int bt_adapter_le_create_scan_filter(bt_scan_filter_h *scan_filter); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Starts listening on passed rfcomm socket. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroys scan filter. + * @since_tizen 2.4 * - * @param[in] socket_fd The file descriptor socket on which start to listen - * @param[in] max_pending_connections The number of pending connections + * @param[in] scan_filter The handle of scan filter * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post This function invokes bt_socket_connection_state_changed_cb(). + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_socket_create_rfcomm() - * @see bt_socket_set_connection_requested_cb() - * @see bt_socket_unset_connection_requested_cb() - * @see bt_socket_connection_requested_cb() + * @see bt_adapter_le_create_scan_filter() */ -int bt_socket_listen(int socket_fd, int max_pending_connections); +int bt_adapter_le_destroy_scan_filter(bt_scan_filter_h scan_filter); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Accepts a connection request. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device address to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] address The device address to filter advertisements + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The connection is requested by bt_socket_connection_requested_cb(). - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_requested_cb() - * @see bt_socket_listen() - * @see bt_socket_reject() -*/ -int bt_socket_accept(int requested_socket_fd); + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_device_address(bt_scan_filter_h scan_filter, const char *address); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Rejects a connection request. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device name to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] name The device name to filter advertisements + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The connection is requested by bt_socket_connection_requested_cb(). - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_requested_cb() - * @see bt_socket_listen() - * @see bt_socket_accept() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * */ -int bt_socket_reject(int socket_fd); +int bt_adapter_le_scan_filter_set_device_name(bt_scan_filter_h scan_filter, const char *name); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). - * @since_tizen 2.3 - * @details The popup appears when an OPP connection is requested from a remote device. - * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. - * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). - * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service - * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. - * @param[in] destination The destination path - * @param[in] push_requested_cb The callback called when a push is requested - * @param[in] user_data The user data to be passed to the callback function + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). * - * @see bt_opp_server_push_requested_cb() - * @see bt_opp_server_deinitialize() - * @see bt_opp_server_accept() - * @see bt_opp_server_reject() */ -int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); +int bt_adapter_le_scan_filter_set_service_uuid(bt_scan_filter_h scan_filter, const char *uuid); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Notifies the call event to the remote bluetooth device. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @remarks Before notifying #BT_AG_CALL_EVENT_ANSWERED or #BT_AG_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) - * if Bluetooth Hands-Free need SCO connection. - * @param[in] event The call event - * @param[in] call_id The call ID - * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. - * In other cases, this value can be NULL. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio device must be connected with bt_audio_connect(). - * @see bt_audio_connect() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * */ -int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number); +int bt_adapter_le_scan_filter_set_service_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); /** - * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Notifies the call list to the remote bluetooth device. - * @since_tizen 2.3 - * @privlevel platform - * @privilege %http://tizen.org/privilege/bluetooth.admin - * @param[in] list The call list + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio device must be connected with bt_audio_connect(). - * @see bt_audio_connect() + * @pre The Bluetooth service must be initialized with bt_initialize(). + * */ -int bt_ag_notify_call_list(bt_call_list_h list); +int bt_adapter_le_scan_filter_set_service_solicitation_uuid(bt_scan_filter_h scan_filter, const char *uuid); /** - * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service solicitation uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_solicitation_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service data. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers the scan filter to use for scanning + * @since_tizen 2.4 + * + * @remarks Several scan filters can be registered. And the specific advertisements, satisfy the one of scan filters, will be found. + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the scan filter to be registered + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters all scan filters to be registered + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_all_scan_filters(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising filter policy to use white list + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] filter_policy The filter policy of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_adapter_le_advertising_filter_policy_e filter_policy); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets a connection state + * @since_tizen 2.4 + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] link_type The link type to get a connection state + * @param[out] connected The connection state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + */ +int bt_device_get_connection_state(const char *remote_address, bt_device_connection_link_type_e link_type, bool *connected); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * @param[in] conn_type The connection type(LE or BREDR) to create bond with remote device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond_by_type(const char *remote_address, + bt_device_connection_link_type_e conn_type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels service search process. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The service search must be in progress by bt_device_start_service_search(). + * + * @see bt_device_start_service_search() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_cancel_service_search(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm_ex(). + * Application should call this API to receive a connection event when launched again by dbus. + * + * @param[in] uuid The UUID of service to provide + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Already registered + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm_ex() + * @see bt_socket_destroy_rfcomm_ex() + */ +int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm_ex(). + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] uuid The UUID (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm_ex(const char *uuid); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] uuid The UUID of service to provide + * @param[in] max_pending_connections The maximum number of pending connections + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. + * + * @param[in] socket_fd The file descriptor socket on which start to listen + * @param[in] max_pending_connections The number of pending connections + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_socket_create_rfcomm() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_unset_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_listen(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Accepts a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_reject() +*/ +int bt_socket_accept(int requested_socket_fd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rejects a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_accept() + */ +int bt_socket_reject(int socket_fd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). + * @since_tizen 2.3 + * @details The popup appears when an OPP connection is requested from a remote device. + * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service + * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] push_requested_cb The callback called when a push is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_push_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call event to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks Before notifying #BT_AG_CALL_EVENT_ANSWERED or #BT_AG_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) + * if Bluetooth Hands-Free need SCO connection. + * @param[in] event The call event + * @param[in] call_id The call ID + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * In other cases, this value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call list to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] list The call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_list(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_voice_recognition_state(bool state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_set_call_handling_event_cb() + */ +int bt_ag_unset_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +int bt_ag_set_multi_call_handling_event_cb(bt_ag_multi_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_set_multi_call_handling_event_cb() + */ +int bt_ag_unset_multi_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_set_dtmf_transmitted_cb() + */ +int bt_ag_unset_dtmf_transmitted_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the speaker gain to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details This function sends a signal to the remote device. This signal has the gain value. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. + * @param[in] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_get_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_notify_speaker_gain(int gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the current speaker gain of the remote device. + * @since_tizen 2.3 + * @details This function gets the value of speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[out] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_notify_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_get_speaker_gain(int *gain); + +/** + * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @brief Checks whether the remoted device enables NREC(Noise Reduction and Echo Canceling) or not. + * @since_tizen 2.3 + * @param[out] enabled The NREC status: (@c true = enabled, @c false = not enabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_nrec_enabled(bool *enabled); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @details This function let you know the change of the speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_speaker_gain_changed_cb() + */ +int bt_ag_unset_speaker_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_microphone_gain_changed_cb() + */ +int bt_ag_unset_microphone_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Creates a handle of call list. + * @since_tizen 2.3 + * @param[out] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_destroy() + */ +int bt_call_list_create(bt_call_list_h *list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Destroys the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_destroy(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Resets the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_reset(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Adds a call to the handle of call list. * @since_tizen 2.3 + * @param[in] list The handle of call list + * @param[in] call_id The call ID + * @param[in] state The state of audio gate call + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device is wbs (Wide Band Speech) mode or not. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[out] wbs_mode The wbs status: (@c true = wide band speech, @c false = narrow band speech) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_wbs_mode(bool *wbs_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the HF(Hands-Free) profile connected status for AG role. + * @since_tizen 2.4 + * @param[out] connected the connected status: (@c true = connected , @c false = not connected ) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_is_connected(bool *connected); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_A2DP_MODULE + * @brief Sets copy protection. streaming application that needs to have the copy protection for the streaming data, shall invoke this API. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] status - TRUE/FALSE + * @return 0 on success, otherwise negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED on failure + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_a2dp_set_content_protection(bool status); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the specification name from the UUID + * @since_tizen 2.4 + * + * @remarks @a name must be released with free() by you. + * + * @param[in] uuid The UUID + * @param[out] name The specification name which defined from www.bluetooth.org + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_get_uuid() + */ +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT handle + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of service, characteristic or descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_destroy(bt_gatt_h gatt_handle); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] permissions The permissions which a characteristic or descriptor's GATT handle has. + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_get_permissions(bt_gatt_h gatt_handle, int *permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] permissions The permissions to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_set_permissions(bt_gatt_h gatt_handle, int permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT service + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the service + * @param[in] type The type of the service + * @param[out] service The GATT handle of the created service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a characteristic to a specified service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] characteristic The characteristic's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + */ +int bt_gatt_service_add_characteristic(bt_gatt_h service, + bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a service to a specified service as included service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] included_service The service's GATT handle to be added as included service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + */ +int bt_gatt_service_add_included_service(bt_gatt_h service, + bt_gatt_h included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT server handle to which the specified service belongs + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[out] server The GATT server handle to which @a service belongs + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_register_service() + */ +int bt_gatt_service_get_server(bt_gatt_h service, bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the characteristic + * @param[in] permissions the permissions of the characteristic + * @param[in] properties The properties of the characteristic + * @param[in] Value The value(byte stream) of the characteristic + * @param[in] value_length The length of @a value + * @param[out] characteristic The GATT handle of the created characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_characteristic_create(const char *uuid, int permissions, + int properties, const char *value, int value_length, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a descriptor to a specified characteristic + * @since_tizen 2.4 + * + * @param[in] characteristic The GATT handle of the characteristic + * @param[in] descriptor The descriptor's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_characteristic_add_descriptor(bt_gatt_h characteristic, + bt_gatt_h descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the properties which a characteristic's GATT handle has + * @since_tizen 2.4 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] properties The properties to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_property_e + */ +int bt_gatt_characteristic_set_properties(bt_gatt_h characteristic, int properties); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic descriptor + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the descriptor + * @param[in] permissions The permissions of the descriptor + * @param[in] value The value(byte stream) associated with the descriptor + * @param[in] value_length The length of @a value + * @param[out] descriptor The GATT handle of the created characteristic descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_descriptor_create(const char *uuid, int permissions, + const char *value, int value_length, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Initializes the GATT Server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_deinitialize() + */ +int bt_gatt_server_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief DeInitializes the GATT server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_initialize() + */ +int bt_gatt_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT server's handle + * @since_tizen 2.4 + * + * @param[out] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_destroy() + */ +int bt_gatt_server_create(bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT server's handle + * @since_tizen 2.4 + * + * @remarks All registered services to GATT server are unregistered + * + * @param[in] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + */ +int bt_gatt_server_destroy(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a read request for a specified characteristic or descriptor is issued from a remote device(GATT client) + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + * @see bt_gatt_server_send_response() + */ +int bt_gatt_server_set_read_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_read_value_requested_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a value of a characteristic or descriptor has been changed by a remote device(GATT client)'s request + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_value_changed_cb() + */ +int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, + bt_gatt_server_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a specified service to the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be registered in @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_unregister_service() + */ +int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a specified service from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be unregistered from @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_SERVICE_NOT_FOUND Service not found + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters all services from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_all_services(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sends a response to the remote device as a result of a read request + * @since_tizen 2.4 + * + * @remarks Until this function is called, a read request is not finished. + * + * @param[in] request_id The identification of a read request + * @param[in] offset The offset from where a value is read + * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. + * @param[in] value_length Value Length + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + */ +int bt_gatt_server_send_response(int request_id, + int offset, char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Notifys a value change of the characteristic to the remote devices which enable a Client Characteristic Configuration Descriptor + * @since_tizen 2.4 + * + * @param[in] characteristic The characteristic which has a changed value + * @param[in] need_confirm If it is true, an indication is sent. If it is false, a notification is sent. + * @param[in] callback The function to be invoked on each remote device when a sending operation is done + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_notification_sent_cb() + */ +int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, + bt_gatt_server_notification_sent_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.4 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated server is destroyed by bt_gatt_server_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] server The GATT server's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_server_get_service(bt_gatt_server_h server, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT server + * @since_tizen 2.4 + * + * @param[in] server The GATT server's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_server_foreach_services(bt_gatt_server_h server, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_song_position_changed_cb() + */ +int bt_avrcp_set_song_position_changed_cb(bt_avrcp_song_position_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_song_position_changed_cb() + */ +int bt_avrcp_unset_song_position_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_set_play_status_changed_cb(bt_avrcp_play_status_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_unset_play_status_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_track_info_changed_cb() + */ +int bt_avrcp_set_track_info_changed_cb(bt_avrcp_track_info_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_track_info_changed_cb() + */ +int bt_avrcp_unset_track_info_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function * @return 0 on success, otherwise a negative error value. @@ -809,114 +2313,156 @@ int bt_ag_notify_call_list(bt_call_list_h list); * * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). * @see bt_audio_initialize() - * @see bt_ag_call_handling_event_cb() - * @see bt_ag_unset_call_handling_event_cb() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_control_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_control_deinitialize() */ -int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data); +int bt_avrcp_control_initialize(bt_avrcp_control_connection_state_changed_cb callback, void *user_data); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_call_handling_event_cb() - * @see bt_ag_set_call_handling_event_cb() + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() */ -int bt_ag_unset_call_handling_event_cb(void); +int bt_avrcp_control_deinitialize(void); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Connects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_multi_call_handling_event_cb() - * @see bt_ag_unset_multi_call_handling_event_cb() + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() */ -int bt_ag_set_multi_call_handling_event_cb(bt_ag_multi_call_handling_event_cb callback, void *user_data); +int bt_avrcp_control_connect(const char *remote_address); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Disconnects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_multi_call_handling_event_cb() - * @see bt_ag_set_multi_call_handling_event_cb() + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() */ -int bt_ag_unset_multi_call_handling_event_cb(void); +int bt_avrcp_control_disconnect(const char *remote_address); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Handle the Bluetooth AVRCP(Audio/Video Remote Control Profile) commands. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] AVRCP Commands Play, Pause, Next, Rewind. + * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_dtmf_transmitted_cb() - * @see bt_ag_unset_dtmf_transmitted_cb() + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() */ -int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data); +int bt_avrcp_control_send_player_command(bt_avrcp_player_command_e cmd); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the equalizer change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state To set the equalizer state ON/OFF + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_dtmf_transmitted_cb() - * @see bt_ag_set_dtmf_transmitted_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_unset_dtmf_transmitted_cb(void); +int bt_avrcp_control_set_equalizer_state(bt_avrcp_equalizer_state_e state); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Notifies the speaker gain to the remote device. - * @since_tizen 2.3 + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the the equalize state of the remote device. + * @since_tizen 2.4 * @privlevel platform * @privilege %http://tizen.org/privilege/bluetooth.admin - * @details This function sends a signal to the remote device. This signal has the gain value. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. - * @param[in] gain The gain of speaker (0 ~ 15) - * @return 0 on success, otherwise a negative error value. + * @param[in] equalizer To get the equalizer value ON/OFF + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter @@ -926,194 +2472,245 @@ int bt_ag_unset_dtmf_transmitted_cb(void); * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. - * @see bt_ag_get_speaker_gain() - * @see bt_ag_set_speaker_gain_changed_cb() - * @see bt_ag_unset_speaker_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_notify_speaker_gain(int gain); +int bt_avrcp_control_get_equalizer_state(bt_avrcp_equalizer_state_e *state); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Gets the current speaker gain of the remote device. - * @since_tizen 2.3 - * @details This function gets the value of speaker gain of the remote device. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * @param[out] gain The gain of speaker (0 ~ 15) - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the repeat change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. - * @see bt_ag_notify_speaker_gain() - * @see bt_ag_set_speaker_gain_changed_cb() - * @see bt_ag_unset_speaker_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_get_speaker_gain(int *gain); +int bt_avrcp_control_set_repeat_mode(bt_avrcp_repeat_mode_e mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Checks whether the remoted device enables NREC(Noise Reduction and Echo Canceling) or not. - * @since_tizen 2.3 - * @param[out] enabled The NREC status: (@c true = enabled, @c false = not enabled) - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the repeat state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. - * @see bt_audio_connect() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_is_nrec_enabled(bool *enabled); +int bt_avrcp_control_get_repeat_mode(bt_avrcp_repeat_mode_e *mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. - * @since_tizen 2.3 - * @details This function let you know the change of the speaker gain of the remote device. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the shuffle change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_unset_speaker_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); +int bt_avrcp_control_set_shuffle_mode(bt_avrcp_shuffle_mode_e mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the shuffle state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_set_speaker_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_unset_speaker_gain_changed_cb(void); +int bt_avrcp_control_get_shuffle_mode(bt_avrcp_shuffle_mode_e *mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. - * @since_tizen 2.3 - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the scan mode change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_unset_microphone_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); +int bt_avrcp_control_set_scan_mode(bt_avrcp_scan_mode_e mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. - * @since_tizen 2.3 - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the scan mode of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_set_microphone_gain_changed_cb() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_ag_unset_microphone_gain_changed_cb(void); +int bt_avrcp_control_get_scan_mode(bt_avrcp_scan_mode_e *mode); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE - * @brief Creates a handle of call list. - * @since_tizen 2.3 - * @param[out] list The handle of call list - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the song position vale of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the position value in milliseconds + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_call_list_destroy() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_call_list_create(bt_call_list_h *list); +int bt_avrcp_control_get_position(unsigned int *position); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE - * @brief Destroys the handle of call list. - * @since_tizen 2.3 - * @param[in] list The handle of call list - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the play status of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the play status PLAYING, STOPPED... + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_call_list_create() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_call_list_destroy(bt_call_list_h list); +int bt_avrcp_control_get_play_status(bt_avrcp_player_state_e *status); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE - * @brief Resets the handle of call list. - * @since_tizen 2.3 - * @param[in] list The handle of call list - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the metadata of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To get the metadata of track played in remote device. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_call_list_create() + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() */ -int bt_call_list_reset(bt_call_list_h list); +int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track); /** * @internal - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE - * @brief Adds a call to the handle of call list. - * @since_tizen 2.3 - * @param[in] list The handle of call list - * @param[in] call_id The call ID - * @param[in] state The state of audio gate call - * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. - * @return 0 on success, otherwise a negative error value. + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief to free the metadata staructure. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To free the memory of metadata structure. + * @return 0 on success, otherwise a negative error value. * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_NOT_SUPPORTED Not supported - * - * @see bt_call_list_create() + * @pre track should point to valid metadata address. + * @see bt_avrcp_control_get_track_info() + * @see bt_avrcp_target_initialize() */ -int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number); +int bt_avrcp_control_free_track_info(bt_avrcp_metadata_attributes_info_s *track); /** * @internal @@ -1290,7 +2887,6 @@ int bt_panu_unset_connection_state_changed_cb(void); * @retval #BT_ERROR_NOT_INITIALIZED Not initialized * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory * @retval #BT_ERROR_OPERATION_FAILED Operation failed * @retval #BT_ERROR_PERMISSION_DENIED Permission denied @@ -1358,4 +2954,3 @@ int bt_device_le_conn_update(const char *device_address, #endif /* __cplusplus */ #endif // __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ - diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h old mode 100755 new mode 100644 index ebff30f..b600547 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -27,6 +27,7 @@ #include #include "bluetooth.h" +#include "bluetooth_internal.h" #ifdef __cplusplus extern "C" { @@ -54,6 +55,7 @@ typedef enum BT_EVENT_VISIBILITY_DURATION_CHANGED, /**< Adapter visibility duration is changed */ BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, /**< Device discovery state is changed */ BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, /**< LE Device discovery state is changed */ + BT_EVENT_LE_SCAN_RESULT_UPDATED, /**< LE Scan result is updated */ BT_EVENT_BOND_CREATED, /**< A bond is created */ BT_EVENT_BOND_DESTROYED, /**< A bond is destroyed */ BT_EVENT_AUTHORIZATION_CHANGED, /**< Authorization is changed */ @@ -86,14 +88,26 @@ typedef enum BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, /**< AVRCP repeat mode change callback */ BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, /**< AVRCP equalizer mode change callback */ BT_EVENT_AVRCP_SCAN_MODE_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_PLAY_STATUS_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_SONG_POSITION_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_TRACK_INFO_CHANGED, /**< AVRCP scan mode change callback */ BT_EVENT_HID_CONNECTION_STATUS, /**< HID connection status callback */ + BT_EVENT_HID_DEVICE_CONNECTION_STATUS, /**< HID Device connection status callback */ + BT_EVENT_HID_DEVICE_DATA_RECEIVED, /**< HID Device Data received callback */ BT_EVENT_DEVICE_CONNECTION_STATUS, /**< Device connection status callback */ BT_EVENT_GATT_CONNECTION_STATUS, /** < GATT connection status callback */ - BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED, /**< GATT characteristic discovered callback */ - BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED, /**< GATT characteristic descriptor discovered callback */ - BT_EVENT_GATT_VALUE_CHANGED, /**< GATT characteristic value changed callback */ - BT_EVENT_GATT_READ_CHARACTERISTIC, /**< GATT characteristic value read callback */ - BT_EVENT_GATT_WRITE_CHARACTERISTIC, /**< GATT characteristic value write callback */ + BT_EVENT_GATT_CLIENT_SERVICE_DISCOVERED, /** GATT services discovered callback */ + BT_EVENT_GATT_CLIENT_VALUE_CHANGED, /**< GATT characteristic value changed callback */ + BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC, /**< GATT characteristic value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC, /**< GATT characteristic value write callback */ + BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, /**< GATT descriptor value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, /**< GATT descriptor value write callback */ + BT_EVENT_GATT_SERVER_READ_REQUESTED, /**< GATT Characteristic/Descriptor Read Requested callback*/ + BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, /**< GATT characteristic discovered callback */ + BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, /**< GATT characteristic descriptor discovered callback */ + BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, /**< GATT characteristic value changed callback */ + BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, /**< GATT characteristic value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, /**< GATT characteristic value write callback */ BT_EVENT_ADVERTISING_STATE_CHANGED, /**< Advertising state changed callback */ BT_EVENT_MANUFACTURER_DATA_CHANGED, /**< Manufacturer data changed callback */ BT_EVENT_CONNECTABLE_CHANGED_EVENT, /**< Adapter connectable changed callback */ @@ -112,39 +126,203 @@ typedef enum BT_EVENT_HF_CALL_HANDLING_EVENT, /**< Audio - HF call event callback */ BT_EVENT_HF_VENDOR_DEP_CMD_EVENT, /**< Audio - HF Vendor Command callback */ BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, /**< Audio - HF 3-way call event callback */ + BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT, /**< Audio - HF call status updated callback */ #endif + BT_EVENT_MAX } bt_event_e; +typedef enum { + BT_GATT_ROLE_SERVER = 0x01, + BT_GATT_ROLE_CLIENT = 0x02, +} bt_gatt_role_e; + +#ifdef TIZEN_WEARABLE +/** + * @internal + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE = 0x00, /**< Connectable undirected advertising (ADV_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_HIGH = 0x01, /* @Deprecated since Tizen 2.4 */ + BT_ADAPTER_LE_ADVERTISING_SCANNABLE = 0x02, /**< Scannable undirected advertising (ADV_SCAN_IND) */ + BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE = 0x03, /**< Non connectable undirected advertising (ADV_NONCOND_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_LOW = 0x04, /* @Deprecated since Tizen 2.4 */ +} bt_adapter_le_advertising_type_e; + +/** + * @internal + */ +typedef enum { + BT_ADAPTER_LE_PACKET_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x02, /** #include #include +#include #ifdef TIZEN_WEARABLE #include #endif #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" +#ifdef TIZEN_LE_DISABLE +#define BT_CHECK_LE_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_LE_SUPPORT() +#endif + +static GSList *advertiser_list = NULL; + int bt_adapter_enable(void) { - int error_code; + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); #ifdef TIZEN_WEARABLE static const char* PRIVILEGE_ID_BLUETOOTH_ADMIN = "http://tizen.org/privilege/bluetooth.admin"; @@ -54,8 +71,9 @@ int bt_adapter_enable(void) int bt_adapter_disable(void) { - int error_code; + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_disable_adapter()); if (error_code != BT_ERROR_NONE) { @@ -68,6 +86,7 @@ int bt_adapter_recover(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_recover_adapter()); if (error_code != BT_ERROR_NONE) { @@ -78,8 +97,9 @@ int bt_adapter_recover(void) int bt_adapter_reset(void) { - int error_code; + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_reset_adapter()); if (error_code != BT_ERROR_NONE) { @@ -90,6 +110,7 @@ int bt_adapter_reset(void) int bt_adapter_get_state(bt_adapter_state_e *adapter_state) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(adapter_state); @@ -101,6 +122,7 @@ int bt_adapter_le_enable(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_enable_adapter_le()); if (error_code != BT_ERROR_NONE) { @@ -113,7 +135,9 @@ int bt_adapter_le_disable(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_disable_adapter_le()); if (error_code != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); @@ -123,6 +147,8 @@ int bt_adapter_le_disable(void) int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state) { + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(adapter_le_state); *adapter_le_state = bluetooth_check_adapter_le(); @@ -134,6 +160,7 @@ int bt_adapter_get_address(char **address) bluetooth_device_address_t loc_address = { {0} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(address); @@ -157,6 +184,7 @@ int bt_adapter_get_version(char **version) int ret = BT_ERROR_NONE; bluetooth_version_t loc_ver = { { 0 } }; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(version); @@ -193,6 +221,7 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers char *local_stack_version = NULL; char *local_profiles = NULL; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(chipset); BT_CHECK_INPUT_PARAMETER(firmware); @@ -220,8 +249,8 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers fseek(fp, 0, SEEK_END); lsize = ftell(fp); if (lsize < 0) { + BT_ERR("ftell() error(0x%x)", lsize); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } buf = (char *)malloc(sizeof(char) * (lsize + 1)); @@ -239,15 +268,15 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers info_start = strstr(buf, "bluetooth"); if (info_start == NULL) { + BT_ERR("strstr() error(0x%x)", info_start); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } info_start += 10; info_end = strstr(buf, "hcd"); if (info_end == NULL) { + BT_ERR("strstr() error(0x%x)", info_end); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } info_size = info_end - info_start - 1; @@ -264,8 +293,8 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers info_end = strchr(buf, '_'); if (info_end == NULL) { + BT_ERR("strchr() error(0x%x)", info_end); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } info_size = info_end - info_start; @@ -287,16 +316,16 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers } if ((fp = fopen(BT_ADAPTER_STACK_INFO_FILE_PATH, "r")) == NULL) { + BT_ERR("fopen() error"); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } fseek(fp, 0, SEEK_END); lsize = ftell(fp); if (lsize < 0) { + BT_ERR("ftell() error(0x%x)", lsize); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } buf = (char *)malloc(sizeof(char) * (lsize + 1)); @@ -309,14 +338,17 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers result = fread(buf, 1, lsize, fp); buf[lsize] = '\0'; - if (result != lsize) - BT_ERR("fread() error"); + if (result != lsize) { + BT_ERR("fread() error(0x%x)", result); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } info_start = buf; info_end = strchr(buf, ','); if (info_end == NULL) { + BT_ERR("strchr() error(0x%x)", info_end); ret = BT_ERROR_OPERATION_FAILED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); goto ERROR; } info_size = info_end - info_start; @@ -362,8 +394,6 @@ ERROR: free(local_firmware); if (local_stack_version) free(local_stack_version); - if (local_profiles) - free(local_profiles); if (buf) free(buf); if (fp) @@ -373,9 +403,10 @@ ERROR: int bt_adapter_get_name(char **name) { - int ret; + int ret = BT_ERROR_NONE; bluetooth_device_name_t loc_name = { {0} }; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(name); @@ -397,8 +428,9 @@ int bt_adapter_get_name(char **name) int bt_adapter_set_name(const char *name) { bluetooth_device_name_t loc_name = { {0} }; - int ret; + int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(name); @@ -416,8 +448,9 @@ int bt_adapter_set_name(const char *name) int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration) { bluetooth_discoverable_mode_t discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; - int ret; + int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(mode); @@ -449,6 +482,7 @@ int bt_adapter_set_visibility(bt_adapter_visibility_mode_e visibility_mode, int bluetooth_discoverable_mode_t discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); switch (visibility_mode) { case BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE: @@ -479,6 +513,7 @@ int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb call { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_CONNECTABLE_CHANGED_EVENT, callback, user_data); @@ -491,6 +526,7 @@ int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb call int bt_adapter_unset_connectable_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_CONNECTABLE_CHANGED_EVENT); return BT_ERROR_NONE; @@ -501,6 +537,7 @@ int bt_adapter_get_connectable(bool *connectable) gboolean is_connectable = FALSE; int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connectable); @@ -519,6 +556,7 @@ int bt_adapter_set_connectable(bool connectable) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_set_connectable(connectable)); @@ -537,6 +575,7 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb, voi int ret = BT_ERROR_NONE; int i = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(foreach_cb); @@ -573,10 +612,8 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb, voi } } - if (dev_list != NULL) { - g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL); - g_ptr_array_free(dev_list, TRUE); - } + g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL); + g_ptr_array_free(dev_list, TRUE); return ret; } @@ -587,6 +624,7 @@ int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info bluetooth_device_address_t addr_hex = { {0,} }; bluetooth_device_info_t *info; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -616,6 +654,7 @@ int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info int bt_adapter_free_device_info(bt_device_info_s *device_info) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_info); @@ -629,6 +668,7 @@ int bt_adapter_is_service_used(const char *service_uuid, bool *used) int ret = BT_ERROR_NONE; gboolean is_used = FALSE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service_uuid); BT_CHECK_INPUT_PARAMETER(used); @@ -653,6 +693,7 @@ int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void * BT_DBG(""); int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_STATE_CHANGED, callback, user_data); @@ -665,6 +706,7 @@ int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void * int bt_adapter_le_set_state_changed_cb(bt_adapter_le_state_changed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); @@ -677,6 +719,7 @@ int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *us { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_NAME_CHANGED, callback, user_data); @@ -691,6 +734,7 @@ int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_VISIBILITY_MODE_CHANGED, callback, user_data); @@ -705,6 +749,7 @@ int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, callback, user_data); @@ -717,6 +762,7 @@ int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data) { + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); @@ -727,6 +773,7 @@ int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_dis int bt_adapter_unset_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_STATE_CHANGED); return BT_ERROR_NONE; @@ -734,6 +781,7 @@ int bt_adapter_unset_state_changed_cb(void) int bt_adapter_le_unset_state_changed_cb(void) { + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_LE_STATE_CHANGED); _bt_le_adapter_deinit(); @@ -742,6 +790,7 @@ int bt_adapter_le_unset_state_changed_cb(void) int bt_adapter_unset_name_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_NAME_CHANGED); return BT_ERROR_NONE; @@ -749,6 +798,7 @@ int bt_adapter_unset_name_changed_cb(void) int bt_adapter_unset_visibility_mode_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_VISIBILITY_MODE_CHANGED); return BT_ERROR_NONE; @@ -758,6 +808,7 @@ int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_VISIBILITY_DURATION_CHANGED, callback, user_data); @@ -770,6 +821,7 @@ int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration int bt_adapter_unset_visibility_duration_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_VISIBILITY_DURATION_CHANGED); return BT_ERROR_NONE; @@ -777,6 +829,7 @@ int bt_adapter_unset_visibility_duration_changed_cb(void) int bt_adapter_unset_device_discovery_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED); return BT_ERROR_NONE; @@ -784,6 +837,7 @@ int bt_adapter_unset_device_discovery_state_changed_cb(void) int bt_adapter_le_unset_device_discovery_state_changed_cb(void) { + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED); _bt_le_adapter_deinit(); @@ -792,8 +846,9 @@ int bt_adapter_le_unset_device_discovery_state_changed_cb(void) int bt_adapter_start_device_discovery(void) { - int error_code; + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_start_discovery(0, 0, BLUETOOTH_DEVICE_MAJOR_MASK_MISC)); if (error_code != BT_ERROR_NONE) { @@ -804,8 +859,9 @@ int bt_adapter_start_device_discovery(void) int bt_adapter_stop_device_discovery(void) { - int error_code; + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_cancel_discovery()); if (error_code != BT_ERROR_NONE) { @@ -818,6 +874,7 @@ int bt_adapter_is_discovering(bool *is_discovering) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(is_discovering); @@ -836,6 +893,7 @@ int bt_adapter_le_start_device_discovery(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_start_le_discovery()); if (error_code != BT_ERROR_NONE) { @@ -848,6 +906,7 @@ int bt_adapter_le_stop_device_discovery(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_stop_le_discovery()); if (error_code != BT_ERROR_NONE) { @@ -860,6 +919,7 @@ int bt_adapter_le_is_discovering(bool *is_discovering) { int ret = 0; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(is_discovering); @@ -879,6 +939,7 @@ int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomiz { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(hash); BT_CHECK_INPUT_PARAMETER(randomizer); @@ -908,6 +969,7 @@ int bt_adapter_set_remote_oob_data(const char *remote_address, bluetooth_device_address_t addr_hex = { {0,} }; bt_oob_data_t oob_data = { {0},}; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -932,6 +994,7 @@ int bt_adapter_remove_remote_oob_data(const char *remote_address) int ret = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -944,11 +1007,65 @@ int bt_adapter_remove_remote_oob_data(const char *remote_address) return ret; } +int bt_adapter_set_manufacturer_data(char *data, int len) +{ + + int ret; + bluetooth_manufacturer_data_t m_data = { 0 }; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(data); + + if (len + 2 > sizeof(m_data.data) || len < 0) + return BT_ERROR_INVALID_PARAMETER; + + m_data.data_len = len; + m_data.data[0] = len + 1; + m_data.data[1] = 0xFF; + + memcpy(&m_data.data[2], data, len); + + ret = _bt_get_error_code(bluetooth_set_manufacturer_data(&m_data)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_MANUFACTURER_DATA_CHANGED, + callback, user_data); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_unset_manufacturer_data_changed_cb(void) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_MANUFACTURER_DATA_CHANGED); + return BT_ERROR_NONE; +} + int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type) { int error_code = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(address); _bt_convert_address_to_hex(&addr_hex, address); @@ -966,6 +1083,7 @@ int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_ int error_code = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(address); _bt_convert_address_to_hex(&addr_hex, address); @@ -982,6 +1100,7 @@ int bt_adapter_le_clear_white_list(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_clear_white_list()); @@ -992,54 +1111,79 @@ int bt_adapter_le_clear_white_list(void) return error_code; } -int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser) +int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode) { int ret = BT_ERROR_NONE; + bluetooth_le_scan_params_t scan_params; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); - BT_CHECK_INPUT_PARAMETER(advertiser); - *advertiser = (bt_advertiser_h)g_malloc0(sizeof(bt_advertiser_s)); - if (*advertiser == NULL) { - ret = BT_ERROR_OUT_OF_MEMORY; + scan_params.type = BT_ADAPTER_LE_ACTIVE_SCAN; + + if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_BALANCED) { + scan_params.interval = 5000; + scan_params.window = 2000; + } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_LATENCY) { + scan_params.interval = 5000; + scan_params.window = 5000; + } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY) { + scan_params.interval = 5000; + scan_params.window = 500; + } else + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_set_scan_parameters(&scan_params)); + if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } - return ret; } + +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser) +{ + bt_advertiser_s *__adv = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + __adv = (bt_advertiser_s*)g_malloc0(sizeof(bt_advertiser_s)); + if (__adv == NULL) { + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + __adv->handle = (int)__adv; + + *advertiser = (bt_advertiser_h)__adv; + + advertiser_list = g_slist_append(advertiser_list, __adv); + + return BT_ERROR_NONE; +} + int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser) { int ret = BT_ERROR_NONE; int error_code; bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); _bt_unset_cb(BT_EVENT_ADVERTISING_STATE_CHANGED); -#if 0 - if (__adv->handle) { - error_code = bluetooth_stop_advertising(__adv->handle); - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); - __adv->handle = 0; - } -#else error_code = bluetooth_set_advertising(FALSE); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); -#endif /* Free advertising data */ - if (__adv->adv_data) - free(__adv->adv_data); - if (__adv->scan_rsp_data) - free(__adv->scan_rsp_data); - free(__adv); + g_free(__adv->adv_data); + g_free(__adv->scan_rsp_data); + g_free(__adv); return BT_ERROR_NONE; } @@ -1099,33 +1243,47 @@ int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, void *data, unsigned int data_size) { - int ret = BT_ERROR_NONE; bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; char **p; unsigned int *len; + unsigned int *system_data_len; char *new_p; + bt_adapter_le_advertising_data_type_e adv_type; + int adv_flag_len = 0; + int adv_ext_len = 0; + + adv_type = (bt_adapter_le_advertising_data_type_e)data_type; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); + if ((data == NULL || data_size == 0) && + (adv_type != BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME && + adv_type != BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL)) { + BT_ERR("empty data for packet type %d", pkt_type); + return BT_ERROR_INVALID_PARAMETER; + } + BT_CHECK_INPUT_PARAMETER(advertiser); - switch (pkt_type) { - case BT_ADAPTER_LE_PACKET_ADVERTISING: + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { p = &__adv->adv_data; len = &__adv->adv_data_len; - break; - - case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: + system_data_len = &__adv->adv_system_data_len; + adv_flag_len = 3; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { p = &__adv->scan_rsp_data; len = &__adv->scan_rsp_data_len; - break; - - default: - BT_ERR("Unknown LE packet type : %d", pkt_type); + system_data_len = &__adv->scan_rsp_system_data_len; + } else return BT_ERROR_INVALID_PARAMETER; - } + + if (adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) + adv_ext_len = *system_data_len + 1; /* 2 bytes are required for Length and AD Type */ - if (*len + data_size + 2 > 31) { + if (adv_flag_len + *len + adv_ext_len + data_size + 2 > 31) { + BT_ERR("Quota exceeded"); return BT_ERROR_QUOTA_EXCEEDED; } @@ -1138,13 +1296,18 @@ int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, } new_p[*len] = data_size + 1; - new_p[*len + 1] = data_type; - memcpy(new_p + (*len + 2), data, data_size); + new_p[*len + 1] = adv_type; + if ((data != NULL) && (data_size != 0)) + memcpy(new_p + (*len + 2), data, data_size); *p = new_p; *len += data_size + 2; - return ret; + if (adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) + *system_data_len += 1; + + return BT_ERROR_NONE; } int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, @@ -1154,9 +1317,14 @@ int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; char **p; unsigned int *len; + unsigned int *system_data_len; char *new_p = NULL; unsigned int new_len = 0; + bt_adapter_le_advertising_data_type_e adv_type; + + adv_type = (bt_adapter_le_advertising_data_type_e)data_type; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); @@ -1164,11 +1332,13 @@ int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, case BT_ADAPTER_LE_PACKET_ADVERTISING: p = &__adv->adv_data; len = &__adv->adv_data_len; + system_data_len = &__adv->adv_system_data_len; break; case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: p = &__adv->scan_rsp_data; len = &__adv->scan_rsp_data_len; + system_data_len = &__adv->scan_rsp_system_data_len; break; default: @@ -1176,7 +1346,7 @@ int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, return BT_ERROR_INVALID_PARAMETER; } - ret = __bt_remove_ad_data_by_type(*p, *len, data_type, &new_p, &new_len); + ret = __bt_remove_ad_data_by_type(*p, *len, adv_type, &new_p, &new_len); if (ret != BT_ERROR_NONE) { return ret; } @@ -1185,134 +1355,720 @@ int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, *p = new_p; *len = new_len; + if (adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) + *system_data_len -= 1; + return ret; } -int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, - bt_adapter_le_packet_type_e pkt_type) +static int __bt_convert_string_to_uuid(const char *string, char **uuid, int *bit) { - int ret = BT_ERROR_NONE; - bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; - char **p; - unsigned int *len; + char *data; + + if (strlen(string) == 4) { // 16 bit uuid + unsigned short val; + char *stop; + data = g_malloc0(sizeof(char) * 2); + val = strtol(string, &stop, 16); + val = htons(val); + memcpy(data, &val, 2); + *uuid = data; + *bit = 16; + } else if (strlen(string) == 36) { // 128 bit uuid + if (string[8] != '-' || string[13] != '-' || + string[18] != '-' || string[23] != '-') { + BT_ERR("Invalid UUID"); + return BT_ERROR_INVALID_PARAMETER; + } - BT_CHECK_INIT_STATUS(); - BT_CHECK_INPUT_PARAMETER(advertiser); + int ret; + unsigned int val0, val4; + unsigned short val1, val2, val3, val5; + data = g_malloc0(sizeof(char) * 16); + /* Fix : NULL_RETURNS */ + if (data == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + ret = sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", + &val0, &val1, &val2, &val3, &val4, &val5); + if (ret != 6) + return BT_ERROR_OPERATION_FAILED; - switch (pkt_type) { - case BT_ADAPTER_LE_PACKET_ADVERTISING: - p = &__adv->adv_data; - len = &__adv->adv_data_len; - break; + val0 = htonl(val0); + val1 = htons(val1); + val2 = htons(val2); + val3 = htons(val3); + val4 = htonl(val4); + val5 = htons(val5); + + memcpy(data, &val0, 4); + memcpy(data + 4, &val1, 2); + memcpy(data + 6, &val2, 2); + memcpy(data + 8, &val3, 2); + memcpy(data + 10, &val4, 4); + memcpy(data + 14, &val5, 2); + + *uuid = data; + *bit = 128; + } else { + BT_ERR("Invalid UUID"); + return BT_ERROR_INVALID_PARAMETER; + } - case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: - p = &__adv->scan_rsp_data; - len = &__adv->scan_rsp_data_len; - break; + return BT_ERROR_NONE; +} - default: - BT_ERR("Unknown LE packet type : %d", pkt_type); +static int __bt_convert_byte_ordering(char *data, int data_len, char **converted_data) +{ + char *swp; + int i, j; + + /* Convert to little endian */ + swp = g_malloc0(data_len); + /* Fix : NULL_RETURNS */ + if (swp == NULL) + return BT_ERROR_OUT_OF_MEMORY; + for (i = 0, j = data_len - 1; i < data_len; i++, j--) + swp[i] = data[j]; + + *converted_data = swp; + + return BT_ERROR_NONE; +} + +static int __bt_find_adv_data_type(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_advertising_data_type_e data_type, + char **data_ptr, int *data_len) +{ + int type; + int len; + int i; + char *adv_data = NULL; + int adv_len = 0; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = __adv->adv_data; + adv_len = __adv->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = __adv->scan_rsp_data; + adv_len = __adv->scan_rsp_data_len; + } else return BT_ERROR_INVALID_PARAMETER; - } - if (*p) { - free(*p); - *p = NULL; + if (!adv_data) + return BT_ERROR_OPERATION_FAILED; + + for (i = 0; i adv_data; + adv_len = __adv->adv_data_len; + system_data_len = __adv->adv_system_data_len; + adv_flag_len = 3; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = __adv->scan_rsp_data; + adv_len = __adv->scan_rsp_data_len; + system_data_len = __adv->scan_rsp_system_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; -#if 0 - error_code = bluetooth_start_advertising(__adv, cb, user_data); - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + if (!adv_data) + return BT_ERROR_OPERATION_FAILED; + + dest_type = data_ptr[1]; + + if (data_type != dest_type) { + BT_ERR("Invalid data type"); + return BT_ERROR_INVALID_PARAMETER; } -#endif - if (__adv->adv_data_len > 0 && __adv->adv_data) { - memcpy(adv.data, __adv->adv_data, __adv->adv_data_len); - error_code = bluetooth_set_advertising_data(&adv, __adv->adv_data_len); - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); - return ret; - } + if (adv_flag_len + adv_len + system_data_len + new_data_len > 31) { + BT_ERR("Quota exceeded"); + return BT_ERROR_QUOTA_EXCEEDED; } - if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { - memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len); - error_code = bluetooth_set_scan_response_data(&resp, __adv->scan_rsp_data_len); - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); - return ret; + new_adv = g_malloc0(adv_len + new_data_len); + if (!new_adv) + return BT_ERROR_OUT_OF_MEMORY; + + for (i = 0; i < adv_len; i++) { + len = adv_data[i]; + type = adv_data[i + 1]; + + if (type == dest_type) { + int rest_data_len; + + memcpy(new_adv + i, &adv_data[i], len + 1); + memcpy(new_adv + i + len + 1, new_data, new_data_len); + new_adv[i] += new_data_len; + + rest_data_len = adv_len - (i + len + 1); + if (rest_data_len > 0) + memcpy(new_adv + i + len + 1 + new_data_len, + &adv_data[i + len + 1], rest_data_len); + + break; + } else { + memcpy(new_adv + i, &adv_data[i], len + 1); + i = i + len; } } - if (adv_params == NULL) { - error_code = bluetooth_set_advertising(TRUE); - } else { - error_code = bluetooth_set_custom_advertising(TRUE, - (bluetooth_advertising_params_t *)adv_params); + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + g_free(__adv->adv_data); + __adv->adv_data = new_adv; + __adv->adv_data_len += new_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + g_free(__adv->scan_rsp_data); + __adv->scan_rsp_data = new_adv; + __adv->scan_rsp_data_len += new_data_len; } - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return BT_ERROR_NONE; +} + +int bt_adapter_le_add_advertising_service_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid) +{ + int ret = BT_ERROR_NONE; + bt_adapter_le_advertising_data_type_e data_type = 0; + int byte_len = 0; + int uuid_bit = 0; + char *uuid_ptr = NULL; + char *data_ptr = NULL; + char *converted_uuid = NULL; + int data_len = 0; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(uuid); + + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) return ret; + + if (uuid_bit == 16) { + byte_len = 2; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS; + } else if (uuid_bit == 128) { + byte_len = 16; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS; } - _bt_set_cb(BT_EVENT_ADVERTISING_STATE_CHANGED, cb, user_data); + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + __bt_find_adv_data_type(advertiser, pkt_type, data_type, &data_ptr, &data_len); + if (data_ptr) { + ret = __bt_append_adv_type_data(advertiser, pkt_type, converted_uuid, byte_len, data_type, data_ptr, data_len); + } else { + ret = bt_adapter_le_add_advertising_data(advertiser, pkt_type, data_type, converted_uuid, byte_len); + } + g_free(converted_uuid); return ret; } -int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser) +int bt_adapter_le_add_advertising_service_solicitation_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid) { int ret = BT_ERROR_NONE; -// bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; - + bt_adapter_le_advertising_data_type_e data_type = 0; + int byte_len = 0; + int uuid_bit = 0; + char *uuid_ptr = NULL; + char *data_ptr = NULL; + char *converted_uuid = NULL; + int data_len = 0; + + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(uuid); -#if 0 - error_code = bluetooth_stop_advertising(__adv, cb, user_data); - ret = _bt_get_error_code(error_code); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) + return ret; + + if (uuid_bit == 16) { + byte_len = 2; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS; + } else if (uuid_bit == 128) { + byte_len = 16; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS; } -#endif - ret = _bt_get_error_code(bluetooth_set_advertising(FALSE)); - if (ret != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + __bt_find_adv_data_type(advertiser, pkt_type, data_type, &data_ptr, &data_len); + if (data_ptr) { + ret = __bt_append_adv_type_data(advertiser, pkt_type, converted_uuid, byte_len, data_type, data_ptr, data_len); + } else { + ret = bt_adapter_le_add_advertising_data(advertiser, pkt_type, data_type, converted_uuid, byte_len); } + g_free(converted_uuid); return ret; } -int bt_adapter_le_enable_privacy(bool enable_privacy) +int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid, + const char *service_data, int service_data_len) { - int error_code = BT_ERROR_NONE; - + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + char *adv_data = NULL; + int uuid_bit; + char *uuid_ptr; + int byte_len; + char *converted_uuid; + + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(service_data); - error_code = _bt_get_error_code(bluetooth_enable_le_privacy(enable_privacy)); + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) + return ret; + + if (uuid_bit == 16) { + byte_len = 2; + } else if (uuid_bit == 128) { + BT_ERR("128 bit UUID is not supported"); + g_free(uuid_ptr); + return BT_ERROR_INVALID_PARAMETER; + } + + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + adv_data = g_malloc0(sizeof(char) * (service_data_len + 2)); + if (!adv_data) { + g_free(converted_uuid); + return BT_ERROR_OUT_OF_MEMORY; + } + + memcpy(adv_data, converted_uuid, 2); + memcpy(adv_data + 2, service_data, service_data_len); + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA, + adv_data, service_data_len + 2); + + g_free(adv_data); + g_free(converted_uuid); + + return ret; +} + +int bt_adapter_le_set_advertising_appearance(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int appearance) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + __bt_find_adv_data_type(advertiser, pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE, &appearance, 2); + + return ret; +} + +int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int manufacturer_id, + const char *manufacturer_data, int manufacturer_data_len) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + char *adv_data = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(manufacturer_data); + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + adv_data = g_malloc0(sizeof(char) * (manufacturer_data_len + 2)); + if (!adv_data) + return BT_ERROR_OUT_OF_MEMORY; + + adv_data[0] = manufacturer_id & 0xffffffff; + adv_data[1] = (manufacturer_id & 0xff00) >> 8; + memcpy(adv_data + 2, manufacturer_data, manufacturer_data_len); + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA, + adv_data, manufacturer_data_len + 2); + + g_free(adv_data); + + return ret; +} + +int bt_adapter_le_set_advertising_device_name(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_name) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (!include_name) { + ret = bt_adapter_le_remove_advertising_data(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME); + return ret; + } + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME, + NULL, 0); + + return ret; +} + +int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_tx_power) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (!include_tx_power) { + ret = bt_adapter_le_remove_advertising_data(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL); + return ret; + } + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL, + NULL, 0); + + return ret; +} + +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type) +{ + int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + char **p; + unsigned int *len; + unsigned int *system_data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + switch (pkt_type) { + case BT_ADAPTER_LE_PACKET_ADVERTISING: + p = &__adv->adv_data; + len = &__adv->adv_data_len; + system_data_len = &__adv->adv_system_data_len; + break; + + case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: + p = &__adv->scan_rsp_data; + len = &__adv->scan_rsp_data_len; + system_data_len = &__adv->scan_rsp_system_data_len; + break; + + default: + BT_ERR("Unknown LE packet type : %d", pkt_type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*p) { + free(*p); + *p = NULL; + } + *len = 0; + *system_data_len = 0; + + return ret; +} + +int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, + bt_adapter_le_advertising_params_s *adv_params, + bt_adapter_le_advertising_state_changed_cb cb, void *user_data) +{ + int ret = BT_ERROR_NONE; + int error_code; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + bluetooth_advertising_data_t adv = { {0} }; + bluetooth_scan_resp_data_t resp = { {0} }; + bluetooth_advertising_params_t param; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (__adv->adv_data_len > 0 && __adv->adv_data) { + memcpy(adv.data, __adv->adv_data, __adv->adv_data_len); + error_code = bluetooth_set_advertising_data(&adv, __adv->adv_data_len); + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { + memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len); + error_code = bluetooth_set_scan_response_data(&resp, __adv->scan_rsp_data_len); + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (adv_params == NULL) { + error_code = bluetooth_set_advertising(TRUE); + } else { + param.interval_min = adv_params->interval_min; + param.interval_max = adv_params->interval_max; + param.filter_policy = BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT; + param.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + error_code = bluetooth_set_custom_advertising(TRUE, ¶m); + } + + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + _bt_set_cb(BT_EVENT_ADVERTISING_STATE_CHANGED, cb, user_data); + + return ret; +} + +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + ret = _bt_get_error_code(bluetooth_set_advertising(FALSE)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, + bt_adapter_le_advertising_state_changed_cb cb, void *user_data) +{ + int ret = BT_ERROR_NONE; + int error_code; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + bluetooth_advertising_data_t adv = { {0} }; + bluetooth_scan_resp_data_t resp = { {0} }; + bluetooth_advertising_params_t param; + float interval = 500; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (__adv->adv_data_len > 0 && __adv->adv_data) { + memcpy(adv.data, __adv->adv_data, __adv->adv_data_len); + error_code = bluetooth_set_advertising_data(&adv, __adv->adv_data_len); + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { + memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len); + error_code = bluetooth_set_scan_response_data(&resp, __adv->scan_rsp_data_len); + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED) + interval = 500; + else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY) + interval = 150; + else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY) + interval = 1000; + + param.interval_min = interval; + param.interval_max = interval; + param.filter_policy = __adv->adv_params.filter_policy; + param.type = __adv->adv_params.type; + error_code = bluetooth_set_custom_advertising(TRUE, ¶m); + + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + __adv->cb = cb; + __adv->user_data = user_data; + + return ret; +} + +void _bt_adapter_le_invoke_advertising_state_cb(int handle, int result, bt_adapter_le_advertising_state_e adv_state) +{ + const GSList *l = NULL; + + for (l = advertiser_list; l; l = g_slist_next(l)) { + bt_advertiser_s *__adv = (bt_advertiser_s *)l->data; + if (__adv->handle == handle) { + if (__adv->cb == NULL) { + BT_ERR("advertiser cb is NULL"); + return; + } + + __adv->cb(result, (bt_advertiser_h)__adv, adv_state, __adv->user_data); + return; + } + } + + BT_ERR("No available advertiser"); +} + +int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, + bt_adapter_le_advertising_mode_e mode) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; + +} + +int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, + bt_adapter_le_advertising_filter_policy_e filter_policy) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_adapter_le_enable_privacy(bool enable_privacy) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error_code = _bt_get_error_code(bluetooth_enable_le_privacy(enable_privacy)); if (error_code != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); @@ -1320,3 +2076,921 @@ int bt_adapter_le_enable_privacy(bool enable_privacy) return error_code; } +#if 0 +static void __bt_adapter_le_convert_scan_filter(bluetooth_le_scan_filter_t *dest, bt_le_scan_filter_s *src) +{ + int bit; + char *data; + + memset(dest, 0x00, sizeof(bluetooth_le_scan_filter_t)); + + if (src->device_address) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS; + _bt_convert_address_to_hex(&dest->device_address, src->device_address); + } + + if (src->device_name) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME; + strncpy(dest->device_name, src->device_name, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX); + dest->device_name[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1] = '\0'; + } + + if (src->service_uuid) { + if (__bt_convert_string_to_uuid(src->service_uuid, &data, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID; + if (bit == 16) + dest->service_uuid.data_len = 2; + else + dest->service_uuid.data_len = 16; + memcpy(dest->service_uuid.data.data, data, dest->service_uuid.data_len); + g_free(data); + + dest->service_uuid_mask.data_len = dest->service_uuid.data_len; + if (src->service_uuid_mask) { + __bt_convert_string_to_uuid(src->service_uuid_mask, &data, &bit); + memcpy(dest->service_uuid_mask.data.data, data, dest->service_uuid_mask.data_len); + g_free(data); + } else { + memset(dest->service_uuid_mask.data.data, 0xFF, dest->service_uuid_mask.data_len); + } + } + } + + if (src->service_solicitation_uuid) { + if (__bt_convert_string_to_uuid(src->service_solicitation_uuid, &data, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID; + + if (bit == 16) + dest->service_solicitation_uuid.data_len = 2; + else + dest->service_solicitation_uuid.data_len = 16; + memcpy(dest->service_solicitation_uuid.data.data, data, dest->service_solicitation_uuid.data_len); + g_free(data); + + dest->service_solicitation_uuid_mask.data_len = dest->service_solicitation_uuid.data_len; + if (src->service_solicitation_uuid_mask) { + __bt_convert_string_to_uuid(src->service_solicitation_uuid_mask, &data, &bit); + memcpy(dest->service_solicitation_uuid_mask.data.data, data, dest->service_solicitation_uuid_mask.data_len); + g_free(data); + } else { + memset(dest->service_solicitation_uuid_mask.data.data, 0xFF, dest->service_solicitation_uuid_mask.data_len); + } + } + } + + if (src->service_data_uuid) { + char *service_uuid; + int uuid_len; + if (__bt_convert_string_to_uuid(src->service_data_uuid, &service_uuid, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA; + if (bit == 16) + uuid_len = 2; + else + uuid_len = 16; + + memcpy(dest->service_data.data.data, service_uuid, uuid_len); + g_free(service_uuid); + memcpy(dest->service_data.data.data + uuid_len, src->service_data, src->service_data_len); + dest->service_data.data_len = uuid_len + src->service_data_len; + + dest->service_data_mask.data_len = uuid_len + src->service_data_len; + memset(dest->service_data_mask.data.data, 0xFF, uuid_len); + if (src->service_data_mask) + memcpy(dest->service_data_mask.data.data + uuid_len, src->service_data_mask, src->service_data_len); + else + memset(dest->service_data_mask.data.data + uuid_len, 0xFF, src->service_data_len); + } + } + + if (src->manufacturer_id > -1) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA; + dest->manufacturer_id = src->manufacturer_id; + + if (src->manufacturer_data) { + memcpy(dest->manufacturer_data.data.data, src->manufacturer_data, src->manufacturer_data_len); + dest->manufacturer_data.data_len = src->manufacturer_data_len; + + dest->manufacturer_data_mask.data_len = src->manufacturer_data_len; + if (src->manufacturer_data_mask) + memcpy(dest->manufacturer_data_mask.data.data, src->manufacturer_data_mask, src->manufacturer_data_len); + else + memset(dest->manufacturer_data_mask.data.data, 0xFF, src->manufacturer_data_len); + } + } +} +#endif + +int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(cb); + + _bt_le_adapter_init(); + _bt_set_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED, cb, user_data); + + error_code = _bt_get_error_code(bluetooth_start_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_stop_scan(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_stop_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int uuid_size = 0; + int uuid_count = 0; + int uuid_index = 0; + int i; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS) + uuid_count += (field_len - 1) / 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS) + uuid_count += (field_len - 1) / 16; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (uuid_count == 0) + return BT_ERROR_NO_DATA; + + *uuids = g_malloc0(sizeof(char*) * uuid_count); + /* Fix : NULL_RETURNS */ + if (*uuids == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + *count = uuid_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS) + uuid_size = 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS) + uuid_size = 16; + else + uuid_size = 0; + + if (uuid_size != 0) { + for (i = 0; i < (field_len - 1); i += uuid_size) { + if (uuid_size == 2) { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 4 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); + } else { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 36 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], + remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], + remain_data[i+7], remain_data[i+6], remain_data[i+5], remain_data[i+4], remain_data[i+3], remain_data[i+2]); + } + uuid_index++; + } + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char **name) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(name); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SHORT_LOCAL_NAME) { + *name = g_malloc0(sizeof(char) * field_len); + /* Fix : NULL_RETURNS */ + if (*name == NULL) + return BT_ERROR_OUT_OF_MEMORY; + memcpy(*name, &adv_data[2], field_len - 1); + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_get_scan_result_tx_power_level(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *power_level) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(power_level); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) { + if (adv_data[2] & 0x80) + *power_level = 0xffffff00 | adv_data[2]; + else + *power_level = (int)adv_data[2]; + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int uuid_size = 0; + int uuid_count = 0; + int uuid_index = 0; + int i; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_count += (field_len - 1) / 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_count += (field_len - 1) / 16; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (uuid_count == 0) + return BT_ERROR_NO_DATA; + + *uuids = g_malloc0(sizeof(char*) * uuid_count); + /* Fix : NULL_RETURNS */ + if (*uuids == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *count = uuid_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_size = 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_size = 16; + else + uuid_size = 0; + + if (uuid_size != 0) { + for (i = 0; i < (field_len - 1); i += uuid_size) { + if (uuid_size == 2) { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 4 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); + } else { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 36 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], + remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], + remain_data[i+7], remain_data[i+6], remain_data[i+5], remain_data[i+4], remain_data[i+3], remain_data[i+2]); + } + uuid_index++; + } + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_service_data_s **data_list, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int data_count = 0; + int data_index = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA) + data_count++; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (data_count == 0) + return BT_ERROR_NO_DATA; + + *data_list = g_malloc0(sizeof(bt_adapter_le_service_data_s) * data_count); + /* Fix : NULL_RETURNS */ + if (*data_list == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *count = data_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA) { + (*data_list)[data_index].service_uuid = g_malloc0(sizeof(char) * 4 + 1); + snprintf((*data_list)[data_index].service_uuid, 5, "%2.2X%2.2X", remain_data[3], remain_data[2]); + + (*data_list)[data_index].service_data = g_memdup(&remain_data[4], field_len - 3); + (*data_list)[data_index].service_data_len = field_len - 3; + + data_index++; + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_free_service_data_list(bt_adapter_le_service_data_s *data_list, int count) +{ + int i; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(data_list); + + for (i = 0; i < count; i++) { + g_free(data_list[i].service_uuid); + g_free(data_list[i].service_data); + } + g_free(data_list); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_appearance(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *appearance) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(appearance); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE) { + *appearance = adv_data[3] << 8; + *appearance += adv_data[2]; + + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + + +int bt_adapter_le_get_scan_result_manufacturer_data(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *manufacturer_id, char **manufacturer_data, int *manufacturer_data_len) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(manufacturer_id); + BT_CHECK_INPUT_PARAMETER(manufacturer_data); + BT_CHECK_INPUT_PARAMETER(manufacturer_data_len); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA) { + *manufacturer_id = remain_data[3] << 8; + *manufacturer_id += remain_data[2]; + + *manufacturer_data = g_memdup(&adv_data[4], field_len - 3); + *manufacturer_data_len = field_len - 3; + + return BT_ERROR_NONE; + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_create_scan_filter(bt_scan_filter_h *scan_filter) +{ + bt_le_scan_filter_s *__filter = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + __filter = (bt_le_scan_filter_s*)g_malloc0(sizeof(bt_le_scan_filter_s)); + if (__filter == NULL) { + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + + __filter->manufacturer_id = -1; + *scan_filter = (bt_scan_filter_h)__filter; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_destroy_scan_filter(bt_scan_filter_h scan_filter) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + g_free(__filter->device_address); + g_free(__filter->device_name); + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + g_free(__filter); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_device_address(bt_scan_filter_h scan_filter, const char *address) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(address); + + g_free(__filter->device_address); + + __filter->device_address = strdup(address); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_device_name(bt_scan_filter_h scan_filter, const char *name) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(name); + + if (strlen(name) > 29) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->device_name); + + __filter->device_name = strdup(name); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_uuid(bt_scan_filter_h scan_filter, const char *uuid) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + + __filter->service_uuid = strdup(uuid); + __filter->service_uuid_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(mask); + + if (strlen(uuid) != strlen(mask)) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + + __filter->service_uuid = strdup(uuid); + __filter->service_uuid_mask = strdup(mask); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_solicitation_uuid(bt_scan_filter_h scan_filter, const char *uuid) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + + __filter->service_solicitation_uuid = strdup(uuid); + __filter->service_solicitation_uuid_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_solicitation_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(mask); + + if (strlen(uuid) != strlen(mask)) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + + __filter->service_solicitation_uuid = strdup(uuid); + __filter->service_solicitation_uuid_mask = strdup(mask); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_data(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(data); + + if (data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + + __filter->service_data_uuid = strdup(uuid); + __filter->service_data = g_memdup(data, data_len); + __filter->service_data_len = data_len; + __filter->service_data_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_data_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(data); + BT_CHECK_INPUT_PARAMETER(mask); + + if (data_len != mask_len || data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + + __filter->service_data_uuid = strdup(uuid); + __filter->service_data = g_memdup(data, data_len); + __filter->service_data_len = data_len; + __filter->service_data_mask = g_memdup(mask, data_len); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_manufacturer_data(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + if (manufacturer_id < 0 || manufacturer_id > 0xFFFF) { + BT_ERR("manufacturer_id is %.8x(0x%08x)", manufacturer_id, BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + if (data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + + __filter->manufacturer_id = manufacturer_id; + if (data != NULL) { + __filter->manufacturer_data = g_memdup(data, data_len); + __filter->manufacturer_data_len = data_len; + } else { + __filter->manufacturer_data = NULL; + __filter->manufacturer_data_len = 0; + } + __filter->manufacturer_data_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(data); + BT_CHECK_INPUT_PARAMETER(mask); + + if (manufacturer_id < 0 || manufacturer_id > 0xFFFF) { + BT_ERR("manufacturer_id is %.8x(0x%08x)", manufacturer_id, BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + if (data_len != mask_len || data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + + __filter->manufacturer_id = manufacturer_id; + __filter->manufacturer_data = g_memdup(data, data_len); + __filter->manufacturer_data_len = data_len; + __filter->manufacturer_data_mask = g_memdup(mask, data_len); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_adapter_le_unregister_all_scan_filters(void) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} diff --git a/src/bluetooth-audio.c b/src/bluetooth-audio.c old mode 100755 new mode 100644 index eaabadf..f0a8acb --- a/src/bluetooth-audio.c +++ b/src/bluetooth-audio.c @@ -19,8 +19,8 @@ #include #include #include "bluetooth.h" -#include "bluetooth_extention.h" #include "bluetooth_internal.h" +#include "bluetooth_extension.h" #include "bluetooth_private.h" #include "bluetooth-audio-api.h" #include "bluetooth-telephony-api.h" @@ -32,6 +32,39 @@ typedef struct _call_list_s { static bool is_audio_initialized = false; +#if defined (TIZEN_HFP_DISABLE) && defined (TIZEN_A2DP_DISABLE) +#define BT_CHECK_AUDIO_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_AUDIO_SUPPORT() +#endif + +#ifdef TIZEN_HFP_DISABLE +#define BT_CHECK_HFP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HFP_SUPPORT() +#endif + +#ifdef TIZEN_A2DP_DISABLE +#define BT_CHECK_A2DP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_A2DP_SUPPORT() +#endif + #define BT_CHECK_AUDIO_INIT_STATUS() \ if (__bt_check_audio_init_status() == BT_ERROR_NOT_INITIALIZED) \ { \ @@ -90,6 +123,7 @@ int bt_audio_initialize(void) { int error; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_audio_init(_bt_audio_event_proxy, NULL); error = _bt_get_error_code(error); @@ -115,6 +149,7 @@ int bt_audio_deinitialize(void) { int error; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); @@ -143,22 +178,36 @@ int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type) int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); -#ifdef TELEPHONY_DISABLED if (type == BT_AUDIO_PROFILE_TYPE_HSP_HFP) { + BT_CHECK_HFP_SUPPORT(); +#ifdef TELEPHONY_DISABLED BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); return BT_ERROR_NOT_SUPPORTED; - } #endif + } else if (type == BT_AUDIO_PROFILE_TYPE_A2DP) { + BT_CHECK_A2DP_SUPPORT(); + } else if (type == BT_AUDIO_PROFILE_TYPE_ALL) { +#if defined (TIZEN_HFP_DISABLE) || defined (TELEPHONY_DISABLED) + BT_ERR("HSP NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + type = BT_AUDIO_PROFILE_TYPE_A2DP; +#else + BT_ERR("A2DP NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + type = BT_AUDIO_PROFILE_TYPE_HSP_HFP; +#endif + } BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); switch(type) { +#ifndef TELEPHONY_DISABLED case BT_AUDIO_PROFILE_TYPE_HSP_HFP: error = bluetooth_ag_connect(&addr_hex); break; +#endif case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_connect(&addr_hex); break; @@ -179,22 +228,28 @@ int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); -#ifdef TELEPHONY_DISABLED if (type == BT_AUDIO_PROFILE_TYPE_HSP_HFP) { + BT_CHECK_HFP_SUPPORT(); +#ifdef TELEPHONY_DISABLED BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); return BT_ERROR_NOT_SUPPORTED; - } #endif + } else if (type == BT_AUDIO_PROFILE_TYPE_A2DP) { + BT_CHECK_A2DP_SUPPORT(); + } BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); switch(type) { +#ifndef TELEPHONY_DISABLED case BT_AUDIO_PROFILE_TYPE_HSP_HFP: error = bluetooth_ag_disconnect(&addr_hex); break; +#endif case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_disconnect(&addr_hex); break; @@ -212,6 +267,7 @@ int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); @@ -221,6 +277,7 @@ int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_c } int bt_audio_unset_connection_state_changed_cb(void) { + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AUDIO_CONNECTION_STATUS) == true) @@ -230,12 +287,9 @@ int bt_audio_unset_connection_state_changed_cb(void) int bt_ag_notify_speaker_gain(int gain) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); error = bluetooth_telephony_set_speaker_gain((unsigned short)gain); @@ -244,17 +298,13 @@ int bt_ag_notify_speaker_gain(int gain) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_get_speaker_gain(int *gain) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(gain); @@ -264,18 +314,14 @@ int bt_ag_get_speaker_gain(int *gain) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_is_nrec_enabled(bool *enabled) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; gboolean is_enabled = FALSE; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(enabled); @@ -291,74 +337,79 @@ int bt_ag_is_nrec_enabled(bool *enabled) *enabled = false; return error; -#endif +} + +int bt_ag_is_wbs_mode(bool *wbs_mode) +{ + int error; + gboolean is_wbs_mode = FALSE; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(wbs_mode); + + error = bluetooth_telephony_is_wbs_mode(&is_wbs_mode); + error = _bt_convert_telephony_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + if (is_wbs_mode) + *wbs_mode = true; + else + *wbs_mode = false; + + return error; } int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_microphone_gain_changed_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE) == true) _bt_unset_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE); return BT_ERROR_NONE; -#endif } int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_speaker_gain_changed_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE) == true) _bt_unset_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE); return BT_ERROR_NONE; -#endif } int bt_ag_open_sco(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); error = bluetooth_telephony_audio_open(); @@ -367,17 +418,13 @@ int bt_ag_open_sco(void) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_close_sco(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); error = bluetooth_telephony_audio_close(); @@ -386,15 +433,11 @@ int bt_ag_close_sco(void) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_is_sco_opened(bool *opened) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(opened); @@ -403,46 +446,34 @@ int bt_ag_is_sco_opened(bool *opened) else *opened = false; return BT_ERROR_NONE; -#endif } int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_sco_state_changed_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS) == true) _bt_unset_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS); return BT_ERROR_NONE; -#endif } int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_INFO("call_id [%d] / event [%d]", call_id, event); @@ -474,26 +505,22 @@ int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, cons call_id); break; default: - error = BT_ERROR_INVALID_PARAMETER; + error = BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM; } error = _bt_convert_telephony_error_code(error); if (error != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_notify_call_list(bt_call_list_h list) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; unsigned int call_count; call_list_s *handle; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(list); @@ -505,17 +532,13 @@ int bt_ag_notify_call_list(bt_call_list_h list) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_notify_voice_recognition_state(bool state) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (state) @@ -527,101 +550,88 @@ int bt_ag_notify_voice_recognition_state(bool state) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; -#endif } int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_CALL_HANDLING_EVENT, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_call_handling_event_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_CALL_HANDLING_EVENT) == true) _bt_unset_cb(BT_EVENT_AG_CALL_HANDLING_EVENT); return BT_ERROR_NONE; -#endif } int bt_ag_set_multi_call_handling_event_cb( bt_ag_multi_call_handling_event_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_multi_call_handling_event_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT) == true) _bt_unset_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT); return BT_ERROR_NONE; -#endif } int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_DTMF_TRANSMITTED, callback, user_data); return BT_ERROR_NONE; -#endif } int bt_ag_unset_dtmf_transmitted_cb(void) { -#ifdef TELEPHONY_DISABLED - BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); - return BT_ERROR_NOT_SUPPORTED; -#else + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_DTMF_TRANSMITTED) == true) _bt_unset_cb(BT_EVENT_AG_DTMF_TRANSMITTED); return BT_ERROR_NONE; -#endif +} + +int bt_ag_is_connected(bool *connected) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(connected); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; } int bt_call_list_create(bt_call_list_h *list) { call_list_s *handle; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(list); @@ -630,6 +640,11 @@ int bt_call_list_create(bt_call_list_h *list) return BT_ERROR_ALREADY_DONE; } handle = g_malloc0(sizeof(call_list_s)); + if (handle == NULL) { + BT_ERR("BT_ERROR_OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + *list = handle; return BT_ERROR_NONE; } @@ -639,6 +654,7 @@ int bt_call_list_destroy(bt_call_list_h list) int result; call_list_s *handle; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(list); @@ -653,6 +669,7 @@ int bt_call_list_reset(bt_call_list_h list) call_list_s *handle; bt_telephony_call_status_info_t *call_status; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(list); @@ -676,6 +693,7 @@ int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state call_list_s *handle; bt_telephony_call_status_info_t *call_status; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(list); @@ -683,6 +701,10 @@ int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state handle = (call_list_s *)list; call_status = g_malloc0(sizeof(bt_telephony_call_status_info_t)); + + /* Fix : NULL_RETURNS */ + if (call_status == NULL) + return BT_ERROR_OUT_OF_MEMORY; call_status->call_id = call_id; call_status->call_status = state; call_status->phone_number = g_strdup(phone_number); @@ -690,3 +712,451 @@ int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state handle->list = g_list_append(handle->list, (gpointer)call_status); return BT_ERROR_NONE; } + +int bt_a2dp_set_content_protection(bool status) +{ + int error; + + error = bluetooth_a2dp_set_content_protection(status); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return error; +} + +#ifdef TIZEN_WEARABLE +int bt_hf_initialize(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_init(_bt_hf_event_proxy, NULL); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_deinitialize(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_deinit(); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_call_event(bt_hf_call_event_e event, char *phone_number) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error = BT_ERROR_NONE; + + BT_CHECK_INIT_STATUS(); + BT_INFO("event [%d]", event); + + switch(event) { + case BT_HF_CALL_EVENT_IDLE: + error = bluetooth_hf_terminate_call(); + break; + case BT_HF_CALL_EVENT_ANSWER: + error = bluetooth_hf_answer_call(); + break; + case BT_HF_CALL_EVENT_HOLD: + break; + case BT_HF_CALL_EVENT_RETRIEVE: + break; + case BT_HF_CALL_EVENT_DIAL: + BT_CHECK_INPUT_PARAMETER(phone_number); + error = bluetooth_hf_initiate_call(phone_number); + break; + case BT_HF_CALL_EVENT_REDIAL: + break; + case BT_HF_CALL_EVENT_RELEASE_ALL_NONACTIVE_CALLS: + error = bluetooth_hf_release_all_call(); + break; + case BT_HF_CALL_EVENT_ACCEPT_AND_RELEASE: + error = bluetooth_hf_release_and_accept(); + break; + case BT_HF_CALL_EVENT_ACCEPT_AND_HOLD: + error = bluetooth_hf_swap_call(); + break; + case BT_HF_CALL_EVENT_ADD_TO_CONVERSATION: + error = bluetooth_hf_join_call(); + break; + default: + error = BLUETOOTH_ERROR_INVALID_PARAM; + break; + } + + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_speaker_gain(int gain) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_set_speaker_gain((unsigned int)gain); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_speaker_gain_changed_cb(bt_hf_speaker_gain_changed_cb callback, void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_speaker_gain_changed_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE) == true) + _bt_unset_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_voice_recognition_state(bool state) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_voice_recognition(state); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_call_status_updated_event_cb(bt_hf_call_status_updated_event_cb callback, void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_call_status_updated_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_close_sco(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_audio_disconnect(); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_send_dtmf(char *dtmf) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_send_dtmf(dtmf); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_is_connected(bool *connected) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + gboolean is_connected = false; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(connected); + + error = bluetooth_hf_is_connected(&is_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + if (is_connected) + *connected = true; + else + *connected = false; + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_is_sco_opened(bool *opened) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + unsigned int audio_connected = BLUETOOTH_HF_AUDIO_DISCONNECTED; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(opened); + + error = bluetooth_hf_get_audio_connected(&audio_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + if (audio_connected == BLUETOOTH_HF_AUDIO_CONNECTED) + *opened = true; + else + *opened = false; + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_get_codec_id(unsigned int *codec_id) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(codec_id); + + error = bluetooth_hf_get_codec(codec_id); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_get_call_status_info_list(GSList **call_list) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + int error; + bt_hf_call_list_s *hf_call_list = NULL; + GList *l; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(call_list); + + error = bluetooth_hf_request_call_list(&hf_call_list); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + *call_list = NULL; + for (l = g_list_first(hf_call_list->list); l; l = g_list_next(l)) { + bt_hf_call_status_info_t *hf_call_info = l->data; + bt_hf_call_status_info_s *call_info = NULL; + + call_info = g_malloc0(sizeof(bt_hf_call_status_info_s)); + call_info->number = strdup(hf_call_info->number); + call_info->direction = hf_call_info->direction; + call_info->status = hf_call_info->status; + call_info->multi_party = hf_call_info->mpart; + call_info->index = hf_call_info->idx; + *call_list = g_slist_append(*call_list, call_info); + } + + bluetooth_hf_free_call_list(hf_call_list); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +#ifdef TIZEN_AUDIO_HF_ENABLE +static void __bt_hf_free_call_status_info(void *data) +{ + bt_hf_call_status_info_s *call_info = (bt_hf_call_status_info_s*)data; + g_free(call_info->number); + g_free(call_info); +} +#endif + +int bt_hf_free_call_status_info_list(GSList *call_list) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(call_list); + + g_slist_free_full(call_list, __bt_hf_free_call_status_info); + + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_sco_state_changed_cb(bt_hf_sco_state_changed_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_sco_state_changed_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_call_handling_event_cb(bt_hf_call_handling_event_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_call_handling_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_multi_call_handling_event_cb( + bt_hf_multi_call_handling_event_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_multi_call_handling_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_ENABLE + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} +#endif diff --git a/src/bluetooth-avrcp.c b/src/bluetooth-avrcp.c old mode 100755 new mode 100644 index 118db9d..d737a10 --- a/src/bluetooth-avrcp.c +++ b/src/bluetooth-avrcp.c @@ -23,6 +23,18 @@ #include "bluetooth-media-control.h" static bool is_avrcp_target_initialized = false; +static bool is_avrcp_control_initialized = false; + +#ifdef TIZEN_AVRCP_DISABLE +#define BT_CHECK_AVRCP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_AVRCP_SUPPORT() +#endif #define BT_CHECK_AVRCP_TARGET_INIT_STATUS() \ if (__bt_check_avrcp_target_init_status() == BT_ERROR_NOT_INITIALIZED) \ @@ -41,6 +53,23 @@ int __bt_check_avrcp_target_init_status(void) return BT_ERROR_NONE; } +#define BT_CHECK_AVRCP_CONTROL_INIT_STATUS() \ + if (__bt_check_avrcp_control_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_avrcp_control_init_status(void) +{ + if (is_avrcp_control_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} + /*The below API is just to conver the error from Audio API's to CAPI error codes, * this is temporary change and changes to proper error code will be done in * subsequent check ins.*/ @@ -53,6 +82,8 @@ int _bt_convert_avrcp_error_code(int error) return BT_ERROR_INVALID_PARAMETER; case BT_MEDIA_ERROR_ALREADY_INITIALIZED: return BT_ERROR_OPERATION_FAILED; + case BT_MEDIA_ERROR_NOT_CONNECTED: + return BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED; default: return BT_ERROR_NONE; } @@ -62,6 +93,7 @@ int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callb { int error; + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_CONNECTION_STATUS, callback, user_data); @@ -81,6 +113,7 @@ int bt_avrcp_target_deinitialize(void) { int error; + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AVRCP_CONNECTION_STATUS) == true) @@ -102,6 +135,8 @@ int bt_avrcp_target_deinitialize(void) int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(EQUALIZER, state); @@ -115,6 +150,8 @@ int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state) int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(REPEAT, mode); @@ -129,6 +166,8 @@ int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode) int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(SHUFFLE, mode); @@ -142,6 +181,8 @@ int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode) int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(SCAN, mode); @@ -156,6 +197,8 @@ int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode) int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(STATUS, state); @@ -170,6 +213,8 @@ int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state) int bt_avrcp_target_notify_position(unsigned int position) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(POSITION, position); @@ -185,6 +230,8 @@ int bt_avrcp_target_notify_track(const char *title, const char *artist, const ch const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_AVRCP_TARGET_INIT_STATUS(); media_metadata_attributes_t metadata; @@ -204,8 +251,309 @@ int bt_avrcp_target_notify_track(const char *title, const char *artist, const ch return error; } +int bt_avrcp_control_initialize(bt_avrcp_control_connection_state_changed_cb callback, + void *user_data) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_CONNECTION_STATUS, callback, user_data); + error = bluetooth_media_control_init(_bt_avrcp_event_proxy, NULL); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + is_avrcp_control_initialized = true; + return BT_ERROR_NONE; +} + +int bt_avrcp_control_deinitialize(void) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AVRCP_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_AVRCP_CONNECTION_STATUS); + + error = bluetooth_media_control_deinit(); + error = _bt_convert_avrcp_error_code(error); + + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + is_avrcp_control_initialized = false; + return BT_ERROR_NONE; +} + +int bt_avrcp_control_connect(const char *remote_address) +{ + int error; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&addr_hex, remote_address); + + error = bluetooth_media_control_connect(&addr_hex); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_disconnect(const char *remote_address) +{ + int error; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&addr_hex, remote_address); + + error = bluetooth_media_control_disconnect(&addr_hex); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_send_player_command(bt_avrcp_player_command_e cmd) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_command(cmd); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_equalizer_state(bt_avrcp_equalizer_state_e state) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(EQUALIZER, state); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_equalizer_state(bt_avrcp_equalizer_state_e *state) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(EQUALIZER, state); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_repeat_mode(bt_avrcp_repeat_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(REPEAT, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_repeat_mode(bt_avrcp_repeat_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(REPEAT, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_shuffle_mode(bt_avrcp_shuffle_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(SHUFFLE, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_shuffle_mode(bt_avrcp_shuffle_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(SHUFFLE, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} +int bt_avrcp_control_set_scan_mode(bt_avrcp_scan_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(SCAN, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_scan_mode(bt_avrcp_scan_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(SCAN, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_position(unsigned int *position) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(POSITION, position); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_play_status(bt_avrcp_player_state_e *status) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(STATUS, status); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track) +{ + int error; + media_metadata_attributes_t metadata = {0,}; + bt_avrcp_metadata_attributes_info_s *tr_info; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(track); + error = bluetooth_media_control_get_track_info(&metadata); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } else { + tr_info = (bt_avrcp_metadata_attributes_info_s *)g_malloc0( + sizeof(bt_avrcp_metadata_attributes_info_s)); + tr_info->title = metadata.title; + tr_info->artist = metadata.artist; + tr_info->album = metadata.album; + tr_info->genre = metadata.genre; + tr_info->total_tracks = metadata.total_tracks; + tr_info->number = metadata.number; + tr_info->duration = metadata.duration; + *track = tr_info; + } + return error; +} + +int bt_avrcp_control_free_track_info(bt_avrcp_metadata_attributes_info_s *track) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(track); + g_free((gpointer)track->title); + g_free((gpointer)track->artist); + g_free((gpointer)track->album); + g_free((gpointer)track->genre); + g_free((gpointer)track); + return BT_ERROR_NONE; +} + int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, callback, user_data); @@ -214,6 +562,7 @@ int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb int bt_avrcp_unset_equalizer_state_changed_cb(void) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED); return BT_ERROR_NONE; @@ -221,6 +570,7 @@ int bt_avrcp_unset_equalizer_state_changed_cb(void) int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, callback, user_data); @@ -229,6 +579,7 @@ int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback int bt_avrcp_unset_repeat_mode_changed_cb(void) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED); return BT_ERROR_NONE; @@ -236,6 +587,7 @@ int bt_avrcp_unset_repeat_mode_changed_cb(void) int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, callback, user_data); @@ -244,6 +596,7 @@ int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callba int bt_avrcp_unset_shuffle_mode_changed_cb(void) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED); return BT_ERROR_NONE; @@ -251,6 +604,7 @@ int bt_avrcp_unset_shuffle_mode_changed_cb(void) int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED, callback, user_data); @@ -259,8 +613,59 @@ int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, vo int bt_avrcp_unset_scan_mode_changed_cb(void) { + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED); return BT_ERROR_NONE; } +int bt_avrcp_set_song_position_changed_cb(bt_avrcp_song_position_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_SONG_POSITION_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_song_position_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_SONG_POSITION_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_play_status_changed_cb(bt_avrcp_play_status_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_PLAY_STATUS_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_play_status_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_PLAY_STATUS_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_track_info_changed_cb(bt_avrcp_track_info_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_TRACK_INFO_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_track_info_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_TRACK_INFO_CHANGED); + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c old mode 100755 new mode 100644 index 1a6db3b..a7283bb --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -24,68 +24,16 @@ #include #include "bluetooth.h" -#include "bluetooth_extention.h" +#include "bluetooth_internal.h" +#include "bluetooth_extension.h" #include "bluetooth_private.h" #include "bluetooth-media-control.h" #include "bluetooth-telephony-api.h" static bool is_initialized = false; static bool is_le_initialized = false; -static bt_event_sig_event_slot_s bt_event_slot_container[] = { - {BT_EVENT_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_LE_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_NAME_CHANGED, NULL, NULL}, - {BT_EVENT_VISIBILITY_MODE_CHANGED, NULL, NULL}, - {BT_EVENT_VISIBILITY_DURATION_CHANGED, NULL, NULL}, - {BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_BOND_CREATED, NULL, NULL}, - {BT_EVENT_BOND_DESTROYED, NULL, NULL}, - {BT_EVENT_AUTHORIZATION_CHANGED, NULL, NULL}, - {BT_EVENT_SERVICE_SEARCHED, NULL, NULL}, - {BT_EVENT_DATA_RECEIVED, NULL, NULL}, - {BT_EVENT_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_RFCOMM_CONNECTION_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_CONNECTION_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_PUSH_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, NULL, NULL}, - {BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_FINISHED, NULL, NULL}, - {BT_EVENT_PAN_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_NAP_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_HDP_CONNECTED, NULL, NULL}, - {BT_EVENT_HDP_DISCONNECTED, NULL, NULL}, - {BT_EVENT_HDP_DATA_RECEIVED, NULL, NULL}, - {BT_EVENT_AUDIO_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_AG_SCO_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_AG_CALL_HANDLING_EVENT, NULL, NULL}, - {BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, NULL, NULL}, - {BT_EVENT_AG_DTMF_TRANSMITTED, NULL, NULL}, - {BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, NULL, NULL}, - {BT_EVENT_AG_SPEAKER_GAIN_CHANGE, NULL, NULL}, - {BT_EVENT_AVRCP_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, NULL, NULL}, - {BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, NULL, NULL}, - {BT_EVENT_AVRCP_SCAN_MODE_CHANGED, NULL, NULL}, - {BT_EVENT_HID_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_DEVICE_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_GATT_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED, NULL, NULL}, - {BT_EVENT_GATT_VALUE_CHANGED, NULL, NULL}, - {BT_EVENT_GATT_READ_CHARACTERISTIC, NULL, NULL}, - {BT_EVENT_GATT_WRITE_CHARACTERISTIC, NULL, NULL}, - {BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED, NULL, NULL}, - {BT_EVENT_ADVERTISING_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_MANUFACTURER_DATA_CHANGED, NULL, NULL}, - {BT_EVENT_CONNECTABLE_CHANGED_EVENT, NULL, NULL}, - {BT_EVENT_AG_VENDOR_CMD, NULL, NULL}, - {BT_EVENT_RSSI_ENABLED_EVENT, NULL, NULL}, - {BT_EVENT_RSSI_ALERT_EVENT, NULL, NULL}, - {BT_EVENT_GET_RSSI_EVENT, NULL, NULL}, -}; + +static bt_event_sig_event_slot_s bt_event_slot_container[BT_EVENT_MAX] = { {NULL, NULL}, }; /* * Internal Functions @@ -100,8 +48,14 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info); static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info); static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info); +static int __bt_get_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s **scan_info, bluetooth_le_device_info_t *source_info); +static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info); static int __bt_get_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s **le_discovery_info, bluetooth_le_device_info_t *source_info); static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s *discovery_info); +#if 0 +static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, bt_gatt_service_s *service); +static int __bt_gatt_client_update_descriptors(bt_gatt_handle_info_t desc_handles, bt_gatt_characteristic_s *characteristic); +#endif /* * Public Functions @@ -109,6 +63,7 @@ static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device int bt_initialize(void) { + BT_CHECK_BT_SUPPORT(); if (is_initialized != true) { if (bluetooth_register_callback(&__bt_event_proxy, NULL) != BLUETOOTH_ERROR_NONE) { BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); @@ -122,6 +77,7 @@ int bt_initialize(void) int bt_deinitialize(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); if (bluetooth_unregister_callback() != BLUETOOTH_ERROR_NONE) { BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); @@ -447,6 +403,10 @@ static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_inf *dest = (bt_device_sdp_info_s *)g_malloc0(sizeof(bt_device_sdp_info_s)); + /* Fix : NULL_RETURNS */ + if (*dest == NULL) + return BT_ERROR_OUT_OF_MEMORY; + if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { __bt_free_bt_device_sdp_info_s(*dest); return BT_ERROR_OUT_OF_MEMORY; @@ -501,6 +461,10 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de { *dest = (bt_device_connection_info_s *)g_malloc0(sizeof(bt_device_connection_info_s)); + /* Fix : NULL_RETURNS */ + if (*dest == NULL) + return BT_ERROR_OUT_OF_MEMORY; + if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { __bt_free_bt_device_connection_info_s(*dest); return BT_ERROR_OUT_OF_MEMORY; @@ -524,6 +488,45 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de return BT_ERROR_NONE; } +#if 0 +static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb( + bt_gatt_h service, bt_gatt_h characteristic, void **user_data) +{ + gchar *svc_path = (gchar *)service; + gchar *chr_path = (gchar *)characteristic; + const GSList *gatt_server_list = NULL; + const GSList *l1, *l2, *l3; + + gatt_server_list = _bt_gatt_get_server_list(); + + for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) { + bt_gatt_server_s *serv = l1->data; + + if (!serv) + return NULL; + + for (l2 = serv->services; l2 != NULL; l2 = l2->next) { + bt_gatt_service_s *svc = l2->data; + + if (g_strcmp0(svc->path, svc_path) == 0) { + for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) { + bt_gatt_characteristic_s *chr = l3->data; + + if (chr && g_strcmp0(chr->path, chr_path) == 0) { + if (chr->read_requested_cb) { + *user_data = chr->read_requested_user_data; + return chr->read_requested_cb; + } else + return NULL; + } + } + } + } + } + return NULL; +} +#endif + static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info) { if (conn_info == NULL) @@ -578,10 +581,10 @@ void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data) static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *user_data) { - int i; int call_id; int *avrcp_mode; int *discoverable_timeout; + int *adv_handle; bluetooth_rfcomm_connection_t *connection_ind = NULL; bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL; bt_socket_connection_s rfcomm_connection; @@ -597,19 +600,25 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us telephony_event_callid_t *call_data = NULL; char *device_addr = NULL; int error_code = BT_ERROR_NONE; - int event_index; + int event_index = -1; bluetooth_network_device_info_t *dev_info = NULL; bt_hdp_connected_t *hdp_conn_info = NULL; bt_hdp_disconnected_t *hdp_disconn_info = NULL; bt_hdp_data_ind_t *hdp_data_ind = NULL; - bt_gatt_discovered_char_t *svc_char = NULL; bt_gatt_char_value_t *char_val = NULL; +#if 0 + bt_gatt_discovered_char_t *svc_char = NULL; bt_gatt_char_property_t *char_desc = NULL; +#endif event_index = __bt_get_cb_index(event); - if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) { + + if (event == BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED || + event == BLUETOOTH_EVENT_ADVERTISING_STARTED || event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) + BT_INFO("NOT use bt_event_slot_container"); + else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) return; - } + memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s)); switch (event) { @@ -1065,6 +1074,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us (call_data->dtmf, bt_event_slot_container[event_index].user_data); break; } + case BLUETOOTH_EVENT_AG_SPEAKER_GAIN: BT_INFO("BLUETOOTH_EVENT_AG_SPEAKER_GAIN"); int *spk_gain = (int *)(param->param_data); @@ -1099,7 +1109,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AV_DISCONNECTED: - BT_INFO("BLUETOOTH_EVENT_Av_DISCONNECTED "); + BT_INFO("BLUETOOTH_EVENT_AV_DISCONNECTED "); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP, @@ -1177,83 +1187,208 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data); break; - case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: { BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED"); - svc_char = (bt_gatt_discovered_char_t *)(param->param_data); - - if (svc_char == NULL) - return; - - for (i = 1; i <= svc_char->handle_info.count; i++) { - ((bt_gatt_characteristics_discovered_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), i, svc_char->handle_info.count, svc_char->handle_info.handle[i-1], - bt_event_slot_container[event_index].user_data); + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_discovered_char_t *svc_char = param->param_data; + int i; + + if (svc_char == NULL) + return; + for (i = 1; i <= svc_char->handle_info.count; i++) { + ((bt_gatt_characteristics_discovered_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), i, svc_char->handle_info.count, svc_char->handle_info.handle[i-1], + bt_event_slot_container[event_index].user_data); + } + _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY); } - - _bt_unset_cb(BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED); - break; + } case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: BT_INFO("BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED"); char_val = (bt_gatt_char_value_t *)(param->param_data); + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_value_t *char_val = param->param_data; + + if (char_val == NULL) + return; + ((bt_gatt_characteristic_changed_cb)bt_event_slot_container[event_index].callback) + (char_val->char_handle, char_val->char_value, char_val->val_len, + bt_event_slot_container[event_index].user_data); + break; + } + if (char_val == NULL) return; - ((bt_gatt_characteristic_changed_cb)bt_event_slot_container[event_index].callback) + ((_bt_gatt_client_value_changed_cb)bt_event_slot_container[event_index].callback) (char_val->char_handle, char_val->char_value, char_val->val_len, bt_event_slot_container[event_index].user_data); break; - case BLUETOOTH_EVENT_GATT_READ_CHAR: + case BLUETOOTH_EVENT_GATT_READ_CHAR: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + BT_INFO("BLUETOOTH_EVENT_GATT_READ_CHAR"); - char_val = (bt_gatt_char_value_t *)(param->param_data); - ((bt_gatt_characteristic_read_cb)bt_event_slot_container[event_index].callback) - (char_val->char_value, char_val->val_len, - bt_event_slot_container[event_index].user_data); - _bt_unset_cb(BT_EVENT_GATT_READ_CHARACTERISTIC); + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_value_t *char_val = param->param_data; + + ((bt_gatt_characteristic_read_cb)bt_event_slot_container[event_index].callback) + (char_val->char_value, char_val->val_len, + bt_event_slot_container[event_index].user_data); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY); + break; + } + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC); + ret = _bt_get_error_code(param->result); + if (ret == BT_ERROR_NONE) { + char_val = (bt_gatt_char_value_t *)(param->param_data); + bt_gatt_set_value(cb_data->gatt_handle, + (char *)char_val->char_value, (int)char_val->val_len); + } + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); break; - case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + } + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_CHAR"); - ((bt_gatt_characteristic_write_cb)bt_event_slot_container[event_index].callback) - (bt_event_slot_container[event_index].user_data); + if (_bt_gatt_is_legacy_client_mode()) { + ((bt_gatt_characteristic_write_cb)bt_event_slot_container[event_index].callback) + (bt_event_slot_container[event_index].user_data); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY); + break; + } + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC); + ret = _bt_get_error_code(param->result); + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); - _bt_unset_cb(BT_EVENT_GATT_WRITE_CHARACTERISTIC); + break; + } + case BLUETOOTH_EVENT_GATT_READ_DESC: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + bt_gatt_char_property_t *desc_val = NULL; + + BT_INFO("BLUETOOTH_EVENT_GATT_READ_DESC"); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR); + ret = _bt_get_error_code(param->result); + if (ret == BT_ERROR_NONE) { + desc_val = (bt_gatt_char_property_t *)(param->param_data); + bt_gatt_set_value(cb_data->gatt_handle, + desc_val->description, (int)desc_val->val_len); + } + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); break; - case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: + } + case BLUETOOTH_EVENT_GATT_WRITE_DESC: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + + BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_DESC"); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR); + ret = _bt_get_error_code(param->result); + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); + + break; + } + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: { BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED"); - char_desc = (bt_gatt_char_property_t *)(param->param_data); + bt_gatt_char_property_t *char_desc = param->param_data; if (char_desc == NULL) return; - ((bt_gatt_characteristic_descriptor_discovered_cb) - bt_event_slot_container[event_index].callback)(_bt_get_error_code(param->result), - char_desc->format.format, char_desc->val_len, char_desc->description, - bt_event_slot_container[event_index].user_data); + bt_event_slot_container[event_index].callback)(_bt_get_error_code(param->result), + char_desc->format.format, char_desc->val_len, char_desc->description, + bt_event_slot_container[event_index].user_data); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY); + break; + } - _bt_unset_cb(BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED); + case BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED: { + const GSList *server_list = NULL; + BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED"); + char_val = (bt_gatt_char_value_t *)(param->param_data); + + if (char_val == NULL) + return; + + for (server_list = _bt_gatt_get_server_list() ; server_list; server_list = g_slist_next(server_list)) { + bt_gatt_server_s *serv = (bt_gatt_server_s*)server_list->data; + GSList *service_list = NULL; + + for (service_list = serv->services; service_list; service_list = g_slist_next(service_list)) { + bt_gatt_service_s *svc = (bt_gatt_service_s*)service_list->data; + GSList *char_list = NULL; + + for (char_list = svc->characteristics; char_list; char_list = g_slist_next(char_list)) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)char_list->data; + if (chr->path && strcmp(char_val->char_handle, chr->path) == 0) { + g_free(chr->value); + chr->value = NULL; + if (char_val->val_len > 0) + chr->value = g_memdup(char_val->char_value, char_val->val_len); + chr->value_length = char_val->val_len; + /* TODO : Fix build error temporary */ + if (chr->server_value_changed_cb) + chr->server_value_changed_cb(NULL, (bt_gatt_server_h)serv, (bt_gatt_h)chr, + 0, (char*)char_val->char_value, char_val->val_len, + chr->server_value_changed_user_data); + } + } + } + } break; + } case BLUETOOTH_EVENT_ADVERTISING_STARTED: BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STARTED"); + adv_handle = (int *)(param->param_data); + + if (bt_event_slot_container[event_index].callback != NULL) { + ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STARTED, + bt_event_slot_container[event_index].user_data); + } - ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STARTED, - bt_event_slot_container[event_index].user_data); + _bt_adapter_le_invoke_advertising_state_cb(*adv_handle, + _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STARTED); break; case BLUETOOTH_EVENT_ADVERTISING_STOPPED: BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STOPPED"); + adv_handle = (int *)(param->param_data); - ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STOPPED, - bt_event_slot_container[event_index].user_data); + if (bt_event_slot_container[event_index].callback != NULL) { + ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STOPPED, + bt_event_slot_container[event_index].user_data); + } + + _bt_adapter_le_invoke_advertising_state_cb(*adv_handle, + _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STOPPED); break; /* case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: @@ -1272,15 +1407,15 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data) { - bt_socket_connection_s rfcomm_connection; + bt_adapter_le_device_scan_result_info_s *scan_info = NULL; bt_adapter_le_device_discovery_info_s *discovery_info = NULL; int event_index = -1; event_index = __bt_get_cb_index(event); - if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) { + if (event == BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND) + BT_INFO("Need to check 2 slots in the case"); + else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) return; - } - memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s)); switch (event) { case BLUETOOTH_EVENT_LE_ENABLED: @@ -1304,16 +1439,32 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: - BT_INFO("BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED"); - if (__bt_get_bt_adapter_le_device_discovery_info_s(&discovery_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { - ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data); - __bt_free_bt_adapter_le_device_discovery_info_s(discovery_info); - } else { - ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data); + BT_INFO("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND"); + event_index = BT_EVENT_LE_SCAN_RESULT_UPDATED; + if (bt_event_slot_container[event_index].callback != NULL) { + if (__bt_get_bt_adapter_le_device_scan_info_s(&scan_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { + ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), scan_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_adapter_le_device_scan_info_s(scan_info); + } else { + ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, bt_event_slot_container[event_index].user_data); + } + } + + event_index = BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED; + if (bt_event_slot_container[event_index].callback != NULL) { + if (__bt_get_bt_adapter_le_device_discovery_info_s(&discovery_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { + ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_adapter_le_device_discovery_info_s(discovery_info); + } else { + ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data); + } } break; + default: break; } @@ -1375,6 +1526,88 @@ static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discove return BT_ERROR_NONE; } +static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info) +{ + int i; + + if (discovery_info == NULL) + return; + + if (discovery_info->remote_name != NULL) + free(discovery_info->remote_name); + + if (discovery_info->remote_address != NULL) + free(discovery_info->remote_address); + + if (discovery_info->service_uuid != NULL) { + for (i = 0; i < discovery_info->service_count; i++) { + if (discovery_info->service_uuid[i] != NULL) + free(discovery_info->service_uuid[i]); + } + free(discovery_info->service_uuid); + } + if (discovery_info->manufacturer_data != NULL) + free(discovery_info->manufacturer_data); + + free(discovery_info); + discovery_info = NULL; +} + +static int __bt_get_bt_adapter_le_device_scan_info_s( + bt_adapter_le_device_scan_result_info_s **scan_info, + bluetooth_le_device_info_t *source_info) +{ + + BT_CHECK_INPUT_PARAMETER(source_info); + + *scan_info = (bt_adapter_le_device_scan_result_info_s *)malloc(sizeof(bt_adapter_le_device_scan_result_info_s)); + if (*scan_info == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + _bt_convert_address_to_string(&((*scan_info)->remote_address), &(source_info->device_address)); + + if (source_info->addr_type == 0x02) + (*scan_info)->address_type = BT_DEVICE_RANDOM_ADDRESS; + else + (*scan_info)->address_type = BT_DEVICE_PUBLIC_ADDRESS; + (*scan_info)->rssi = (int)source_info->rssi; + (*scan_info)->adv_data_len = source_info->adv_ind_data.data_len; + if ((*scan_info)->adv_data_len > 0) { + (*scan_info)->adv_data = malloc(source_info->adv_ind_data.data_len); + memcpy((*scan_info)->adv_data, source_info->adv_ind_data.data.data, source_info->adv_ind_data.data_len); + } else { + (*scan_info)->adv_data = NULL; + } + + (*scan_info)->scan_data_len = source_info->scan_resp_data.data_len; + if ((*scan_info)->scan_data_len > 0) { + (*scan_info)->scan_data = malloc(source_info->scan_resp_data.data_len); + memcpy((*scan_info)->scan_data, source_info->scan_resp_data.data.data, source_info->scan_resp_data.data_len); + } else { + (*scan_info)->scan_data = NULL; + } + + return BT_ERROR_NONE; +} + +static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info) +{ + if (scan_info == NULL) + return; + + if (scan_info->remote_address != NULL) + free(scan_info->remote_address); + + if (scan_info->adv_data != NULL) + free(scan_info->adv_data); + if (scan_info->scan_data != NULL) + free(scan_info->scan_data); + + free(scan_info); + scan_info = NULL; +} + static int __bt_get_bt_adapter_le_device_discovery_info_s( bt_adapter_le_device_discovery_info_s **le_discovery_info, bluetooth_le_device_info_t *source_info) @@ -1410,33 +1643,6 @@ static int __bt_get_bt_adapter_le_device_discovery_info_s( return BT_ERROR_NONE; } -static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info) -{ - int i; - - if (discovery_info == NULL) - return; - - if (discovery_info->remote_name != NULL) - free(discovery_info->remote_name); - - if (discovery_info->remote_address != NULL) - free(discovery_info->remote_address); - - if (discovery_info->service_uuid != NULL) { - for (i = 0; i < discovery_info->service_count; i++) { - if (discovery_info->service_uuid[i] != NULL) - free(discovery_info->service_uuid[i]); - } - free(discovery_info->service_uuid); - } - if (discovery_info->manufacturer_data != NULL) - free(discovery_info->manufacturer_data); - - free(discovery_info); - discovery_info = NULL; -} - static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s *discovery_info) { if (discovery_info == NULL) @@ -1454,6 +1660,29 @@ static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device discovery_info = NULL; } +static int __bt_get_gatt_client_cb_index(int event) +{ + switch (event) { + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY; + else + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED; + case BLUETOOTH_EVENT_GATT_READ_CHAR: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY; + else + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC; + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY; + else + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC; + } + + return -1; +} + static int __bt_get_cb_index(int event) { switch (event) { @@ -1578,16 +1807,22 @@ static int __bt_get_cb_index(int event) case BLUETOOTH_HID_DISCONNECTED: return BT_EVENT_HID_CONNECTION_STATUS; case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: - return BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED; + return BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY; + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: + return BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY; case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: - return BT_EVENT_GATT_VALUE_CHANGED; case BLUETOOTH_EVENT_GATT_READ_CHAR: - return BT_EVENT_GATT_READ_CHARACTERISTIC; - case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: - return BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED; + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + return __bt_get_gatt_client_cb_index(event); + case BLUETOOTH_EVENT_GATT_READ_DESC: + return BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR; + case BLUETOOTH_EVENT_GATT_WRITE_DESC: + return BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR; case BLUETOOTH_EVENT_ADVERTISING_STARTED: case BLUETOOTH_EVENT_ADVERTISING_STOPPED: return BT_EVENT_ADVERTISING_STATE_CHANGED; + case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: + return BT_EVENT_MANUFACTURER_DATA_CHANGED; case BLUETOOTH_EVENT_CONNECTABLE_CHANGED: return BT_EVENT_CONNECTABLE_CHANGED_EVENT; default: @@ -1606,3 +1841,113 @@ static void __bt_convert_lower_to_upper(char *origin) } } } + +#if 0 +static void bt_gatt_client_handle_destroy(bt_gatt_h gatt_handle) +{ + if (gatt_handle) + bt_gatt_destroy(gatt_handle); +} + +static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, + bt_gatt_service_s *service) +{ + GSList *chr_list = NULL; + int i; + + for (i = 0; i < char_handles.count; i++) { + bt_gatt_characteristic_s *chr = NULL; + bt_gatt_char_property_t char_property; + int ret; + + memset(&char_property, 0x00, sizeof(char_property)); + ret = bluetooth_gatt_get_characteristics_property( + char_handles.handle[i], &char_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_characteristics_property is failed"); + goto next; + } + + ret = bt_gatt_characteristic_create(char_property.uuid, 0, + char_property.permission, (char *)char_property.val, + (int)char_property.val_len, (bt_gatt_h *)&chr); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_characteristic_create is failed"); + goto next; + } + + if (char_property.permission & BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE) + chr->write_type = BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE; + else if (char_property.permission & BT_GATT_PROPERTY_WRITE) + chr->write_type = BT_GATT_WRITE_TYPE_WRITE; + + chr->path = g_strdup(char_handles.handle[i]); + BT_DBG("path : %s", chr->path); + chr->parent = (void *)service; + chr->role = BT_GATT_ROLE_CLIENT; + + if (char_property.char_desc_handle.count != 0 && char_property.char_desc_handle.handle) { + + /* Add characteristics descriptor */ + __bt_gatt_client_update_descriptors(char_property.char_desc_handle, chr); + } + + chr_list = g_slist_append(chr_list, chr); +next: + bluetooth_gatt_free_char_property(&char_property); + } + + g_slist_free_full(service->characteristics, + bt_gatt_client_handle_destroy); + service->characteristics = chr_list; + return BT_ERROR_NONE; +} + +static int __bt_gatt_client_update_descriptors(bt_gatt_handle_info_t desc_handles, + bt_gatt_characteristic_s *characteristic) + +{ + GSList *desc_list = NULL; + int i; + + /* Add characteristics descriptor */ + + for (i = 0; i < desc_handles.count; i++) { + bt_gatt_descriptor_s *desc = NULL; + bt_gatt_char_descriptor_property_t desc_property; + int ret; + + memset(&desc_property, 0x00, sizeof(desc_property)); + ret = bluetooth_gatt_get_char_descriptor_property( + desc_handles.handle[i], &desc_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_char_descriptor_property is failed"); + goto next; + } + + ret = bt_gatt_descriptor_create(desc_property.uuid, 0, + (char*)desc_property.val, (int)desc_property.val_len, + (bt_gatt_h *)&desc); + + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_characteristic_create is failed"); + goto next; + } + desc->path = g_strdup(desc_handles.handle[i]); + BT_DBG("path : %s", desc->path); + desc->parent = (void *)characteristic; + desc->role = BT_GATT_ROLE_CLIENT; + desc_list = g_slist_append(desc_list, desc); + +next: + bluetooth_gatt_free_desc_property(&desc_property); + } + + g_slist_free_full(characteristic->descriptors, + bt_gatt_client_handle_destroy); + characteristic->descriptors = desc_list; + return BT_ERROR_NONE; +} +#endif diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c old mode 100755 new mode 100644 index 1a132da..21843dc --- a/src/bluetooth-device.c +++ b/src/bluetooth-device.c @@ -20,6 +20,7 @@ #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" int bt_device_create_bond(const char *device_address) @@ -27,6 +28,7 @@ int bt_device_create_bond(const char *device_address) bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -44,6 +46,8 @@ int bt_device_create_bond_by_type(const char *device_address, { bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -60,6 +64,7 @@ int bt_device_cancel_bonding(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_cancel_bonding()); if (error_code != BT_ERROR_NONE) { @@ -74,6 +79,7 @@ int bt_device_destroy_bond(const char *device_address) bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -91,6 +97,7 @@ int bt_device_set_alias(const char *device_address, const char *alias) bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); BT_CHECK_INPUT_PARAMETER(alias); @@ -109,6 +116,7 @@ int bt_device_set_authorization(const char *device_address, bt_device_authorizat gboolean trusted = FALSE; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -128,6 +136,7 @@ int bt_device_start_service_search(const char *device_address) bluetooth_device_address_t addr_hex = { {0,} }; int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -148,6 +157,7 @@ int bt_device_cancel_service_search(void) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); ret = _bt_get_error_code(bluetooth_cancel_service_search()); if (ret != BT_ERROR_NONE) { @@ -168,6 +178,7 @@ int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_c BT_PROFILE_AG, BT_PROFILE_GATT, BT_PROFILE_NAP_SERVER, 0}; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(callback); @@ -201,6 +212,7 @@ int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_p int ret; gboolean is_connected = FALSE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -221,6 +233,7 @@ int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_p int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_BOND_CREATED, callback, user_data); @@ -230,6 +243,7 @@ int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_BOND_DESTROYED, callback, user_data); @@ -239,6 +253,7 @@ int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void * int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AUTHORIZATION_CHANGED, callback, user_data); @@ -248,6 +263,7 @@ int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb ca int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_SERVICE_SEARCHED, callback, user_data); @@ -255,8 +271,22 @@ int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, vo return BT_ERROR_NONE; } +int bt_device_get_connection_state(const char *remote_address, + bt_device_connection_link_type_e link_type, bool *connected) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(connected); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_DEVICE_CONNECTION_STATUS, callback, user_data); @@ -266,6 +296,7 @@ int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed int bt_device_unset_bond_created_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_BOND_CREATED); return BT_ERROR_NONE; @@ -273,6 +304,7 @@ int bt_device_unset_bond_created_cb(void) int bt_device_unset_bond_destroyed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_BOND_DESTROYED); return BT_ERROR_NONE; @@ -280,6 +312,7 @@ int bt_device_unset_bond_destroyed_cb(void) int bt_device_unset_authorization_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AUTHORIZATION_CHANGED); return BT_ERROR_NONE; @@ -287,6 +320,7 @@ int bt_device_unset_authorization_changed_cb(void) int bt_device_unset_service_searched_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_SERVICE_SEARCHED); return BT_ERROR_NONE; @@ -294,6 +328,7 @@ int bt_device_unset_service_searched_cb(void) int bt_device_unset_connection_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_DEVICE_CONNECTION_STATUS); return BT_ERROR_NONE; @@ -306,6 +341,7 @@ int bt_device_le_conn_update(const char *device_address, bluetooth_le_conn_update_t param= { 0 }; int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); BT_CHECK_INPUT_PARAMETER(parameters); @@ -329,15 +365,17 @@ int bt_device_get_service_mask_from_uuid_list(char **uuids, int no_of_service, bt_service_class_t *service_mask_list) { - BT_DBG("Get service mask from uuid list"); - BT_CHECK_INPUT_PARAMETER(uuids); - BT_CHECK_INPUT_PARAMETER(service_mask_list); - int i = 0; unsigned int service = 0; char **parts = NULL; bt_service_class_t service_mask = 0; + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(service_mask_list); + BT_CHECK_INIT_STATUS(); + + BT_DBG("Get service mask from uuid list"); BT_DBG("no_of_service = %d", no_of_service); for (i = 0; i < no_of_service; i++) { @@ -385,7 +423,7 @@ int bt_device_get_service_mask_from_uuid_list(char **uuids, break; case BLUETOOTH_AUDIO_SOURCE_UUID: - service_mask |= BT_SC_NONE; + service_mask |= BT_SC_A2DP_SOURCE_SERVICE_MASK; break; case BLUETOOTH_AUDIO_SINK_UUID: @@ -404,10 +442,6 @@ int bt_device_get_service_mask_from_uuid_list(char **uuids, service_mask |= BT_SC_NONE; break; - case BLUETOOTH_ADVANCED_AUDIO_PROFILE_UUID: - service_mask |= BT_SC_A2DP_SERVICE_MASK; - break; - case BLUETOOTH_AV_REMOTE_CONTROL_UUID: service_mask |= BT_SC_AVRCP_SERVICE_MASK; break; diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c old mode 100755 new mode 100644 index d2fa1c4..4cb0c13 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -15,11 +15,130 @@ */ #include +#include #include #include #include "bluetooth.h" #include "bluetooth_private.h" +#include "bluetooth_internal.h" +#include "bluetooth_type_internal.h" + +#define BT_ADDR_STR_LEN 17 + +static GSList *gatt_client_list = NULL; + +static GSList *gatt_server_list = NULL; +static bool is_gatt_server_initialized = false; + +#ifdef TIZEN_GATT_DISABLE +#define BT_CHECK_GATT_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_GATT_SUPPORT() +#endif + +#define BT_CHECK_GATT_SERVER_INIT_STATUS() \ + if (__bt_check_gatt_server_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_gatt_server_init_status(void) +{ + if (is_gatt_server_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} + +static char *__convert_uuid_to_uuid128(const char *uuid) +{ + int len; + char *uuid128; + + len = strlen(uuid); + + switch (len) { + case 4: /* UUID 16bits */ + uuid128 = g_strdup_printf("0000%s-0000-1000-8000-00805F9B34FB", uuid); + break; + + case 8: /* UUID 32bits */ + uuid128 = g_strdup_printf("%s-0000-1000-8000-00805F9B34FB", uuid); + break; + + case 36: /* UUID 128bits */ + uuid128 = strdup(uuid); + break; + + default: + return NULL; + } + + return uuid128; +} + +static int __get_gatt_handle_by_uuid(GSList *list, const char *uuid, + bt_gatt_h *gatt_handle) +{ + GSList *l; + char *uuid128_a; + char *uuid128_b; + + uuid128_a = __convert_uuid_to_uuid128(uuid); + if (uuid128_a == NULL) { + BT_ERR("Wrong type of uuid : %s", uuid); + return BT_ERROR_INVALID_PARAMETER; + } + + for (l = list; l; l = g_slist_next(l)) { + bt_gatt_common_s *common = (bt_gatt_common_s *)l->data; + + uuid128_b = __convert_uuid_to_uuid128(common->uuid); + if (g_ascii_strcasecmp(uuid128_a, uuid128_b) == 0) { + g_free(uuid128_b); + break; + } + + g_free(uuid128_b); + } + + if (!l) + return BT_ERROR_NO_DATA; + + *gatt_handle = l->data; + + return BT_ERROR_NONE; +} + +const GSList* _bt_gatt_get_client_list(void) +{ + return gatt_client_list; +} + +const GSList* _bt_gatt_get_server_list(void) +{ + return gatt_server_list; +} + +bool _bt_gatt_is_legacy_client_mode(void) +{ + if (gatt_client_list) { + BT_INFO("New GATT Client APIs"); + return false; + } + + BT_INFO("Legacy GATT Client APIs"); + return true; +} int bt_gatt_foreach_primary_services(const char *remote_address, bt_gatt_primary_service_cb callback, @@ -31,6 +150,7 @@ int bt_gatt_foreach_primary_services(const char *remote_address, bluetooth_device_address_t addr_hex = { {0,} }; bt_gatt_handle_info_t *prim_svc; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(callback); @@ -76,6 +196,7 @@ int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service); BT_CHECK_INPUT_PARAMETER(callback); @@ -85,7 +206,7 @@ int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } else { - _bt_set_cb(BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED, callback, user_data); + _bt_set_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, callback, user_data); } return ret; @@ -97,6 +218,7 @@ int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid) int ret; bt_gatt_service_property_t property; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service); @@ -129,6 +251,7 @@ int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, bool foreach_call = true; bt_gatt_service_property_t property; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service); BT_CHECK_INPUT_PARAMETER(callback); @@ -165,19 +288,21 @@ int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb callback, void *user_data) { + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); - _bt_set_cb(BT_EVENT_GATT_VALUE_CHANGED, callback, user_data); + _bt_set_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, callback, user_data); return BT_ERROR_NONE; } int bt_gatt_unset_characteristic_changed_cb() { + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); - _bt_unset_cb(BT_EVENT_GATT_VALUE_CHANGED); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY); return BT_ERROR_NONE; } @@ -186,6 +311,7 @@ int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service) { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service); @@ -201,6 +327,7 @@ int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service) { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service); @@ -219,6 +346,7 @@ int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, int ret; bt_gatt_char_property_t property; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(characteristic); @@ -253,6 +381,7 @@ int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(characteristic); BT_CHECK_INPUT_PARAMETER(value); @@ -276,6 +405,7 @@ int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(characteristic); BT_CHECK_INPUT_PARAMETER(value); @@ -290,7 +420,7 @@ int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } else { - _bt_set_cb(BT_EVENT_GATT_WRITE_CHARACTERISTIC, callback, characteristic); + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, callback, characteristic); } return ret; @@ -301,6 +431,7 @@ int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h *clone, { int error = BT_ERROR_NONE; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(origin); @@ -313,6 +444,7 @@ int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle) { int error = BT_ERROR_NONE; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(handle); @@ -326,6 +458,7 @@ int bt_gatt_read_characteristic_value(bt_gatt_attribute_h characteristic, { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(characteristic); BT_CHECK_INPUT_PARAMETER(callback); @@ -335,7 +468,7 @@ int bt_gatt_read_characteristic_value(bt_gatt_attribute_h characteristic, if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } else { - _bt_set_cb(BT_EVENT_GATT_READ_CHARACTERISTIC, callback, NULL); + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, callback, NULL); } return ret; @@ -347,17 +480,18 @@ int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristi { int ret; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(characteristic_handle); BT_CHECK_INPUT_PARAMETER(callback); ret = _bt_get_error_code(bluetooth_gatt_discover_characteristic_descriptor - ((const char *)characteristic_handle)); + ((const char *)characteristic_handle)); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } else { - _bt_set_cb(BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED, callback, user_data); + _bt_set_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, callback, user_data); } return ret; @@ -368,6 +502,7 @@ int bt_gatt_connect(const char *address, bool auto_connect) int ret; bluetooth_device_address_t bd_addr = { {0,} }; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(address); _bt_convert_address_to_hex(&bd_addr, address); @@ -385,6 +520,7 @@ int bt_gatt_disconnect(const char *address) int ret; bluetooth_device_address_t bd_addr = { {0,} }; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(address); _bt_convert_address_to_hex(&bd_addr, address); @@ -399,6 +535,7 @@ int bt_gatt_disconnect(const char *address) int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_GATT_CONNECTION_STATUS, callback, user_data); @@ -408,8 +545,1857 @@ int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb int bt_gatt_unset_connection_state_changed_cb(void) { + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_GATT_CONNECTION_STATUS); return BT_ERROR_NONE; } +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name) +{ + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(name); + + int i; + int offset = 0; + static struct { + const char *uuid; + const char *specification_name; + } bt_uuid_name[] = { + /* GATT Services */ + {"1800", "Generic Access"}, + {"1801", "Generic Attribute"}, + {"1802", "Immediate Alert"}, + {"1803", "Link Loss"}, + {"1804", "Tx Power"}, + {"1805", "Current Time Service"}, + {"1806", "Reference Time Update Service"}, + {"1807", "Next DST Change Service"}, + {"1808", "Glucose"}, + {"1809", "Health Thermometer"}, + {"180A", "Device Information"}, + {"180D", "Heart Rate"}, + {"180F", "Battery Service"}, + {"1810", "Blood Pressure"}, + {"1811", "Alert Notification Service"}, + {"1812", "Human Interface Device"}, + + /* GATT Declarations */ + {"2800", "Primary Service Declaration"}, + {"2801", "Secondary Service Declaration"}, + {"2802", "Include Declaration"}, + {"2803", "Characteristic Declaration"}, + + /* GATT Descriptors */ + {"2900", "Characteristic Extended Properties"}, + {"2901", "Characteristic User Description"}, + {"2902", "Client Characteristic Configuration"}, + {"2903", "Server Characteristic Configuration"}, + {"2904", "Characteristic Format"}, + {"2905", "Characteristic Aggregate Formate"}, + {"2906", "Valid Range"}, + {"2907", "External Report Reference"}, + {"2908", "Report Reference"}, + + /* GATT Characteristics */ + {"2A00", "Device Name"}, + {"2A01", "Appearance"}, + {"2A02", "Peripheral Privacy Flag"}, + {"2A03", "Reconnection Address"}, + {"2A04", "Peripheral Preferred Connection Parameters"}, + {"2A05", "Service Changed"}, + {"2A06", "Alert Level"}, + {"2A07", "Tx Power Level"}, + {"2A08", "Date Time"}, + {"2A09", "Day of Week"}, + {"2A0A", "Day Date Time"}, + {"2A19", "Battery Level"}, + {"2A1E", "Intermediate Temperature"}, + {"2A23", "System ID"}, + {"2A24", "Model Number String"}, + {"2A25", "Serial Number String"}, + {"2A26", "Firmware Revision String"}, + {"2A27", "Hardware Revision String"}, + {"2A28", "Software Revision String"}, + {"2A29", "Manufacturer Name String"}, + {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"}, + {"2A2B", "Current Time"}, + {"2A37", "Heart Rate Measurement"}, + {"2A38", "Body Sensor Location"}, + {"2A3F", "Alert Status"}, + {"2A46", "New Alert"}, + {"2A4A", "HID Information"}, + {"2A4C", "HID Control Point"}, + {"2A50", "PnP ID"}, + {NULL, NULL} + }; + + if (strlen(uuid) >= 8) + offset = 4; + + for (i = 0; bt_uuid_name[i].uuid; i++) { + if (!g_ascii_strncasecmp(uuid + offset, bt_uuid_name[i].uuid, 4)) { + *name = g_strdup(bt_uuid_name[i].specification_name); + return BT_ERROR_NONE; + } + } + + *name = g_strdup("Unknown"); + return BT_ERROR_NONE; +} + +static void __bt_gatt_free_descriptor(bt_gatt_h gatt_handle) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + g_free(desc->path); + g_free(desc->uuid); + g_free(desc->value); + g_free(desc); +} + +static void __bt_gatt_free_characteristic(bt_gatt_h gatt_handle) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + + g_slist_free_full(chr->descriptors, __bt_gatt_free_descriptor); + + g_free(chr->path); + g_free(chr->uuid); + g_free(chr->value); + g_free(chr); +} + +static void __bt_gatt_free_service(bt_gatt_h gatt_handle) +{ + int ret = BT_ERROR_NONE; + bt_gatt_service_s *svc = (bt_gatt_service_s*)gatt_handle; + + g_slist_free_full(svc->included_services, __bt_gatt_free_service); + g_slist_free_full(svc->characteristics, __bt_gatt_free_characteristic); + + if (svc->role == BT_GATT_ROLE_SERVER) { + ret = _bt_get_error_code(bluetooth_gatt_unregister_service(svc->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x) : Failed to unregister service", + _bt_convert_error_to_string(ret), ret); + } + + g_free(svc->path); + g_free(svc->uuid); + g_free(svc); +} + +static void __bt_gatt_destroy_descriptor(bt_gatt_h gatt_handle) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + bt_gatt_characteristic_s *parent_chr = (bt_gatt_characteristic_s*)desc->parent; + + if (parent_chr) + parent_chr->descriptors = g_slist_remove(parent_chr->descriptors, desc); + + __bt_gatt_free_descriptor(gatt_handle); +} + +static void __bt_gatt_destroy_characteristic(bt_gatt_h gatt_handle) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_service_s *parent_svc = (bt_gatt_service_s*)chr->parent; + + if (parent_svc) + parent_svc->characteristics = g_slist_remove(parent_svc->characteristics, chr); + + __bt_gatt_free_characteristic(gatt_handle); +} + +static void __bt_gatt_destroy_service(bt_gatt_h gatt_handle) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)gatt_handle; + bt_gatt_server_s *server = NULL; + bt_gatt_client_s *client = NULL; + bt_gatt_service_s *parent_svc = NULL; + + if (svc->is_included_service == FALSE) { + if (svc->role == BT_GATT_ROLE_SERVER) { + server = (bt_gatt_server_s*)svc->parent; + if (server) + server->services = g_slist_remove(server->services, svc); + } else { + client = (bt_gatt_client_s*)svc->parent; + if (client) + client->services = g_slist_remove(client->services, svc); + } + } else { + parent_svc = (bt_gatt_service_s*)svc->parent; + if (parent_svc) + parent_svc->included_services = g_slist_remove(parent_svc->included_services, svc); + } + + __bt_gatt_free_service(gatt_handle); +} + +static int __convert_int_to_signed_bits(int i, int size) +{ + if (i < 0) + i = (1 << (size - 1)) + (i & ((1 << (size - 1)) - 1)); + + return i; + } + +static int __convert_unsigned_to_signed(int value, int size) +{ + if ((value & (1 << (size-1))) != 0) { + value = -1 * ((1 << (size-1)) - (value & ((1 << (size-1)) - 1))); + } + return value; +} + +static int __convert_unsigned_byte_to_int(char b) +{ + return b & 0xFF; +} + +static int __convert_unsigned_bytes_to_int16(char b0, char b1) +{ + return (__convert_unsigned_byte_to_int(b0) + (__convert_unsigned_byte_to_int(b1) << 8)); +} + +static int __convert_unsigned_bytes_to_int32(char b0, char b1, char b2, char b3) +{ + return (__convert_unsigned_byte_to_int(b0) + (__convert_unsigned_byte_to_int(b1) << 8)) + + (__convert_unsigned_byte_to_int(b2) << 16) + (__convert_unsigned_byte_to_int(b3) << 24); +} + +static float __convert_bytes_to_short_float(char b0, char b1) +{ + int mantissa; + int exponent; + float tmp; + mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + + ((__convert_unsigned_byte_to_int(b1) & 0x0F) << 8), 12); + exponent = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b1) >> 4, 4); + tmp = pow(10, exponent); + + return (float)(mantissa * tmp); +} + +float __convert_bytes_to_float(char b0, char b1, char b2, char b3) +{ + int mantissa; + float exponent; + mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + + (__convert_unsigned_byte_to_int(b1) << 8) + + (__convert_unsigned_byte_to_int(b2) << 16), 24); + exponent = pow(10, b3); + + return (float)(mantissa * exponent); +} + +static int __get_data_type_float_size(bt_data_type_float_e type) +{ + switch (type) { + case BT_DATA_TYPE_SFLOAT: + return 2; + case BT_DATA_TYPE_FLOAT: + return 4; + default: + return 0; + } + } + +static int __get_data_type_int_size(bt_data_type_int_e format) +{ + switch (format) { + case BT_DATA_TYPE_SINT8: + case BT_DATA_TYPE_UINT8: + return 1; + case BT_DATA_TYPE_SINT16: + case BT_DATA_TYPE_UINT16: + return 2; + case BT_DATA_TYPE_SINT32: + case BT_DATA_TYPE_UINT32: + return 4; + default: + return 0; + } + } + +int bt_gatt_destroy(bt_gatt_h gatt_handle) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_SERVICE) + __bt_gatt_destroy_service(gatt_handle); + else if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + __bt_gatt_destroy_characteristic(gatt_handle); + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + __bt_gatt_destroy_descriptor(gatt_handle); + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_value(bt_gatt_h gatt_handle, char **value, int *value_length) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + BT_CHECK_INPUT_PARAMETER(value_length); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + *value_length = chr->value_length; + if (chr->value_length > 0) + *value = g_memdup(chr->value, chr->value_length); + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + *value_length = desc->value_length; + if (desc->value_length > 0) + *value = g_memdup(desc->value, desc->value_length); + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, int offset, int *value) +{ + char *val; + int val_len; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = chr->value; + val_len = chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = desc->value; + val_len = desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if ((offset + __get_data_type_int_size(type)) > val_len) { + BT_ERR("Offset exceed the memory"); + return BT_ERROR_INVALID_PARAMETER; + } + + switch (type) { + case BT_DATA_TYPE_UINT8: + *value = __convert_unsigned_byte_to_int(val[offset]); + break; + case BT_DATA_TYPE_UINT16: + *value = __convert_unsigned_bytes_to_int16(val[offset], val[offset+1]); + break; + + case BT_DATA_TYPE_UINT32: + *value = __convert_unsigned_bytes_to_int32(val[offset], val[offset+1], + val[offset+2], val[offset+3]); + break; + case BT_DATA_TYPE_SINT8: + *value = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(val[offset]), 8); + break; + + case BT_DATA_TYPE_SINT16: + *value = __convert_unsigned_to_signed(__convert_unsigned_bytes_to_int16(val[offset], + val[offset+1]), 16); + break; + + case BT_DATA_TYPE_SINT32: + *value = __convert_unsigned_to_signed(__convert_unsigned_bytes_to_int32(val[offset], + val[offset+1], val[offset+2], val[offset+3]), 32); + break; + default: + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, int offset, float *value) +{ + char *val; + int val_len; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = chr->value; + val_len = chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = desc->value; + val_len = desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if ((offset + __get_data_type_float_size(type)) > val_len) { + BT_ERR("Offset exceed the memory"); + return BT_ERROR_INVALID_PARAMETER; + } + + switch (type) { + case BT_DATA_TYPE_SFLOAT: + *value = __convert_bytes_to_short_float(val[offset], val[offset+1]); + break; + + case BT_DATA_TYPE_FLOAT: + *value = __convert_bytes_to_float(val[offset], val[offset+1], + val[offset+2], val[offset+3]); + break; + default: + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_value(bt_gatt_h gatt_handle, const char *value, int value_length) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, value, value_length)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + g_free(*val); + *val = NULL; + if (value_length > 0) + *val = g_memdup(value, value_length); + *val_len = value_length; + + return BT_ERROR_NONE; +} + +int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, int value, int offset) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + char *tmp; + int fmt_size; + int idx = offset; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val_len < offset) { + BT_ERR("Offset is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + fmt_size = __get_data_type_int_size(type); + if (*val == NULL) { + *val = g_malloc0(fmt_size); + *val_len = fmt_size; + } else if (*val_len == offset) {// Added + tmp = g_malloc0(*val_len + fmt_size); + /* Fix : NULL_RETURNS */ + if (!tmp) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len += fmt_size; + } else if (*val_len < offset + fmt_size) {// Overlapped + tmp = g_malloc0(offset + fmt_size); + /* Fix : NULL_RETURNS */ + if (!tmp) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len = offset + fmt_size; + } + + switch (type) { + case BT_DATA_TYPE_SINT8: + value = __convert_int_to_signed_bits(value, 8); + case BT_DATA_TYPE_UINT8: + if (*val) + (*val)[idx] = (char)(value & 0xFF); + break; + + case BT_DATA_TYPE_SINT16: + value = __convert_int_to_signed_bits(value, 16); + case BT_DATA_TYPE_UINT16: + if (*val) { + (*val)[idx++] = (char)(value & 0xFF); + (*val)[idx] = (char)((value >> 8) & 0xFF); + } + break; + + case BT_DATA_TYPE_SINT32: + value = __convert_int_to_signed_bits(value, 32); + case BT_DATA_TYPE_UINT32: + if (*val) { + (*val)[idx++] = (char)(value & 0xFF); + (*val)[idx++] = (char)((value >> 8) & 0xFF); + (*val)[idx++] = (char)((value >> 16) & 0xFF); + (*val)[idx] = (char)((value >> 24) & 0xFF); + } + break; + + default: + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, *val, *val_len)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int mantissa, int exponent, int offset) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + int mant; + int exp; + char *tmp; + int fmt_size; + int idx = offset; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val_len < offset) { + BT_ERR("Offset is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + fmt_size = __get_data_type_float_size(type); + if (fmt_size == 0) { + BT_ERR("Format is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val == NULL) { + *val = g_malloc0(fmt_size); + /* Fix : NULL_RETURNS */ + if (*val == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *val_len = fmt_size; + } else if (*val_len == offset) {// Added + tmp = g_malloc0(*val_len + fmt_size); + /* Fix : NULL_RETURNS */ + if (tmp == NULL) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len += fmt_size; + } else if (*val_len < offset + fmt_size) {// Overlapped + tmp = g_malloc0(offset + fmt_size); + /* Fix : NULL_RETURNS */ + if (tmp == NULL) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len = offset + fmt_size; + } + + switch (type) { + case BT_DATA_TYPE_FLOAT: + mant = __convert_int_to_signed_bits(mantissa, 24); + exp = __convert_int_to_signed_bits(exponent, 8); + (*val)[idx++] = (char)(mant & 0xFF); + (*val)[idx++] = (char)((mant >> 8) & 0xFF); + (*val)[idx++] = (char)((mant >> 16) & 0xFF); + (*val)[idx] = (char)(exp & 0xFF); + break; + + case BT_DATA_TYPE_SFLOAT: + mant = __convert_int_to_signed_bits(mantissa, 12); + exp = __convert_int_to_signed_bits(exponent, 4); + (*val)[idx++] = (char)(mant & 0xFF); + (*val)[idx] = (char)((mant >> 8) & 0x0F); + (*val)[idx] += (char)((exp & 0x0F) << 4); + break; + + default: + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, *val, *val_len)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_permissions(bt_gatt_h gatt_handle, int *permissions) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(permissions); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + *permissions = chr->permissions; + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + *permissions = desc->permissions; + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_permissions(bt_gatt_h gatt_handle, int permissions) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + chr->permissions = permissions; + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + desc->permissions = permissions; + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_uuid(bt_gatt_h gatt_handle, char **uuid) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(uuid); + + *uuid = g_strdup(handle->uuid); + + return BT_ERROR_NONE; +} + +int bt_gatt_get_type(bt_gatt_h gatt_handle, bt_gatt_type_e *gatt_type) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(gatt_type); + + *gatt_type = handle->type; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type, + bt_gatt_h *service) +{ + bt_gatt_service_s *svc; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + svc = (bt_gatt_service_s*)g_malloc0(sizeof(bt_gatt_service_s)); + if (svc == NULL) + return BT_ERROR_OUT_OF_MEMORY; + svc->type = BT_GATT_TYPE_SERVICE; + svc->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + svc->uuid = __convert_uuid_to_uuid128(uuid); + else + svc->uuid = strdup(uuid); + if (svc->uuid == NULL) { + g_free(svc); + return BT_ERROR_OUT_OF_MEMORY; + } + svc->is_included_service = false; + svc->service_type = type; + + *service = (bt_gatt_h)svc; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_add_characteristic(bt_gatt_h service, + bt_gatt_h characteristic) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)characteristic; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(characteristic); + if (chr->parent) { + BT_ERR("This characteristic is already added."); + return BT_ERROR_INVALID_PARAMETER; + } + + svc->characteristics = g_slist_append(svc->characteristics, chr); + chr->parent = (void *)service; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_add_included_service(bt_gatt_h service, + bt_gatt_h included_service) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_service_s *included_svc = (bt_gatt_service_s*)included_service; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(included_service); + if (included_svc->parent) { + BT_ERR("This service is already added."); + return BT_ERROR_INVALID_PARAMETER; + } + + svc->included_services = g_slist_append(svc->included_services, included_svc); + included_svc->parent = (void *)service; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_server(bt_gatt_h service, bt_gatt_server_h *server) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s *)service; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(server); + + if (svc->is_included_service) { + BT_ERR("This is included service of %p", svc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + if (svc->role != BT_GATT_ROLE_SERVER) { + BT_ERR("This is not server's service"); + return BT_ERROR_INVALID_PARAMETER; + } + + *server = (bt_gatt_server_h)svc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_client(bt_gatt_h service, bt_gatt_client_h *client) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s *)service; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(client); + + if (svc->is_included_service) { + BT_ERR("This is included service of %p", svc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + if (svc->role != BT_GATT_ROLE_CLIENT) { + BT_ERR("This is not client's service"); + return BT_ERROR_INVALID_PARAMETER; + } + + *client = (bt_gatt_client_h)svc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_characteristic(bt_gatt_h service, const char *uuid, + bt_gatt_h *characteristic) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(characteristic); + + ret = __get_gatt_handle_by_uuid(svc->characteristics, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *characteristic = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_service_foreach_characteristics(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_characteristic_s *chr = NULL; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(svc->characteristics); + + for (l = svc->characteristics; l; l = g_slist_next(l)) { + chr = l->data; + if (!callback(total, index++, (bt_gatt_h)chr, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_included_service(bt_gatt_h service, const char *uuid, + bt_gatt_h *included_service) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(included_service); + + ret = __get_gatt_handle_by_uuid(svc->included_services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *included_service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_service_foreach_included_services(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_service_s *included_svc = NULL; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(svc->included_services); + + for (l = svc->included_services; l; l = g_slist_next(l)) { + included_svc = l->data; + if (!callback(total, index++, (bt_gatt_h)included_svc, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_create(const char *uuid, int permissions, + int properties, const char *value, int value_length, + bt_gatt_h *characteristic) +{ + int ret = BT_ERROR_NONE; + bt_gatt_characteristic_s *chr = NULL; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(characteristic); + if (value_length > 0) + BT_CHECK_INPUT_PARAMETER(value); + + chr = malloc(sizeof(*chr)); + if (chr == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + memset(chr, 0x00, sizeof(*chr)); + + chr->type = BT_GATT_TYPE_CHARACTERISTIC; + chr->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + chr->uuid = __convert_uuid_to_uuid128(uuid); + else + chr->uuid = g_strdup(uuid); + if (chr->uuid == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + chr->permissions = permissions; + chr->properties = properties; + chr->write_type = BT_GATT_WRITE_TYPE_WRITE; + chr->value_length = value_length; + if (value_length > 0) { + chr->value = g_memdup(value, value_length); + if (chr->value == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + } + + *characteristic = (bt_gatt_h)chr; + + return BT_ERROR_NONE; + +fail: + g_free(chr->value); + g_free(chr->uuid); + g_free(chr); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_characteristic_add_descriptor(bt_gatt_h characteristic, + bt_gatt_h descriptor) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)descriptor; + + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(descriptor); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC || + desc->type != BT_GATT_TYPE_DESCRIPTOR) { + BT_ERR("Wrong type. chr : %d, desc : %d", chr->type, desc->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (desc->parent) { + BT_ERR("Already added descriptor : %p", desc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->descriptors = g_slist_append(chr->descriptors, desc); + desc->parent = (void *)characteristic; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_service(bt_gatt_h characteristic, bt_gatt_h *service) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(service); + + *service = (bt_gatt_h)chr->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_properties(bt_gatt_h characteristic, int *properties) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(properties); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + *properties = chr->properties; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_set_properties(bt_gatt_h characteristic, int properties) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->properties = properties; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e *write_type) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(write_type); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + *write_type = chr->write_type; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_set_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e write_type) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->write_type = write_type; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_descriptor(bt_gatt_h characteristic, const char *uuid, + bt_gatt_h *descriptor) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(descriptor); + + ret = __get_gatt_handle_by_uuid(chr->descriptors, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *descriptor = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_characteristic_foreach_descriptors(bt_gatt_h characteristic, + bt_gatt_foreach_cb callback, void *user_data) +{ + GSList *l; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + int total; + int i; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + total = g_slist_length(chr->descriptors); + + i = 1; + for (l = chr->descriptors; l; l = g_slist_next(l)) { + if (!callback(total, i++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_descriptor_create(const char *uuid, int permissions, + const char *value, int value_length, + bt_gatt_h *descriptor) +{ + int ret = BT_ERROR_NONE; + bt_gatt_descriptor_s *desc = NULL; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(descriptor); + if (value_length > 0) + BT_CHECK_INPUT_PARAMETER(value); + + desc = malloc(sizeof(*desc)); + if (desc == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + memset(desc, 0x00, sizeof(*desc)); + + desc->type = BT_GATT_TYPE_DESCRIPTOR; + desc->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + desc->uuid = __convert_uuid_to_uuid128(uuid); + else + desc->uuid = g_strdup(uuid); + if (desc->uuid == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + desc->permissions = permissions; + desc->value_length = value_length; + if (value_length > 0) { + desc->value = g_memdup(value, value_length); + if (desc->value == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + } + + *descriptor = (bt_gatt_h)desc; + + return ret; + +fail: + g_free(desc->uuid); + g_free(desc->value); + g_free(desc); + + return ret; +} + +int bt_gatt_descriptor_get_characteristic(bt_gatt_h descriptor, bt_gatt_h *characteristic) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)descriptor; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(descriptor); + BT_CHECK_INPUT_PARAMETER(characteristic); + + *characteristic = (bt_gatt_h)desc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_initialize(void) +{ + BT_CHECK_INIT_STATUS(); + + int ret = BT_ERROR_NONE; + + if (!is_gatt_server_initialized) { + ret = _bt_get_error_code(bluetooth_gatt_init()); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", + _bt_convert_error_to_string(ret), ret); + return BT_ERROR_OPERATION_FAILED; + } + + is_gatt_server_initialized = true; + return BT_ERROR_NONE; + } + + BT_DBG("Gatt-service already initialized"); + + return ret; +} + +int bt_gatt_server_deinitialize(void) +{ + BT_CHECK_INIT_STATUS(); + + int ret = BT_ERROR_NONE; + + if (is_gatt_server_initialized) { + GSList *l; + for (l = gatt_server_list; l; l = g_slist_next(l)) { + bt_gatt_server_s *serv = l->data; + g_slist_free_full(serv->services, __bt_gatt_free_service); + g_free(serv); + } + g_slist_free(gatt_server_list); + gatt_server_list = NULL; + + ret = _bt_get_error_code(bluetooth_gatt_deinit()); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", + _bt_convert_error_to_string(ret), ret); + return BT_ERROR_OPERATION_FAILED; + } + + is_gatt_server_initialized = false; + return BT_ERROR_NONE; + } + + BT_DBG("Gatt-service is not initialized"); + + return ret; +} + +int bt_gatt_server_create(bt_gatt_server_h *server) +{ + bt_gatt_server_s *serv = NULL; + + BT_CHECK_INPUT_PARAMETER(server); + + serv = g_malloc0(sizeof(bt_gatt_server_s)); + if (serv == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + *server = (bt_gatt_server_h)serv; + + gatt_server_list = g_slist_append(gatt_server_list, serv); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_destroy(bt_gatt_server_h server) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + + BT_CHECK_INPUT_PARAMETER(server); + + g_slist_free_full(serv->services, __bt_gatt_free_service); + gatt_server_list = g_slist_remove(gatt_server_list, serv); + g_free(serv); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_set_read_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_read_value_requested_cb callback, + void *user_data) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->read_requested_cb = callback; + chr->read_requested_user_data = user_data; + + _bt_set_cb(BT_EVENT_GATT_SERVER_READ_REQUESTED, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service) +{ + int ret = BT_ERROR_NONE; + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + GSList *char_l; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(service); + + if (g_slist_find(serv->services, svc)) { + BT_ERR("Already added service."); + return BT_ERROR_ALREADY_DONE; + } + + ret = _bt_get_error_code(bluetooth_gatt_add_service(svc->uuid, &svc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + for (char_l = svc->characteristics; char_l; char_l = g_slist_next(char_l)) { + GSList *desc_l; + bt_gatt_characteristic_s *chr = char_l->data; + + ret = _bt_get_error_code(bluetooth_gatt_add_new_characteristic(svc->path, chr->uuid, + (bt_gatt_characteristic_property_t)chr->properties, &chr->path)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + ret = _bt_get_error_code(bluetooth_gatt_set_characteristic_value(chr->path, + chr->value, chr->value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + for (desc_l = chr->descriptors; desc_l; desc_l = g_slist_next(desc_l)) { + bt_gatt_descriptor_s *desc = desc_l->data; + + ret = _bt_get_error_code(bluetooth_gatt_add_descriptor(chr->path, desc->uuid, &desc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + ret = _bt_get_error_code(bluetooth_gatt_set_descriptor_value(desc->path, desc->value, desc->value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + } + } + + ret = _bt_get_error_code(bluetooth_gatt_register_service(svc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + serv->services = g_slist_append(serv->services, svc); + svc->parent = (void *)server; + + return ret; + +fail: + bluetooth_gatt_unregister_service(svc->path); + + return ret; +} + +int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(service); + + if (!g_slist_find(serv->services, svc)) { + BT_ERR("Service is NOT found."); + return BT_ERROR_SERVICE_NOT_FOUND; + } + + __bt_gatt_destroy_service(svc); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_unregister_all_services(bt_gatt_server_h server) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + + g_slist_free_full(serv->services, __bt_gatt_free_service); + serv->services = NULL; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_send_response(int request_id, + int offset, char *value, int value_length) +{ + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(value); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, + bt_gatt_server_notification_sent_cb callback, void *user_data) +{ + return BT_ERROR_NONE; +} + +int bt_gatt_server_set_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_server_value_changed_cb callback, + void *user_data) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->server_value_changed_cb = callback; + chr->server_value_changed_user_data = user_data; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_get_service(bt_gatt_server_h server, const char *uuid, + bt_gatt_h *service) +{ + bt_gatt_server_s *server_s = (bt_gatt_server_s *)server; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + ret = __get_gatt_handle_by_uuid(server_s->services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_server_foreach_services(bt_gatt_server_h server, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_server_s *server_s = (bt_gatt_server_s *)server; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(server_s->services); + + for (l = server_s->services; l; l = g_slist_next(l)) { + if (!callback(total, index++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client) +{ + int ret = BT_ERROR_NONE; + bt_gatt_client_s *client_s; + GSList *l; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + + for (l = gatt_client_list; l; l = g_slist_next(gatt_client_list)) { + bt_gatt_client_s *c = (bt_gatt_client_s *)l->data; + + if (!g_ascii_strcasecmp(c->remote_address, remote_address)) { + BT_ERR("Gatt client for %s is already created", + remote_address); + return BT_ERROR_ALREADY_DONE; + } + } + + client_s = g_malloc0(sizeof(*client_s)); + if (client_s == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + memset(client_s, 0x00, sizeof(*client_s)); + + client_s->remote_address = g_strdup(remote_address); + if (client_s->remote_address == NULL) { + free(client_s); + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + client_s->services_discovered = false; + + *client = (bt_gatt_client_h)client_s; + gatt_client_list = g_slist_append(gatt_client_list, client_s); + + return ret; +} + +int bt_gatt_client_destroy(bt_gatt_client_h client) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + + g_free(client_s->remote_address); + g_slist_free_full(client_s->services, __bt_gatt_free_service); + gatt_client_list = g_slist_remove(gatt_client_list, client_s); + g_free(client_s); + + return BT_ERROR_NONE; +} + +int bt_gatt_client_get_remote_address(bt_gatt_client_h client, + char **remote_address) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(remote_address); + + *remote_address = g_strdup(client_s->remote_address); + + return BT_ERROR_NONE; +} + +static bool __bt_gatt_client_is_in_progress(void) +{ + if (_bt_check_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR)) { + BT_ERR("Operation is in progress"); + return true; + } + + return false; +} + +int bt_gatt_client_read_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + bt_gatt_common_s *c = (bt_gatt_common_s *)gatt_handle; + bt_gatt_client_cb_data_s *cb_data; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + if (__bt_gatt_client_is_in_progress()) { + BT_ERR("Operation is in progress"); + return BT_ERROR_NOW_IN_PROGRESS; + } + + cb_data = malloc(sizeof(bt_gatt_client_cb_data_s)); + if (cb_data == NULL) { + BT_ERR("Cannot alloc cb_data"); + return BT_ERROR_OPERATION_FAILED; + } + + cb_data->gatt_handle = gatt_handle; + cb_data->user_data = user_data; + + if (c->type == BT_GATT_TYPE_CHARACTERISTIC) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_read_characteristic_value(chr->path)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC, callback, cb_data); + } + } else if (c->type == BT_GATT_TYPE_DESCRIPTOR) { + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_read_descriptor_value(desc->path)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, callback, cb_data); + } + } else { + BT_ERR("Invalid handle type for read "); + g_free(cb_data); + } + + return ret; +} + +int bt_gatt_client_write_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data) +{ + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +static const bt_gatt_client_h __find_gatt_client(const char *remote_address) +{ + GSList *l = NULL; + + for (l = gatt_client_list; l; l = g_slist_next(l)) { + bt_gatt_client_s *client_s = l->data; + + if (!g_strcmp0(client_s->remote_address, remote_address)) { + return (const bt_gatt_client_h)l->data; + } + } + + return NULL; +} + +static gboolean __get_bdaddr_from_path(const char *path, char *addr) +{ + int i; + char *tmp; + + /* + * e.g. + * /org/bluez/hci0/dev_E7_56_2A_AA_0C_FD/service001b + */ + tmp = g_strstr_len(path, strlen(path), "dev_"); + if (tmp == NULL) + return FALSE; + tmp += 4; + + for (i = 0; *tmp != '\0' && i < BT_ADDR_STR_LEN; i++, tmp++) { + if (*tmp == '_') + addr[i] = ':'; + else + addr[i] = *tmp; + } + addr[i] = '\0'; + + BT_DBG("path : %s, addr : %s", path, addr); + + return TRUE; +} + +static void __value_changed_cb(char *char_path, + char *value, int value_length, void *user_data) +{ + GSList *l; + GSList *ll; + bt_gatt_client_h client; + bt_gatt_client_s *client_s; + bt_gatt_service_s *svc; + bt_gatt_characteristic_s *chr; + char remote_address[BT_ADDR_STR_LEN + 1] = { 0, }; + + BT_DBG("%s", char_path); + + if (__get_bdaddr_from_path(char_path, remote_address) == FALSE) { + BT_ERR("Cannot get addr from path : %s", char_path); + return; + } + + client = __find_gatt_client(remote_address); + if (client == NULL) { + BT_ERR("Cannot find client [%s]", remote_address); + return; + } + + client_s = (bt_gatt_client_s *)client; + for (l = client_s->services; l; l = g_slist_next(l)) { + svc = (bt_gatt_service_s *)l->data; + for (ll = svc->characteristics; ll; ll = g_slist_next(ll)) { + chr = (bt_gatt_characteristic_s *)ll->data; + if (g_ascii_strcasecmp(chr->path, char_path) == 0) { + if (chr->value_changed_cb) + chr->value_changed_cb(chr, value, + value_length, + chr->value_changed_user_data); + + bt_gatt_set_value(chr, value, value_length); + return; + } + } + } +} + +int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_client_characteristic_value_changed_cb callback, + void *user_data) +{ + int ret; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->value_changed_cb = callback; + chr->value_changed_user_data = user_data; + + if (chr->properties & + (BT_GATT_PROPERTY_NOTIFY | BT_GATT_PROPERTY_INDICATE)) { + ret = _bt_get_error_code(bluetooth_gatt_watch_characteristics( + chr->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + else + _bt_set_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED, + __value_changed_cb, NULL); + } else { + BT_DBG("notify or indication is not supported"); + ret = BT_ERROR_NOT_SUPPORTED; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_client_unset_characteristic_value_changed_cb(bt_gatt_h characteristic) +{ + int ret; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->properties & + (BT_GATT_PROPERTY_NOTIFY | BT_GATT_PROPERTY_INDICATE)) { + ret = _bt_get_error_code(bluetooth_gatt_unwatch_characteristics( + chr->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + else { + chr->value_changed_cb = NULL; + chr->value_changed_user_data = NULL; + } + } else { + BT_DBG("notify or indication is not supported"); + ret = BT_ERROR_NOT_SUPPORTED; + } + + return ret; +} + +int bt_gatt_client_get_service(bt_gatt_client_h client, const char *uuid, + bt_gatt_h *service) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + ret = __get_gatt_handle_by_uuid(client_s->services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_client_foreach_services(bt_gatt_client_h client, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(client_s->services); + + for (l = client_s->services; l; l = g_slist_next(l)) { + if (!callback(total, index++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-hdp.c b/src/bluetooth-hdp.c old mode 100755 new mode 100644 index cdca1f1..116c62d --- a/src/bluetooth-hdp.c +++ b/src/bluetooth-hdp.c @@ -24,11 +24,23 @@ #include "bluetooth.h" #include "bluetooth_private.h" +#ifdef TIZEN_HDP_DISABLE +#define BT_CHECK_HDP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HDP_SUPPORT() +#endif + int bt_hdp_register_sink_app(unsigned short data_type, char **app_id) { int error = BT_ERROR_NONE; char *app_handle = NULL; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); error = bluetooth_hdp_activate(data_type, HDP_ROLE_SINK, HDP_QOS_ANY, &app_handle); @@ -50,6 +62,7 @@ int bt_hdp_unregister_sink_app(const char *app_id) { int error = BT_ERROR_NONE; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); error = bluetooth_hdp_deactivate(app_id); @@ -64,8 +77,9 @@ int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size) { int error = BT_ERROR_NONE; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); - if (NULL == data) { + if (NULL == data || 0 >= size) { BT_ERR("%s", _bt_convert_error_to_string(BT_ERROR_INVALID_PARAMETER)); } error = bluetooth_hdp_send_data(channel, data, size); @@ -80,6 +94,8 @@ int bt_hdp_connect_to_source(const char *remote_address, const char *app_id) { int error = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -96,6 +112,8 @@ int bt_hdp_disconnect(const char *remote_address, unsigned int channel) { int error = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -111,6 +129,7 @@ int bt_hdp_disconnect(const char *remote_address, unsigned int channel) int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connected_cb); BT_CHECK_INPUT_PARAMETER(disconnected_cb); @@ -122,6 +141,7 @@ int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, int bt_hdp_unset_connection_state_changed_cb(void) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); if ( _bt_check_cb(BT_EVENT_HDP_CONNECTED) == true) _bt_unset_cb(BT_EVENT_HDP_CONNECTED); @@ -134,6 +154,7 @@ int bt_hdp_unset_connection_state_changed_cb(void) int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_HDP_DATA_RECEIVED, callback, user_data); @@ -142,6 +163,7 @@ int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, int bt_hdp_unset_data_received_cb(void) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); if ( _bt_check_cb(BT_EVENT_HDP_DATA_RECEIVED) == true) _bt_unset_cb(BT_EVENT_HDP_DATA_RECEIVED); diff --git a/src/bluetooth-hid.c b/src/bluetooth-hid.c old mode 100755 new mode 100644 index b8a168a..729275d --- a/src/bluetooth-hid.c +++ b/src/bluetooth-hid.c @@ -27,6 +27,28 @@ static bool is_hid_host_initialized = false; +#ifdef TIZEN_HID_HOST_DISABLE +#define BT_CHECK_HID_HOST_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HID_HOST_SUPPORT() +#endif + +#ifdef TIZEN_HID_DEVICE_DISABLE +#define BT_CHECK_HID_DEVICE_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HID_DEVICE_SUPPORT() +#endif + #define BT_CHECK_HID_HOST_INIT_STATUS() \ if (__bt_check_hid_host_init_status() == BT_ERROR_NOT_INITIALIZED) \ { \ @@ -49,6 +71,7 @@ int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb { int error; + BT_CHECK_HID_HOST_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connection_cb); @@ -69,6 +92,7 @@ int bt_hid_host_deinitialize() { int error; + BT_CHECK_HID_HOST_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_HID_HOST_INIT_STATUS(); @@ -90,6 +114,7 @@ int bt_hid_host_connect(const char *remote_address) int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_HID_HOST_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_HID_HOST_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -109,6 +134,7 @@ int bt_hid_host_disconnect(const char *remote_address) int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_HID_HOST_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_HID_HOST_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); diff --git a/src/bluetooth-opp-client.c b/src/bluetooth-opp-client.c old mode 100755 new mode 100644 index 6e870a1..a05321b --- a/src/bluetooth-opp-client.c +++ b/src/bluetooth-opp-client.c @@ -27,6 +27,17 @@ GList *sending_files; static bool is_opp_client_initialized = false; +#ifdef TIZEN_OPP_CLIENT_DISABLE +#define BT_CHECK_OPP_CLIENT_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_OPP_CLIENT_SUPPORT() +#endif + #define BT_CHECK_OPP_CLIENT_INIT_STATUS() \ if (__bt_check_opp_client_init_status() == BT_ERROR_NOT_INITIALIZED) \ { \ @@ -82,6 +93,7 @@ int bt_opp_client_initialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_opc_init()); @@ -100,6 +112,7 @@ int bt_opp_client_deinitialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_CLIENT_INIT_STATUS(); @@ -120,9 +133,11 @@ int bt_opp_client_add_file(const char *file) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_CLIENT_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(file); + BT_CHECK_ADAPTER_STATUS(); if (access(file, F_OK) == 0) { sending_files = g_list_append(sending_files, strdup(file)); @@ -144,8 +159,10 @@ int bt_opp_client_clear_files(void) int file_num = 0; char *c_file = NULL; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_CLIENT_INIT_STATUS(); + BT_CHECK_ADAPTER_STATUS(); if (sending_files) { file_num = g_list_length(sending_files); @@ -176,6 +193,7 @@ int bt_opp_client_push_files(const char *remote_address, bluetooth_device_address_t addr_hex = { {0,} }; char **files = NULL; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_CLIENT_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -207,6 +225,7 @@ int bt_opp_client_cancel_push(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_CLIENT_INIT_STATUS(); diff --git a/src/bluetooth-opp-server.c b/src/bluetooth-opp-server.c old mode 100755 new mode 100644 index 6b92619..9830305 --- a/src/bluetooth-opp-server.c +++ b/src/bluetooth-opp-server.c @@ -24,6 +24,18 @@ static bool is_opp_server_initialized = false; +#ifdef TIZEN_OPP_SERVER_DISABLE +#define BT_CHECK_OPP_SERVER_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_OPP_SERVER_SUPPORT() +#endif + + #define BT_CHECK_OPP_SERVER_INIT_STATUS() \ if (__bt_check_opp_server_init_status() == BT_ERROR_NOT_INITIALIZED) \ { \ @@ -47,6 +59,7 @@ int bt_opp_server_initialize(const char *destination, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); @@ -70,6 +83,7 @@ int bt_opp_server_initialize_by_connection_request(const char *destination, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); @@ -91,6 +105,7 @@ int bt_opp_server_deinitialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_SERVER_INIT_STATUS(); @@ -122,6 +137,7 @@ int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_SERVER_INIT_STATUS(); @@ -151,6 +167,7 @@ int bt_opp_server_reject(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_SERVER_INIT_STATUS(); @@ -177,6 +194,7 @@ int bt_opp_server_set_destination(const char *destination) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_SERVER_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); @@ -194,6 +212,7 @@ int bt_opp_server_cancel_transfer(int transfer_id) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_OPP_SERVER_INIT_STATUS(); diff --git a/src/bluetooth-pan.c b/src/bluetooth-pan.c old mode 100755 new mode 100644 index 052d404..d177add --- a/src/bluetooth-pan.c +++ b/src/bluetooth-pan.c @@ -24,12 +24,22 @@ #include "bluetooth.h" #include "bluetooth_private.h" -GList *sending_files; +#ifdef TIZEN_PAN_DISABLE +#define BT_CHECK_PAN_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_PAN_SUPPORT() +#endif int bt_nap_activate(void) { int error = BT_ERROR_NONE; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_network_activate_server(); error = _bt_get_error_code(error); @@ -43,6 +53,7 @@ int bt_nap_deactivate(void) { int error = BT_ERROR_NONE; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_network_deactivate_server(); error = _bt_get_error_code(error); @@ -58,6 +69,7 @@ int bt_nap_disconnect_all(void) { int error = BT_ERROR_NONE; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_network_deactivate_server(); error = _bt_get_error_code(error); @@ -75,6 +87,7 @@ int bt_nap_disconnect(const char *remote_address) int error = BT_ERROR_INVALID_PARAMETER; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -91,6 +104,7 @@ int bt_nap_set_connection_state_changed_cb( bt_nap_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_NAP_CONNECTION_STATE_CHANGED, callback, user_data); @@ -108,6 +122,7 @@ int bt_panu_set_connection_state_changed_cb( bt_panu_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_PAN_CONNECTION_STATE_CHANGED, callback, user_data); @@ -125,6 +140,7 @@ int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type) int error = BT_ERROR_INVALID_PARAMETER; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -145,6 +161,7 @@ int bt_panu_disconnect(const char *remote_address) int error = BT_ERROR_INVALID_PARAMETER; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); diff --git a/src/bluetooth-socket.c b/src/bluetooth-socket.c old mode 100755 new mode 100644 index 56ecc4a..661f083 --- a/src/bluetooth-socket.c +++ b/src/bluetooth-socket.c @@ -27,6 +27,7 @@ int bt_socket_create_rfcomm(const char *uuid, int *socket_fd) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(uuid); BT_CHECK_INPUT_PARAMETER(socket_fd); @@ -46,6 +47,7 @@ int bt_socket_destroy_rfcomm(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_remove_socket(socket_fd)); if (error_code != BT_ERROR_NONE) { @@ -58,6 +60,7 @@ int bt_socket_destroy_rfcomm(int socket_fd) int bt_socket_is_service_used(const char* service_uuid, bool *used) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service_uuid); BT_CHECK_INPUT_PARAMETER(used); @@ -71,6 +74,7 @@ int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connection { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_listen_and_accept(socket_fd, max_pending_connections)); if (error_code != BT_ERROR_NONE) { @@ -85,6 +89,7 @@ int bt_socket_listen(int socket_fd, int max_pending_connections) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_listen(socket_fd, max_pending_connections)); @@ -98,6 +103,11 @@ int bt_socket_listen(int socket_fd, int max_pending_connections) int bt_socket_accept(int socket_fd) { + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + /* Will implement after synch bluetooth-frwk */ + return BT_ERROR_NOT_SUPPORTED; } @@ -105,6 +115,7 @@ int bt_socket_reject(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_reject_connection(socket_fd)); @@ -116,11 +127,49 @@ int bt_socket_reject(int socket_fd) return error_code; } +int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(bus_name); + BT_CHECK_INPUT_PARAMETER(object_path); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_socket_destroy_rfcomm_ex(const char *uuid) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + +int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(bus_name); + BT_CHECK_INPUT_PARAMETER(object_path); + + /* Will implement after synch bluetooth-frwk */ + + return BT_ERROR_NOT_SUPPORTED; +} + int bt_socket_connect_rfcomm(const char *remote_address, const char *remote_port_uuid) { bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(remote_port_uuid); @@ -140,6 +189,7 @@ int bt_socket_disconnect_rfcomm(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_disconnect(socket_fd)); @@ -155,6 +205,7 @@ int bt_socket_send_data(int socket_fd, const char *data, int length) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); ret = bluetooth_rfcomm_write(socket_fd, data, length); @@ -180,6 +231,7 @@ int bt_socket_send_data(int socket_fd, const char *data, int length) int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_DATA_RECEIVED, callback, user_data); @@ -188,6 +240,7 @@ int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *us int bt_socket_unset_data_received_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_DATA_RECEIVED); return BT_ERROR_NONE; @@ -195,6 +248,7 @@ int bt_socket_unset_data_received_cb(void) int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_RFCOMM_CONNECTION_REQUESTED, callback, user_data); @@ -203,6 +257,7 @@ int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb call int bt_socket_unset_connection_requested_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_RFCOMM_CONNECTION_REQUESTED); return BT_ERROR_NONE; @@ -210,6 +265,7 @@ int bt_socket_unset_connection_requested_cb(void) int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_CONNECTION_STATE_CHANGED, callback, user_data); @@ -218,6 +274,7 @@ int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed int bt_socket_unset_connection_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_CONNECTION_STATE_CHANGED); return BT_ERROR_NONE; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index c56d3df..214d3db 100755 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -35,7 +35,7 @@ #include "bluetooth.h" #include "bluetooth_internal.h" -#include "bluetooth_extention.h" +#include "bluetooth_extension.h" #include "bluetooth-telephony-api.h" #include "bt_unit_test.h"