Tizen Native API
|
Functions | |
int | bt_device_get_service_mask_from_uuid_list (char **uuids, int no_of_service, bt_service_class_t *service_mask_list) |
Get the service mask from the uuid list. | |
int | bt_device_create_bond (const char *remote_address) |
Creates a bond with a remote Bluetooth device, asynchronously. | |
int | bt_device_cancel_bonding (void) |
Cancels the bonding process. | |
int | bt_device_destroy_bond (const char *remote_address) |
Destroys the bond, asynchronously. | |
int | bt_device_set_alias (const char *remote_address, const char *alias) |
Sets an alias for the bonded device. | |
int | bt_device_set_authorization (const char *remote_address, bt_device_authorization_e authorization_state) |
Sets the authorization of a bonded device, asynchronously. | |
int | bt_device_start_service_search (const char *remote_address) |
Starts the search for services supported by the specified device, asynchronously. | |
int | bt_device_foreach_connected_profiles (const char *remote_address, bt_device_connected_profile callback, void *user_data) |
Gets the connected profiles. | |
int | bt_device_is_profile_connected (const char *remote_address, bt_profile_e bt_profile, bool *connected_status) |
Gets the profile connected status. | |
int | bt_device_set_bond_created_cb (bt_device_bond_created_cb callback, void *user_data) |
Registers a callback function to be invoked when the bond creates. | |
int | bt_device_unset_bond_created_cb (void) |
Unregisters the callback function. | |
int | bt_device_set_bond_destroyed_cb (bt_device_bond_destroyed_cb callback, void *user_data) |
Registers a callback function to be invoked when the bond destroys. | |
int | bt_device_unset_bond_destroyed_cb (void) |
Unregisters the callback function. | |
int | bt_device_set_authorization_changed_cb (bt_device_authorization_changed_cb callback, void *user_data) |
Registers a callback function to be invoked when the authorization of device changes. | |
int | bt_device_unset_authorization_changed_cb (void) |
Unregisters the callback function. | |
int | bt_device_set_service_searched_cb (bt_device_service_searched_cb callback, void *user_data) |
Registers a callback function to be invoked when the process of service search finishes. | |
int | bt_device_unset_service_searched_cb (void) |
Unregisters the callback function. | |
int | bt_device_set_connection_state_changed_cb (bt_device_connection_state_changed_cb callback, void *user_data) |
Registers a callback function to be invoked when the connection state is changed. | |
int | bt_device_unset_connection_state_changed_cb (void) |
Unregisters the callback function to be invoked when the connection state is changed. | |
Typedefs | |
typedef void(* | bt_device_bond_created_cb )(int result, bt_device_info_s *device_info, void *user_data) |
Called when the process of creating bond finishes. | |
typedef bool(* | bt_device_connected_profile )(bt_profile_e profile, void *user_data) |
Called when you get connected profiles repeatedly. | |
typedef void(* | bt_device_bond_destroyed_cb )(int result, char *remote_address, void *user_data) |
Called when the bond destroys. | |
typedef void(* | bt_device_authorization_changed_cb )(bt_device_authorization_e authorization, char *remote_address, void *user_data) |
Called when the authorization of device changes. | |
typedef void(* | bt_device_service_searched_cb )(int result, bt_device_sdp_info_s *sdp_info, void *user_data) |
Called when the process of service search finishes. | |
typedef void(* | bt_device_connection_state_changed_cb )(bool connected, bt_device_connection_info_s *conn_info, void *user_data) |
Called when the connection state is changed. |
Bluetooth Device API provides functions for managing bonds with other devices and searching for supported services.
Required Header
#include <bluetooth.h>
Overview
This set of functions is used to handle the connection with other devices. Connected devices exchange keys needed for encrypted communication, but each connection has to be approved by the latest application user. You can also set authorization of other devices. Authorized devices are connected, and it is connected automatically without the latest user being asked for authorization. In addition, this is used to search for services available on remote devices.
Related Features
This API is related with the following features:
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information,thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Asynchronous Operations
FUNCTION | CALLBACK | DESCRIPTION |
---|---|---|
bt_device_create_bond() bt_device_cancel_bonding() | bt_device_bond_created_cb() | Used to create bond or cancel creating bond. |
bt_device_destroy_bond() | bt_device_bond_destroyed_cb() | Used to destroy bond. |
bt_device_set_authorization() | bt_device_authorization_changed_cb() | Used to set as authorized or unauthorized device. |
bt_device_start_service_search() | bt_device_service_searched_cb() | Used to start or cancel service search. |
Callback(Event) Operations
REGISTER | UNREGISTER | CALLBACK | DESCRIPTION |
---|---|---|---|
bt_device_set_bond_created_cb() | bt_device_unset_bond_created_cb() | bt_device_bond_created_cb() | Used to be notified of the result of creating bond. |
bt_device_set_bond_destroyed_cb() | bt_device_unset_bond_destroyed_cb() | bt_device_bond_destroyed_cb() | Used to be notified of the result of destroying bond. |
bt_device_set_authorization_changed_cb() | bt_device_unset_authorization_changed_cb() | bt_device_authorization_changed_cb() | Used to be notified of change of authorization. |
bt_device_set_service_searched_cb() | bt_device_unset_service_searched_cb() | bt_device_service_searched_cb() | Used to be notified of change of service search state. |
Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api.
Typedef Documentation
typedef void(* bt_device_authorization_changed_cb)(bt_device_authorization_e authorization, char *remote_address, void *user_data) |
Called when the authorization of device changes.
- Since :
- 2.3
- Parameters:
-
[in] authorization The authorization of device [in] remote_address The address of the remote Bluetooth device which is (un)authorized [in] user_data The user data passed from the callback registration function
- Precondition:
- bt_device_set_authorization() will invoke this function if you register this callback using bt_device_set_authorization_changed_cb().
typedef void(* bt_device_bond_created_cb)(int result, bt_device_info_s *device_info, void *user_data) |
Called when the process of creating bond finishes.
- Since :
- 2.3
- Remarks:
- If the remote user does not respond within 60 seconds, a time out will happen with BT_ERROR_TIMED_OUT result code.
If bt_device_cancel_bonding() is called and it returns BT_ERROR_NONE, then this callback function will be called with BT_ERROR_CANCELLED result.
If creating a bond succeeds but service search fails, then this callback will be called with BT_ERROR_SERVICE_SEARCH_FAILED. In this case, you should try service search again by bt_device_start_service_search() to get the supported service list.
- Parameters:
-
[in] result The result of the bonding device [in] device_info The device information which you creates bond with [in] user_data The user data passed from the callback registration function
- Precondition:
- Either bt_device_create_bond() will invoke this function if you register this callback using bt_device_set_bond_created_cb().
typedef void(* bt_device_bond_destroyed_cb)(int result, char *remote_address, void *user_data) |
Called when the bond destroys.
- Since :
- 2.3
- Parameters:
-
[in] result The result that a bond is destroyed [in] remote_address The address of the remote Bluetooth device to destroy bond with [in] user_data The user data passed from the callback registration function
- Precondition:
- bt_device_destroy_bond() will invoke this function if you register this callback using bt_device_set_bond_destroyed_cb().
typedef bool(* bt_device_connected_profile)(bt_profile_e profile, void *user_data) |
Called when you get connected profiles repeatedly.
- Since :
- 2.3
- Parameters:
-
[in] profile The connected Bluetooth profile [in] user_data The user data passed from the foreach function
- Returns:
true
to continue with the next iteration of the loop,
false
to break out of the loop.
- Precondition:
- bt_device_foreach_connected_profiles() will invoke this function.
typedef void(* bt_device_connection_state_changed_cb)(bool connected, bt_device_connection_info_s *conn_info, void *user_data) |
Called when the connection state is changed.
- Since :
- 2.3
- Parameters:
-
[in] connected The connection status: ( true
= connected,false
= disconnected)[in] conn_info The connection information [in] user_data The user data passed from the callback registration function
typedef void(* bt_device_service_searched_cb)(int result, bt_device_sdp_info_s *sdp_info, void *user_data) |
Called when the process of service search finishes.
- Since :
- 2.3
- Remarks:
- Parameters:
-
[in] result The result of the service searching [in] sdp_info The structure of service lists found on a device [in] user_data The user data passed from the callback registration function
- Precondition:
- Either bt_device_start_service_search() will invoke this function if you register this callback using bt_device_set_service_searched_cb().
Enumeration Type Documentation
enum bt_appearance_type_e |
Enumerations of gap appearance type.
- Since :
- 2.3
Enumerations of device disconnect reason.
- Since :
- 2.3
Enumerations of major device class.
- Since :
- 2.3
- Enumerator:
Enumerations of major service class.
- Since :
- 2.3
- Enumerator:
Enumerations of minor device class.
- Since :
- 2.3
- Enumerator:
enum bt_profile_e |
Enumerations of Bluetooth profile.
- Since :
- 2.3
- Enumerator:
enum bt_service_class_t |
Enumerations of service class.
- Since :
- 2.3
- Enumerator:
Function Documentation
int bt_device_cancel_bonding | ( | void | ) |
Cancels the bonding process.
- Since :
- 2.3
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Remarks:
- Use this function when the remote Bluetooth device is not responding to the bond request or you wish to cancel the bonding request.
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_NOT_IN_PROGRESS Operation not in progress BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The creating a bond must be in progress by bt_device_create_bond().
int bt_device_create_bond | ( | const char * | remote_address | ) |
Creates a bond with a remote Bluetooth device, asynchronously.
- Since :
- 2.3
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Remarks:
- A bond can be destroyed by bt_device_destroy_bond().
The bonding request can be cancelled by bt_device_cancel_bonding().
- Parameters:
-
[in] remote_address The address of the remote Bluetooth device with which the bond should be created
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_RESOURCE_BUSY Device or resource busy BT_ERROR_OPERATION_FAILED Operation failed BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- The remote device must be discoverable with bt_adapter_start_device_discovery().
- Postcondition:
- This function invokes bt_device_bond_created_cb().
int bt_device_destroy_bond | ( | const char * | remote_address | ) |
Destroys the bond, asynchronously.
- Since :
- 2.3
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Parameters:
-
[in] remote_address The address of the remote Bluetooth device to remove bonding
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_RESOURCE_BUSY Device or resource busy BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded BT_ERROR_OPERATION_FAILED Operation failed BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- The bond with the remote device must be created with bt_device_create_bond().
- Postcondition:
- This function invokes bt_device_bond_destroyed_cb().
int bt_device_foreach_connected_profiles | ( | const char * | remote_address, |
bt_device_connected_profile | callback, | ||
void * | user_data | ||
) |
Gets the connected profiles.
- Since :
- 2.3
- Parameters:
-
[in] remote_address The address of the remote device [in] callback The callback function to invoke [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- Postcondition:
- bt_device_connected_profile() will be invoked.
- See also:
- bt_device_connected_profile()
int bt_device_get_service_mask_from_uuid_list | ( | char ** | uuids, |
int | no_of_service, | ||
bt_service_class_t * | service_mask_list | ||
) |
Get the service mask from the uuid list.
- Since :
- 2.3
- Parameters:
-
[in] uuids The UUID list of the device. [in] no_of_service The number of the UUID list count. [out] service_mask_list Service mask list converted from the given UUID list.
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- See also:
- bt_service_class_t
int bt_device_is_profile_connected | ( | const char * | remote_address, |
bt_profile_e | bt_profile, | ||
bool * | connected_status | ||
) |
Gets the profile connected status.
- Since :
- 2.3
- Parameters:
-
[in] remote_address The address of the remote device [in] bt_profile wish to know bt_profile [out] connected_status the connected status
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded BT_ERROR_OPERATION_FAILED Operation failed BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
int bt_device_set_alias | ( | const char * | remote_address, |
const char * | alias | ||
) |
Sets an alias for the bonded device.
- Since :
- 2.3
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Parameters:
-
[in] remote_address The address of the remote Bluetooth device [in] alias The alias of the remote Bluetooth device
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded BT_ERROR_OPERATION_FAILED Operation failed BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- The bond with the remote device must be created with bt_device_create_bond().
- See also:
- bt_device_create_bond()
int bt_device_set_authorization | ( | const char * | remote_address, |
bt_device_authorization_e | authorization_state | ||
) |
Sets the authorization of a bonded device, asynchronously.
- Since :
- 2.3
- Privilege Level:
- public
- Privilege:
- http://tizen.org/privilege/bluetooth
- Remarks:
- Once a device is authorized, you don't need to receive a confirmation.
- Parameters:
-
[in] remote_address The address of the remote Bluetooth device to authorize [in] authorization_state The Bluetooth authorization state
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded BT_ERROR_OPERATION_FAILED Operation failed BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- The bond with the remote device must be created with bt_device_create_bond().
- Postcondition:
- bt_device_authorization_changed_cb() will be invoked.
int bt_device_set_authorization_changed_cb | ( | bt_device_authorization_changed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be invoked when the authorization of device changes.
- Since :
- 2.3
- Parameters:
-
[in] callback The callback function to register [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- bt_device_authorization_changed_cb() will be invoked.
int bt_device_set_bond_created_cb | ( | bt_device_bond_created_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be invoked when the bond creates.
- Since :
- 2.3
- Parameters:
-
[in] callback The callback function to register [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- bt_device_bond_created_cb() will be invoked.
int bt_device_set_bond_destroyed_cb | ( | bt_device_bond_destroyed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be invoked when the bond destroys.
- Since :
- 2.3
- Parameters:
-
[in] callback The callback function to register [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- bt_device_bond_destroyed_cb() will be invoked.
int bt_device_set_connection_state_changed_cb | ( | bt_device_connection_state_changed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be invoked when the connection state is changed.
- Since :
- 2.3
- Parameters:
-
[in] callback The callback function to register [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- bt_device_connection_state_changed_cb() will be invoked.
int bt_device_set_service_searched_cb | ( | bt_device_service_searched_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be invoked when the process of service search finishes.
- Since :
- 2.3
- Parameters:
-
[in] callback The callback function to register [in] user_data The user data to be passed to the callback function
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
- Postcondition:
- bt_device_service_searched_cb() will be invoked.
int bt_device_start_service_search | ( | const char * | remote_address | ) |
Starts the search for services supported by the specified device, asynchronously.
- Since :
- 2.3
- Privilege Level:
- 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.
The service search takes a couple of seconds to complete normally.
- Parameters:
-
[in] remote_address The address of the remote Bluetooth device whose services need to be checked
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_INVALID_PARAMETER Invalid parameter BT_ERROR_NOT_ENABLED Not enabled BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded BT_ERROR_SERVICE_SEARCH_FAILED Service search failed BT_ERROR_PERMISSION_DENIED Permission denied BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The state of local Bluetooth must be BT_ADAPTER_ENABLED.
- The remote device must be discoverable with bt_adapter_start_device_discovery().
- The bond with the remote device must be created with bt_device_create_bond().
- Postcondition:
- This function invokes bt_device_service_searched_cb().
int bt_device_unset_authorization_changed_cb | ( | void | ) |
Unregisters the callback function.
- Since :
- 2.3
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
int bt_device_unset_bond_created_cb | ( | void | ) |
Unregisters the callback function.
- Since :
- 2.3
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
int bt_device_unset_bond_destroyed_cb | ( | void | ) |
Unregisters the callback function.
- Since :
- 2.3
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
int bt_device_unset_connection_state_changed_cb | ( | void | ) |
Unregisters the callback function to be invoked when the connection state is changed.
- Since :
- 2.3
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().
int bt_device_unset_service_searched_cb | ( | void | ) |
Unregisters the callback function.
- Since :
- 2.3
- Returns:
- 0 on success, otherwise a negative error value.
- Return values:
-
BT_ERROR_NONE Successful BT_ERROR_NOT_INITIALIZED Not initialized BT_ERROR_NOT_SUPPORTED Not supported
- Precondition:
- The Bluetooth service must be initialized with bt_initialize().