Zephyr Project
A Scalable Open Source RTOS for IoT Embedded Devices
bluetooth.h File Reference

Bluetooth subsystem core APIs. More...

#include <stdbool.h>
#include <string.h>
#include <sys/util.h>
#include <net/buf.h>
#include <bluetooth/gap.h>
#include <bluetooth/addr.h>
#include <bluetooth/crypto.h>

Go to the source code of this file.

Data Structures

struct  bt_le_ext_adv_sent_info
 
struct  bt_le_ext_adv_connected_info
 
struct  bt_le_ext_adv_scanned_info
 
struct  bt_le_ext_adv_cb
 
struct  bt_data
 Bluetooth data. More...
 
struct  bt_le_adv_param
 
struct  bt_le_per_adv_param
 
struct  bt_le_ext_adv_start_param
 
struct  bt_le_ext_adv_info
 Advertising set info structure. More...
 
struct  bt_le_per_adv_sync_synced_info
 
struct  bt_le_per_adv_sync_term_info
 
struct  bt_le_per_adv_sync_recv_info
 
struct  bt_le_per_adv_sync_state_info
 
struct  bt_le_per_adv_sync_cb
 
struct  bt_le_per_adv_sync_param
 
struct  bt_le_per_adv_sync_info
 Advertising set info structure. More...
 
struct  bt_le_per_adv_sync_transfer_param
 
struct  bt_le_scan_param
 
struct  bt_le_scan_recv_info
 
struct  bt_le_scan_cb
 
struct  bt_le_oob_sc_data
 
struct  bt_le_oob
 
struct  bt_br_discovery_result
 BR/EDR discovery result structure. More...
 
struct  bt_br_discovery_param
 
struct  bt_br_oob
 
struct  bt_bond_info
 

Macros

#define BT_ID_DEFAULT   0
 
#define BT_DATA(_type, _data, _data_len)
 Helper to declare elements of bt_data arrays. More...
 
#define BT_DATA_BYTES(_type, _bytes...)
 Helper to declare elements of bt_data arrays. More...
 
#define BT_LE_ADV_PARAM_INIT(_options, _int_min, _int_max, _peer)
 Initialize advertising parameters. More...
 
#define BT_LE_ADV_PARAM(_options, _int_min, _int_max, _peer)
 Helper to declare advertising parameters inline. More...
 
#define BT_LE_ADV_CONN_DIR(_peer)
 
#define BT_LE_ADV_CONN
 
#define BT_LE_ADV_CONN_NAME
 
#define BT_LE_ADV_CONN_NAME_AD
 
#define BT_LE_ADV_CONN_DIR_LOW_DUTY(_peer)
 
#define BT_LE_ADV_NCONN
 
#define BT_LE_ADV_NCONN_NAME
 
#define BT_LE_ADV_NCONN_IDENTITY
 
#define BT_LE_EXT_ADV_CONN_NAME
 
#define BT_LE_EXT_ADV_NCONN
 
#define BT_LE_EXT_ADV_NCONN_NAME
 
#define BT_LE_EXT_ADV_NCONN_IDENTITY
 
#define BT_LE_EXT_ADV_CODED_NCONN
 
#define BT_LE_EXT_ADV_CODED_NCONN_NAME
 
#define BT_LE_EXT_ADV_CODED_NCONN_IDENTITY
 
#define BT_LE_EXT_ADV_START_PARAM_INIT(_timeout, _n_evts)
 
#define BT_LE_EXT_ADV_START_PARAM(_timeout, _n_evts)
 
#define BT_LE_EXT_ADV_START_DEFAULT   BT_LE_EXT_ADV_START_PARAM(0, 0)
 
#define BT_LE_PER_ADV_PARAM_INIT(_int_min, _int_max, _options)
 
#define BT_LE_PER_ADV_PARAM(_int_min, _int_max, _options)
 
#define BT_LE_PER_ADV_DEFAULT
 
#define BT_LE_SCAN_PARAM_INIT(_type, _options, _interval, _window)
 Initialize scan parameters. More...
 
#define BT_LE_SCAN_PARAM(_type, _options, _interval, _window)
 Helper to declare scan parameters inline. More...
 
#define BT_LE_SCAN_ACTIVE
 Helper macro to enable active scanning to discover new devices. More...
 
#define BT_LE_SCAN_PASSIVE
 Helper macro to enable passive scanning to discover new devices. More...
 
#define BT_LE_SCAN_CODED_ACTIVE
 Helper macro to enable active scanning to discover new devices. Include scanning on Coded PHY in addition to 1M PHY. More...
 
#define BT_LE_SCAN_CODED_PASSIVE
 Helper macro to enable passive scanning to discover new devices. Include scanning on Coded PHY in addition to 1M PHY. More...
 

Typedefs

typedef void(* bt_ready_cb_t) (int err)
 Callback for notifying that Bluetooth has been enabled. More...
 
typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, struct net_buf_simple *buf)
 Callback type for reporting LE scan results. More...
 
typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results, size_t count)
 Callback type for reporting BR/EDR discovery (inquiry) results. More...
 

Enumerations

enum  {
  BT_LE_ADV_OPT_NONE = 0, BT_LE_ADV_OPT_CONNECTABLE = BIT(0), BT_LE_ADV_OPT_ONE_TIME = BIT(1), BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
  BT_LE_ADV_OPT_USE_NAME = BIT(3), BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY = BIT(4), BT_LE_ADV_OPT_DIR_ADDR_RPA = BIT(5), BT_LE_ADV_OPT_FILTER_SCAN_REQ = BIT(6),
  BT_LE_ADV_OPT_FILTER_CONN = BIT(7), BT_LE_ADV_OPT_NOTIFY_SCAN_REQ = BIT(8), BT_LE_ADV_OPT_SCANNABLE = BIT(9), BT_LE_ADV_OPT_EXT_ADV = BIT(10),
  BT_LE_ADV_OPT_NO_2M = BIT(11), BT_LE_ADV_OPT_CODED = BIT(12), BT_LE_ADV_OPT_ANONYMOUS = BIT(13), BT_LE_ADV_OPT_USE_TX_POWER = BIT(14),
  BT_LE_ADV_OPT_DISABLE_CHAN_37 = BIT(15), BT_LE_ADV_OPT_DISABLE_CHAN_38 = BIT(16), BT_LE_ADV_OPT_DISABLE_CHAN_39 = BIT(17), BT_LE_ADV_OPT_FORCE_NAME_IN_AD = BIT(18)
}
 
enum  { BT_LE_PER_ADV_OPT_NONE = 0, BT_LE_PER_ADV_OPT_USE_TX_POWER = BIT(1) }
 
enum  {
  BT_LE_PER_ADV_SYNC_OPT_NONE = 0, BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST = BIT(0), BT_LE_PER_ADV_SYNC_OPT_REPORTING_INITIALLY_DISABLED = BIT(1), BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOA = BIT(2),
  BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOD_1US = BIT(3), BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOD_2US = BIT(4), BT_LE_PER_ADV_SYNC_OPT_SYNC_ONLY_CONST_TONE_EXT = BIT(5)
}
 
enum  {
  BT_LE_PER_ADV_SYNC_TRANSFER_OPT_NONE = 0, BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOA = BIT(0), BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOD_1US = BIT(1), BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOD_2US = BIT(2),
  BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_ONLY_CTE = BIT(3)
}
 
enum  {
  BT_LE_SCAN_OPT_NONE = 0, BT_LE_SCAN_OPT_FILTER_DUPLICATE = BIT(0), BT_LE_SCAN_OPT_FILTER_WHITELIST = BIT(1), BT_LE_SCAN_OPT_CODED = BIT(2),
  BT_LE_SCAN_OPT_NO_1M = BIT(3)
}
 
enum  { BT_LE_SCAN_TYPE_PASSIVE = 0x00, BT_LE_SCAN_TYPE_ACTIVE = 0x01 }
 

Functions

int bt_enable (bt_ready_cb_t cb)
 Enable Bluetooth. More...
 
int bt_set_name (const char *name)
 Set Bluetooth Device Name. More...
 
const char * bt_get_name (void)
 Get Bluetooth Device Name. More...
 
int bt_set_id_addr (const bt_addr_le_t *addr)
 Set the local Identity Address. More...
 
void bt_id_get (bt_addr_le_t *addrs, size_t *count)
 Get the currently configured identities. More...
 
int bt_id_create (bt_addr_le_t *addr, uint8_t *irk)
 Create a new identity. More...
 
int bt_id_reset (uint8_t id, bt_addr_le_t *addr, uint8_t *irk)
 Reset/reclaim an identity for reuse. More...
 
int bt_id_delete (uint8_t id)
 Delete an identity. More...
 
int bt_le_adv_start (const struct bt_le_adv_param *param, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len)
 Start advertising. More...
 
int bt_le_adv_update_data (const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len)
 Update advertising. More...
 
int bt_le_adv_stop (void)
 Stop advertising. More...
 
int bt_le_ext_adv_create (const struct bt_le_adv_param *param, const struct bt_le_ext_adv_cb *cb, struct bt_le_ext_adv **adv)
 Create advertising set. More...
 
int bt_le_ext_adv_start (struct bt_le_ext_adv *adv, struct bt_le_ext_adv_start_param *param)
 Start advertising with the given advertising set. More...
 
int bt_le_ext_adv_stop (struct bt_le_ext_adv *adv)
 Stop advertising with the given advertising set. More...
 
int bt_le_ext_adv_set_data (struct bt_le_ext_adv *adv, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len)
 Set an advertising set's advertising or scan response data. More...
 
int bt_le_ext_adv_update_param (struct bt_le_ext_adv *adv, const struct bt_le_adv_param *param)
 Update advertising parameters. More...
 
int bt_le_ext_adv_delete (struct bt_le_ext_adv *adv)
 Delete advertising set. More...
 
uint8_t bt_le_ext_adv_get_index (struct bt_le_ext_adv *adv)
 Get array index of an advertising set. More...
 
int bt_le_ext_adv_get_info (const struct bt_le_ext_adv *adv, struct bt_le_ext_adv_info *info)
 Get advertising set info. More...
 
int bt_le_per_adv_set_param (struct bt_le_ext_adv *adv, const struct bt_le_per_adv_param *param)
 Set or update the periodic advertising parameters. More...
 
int bt_le_per_adv_set_data (const struct bt_le_ext_adv *adv, const struct bt_data *ad, size_t ad_len)
 Set or update the periodic advertising data. More...
 
int bt_le_per_adv_start (struct bt_le_ext_adv *adv)
 Starts periodic advertising. More...
 
int bt_le_per_adv_stop (struct bt_le_ext_adv *adv)
 Stops periodic advertising. More...
 
uint8_t bt_le_per_adv_sync_get_index (struct bt_le_per_adv_sync *per_adv_sync)
 Get array index of an periodic advertising sync object. More...
 
int bt_le_per_adv_sync_get_info (struct bt_le_per_adv_sync *per_adv_sync, struct bt_le_per_adv_sync_info *info)
 Get periodic adv sync information. More...
 
struct bt_le_per_adv_sync * bt_le_per_adv_sync_lookup_addr (const bt_addr_le_t *adv_addr, uint8_t sid)
 Look up an existing periodic advertising sync object by advertiser address. More...
 
int bt_le_per_adv_sync_create (const struct bt_le_per_adv_sync_param *param, struct bt_le_per_adv_sync **out_sync)
 Create a periodic advertising sync object. More...
 
int bt_le_per_adv_sync_delete (struct bt_le_per_adv_sync *per_adv_sync)
 Delete periodic advertising sync. More...
 
void bt_le_per_adv_sync_cb_register (struct bt_le_per_adv_sync_cb *cb)
 Register periodic advertising sync callbacks. More...
 
int bt_le_per_adv_sync_recv_enable (struct bt_le_per_adv_sync *per_adv_sync)
 Enables receiving periodic advertising reports for a sync. More...
 
int bt_le_per_adv_sync_recv_disable (struct bt_le_per_adv_sync *per_adv_sync)
 Disables receiving periodic advertising reports for a sync. More...
 
int bt_le_per_adv_sync_transfer (const struct bt_le_per_adv_sync *per_adv_sync, const struct bt_conn *conn, uint16_t service_data)
 Transfer the periodic advertising sync information to a peer device. More...
 
int bt_le_per_adv_set_info_transfer (const struct bt_le_ext_adv *adv, const struct bt_conn *conn, uint16_t service_data)
 Transfer the information about a periodic advertising set. More...
 
int bt_le_per_adv_sync_transfer_subscribe (const struct bt_conn *conn, const struct bt_le_per_adv_sync_transfer_param *param)
 Subscribe to periodic advertising sync transfers (PASTs). More...
 
int bt_le_per_adv_sync_transfer_unsubscribe (const struct bt_conn *conn)
 Unsubscribe from periodic advertising sync transfers (PASTs). More...
 
int bt_le_per_adv_list_add (const bt_addr_le_t *addr, uint8_t sid)
 Add a device to the periodic advertising list. More...
 
int bt_le_per_adv_list_remove (const bt_addr_le_t *addr, uint8_t sid)
 Remove a device from the periodic advertising list. More...
 
int bt_le_per_adv_list_clear (void)
 Clear the periodic advertising list. More...
 
int bt_le_scan_start (const struct bt_le_scan_param *param, bt_le_scan_cb_t cb)
 Start (LE) scanning. More...
 
int bt_le_scan_stop (void)
 Stop (LE) scanning. More...
 
void bt_le_scan_cb_register (struct bt_le_scan_cb *cb)
 Register scanner packet callbacks. More...
 
void bt_le_scan_cb_unregister (struct bt_le_scan_cb *cb)
 Unregister scanner packet callbacks. More...
 
int bt_le_whitelist_add (const bt_addr_le_t *addr)
 Add device (LE) to whitelist. More...
 
int bt_le_whitelist_rem (const bt_addr_le_t *addr)
 Remove device (LE) from whitelist. More...
 
int bt_le_whitelist_clear (void)
 Clear whitelist. More...
 
int bt_le_set_chan_map (uint8_t chan_map[5])
 Set (LE) channel map. More...
 
void bt_data_parse (struct net_buf_simple *ad, bool(*func)(struct bt_data *data, void *user_data), void *user_data)
 Helper for parsing advertising (or EIR or OOB) data. More...
 
int bt_le_oob_get_local (uint8_t id, struct bt_le_oob *oob)
 Get local LE Out of Band (OOB) information. More...
 
int bt_le_ext_adv_oob_get_local (struct bt_le_ext_adv *adv, struct bt_le_oob *oob)
 Get local LE Out of Band (OOB) information. More...
 
int bt_br_discovery_start (const struct bt_br_discovery_param *param, struct bt_br_discovery_result *results, size_t count, bt_br_discovery_cb_t cb)
 Start BR/EDR discovery. More...
 
int bt_br_discovery_stop (void)
 Stop BR/EDR discovery. More...
 
int bt_br_oob_get_local (struct bt_br_oob *oob)
 Get BR/EDR local Out Of Band information. More...
 
int bt_br_set_discoverable (bool enable)
 Enable/disable set controller in discoverable state. More...
 
int bt_br_set_connectable (bool enable)
 Enable/disable set controller in connectable state. More...
 
int bt_unpair (uint8_t id, const bt_addr_le_t *addr)
 Clear pairing information. More...
 
void bt_foreach_bond (uint8_t id, void(*func)(const struct bt_bond_info *info, void *user_data), void *user_data)
 Iterate through all existing bonds. More...
 

Detailed Description

Bluetooth subsystem core APIs.