[ English | 简体中文 ]
Bluetooth GAP API
The openvela Bluetooth GAP (Generic Access Profile) interface provides adapter management, including enabling/disabling, device discovery, property configuration, and pairing management.
Header file: #include "bt_adapter.h"
openvela Implementation Notes
- Dual-mode support: Supports independent control of Classic Bluetooth (BR/EDR) and Bluetooth Low Energy (BLE)
- Asynchronous mode: Most APIs provide both synchronous and asynchronous versions. Asynchronous versions are named with the
_asyncsuffix and return results via callback - Instance management: The first parameter of every API is
bt_instance_t* ins(Bluetooth client instance), obtained frombt_open() - State machine: The adapter state follows the transition flow OFF → BLE_TURNING_ON → BLE_ON → TURNING_ON → ON
Adapter Control
bt_adapter_get_state
bt_adapter_state_t bt_adapter_get_state(bt_instance_t* ins);
Gets the adapter state.
Parameters:
insBluetooth client instance, see bt_instance_t.
Returns:
The current adapter state.
bt_adapter_is_support_le
bool bt_adapter_is_support_le(bt_instance_t* ins);
Queries whether BLE is supported.
Parameters:
insBluetooth client instance.
Returns:
Returns true if BLE is supported, false otherwise.
bt_adapter_is_support_leaudio
bool bt_adapter_is_support_leaudio(bt_instance_t* ins);
Queries whether LE Audio is supported.
Parameters:
insBluetooth client instance.
Returns:
Returns true if LE Audio is supported, false otherwise.
Device Discovery
bt_adapter_set_discovery_filter
bt_status_t bt_adapter_set_discovery_filter(bt_instance_t* ins);
Sets the device discovery filter.
Parameters:
insBluetooth client instance, see bt_instance_t.
bt_adapter_start_discovery
bt_status_t bt_adapter_start_discovery(bt_instance_t* ins, uint32_t timeout);
Starts device discovery.
Parameters:
insBluetooth client instance, see bt_instance_t.timeoutTimeout duration.
Returns:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
bt_adapter_cancel_discovery
bt_status_t bt_adapter_cancel_discovery(bt_instance_t* ins);
Cancels device discovery.
Parameters:
insBluetooth client instance, see bt_instance_t.
Returns:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
bt_adapter_is_discovering
bool bt_adapter_is_discovering(bt_instance_t* ins);
Queries whether a device discovery is in progress.
Parameters:
insBluetooth client instance.
Returns:
Returns true if discovery is in progress, false otherwise.
Property Management
bt_adapter_get_type
bt_device_type_t bt_adapter_get_type(bt_instance_t* ins);
Gets the device type.
Parameters:
insBluetooth client instance, see bt_instance_t.
bt_adapter_set_name
bt_status_t bt_adapter_set_name(bt_instance_t* ins, const char* name);
Sets the device name.
Parameters:
insBluetooth client instance.nameName.
Returns:
Returns BT_STATUS_SUCCESS on success, or a negative error code on failure.
bt_adapter_get_name
void bt_adapter_get_name(bt_instance_t* ins, char* name, int length);
Gets the device name.
Parameters:
insBluetooth client instance, see bt_instance_t.nameOutput parameter, stores the adapter name.lengthBuffer length.
bt_adapter_set_scan_mode
bt_status_t bt_adapter_set_scan_mode(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable);
Sets the scan mode.
Parameters:
insBluetooth client instance.modeScan mode.bondableWhether pairing is allowed.
Returns:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
bt_adapter_get_scan_mode
bt_scan_mode_t bt_adapter_get_scan_mode(bt_instance_t* ins);
Gets the scan mode.
Parameters:
insBluetooth client instance.
Returns:
The current scan mode.
bt_adapter_set_device_class
bt_status_t bt_adapter_set_device_class(bt_instance_t* ins, uint32_t cod);
Sets the device class (CoD).
Parameters:
insBluetooth client instance.codDevice class (CoD).
Returns:
Returns BT_STATUS_SUCCESS on success, or a negative error code on failure.
bt_adapter_get_device_class
uint32_t bt_adapter_get_device_class(bt_instance_t* ins);
Gets the device class (CoD).
Parameters:
insBluetooth client instance.
Returns:
The current device class (CoD).
bt_adapter_set_debug_mode
bt_status_t bt_adapter_set_debug_mode(bt_instance_t* ins, bt_debug_mode_t mode, uint8_t operation);
Sets the Bluetooth adapter debug mode for factory testing and RF certification.
Parameters:
insBluetooth client instance, see bt_instance_t.modeDebug mode.operationDebug operation.
bt_adapter_set_le_address
bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr);
Sets the local BLE address.
Parameters:
insBluetooth client instance, see bt_instance_t.addrPointer to the BLE identity address.
bt_adapter_set_le_appearance
bt_status_t bt_adapter_set_le_appearance(bt_instance_t* ins, uint16_t appearance);
Sets the BLE appearance value.
Parameters:
insBluetooth client instance, see bt_instance_t.appearanceBLE appearance value.
bt_adapter_le_add_whitelist_with_type
bt_status_t bt_adapter_le_add_whitelist_with_type(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type);
Adds a device of the specified address type to the BLE whitelist.
Parameters:
insBluetooth client instance, see bt_instance_t.addrDevice address.typeAddress type.
Pairing and Security
bt_adapter_set_io_capability
bt_status_t bt_adapter_set_io_capability(bt_instance_t* ins, bt_io_capability_t cap);
Sets the IO capability.
Parameters:
insBluetooth client instance, see bt_instance_t.capIO capability value.
bt_adapter_get_bonded_devices
bt_status_t bt_adapter_get_bonded_devices(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator);
Gets the list of bonded devices.
Parameters:
insBluetooth client instance, see bt_instance_t.transportTransport type, see bt_transport_t.allocatorMemory allocation function.addrOutput parameter, stores the array of bonded device addresses.numOutput parameter, stores the number of devices.
bt_adapter_disconnect_all_devices
void bt_adapter_disconnect_all_devices(bt_instance_t* ins);
Disconnects all connected devices.
Parameters:
insBluetooth client instance, see bt_instance_t.
bt_adapter_get_le_io_capability
uint32_t bt_adapter_get_le_io_capability(bt_instance_t* ins);
Gets the BLE IO capability.
Parameters:
insBluetooth client instance.
Returns:
Returns the BLE IO capability value.
BLE Management
bt_adapter_enable
bt_status_t bt_adapter_enable(bt_instance_t* ins);
Enables the Bluetooth adapter.
Parameters:
insBluetooth client instance.
Returns:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
bt_adapter_disable
bt_status_t bt_adapter_disable(bt_instance_t* ins);
Disables the Bluetooth adapter.
Parameters:
insBluetooth client instance, see bt_instance_t.
Returns:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
bt_adapter_disable_safe
bt_status_t bt_adapter_disable_safe(bt_instance_t* ins);
Safely disables the Bluetooth adapter, waiting for all connections to be disconnected before shutting down.
Parameters:
insBluetooth client instance, see bt_instance_t.
bt_adapter_disable_le
bt_status_t bt_adapter_disable_le(bt_instance_t* ins);
Disables Bluetooth Low Energy (BLE).
Parameters:
insBluetooth client instance, see bt_instance_t.
bt_adapter_is_le_enabled
bool bt_adapter_is_le_enabled(bt_instance_t* ins);
Queries whether BLE is enabled.
Parameters:
insBluetooth client instance.
Returns:
Returns true if BLE is enabled, false otherwise.
bt_adapter_le_enable_key_derivation
bt_status_t bt_adapter_le_enable_key_derivation(bt_instance_t* ins, bool brkey_to_lekey, bool lekey_to_brkey);
Enables BLE key derivation.
Parameters:
insBluetooth client instance, see bt_instance_t.brkey_to_lekeyWhether to enable BR→LE key derivation.lekey_to_brkeyWhether to enable LE→BR key derivation.
bt_adapter_le_remove_whitelist
bt_status_t bt_adapter_le_remove_whitelist(bt_instance_t* ins, bt_address_t* addr);
Removes a device from the BLE whitelist.
Parameters:
insBluetooth client instance, see bt_instance_t.addrAddress of the device to remove.
bt_adapter_set_page_scan_parameters
bt_status_t bt_adapter_set_page_scan_parameters(bt_instance_t* ins, bt_scan_type_t type, uint16_t interval, uint16_t window);
Sets the page scan parameters.
Parameters:
insBluetooth client instance, see bt_instance_t.typeScan type.intervalScan interval.windowScan window.
Asynchronous Interfaces
bt_adapter_register_callback_async
bt_status_t bt_adapter_register_callback_async(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs, bt_register_callback_cb_t cb, void* userdata);
Asynchronous version.
Parameters:
insBluetooth client instance.adapter_cbsAdapter callback function set.cbCallback function.userdataUser data.
bt_adapter_unregister_callback_async
bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cookie, bt_bool_cb_t cb, void* userdata);
Unregisters a callback function (asynchronous version).
Parameters:
insBluetooth client instance.cookieUser context.cbCallback function.userdataUser data.
bt_adapter_enable_async
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Adapter state change callback (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_disable_async
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Disables the Bluetooth adapter (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_enable_le_async
bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Enables Bluetooth Low Energy (BLE) (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_disable_le_async
bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Disables Bluetooth Low Energy (BLE) (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_get_state_async
bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_cb_t get_state_cb, void* userdata);
Gets the current adapter state (asynchronous version).
Parameters:
insBluetooth client instance.get_state_cbCallback function for getting the state.userdataUser data.
bt_adapter_is_le_enabled_async
bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
Checks if BLE is enabled (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_get_type_async
bt_status_t bt_adapter_get_type_async(bt_instance_t* ins, bt_device_type_cb_t get_dtype_cb, void* userdata);
Gets the adapter device type (asynchronous version).
Parameters:
insBluetooth client instance.get_dtype_cbCallback function for getting the device type.userdataUser data.
bt_adapter_set_discovery_filter_async
bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Sets the discovery filter (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_start_discovery_async
bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeout, bt_status_cb_t cb, void* userdata);
Starts device discovery (asynchronous version).
Parameters:
insBluetooth client instance.timeoutTimeout duration.cbCallback function.userdataUser data.
bt_adapter_cancel_discovery_async
bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Cancels device discovery (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_is_discovering_async
bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
Queries whether the adapter is performing device discovery (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_get_address_async
bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb, void* userdata);
Reads the Bluetooth controller address (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_set_name_async
bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_status_cb_t cb, void* userdata);
Sets the adapter local name (asynchronous version).
Parameters:
insBluetooth client instance.nameName.cbCallback function.userdataUser data.
bt_adapter_get_name_async
bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_name_cb, void* userdata);
Gets the adapter local name (asynchronous version).
Parameters:
insBluetooth client instance.get_name_cbCallback function for getting the name.userdataUser data.
bt_adapter_get_uuids_async
bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uuids_cb, void* userdata);
Gets the list of UUIDs supported by the adapter (asynchronous version).
Parameters:
insBluetooth client instance.get_uuids_cbCallback function for getting the UUID list.userdataUser data.
bt_adapter_set_scan_mode_async
bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable, bt_status_cb_t cb, void* userdata);
Sets the adapter scan mode (asynchronous version).
Parameters:
insBluetooth client instance.modeMode.bondableWhether pairing is allowed.cbCallback function.userdataUser data.
bt_adapter_get_scan_mode_async
bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_scan_mode_cb_t get_scan_mode_cb, void* userdata);
Gets the adapter scan mode (asynchronous version).
Parameters:
insBluetooth client instance.get_scan_mode_cbCallback function for getting the scan mode.userdataUser data.
bt_adapter_set_device_class_async
bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod, bt_status_cb_t cb, void* userdata);
Sets the adapter device class (asynchronous version).
Parameters:
insBluetooth client instance.codDevice class (CoD).cbCallback function.userdataUser data.
bt_adapter_get_device_class_async
bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t get_cod_cb, void* userdata);
Gets the adapter device class (asynchronous version).
Parameters:
insBluetooth client instance.get_cod_cbCallback function for getting the device class.userdataUser data.
bt_adapter_set_io_capability_async
bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capability_t cap, bt_status_cb_t cb, void* userdata);
Sets the BR/EDR adapter IO capability (asynchronous version).
Parameters:
insBluetooth client instance.capIO capability value.cbCallback function.userdataUser data.
bt_adapter_get_io_capability_async
bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_get_io_capability_cb_t get_ioc_cb, void* userdata);
Gets the BR/EDR adapter IO capability (asynchronous version).
Parameters:
insBluetooth client instance.get_ioc_cbCallback function for getting the IO capability.userdataUser data.
bt_adapter_set_inquiry_scan_parameters_async
bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type, uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata);
Sets the inquiry scan parameters (asynchronous version).
Parameters:
insBluetooth client instance.typeType.intervalInterval.windowScan window (in time slots).cbCallback function.userdataUser data.
bt_adapter_set_page_scan_parameters_async
bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type, uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata);
Sets the page scan parameters (asynchronous version).
Parameters:
insBluetooth client instance.typeType.intervalInterval.windowScan window (in time slots).cbCallback function.userdataUser data.
bt_adapter_set_le_io_capability_async
bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t le_io_cap, bt_status_cb_t cb, void* userdata);
Sets the BLE adapter IO capability (asynchronous version).
Parameters:
insBluetooth client instance.le_io_capBLE IO capability value.cbCallback function.userdataUser data.
bt_adapter_get_le_io_capability_async
bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_t get_le_ioc_cb, void* userdata);
Gets the BLE adapter IO capability (asynchronous version).
Parameters:
insBluetooth client instance.get_le_ioc_cbCallback function for getting the BLE IO capability.userdataUser data.
bt_adapter_get_le_address_async
bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_le_address_cb_t cb, void* userdata);
Gets the BLE adapter address (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_set_le_address_async
bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
Sets the BLE private address (asynchronous version).
Parameters:
insBluetooth client instance.addrRemote device Bluetooth address.cbCallback function.userdataUser data.
bt_adapter_set_le_identity_address_async
bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_address_t* addr, bool is_public, bt_status_cb_t cb, void* userdata);
Sets the BLE identity address (asynchronous version).
Parameters:
insBluetooth client instance.addrRemote device Bluetooth address.is_publicWhether to use a public address.cbCallback function.userdataUser data.
bt_adapter_set_le_appearance_async
bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appearance, bt_status_cb_t cb, void* userdata);
Sets the BLE adapter appearance (asynchronous version).
Parameters:
insBluetooth client instance.appearanceAppearance value.cbCallback function.userdataUser data.
bt_adapter_get_le_appearance_async
bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t cb, void* userdata);
Gets the BLE adapter appearance (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_le_enable_key_derivation_async
bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins, bool brkey_to_lekey, bool lekey_to_brkey, bt_status_cb_t cb, void* userdata);
Enables or disables cross-transport key derivation (asynchronous version).
Parameters:
insBluetooth client instance.brkey_to_lekeyWhether to enable BR key derivation to LE key.lekey_to_brkeyWhether to enable LE key derivation to BR key.cbCallback function.userdataUser data.
bt_adapter_le_add_whitelist_async
bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
Adds a device to the BLE whitelist (asynchronous version).
Parameters:
insBluetooth client instance.addrRemote device Bluetooth address.cbCallback function.userdataUser data.
bt_adapter_le_remove_whitelist_async
bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
Removes a device from the BLE whitelist (asynchronous version).
Parameters:
insBluetooth client instance.addrRemote device Bluetooth address.cbCallback function.userdataUser data.
bt_adapter_get_bonded_devices_async
bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_bonded_cb, void* userdata);
Gets the list of bonded devices (asynchronous version).
Parameters:
insBluetooth client instance.transportTransport type (BR/EDR or BLE).get_bonded_cbCallback function for getting the bonded device list.userdataUser data.
bt_adapter_get_connected_devices_async
bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_connected_cb, void* userdata);
Gets the list of connected devices (asynchronous version).
Parameters:
insBluetooth client instance.transportTransport type (BR/EDR or BLE).get_connected_cbCallback function for getting the connected device list.userdataUser data.
bt_adapter_set_afh_channel_classification_async
bt_status_t bt_adapter_set_afh_channel_classification_async(bt_instance_t* ins, uint16_t central_frequency, uint16_t band_width, uint16_t number, bt_status_cb_t cb, void* userdata);
Sets AFH (Adaptive Frequency Hopping) channel classification (asynchronous version).
Parameters:
insBluetooth client instance.central_frequencyCentral frequency (MHz).band_widthBandwidth (MHz).numberNumber.cbCallback function.userdataUser data.
bt_adapter_set_auto_sniff_async
bt_status_t bt_adapter_set_auto_sniff_async(bt_instance_t* ins, bt_auto_sniff_params_t* params, bt_status_cb_t cb, void* userdata);
Sets the automatic sniff mode parameters (asynchronous version).
Parameters:
insBluetooth client instance.paramsParameter structure.cbCallback function.userdataUser data.
bt_adapter_disconnect_all_devices_async
bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
Disconnects all connected devices (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_is_support_bredr_async
bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
Checks if BR/EDR is supported (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_is_support_le_async
bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
Checks if BLE is supported (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.
bt_adapter_is_support_leaudio_async
bt_status_t bt_adapter_is_support_leaudio_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
Queries whether LE Audio is supported (asynchronous version).
Parameters:
insBluetooth client instance.cbCallback function.userdataUser data.