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

Bluetooth Low Energy GATT Server/Client API. More...

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

Go to the source code of this file.

Classes

struct  BLE_UUID128
 128-bit UUID structure for BLE More...
 
struct  BLE_UUID_ALIAS
 UUID base + alias structure. More...
 
struct  BLE_UUID
 BLE UUID structure. More...
 
struct  BLE_ATTR_PERM
 Attribute permission structure. More...
 
struct  BLE_CHAR_VALUE
 characteristic value attribute structure More...
 
struct  BLE_CHAR_PROP
 Characteristic standard properties. More...
 
struct  ble_gatt_peripheral_ops_s
 Bluetooth LE characteristic callbacks(for Peripheral) More...
 
struct  ble_gatt_char_s
 Bluetooth LE GATT characteristic context. More...
 
struct  ble_gatt_service_s
 Bluetooth LE GATT service context. More...
 
struct  ble_gatt_state_s
 Bluetooth LE GATT context. More...
 
struct  ble_gattc_handle_range_s
 GATTC handle range structure. More...
 
struct  ble_gattc_char_s
 GATTC characteristic structure. More...
 
struct  ble_gattc_db_disc_char_s
 GATTC discovered characteristic data structure. More...
 
struct  ble_gattc_db_disc_srv_s
 GATTC discovered service data structure. More...
 
struct  ble_gattc_db_discovery_s
 GATTC discovered attribute database data structure. More...
 
struct  ble_gatt_coverrun_state_s
 
struct  ble_gatt_event_db_discovery_t
 GATTC attribute database discovery event structure. More...
 
struct  ble_gatt_central_ops_s
 Bluetooth LE characteristic callbacks(for Central) More...
 

Macros

#define EXTERN   extern "C"
 
Max number of services
#define BLE_MAX_SERVICES   1
 
Max number of characteristics
#define BLE_MAX_CHARACTERISTICS   1
 
Max size of characteristics value
#define BLE_MAX_CHAR_SIZE   20
 
Invalid service handle ID
#define BLE_GATT_INVALID_SERVICE_HANDLE   UINT16_MAX
 
Invalid attribute handle ID
#define BLE_GATT_INVALID_ATTRIBUTE_HANDLE   (0x0000)
 
Support Max services
#define BLE_DB_DISCOVERY_MAX_SRV   3
 
Support Max characteristics per service
#define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV   4
 

Enumerations

enum  BLE_GATT_UUID_TYPE { BLE_UUID_TYPE_UUID128 = 0 , BLE_UUID_TYPE_BASEALIAS_BTSIG , BLE_UUID_TYPE_BASEALIAS_VENDOR }
 GATTS UUID type. More...
 
enum  BLE_GATT_TYPE { BLE_GATTS_SRVTYP_PRIMARY = 1 , BLE_GATTS_SRVTYP_SECONDARY }
 GATTS service type. More...
 
enum  BLE_SEC_MODE {
  BLE_SEC_MODE_NO_ACCESS = 0x00 , BLE_SEC_MODE1LV1_NO_SEC , BLE_SEC_MODE1LV2_NO_MITM_ENC , BLE_SEC_MODE1LV3_MITM_ENC ,
  BLE_SEC_MODE2LV1_NO_MITM_DATA_SGN , BLE_SEC_MODE2LV2__MITM_DATA_SGN
}
 

Functions

bool ble_gatt_is_supported (void)
 Get Bluetooth Low Ennergy GATT support or not support. More...
 
int ble_create_service (struct ble_gatt_service_s **service)
 BLE Create GATT Service Create GATT Service instance and return instance pointer via *service. More...
 
int ble_register_servce (struct ble_gatt_service_s *service)
 BLE Register GATT Service Register GATT Service to HAL. More...
 
int ble_add_characteristic (struct ble_gatt_service_s *service, struct ble_gatt_char_s *charc)
 BLE add Characteristic to service Add characteristic to service. More...
 
int ble_characteristic_notify (uint16_t conn_handle, struct ble_gatt_char_s *charc, uint8_t *data, int len)
 BLE Notify Characteristic value Notify characteristic value to Central (For Peripheral role) More...
 
int ble_characteristic_read (uint16_t conn_handle, struct ble_gatt_char_s *charc)
 BLE Read Characteristic value (Deprecated) Send read characteristic request to peripheral (For Central role) More...
 
int ble_characteristic_write (uint16_t conn_handle, struct ble_gatt_char_s *charc, uint8_t *data, int len)
 BLE Write Characteristic value (Deprecated) Send write characteristic request to peripheral (For Central role) More...
 
int ble_read_characteristic (uint16_t conn_handle, uint16_t char_handle)
 BLE Read Characteristic value Send read characteristic request to peripheral (For Central role) More...
 
int ble_write_characteristic (uint16_t conn_handle, uint16_t char_handle, uint8_t *data, int len, bool rsp)
 BLE Write Characteristic value Send write characteristic request to peripheral (For Central role) More...
 
int ble_descriptor_read (uint16_t conn_handle, uint16_t handle)
 BLE Read Descriptor value Send read descriptor request to peripheral (For Central role) More...
 
int ble_descriptor_write (uint16_t conn_handle, uint16_t handle, uint8_t *data, int len)
 BLE Write Descriptor value Send write descriptor request to peripheral (For Central role) More...
 
int ble_start_db_discovery (uint16_t conn_handle)
 BLE start database discovery Send database discovery request to peripheral (For Central role) In case of device/nrf52 configuration, 128-bit UUID information is not discovered correctly. Then, you may use ble_discover_uuid() API. More...
 
int ble_continue_db_discovery (uint16_t start_handle, uint16_t conn_handle)
 BLE continue database discovery Send continue database discovery request to peripheral (For Central role) In case of device/nrf52 configuration, 128-bit UUID information is not discovered correctly. Then, you may use ble_discover_uuid() API. More...
 
int ble_discover_uuid (uint16_t conn_handle, BLE_UUID *srv_uuid, BLE_UUID *char_uuid)
 Discover GATT database with specific UUID. More...
 

Detailed Description

Bluetooth Low Energy GATT Server/Client API.

Author
Sony Semiconductor Solutions Corporation

This API is for using BLE GATT and includes Function and Callback

Enumeration Type Documentation

◆ BLE_GATT_UUID_TYPE

GATTS UUID type.

Enumerator
BLE_UUID_TYPE_UUID128 

UUID type 128-bit UUID

BLE_UUID_TYPE_BASEALIAS_BTSIG 

UUID type base alias bluetooth SIG qualified

BLE_UUID_TYPE_BASEALIAS_VENDOR 

UUID type base alias vendor

◆ BLE_GATT_TYPE

GATTS service type.

Enumerator
BLE_GATTS_SRVTYP_PRIMARY 

GATTS service type primary

BLE_GATTS_SRVTYP_SECONDARY 

GATTS service type secondary

◆ BLE_SEC_MODE

Enumerator
BLE_SEC_MODE_NO_ACCESS 

No access rigths

BLE_SEC_MODE1LV1_NO_SEC 

Security mode 1 level 1, no security open link

BLE_SEC_MODE1LV2_NO_MITM_ENC 

Security mode 1 level 2, unauthenticated pairing with encryption

BLE_SEC_MODE1LV3_MITM_ENC 

Security mode 1 level 3, authenticated pairing with encryption

BLE_SEC_MODE2LV1_NO_MITM_DATA_SGN 

Security mode 2 level 1, unauthenticated pairing with data signing, not supported now

BLE_SEC_MODE2LV2__MITM_DATA_SGN 

Security mode 2 level 2, authenticated pairing with data signing, not supported now

Function Documentation

◆ ble_gatt_is_supported()

bool ble_gatt_is_supported ( void  )

Get Bluetooth Low Ennergy GATT support or not support.

Return values
Suppotor Not support

◆ ble_create_service()

int ble_create_service ( struct ble_gatt_service_s **  service)

BLE Create GATT Service Create GATT Service instance and return instance pointer via *service.

Parameters
[out]serviceBluetooth LE service context ble_gatt_service_s
Return values
errorcode

◆ ble_register_servce()

int ble_register_servce ( struct ble_gatt_service_s service)

BLE Register GATT Service Register GATT Service to HAL.

Parameters
[in]serviceBluetooth LE GATT service context ble_gatt_service_s
Return values
errorcode

◆ ble_add_characteristic()

int ble_add_characteristic ( struct ble_gatt_service_s service,
struct ble_gatt_char_s charc 
)

BLE add Characteristic to service Add characteristic to service.

Parameters
[in]serviceBluetooth LE GATT service context ble_gatt_service_s
[in]charcBluetooth LE GATT characteristic context ble_gatt_char_s
Return values
errorcode

◆ ble_characteristic_notify()

int ble_characteristic_notify ( uint16_t  conn_handle,
struct ble_gatt_char_s charc,
uint8_t *  data,
int  len 
)

BLE Notify Characteristic value Notify characteristic value to Central (For Peripheral role)

Parameters
[in]conn_handleconnection handle for which notification is sent
[in]charcTarget characteristic ble_gatt_char_s
[in]dataNotify data
[in]lenNotify data length
Return values
errorcode

◆ ble_characteristic_read()

int ble_characteristic_read ( uint16_t  conn_handle,
struct ble_gatt_char_s charc 
)

BLE Read Characteristic value (Deprecated) Send read characteristic request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle for which read request is sent
[in]charcBluetooth LE GATT characteristic context ble_gatt_char_s
Return values
errorcode

◆ ble_characteristic_write()

int ble_characteristic_write ( uint16_t  conn_handle,
struct ble_gatt_char_s charc,
uint8_t *  data,
int  len 
)

BLE Write Characteristic value (Deprecated) Send write characteristic request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle for which write request is sent
[in]charcBluetooth LE GATT characteristic context ble_gatt_char_s
[in]dataWrite data
[in]lenWrite data length
Return values
errorcode

◆ ble_read_characteristic()

int ble_read_characteristic ( uint16_t  conn_handle,
uint16_t  char_handle 
)

BLE Read Characteristic value Send read characteristic request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle for which write request is sent
[in]char_handlecharacteristic handle for which write request is sent
Return values
errorcode

◆ ble_write_characteristic()

int ble_write_characteristic ( uint16_t  conn_handle,
uint16_t  char_handle,
uint8_t *  data,
int  len,
bool  rsp 
)

BLE Write Characteristic value Send write characteristic request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle for which write request is sent
[in]char_handlecharacteristic handle for which write request is sent
[in]dataWrite data
[in]lenWrite data length
[in]rspRequire write response to receive write result
Return values
errorcode

◆ ble_descriptor_read()

int ble_descriptor_read ( uint16_t  conn_handle,
uint16_t  handle 
)

BLE Read Descriptor value Send read descriptor request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle
[in]handledesctiptor handle
Return values
errorcode

◆ ble_descriptor_write()

int ble_descriptor_write ( uint16_t  conn_handle,
uint16_t  handle,
uint8_t *  data,
int  len 
)

BLE Write Descriptor value Send write descriptor request to peripheral (For Central role)

Parameters
[in]conn_handleconnection handle
[in]handledesctiptor handle
[in]dataWrite data
[in]lenWrite data length
Return values
errorcode

◆ ble_start_db_discovery()

int ble_start_db_discovery ( uint16_t  conn_handle)

BLE start database discovery Send database discovery request to peripheral (For Central role) In case of device/nrf52 configuration, 128-bit UUID information is not discovered correctly. Then, you may use ble_discover_uuid() API.

Parameters
[in]conn_handleBluetooth LE GATT connection handle
Return values
errorcode

◆ ble_continue_db_discovery()

int ble_continue_db_discovery ( uint16_t  start_handle,
uint16_t  conn_handle 
)

BLE continue database discovery Send continue database discovery request to peripheral (For Central role) In case of device/nrf52 configuration, 128-bit UUID information is not discovered correctly. Then, you may use ble_discover_uuid() API.

Parameters
[in]start_handleBluetooth LE GATT start handle
[in]conn_handleBluetooth LE GATT connection handle
Return values
errorcode

◆ ble_discover_uuid()

int ble_discover_uuid ( uint16_t  conn_handle,
BLE_UUID srv_uuid,
BLE_UUID char_uuid 
)

Discover GATT database with specific UUID.

Parameters
[in]conn_handleBLE connection handle
[in]srv_uuidService UUID to be discovered
[in]char_uuidCharacteristic UUID to be discovered
Return values
errorcode