Developer World
Spresense SDK Library v3.2.0-ebc0364
bt_common.h File Reference

Bluetooth generic API. More...

#include <stdint.h>
#include <bluetooth/bluetooth.h>

Go to the source code of this file.

Classes

struct  bt_common_state_s
 Bluetooth base context. More...
 
struct  bt_acl_state_s
 Bluetooth ACL context. More...
 
struct  ble_state_s
 Bluetooth LE context. More...
 
struct  ble_addr_s
 BLE address. More...
 
struct  ble_idkey_s
 
struct  ble_cccd_s
 
struct  ble_bondinfo_s
 Bluetooth LE bonding information. More...
 
struct  bt_common_ops_s
 Bluetooth Common application callbacks. More...
 
struct  ble_common_ops_s
 Bluetooth LE Common application callbacks. More...
 
struct  bt_eir_s
 The format of one data in advertising data. More...
 

Macros

#define BT_ADV_DATA_MAX_LEN   (255)
 
#define BT_ADV_DATA_LEN_LEN   (1)
 
#define BT_ADV_DATA_TYPE_LEN   (1)
 
#define BT_EIR_LEN
 
#define BLE_IRK_LEN   (16)
 
#define BLE_CSRK_LEN   (16)
 
#define BLE_LTK_LEN   (16)
 
#define BLE_RAND_LEN   (8)
 
#define BLESTAT_SUCCESS   0x00
 
#define BLESTAT_MEMCAP_EXCD   0x07
 
#define BLESTAT_CONNECT_TIMEOUT   0x08
 
#define BLESTAT_PEER_TERMINATED   0x13
 
#define BLESTAT_PEER_TERM_LOWRES   0x14
 
#define BLESTAT_PEER_TERM_POFF   0x15
 
#define BLESTAT_TERMINATED   0x16
 
#define BLESTAT_UNSPEC_ERR   0x1F
 
#define BLESTAT_DEVICE_BUSY   0x3A
 
#define BLESTAT_PARAM_REJECTED   0x3B
 
#define BLESTAT_CONNECT_FAILED   0x3E
 
#define EXTERN   extern "C"
 

Enumerations

enum  BT_CONNECT_STATUS { BT_DISCONNECTED = 0 , BT_DISCONNECTING = 1 , BT_CONNECTING = 2 , BT_CONNECTED = 3 }
 BT profile connection status. More...
 

Functions

int bt_init (void)
 Bluetooth module initialize For initialize a pin config, NV storage, UART, etc. More...
 
int bt_finalize (void)
 Bluetooth module finalize. More...
 
int bt_set_address (BT_ADDR *addr)
 Set Bluetooth module address This is Spresense side address and should be call before bt_enable. More...
 
int bt_get_address (BT_ADDR *addr)
 Get Bluetooth module address. More...
 
int bt_set_name (char *name)
 Set Bluetooth module name This name visible for other devices and should be call before bt_enable. More...
 
int bt_get_name (char *name)
 Get Bluetooth module name. More...
 
int bt_enable (void)
 Bluetooth module enable Bluetooth set power on(and download firmware, etc). More...
 
int bt_disable (void)
 Bluetooth module disable Bluetooth set power off. More...
 
int bt_pairing_enable (void)
 Bluetooth pairing enable Entering bluetooth pairing mode. More...
 
int bt_paring_disable (void)
 Bluetooth pairing disable Escaping bluetooth pairing mode. More...
 
int bt_get_bond_list (BT_ADDR *addr, int *num)
 Bluetooth get bond device list Get bond devices list with BD_ADDR. More...
 
int bt_unbond (BT_ADDR *addr)
 Bluetooth unbond by BD_ADDR Unbond device by BD_ADDR. More...
 
int bt_set_visibility (BT_VISIBILITY visibility)
 Bluetooth set visible Visible this device from others. More...
 
int bt_start_inquiry (void)
 Bluetooth inquiry start Start to inquiry for connect peer device. More...
 
int bt_cancel_inquiry (void)
 Bluetooth inquiry cancel Cancel to inquiry. More...
 
int bt_register_common_cb (struct bt_common_ops_s *bt_common_ops)
 Bluetooth register common callbacks Register Connect/Pairing/Inquiry callback. More...
 
int ble_set_address (BT_ADDR *addr)
 Set Bluetooth LE module address This is Spresense side address and should be call before bt_enable. More...
 
int ble_get_address (BT_ADDR *addr)
 Get Bluetooth LE module address. More...
 
int ble_set_name (char *name)
 Set Bluetooth LE module name This name visible for other devices and should be call before bt_enable. More...
 
int ble_get_name (char *name)
 Get Bluetooth LE module name. More...
 
int ble_enable (void)
 Bluetooth LE enable. More...
 
int ble_disable (void)
 Bluetooth LE disable. More...
 
int ble_connect (struct ble_state_s *ble_state)
 Bluetooth LE connect for Central. More...
 
int ble_disconnect (struct ble_state_s *ble_state)
 Bluetooth LE dicsonnect for Central. More...
 
int ble_start_advertise (void)
 Bluetooth LE start advertise Start BLE advertise mode. More...
 
int ble_cancel_advertise (void)
 Bluetooth LE cancel advertise Cancel BLE advertise mode. More...
 
int ble_start_scan (bool duplicate_filter)
 Bluetooth LE start scan Start BLE scan mode. More...
 
int ble_cancel_scan (void)
 Bluetooth LE cancel scan Cancel BLE scan mode. More...
 
int ble_register_common_cb (struct ble_common_ops_s *ble_common_ops)
 Bluetooth LE register common callbacks Register Connect/Advertise/Scan callback. More...
 
uint16_t ble_set_request_mtusize (uint16_t sz)
 Set MTU size that application requests. More...
 
uint16_t ble_get_request_mtusize (void)
 Get MTU size that application requests. More...
 
int ble_get_negotiated_mtusize (uint16_t handle)
 Get negotiated MTU size. More...
 
int ble_pairing (uint16_t handle)
 Execute pairing. More...
 
int ble_parse_advertising_data (BLE_AD_TYPE target, uint8_t *adv_data, uint8_t adv_len, struct bt_eir_s *eir)
 Parse advertise data. More...
 

Detailed Description

Bluetooth generic API.

Author
Sony Semiconductor Solutions Corporation

This API is generic functions for bluetooth operations

Macro Definition Documentation

◆ BT_EIR_LEN

#define BT_EIR_LEN
Value:
(BT_ADV_DATA_MAX_LEN \
- BT_ADV_DATA_LEN_LEN \
- BT_ADV_DATA_TYPE_LEN)

◆ BLESTAT_SUCCESS

#define BLESTAT_SUCCESS   0x00

BLE status code Success

◆ BLESTAT_MEMCAP_EXCD

#define BLESTAT_MEMCAP_EXCD   0x07

Memory Capacity Exceeded

◆ BLESTAT_CONNECT_TIMEOUT

#define BLESTAT_CONNECT_TIMEOUT   0x08

Connection Timeout

◆ BLESTAT_PEER_TERMINATED

#define BLESTAT_PEER_TERMINATED   0x13

Peer Device Terminated Connection

◆ BLESTAT_PEER_TERM_LOWRES

#define BLESTAT_PEER_TERM_LOWRES   0x14

Peer Device Terminated Connection due to Low Resources

◆ BLESTAT_PEER_TERM_POFF

#define BLESTAT_PEER_TERM_POFF   0x15

Peer Device Terminated Connection due to Power Off

◆ BLESTAT_TERMINATED

#define BLESTAT_TERMINATED   0x16

Connection Terminated By Own device

◆ BLESTAT_UNSPEC_ERR

#define BLESTAT_UNSPEC_ERR   0x1F

Unspecified Error

◆ BLESTAT_DEVICE_BUSY

#define BLESTAT_DEVICE_BUSY   0x3A

Controller Busy

◆ BLESTAT_PARAM_REJECTED

#define BLESTAT_PARAM_REJECTED   0x3B

Unacceptable Connection Parameters

◆ BLESTAT_CONNECT_FAILED

#define BLESTAT_CONNECT_FAILED   0x3E

Connection Failed to be Established / Synchronization Timeout

Enumeration Type Documentation

◆ BT_CONNECT_STATUS

BT profile connection status.

Enumerator
BT_DISCONNECTED 

Disconnected

BT_DISCONNECTING 

Disconnect operation working

BT_CONNECTING 

Connect operation working

BT_CONNECTED 

Connected

Function Documentation

◆ bt_init()

int bt_init ( void  )

Bluetooth module initialize For initialize a pin config, NV storage, UART, etc.

Return values
errorcode

◆ bt_finalize()

int bt_finalize ( void  )

Bluetooth module finalize.

Return values
errorcode

◆ bt_set_address()

int bt_set_address ( BT_ADDR addr)

Set Bluetooth module address This is Spresense side address and should be call before bt_enable.

Parameters
[in]addrBluetooth device address BT_ADDR
Return values
errorcode

◆ bt_get_address()

int bt_get_address ( BT_ADDR addr)

Get Bluetooth module address.

Parameters
[out]addrBluetooth device address BT_ADDR
Return values
errorcode

◆ bt_set_name()

int bt_set_name ( char *  name)

Set Bluetooth module name This name visible for other devices and should be call before bt_enable.

Parameters
[in]nameBluetooth device name
Return values
errorcode

◆ bt_get_name()

int bt_get_name ( char *  name)

Get Bluetooth module name.

Parameters
[out]nameBluetooth device name
Return values
errorcode

◆ bt_enable()

int bt_enable ( void  )

Bluetooth module enable Bluetooth set power on(and download firmware, etc).

Return values
errorcode

◆ bt_disable()

int bt_disable ( void  )

Bluetooth module disable Bluetooth set power off.

Return values
errorcode

◆ bt_pairing_enable()

int bt_pairing_enable ( void  )

Bluetooth pairing enable Entering bluetooth pairing mode.

Return values
errorcode

◆ bt_paring_disable()

int bt_paring_disable ( void  )

Bluetooth pairing disable Escaping bluetooth pairing mode.

Return values
errorcode

◆ bt_get_bond_list()

int bt_get_bond_list ( BT_ADDR addr,
int *  num 
)

Bluetooth get bond device list Get bond devices list with BD_ADDR.

Parameters
[in]addrDevice address list BT_ADDR
[in]numNumber of BD_ADDR
Return values
errorcode

◆ bt_unbond()

int bt_unbond ( BT_ADDR addr)

Bluetooth unbond by BD_ADDR Unbond device by BD_ADDR.

Parameters
[out]addrUnbond device BD_ADDR BT_ADDR
Return values
errorcode

◆ bt_set_visibility()

int bt_set_visibility ( BT_VISIBILITY  visibility)

Bluetooth set visible Visible this device from others.

Parameters
[in]visibilityDevice visibility parameter BT_VISIBILITY
Return values
errorcode

◆ bt_start_inquiry()

int bt_start_inquiry ( void  )

Bluetooth inquiry start Start to inquiry for connect peer device.

Return values
errorcode

◆ bt_cancel_inquiry()

int bt_cancel_inquiry ( void  )

Bluetooth inquiry cancel Cancel to inquiry.

Return values
errorcode

◆ bt_register_common_cb()

int bt_register_common_cb ( struct bt_common_ops_s bt_common_ops)

Bluetooth register common callbacks Register Connect/Pairing/Inquiry callback.

Parameters
[in]bt_common_opsApplication callback bt_common_ops_s
Return values
errorcode

◆ ble_set_address()

int ble_set_address ( BT_ADDR addr)

Set Bluetooth LE module address This is Spresense side address and should be call before bt_enable.

Parameters
[in]addrBluetooth LE device address BT_ADDR
Return values
errorcode

◆ ble_get_address()

int ble_get_address ( BT_ADDR addr)

Get Bluetooth LE module address.

Parameters
[out]addrBluetooth LE device address BT_ADDR
Return values
errorcode

◆ ble_set_name()

int ble_set_name ( char *  name)

Set Bluetooth LE module name This name visible for other devices and should be call before bt_enable.

Parameters
[in]nameBluetooth LE device name
Return values
errorcode

◆ ble_get_name()

int ble_get_name ( char *  name)

Get Bluetooth LE module name.

Parameters
[out]nameBluetooth LE device name
Return values
errorcode

◆ ble_enable()

int ble_enable ( void  )

Bluetooth LE enable.

Return values
errorcode

◆ ble_disable()

int ble_disable ( void  )

Bluetooth LE disable.

Return values
errorcode

◆ ble_connect()

int ble_connect ( struct ble_state_s ble_state)

Bluetooth LE connect for Central.

Parameters
[in]ble_stateBluetooth context ble_state_s
Return values
errorcode

◆ ble_disconnect()

int ble_disconnect ( struct ble_state_s ble_state)

Bluetooth LE dicsonnect for Central.

Parameters
[in]ble_stateBluetooth context ble_state_s
Return values
errorcode

◆ ble_start_advertise()

int ble_start_advertise ( void  )

Bluetooth LE start advertise Start BLE advertise mode.

Return values
errorcode

◆ ble_cancel_advertise()

int ble_cancel_advertise ( void  )

Bluetooth LE cancel advertise Cancel BLE advertise mode.

Return values
errorcode

◆ ble_start_scan()

int ble_start_scan ( bool  duplicate_filter)

Bluetooth LE start scan Start BLE scan mode.

Parameters
[in]duplicate_filtertrue means that duplicate scan results are filtered out.
Return values
errorcode

◆ ble_cancel_scan()

int ble_cancel_scan ( void  )

Bluetooth LE cancel scan Cancel BLE scan mode.

Return values
errorcode

◆ ble_register_common_cb()

int ble_register_common_cb ( struct ble_common_ops_s ble_common_ops)

Bluetooth LE register common callbacks Register Connect/Advertise/Scan callback.

Parameters
[in]ble_common_opsApplication callback ble_common_ops_s
Return values
errorcode

◆ ble_set_request_mtusize()

uint16_t ble_set_request_mtusize ( uint16_t  sz)

Set MTU size that application requests.

Parameters
[in]szMTU size that application requests
Return values
AcceptedMTU size

◆ ble_get_request_mtusize()

uint16_t ble_get_request_mtusize ( void  )

Get MTU size that application requests.

Return values
AcceptedMTU size

◆ ble_get_negotiated_mtusize()

int ble_get_negotiated_mtusize ( uint16_t  handle)

Get negotiated MTU size.

Parameters
[in]handleconnection handle
Return values
Positivevalue measn Negotiated MTU size, otherwise errno.

◆ ble_pairing()

int ble_pairing ( uint16_t  handle)

Execute pairing.

Parameters
[in]handleconnection handle
Return values
BLE_SUCCESSor negated errno.

◆ ble_parse_advertising_data()

int ble_parse_advertising_data ( BLE_AD_TYPE  target,
uint8_t *  adv_data,
uint8_t  adv_len,
struct bt_eir_s eir 
)

Parse advertise data.

Parameters
[in]targetparse target EIR type
[in]adv_dataadvertising data
[in]adv_lenlength of advertising data
[in]eirparse result