Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Data Structures

struct  bt_gatt_ccc_cfg
 GATT CCC configuration entry. More...
 
struct  bt_gatt_notify_params
 
struct  bt_gatt_indicate_params
 GATT Indicate Value parameters. More...
 

Macros

#define BT_GATT_SERVICE_DEFINE(_name, ...)
 Statically define and register a service.
 
#define BT_GATT_SERVICE_INSTANCE_DEFINE( _name, _instances, _instance_num, _attrs_def)
 Statically define service structure array.
 
#define BT_GATT_SERVICE(_attrs)
 Service Structure Declaration Macro.
 
#define BT_GATT_PRIMARY_SERVICE(_service)
 Primary Service Declaration Macro.
 
#define BT_GATT_SECONDARY_SERVICE(_service)
 Secondary Service Declaration Macro.
 
#define BT_GATT_INCLUDE_SERVICE(_service_incl)
 Include Service Declaration Macro.
 
#define BT_GATT_CHRC_INIT(_uuid, _handle, _props)
 
#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data)
 Characteristic and Value Declaration Macro.
 
#define BT_GATT_CCC_MAX   0
 
#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match)
 Initialize Client Characteristic Configuration Declaration Macro.
 
#define BT_GATT_CCC_MANAGED(_ccc, _perm)
 Managed Client Characteristic Configuration Declaration Macro.
 
#define BT_GATT_CCC(_changed, _perm)
 Client Characteristic Configuration Declaration Macro.
 
#define BT_GATT_CEP(_value)
 Characteristic Extended Properties Declaration Macro.
 
#define BT_GATT_CUD(_value, _perm)
 Characteristic User Format Descriptor Declaration Macro.
 
#define BT_GATT_CPF(_value)
 Characteristic Presentation Format Descriptor Declaration Macro.
 
#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data)    BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
 Descriptor Declaration Macro.
 
#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
 Attribute Declaration Macro.
 

Typedefs

typedef uint8_t(* bt_gatt_attr_func_t) (const struct bt_gatt_attr *attr, uint16_t handle, void *user_data)
 Attribute iterator callback.
 
typedef void(* bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data)
 Notification complete result callback.
 
typedef void(* bt_gatt_indicate_func_t) (struct bt_conn *conn, struct bt_gatt_indicate_params *params, uint8_t err)
 Indication complete result callback.
 
typedef void(* bt_gatt_indicate_params_destroy_t) (struct bt_gatt_indicate_params *params)
 

Enumerations

enum  { BT_GATT_ITER_STOP = 0 , BT_GATT_ITER_CONTINUE }
 

Functions

static const char * bt_gatt_err_to_str (int gatt_err)
 Converts a GATT error to string.
 
void bt_gatt_cb_register (struct bt_gatt_cb *cb)
 Register GATT callbacks.
 
int bt_gatt_authorization_cb_register (const struct bt_gatt_authorization_cb *cb)
 Register GATT authorization callbacks.
 
int bt_gatt_service_register (struct bt_gatt_service *svc)
 Register GATT service.
 
int bt_gatt_service_unregister (struct bt_gatt_service *svc)
 Unregister GATT service.
 
bool bt_gatt_service_is_registered (const struct bt_gatt_service *svc)
 Check if GATT service is registered.
 
void bt_gatt_foreach_attr_type (uint16_t start_handle, uint16_t end_handle, const struct bt_uuid *uuid, const void *attr_data, uint16_t num_matches, bt_gatt_attr_func_t func, void *user_data)
 Attribute iterator by type.
 
static void bt_gatt_foreach_attr (uint16_t start_handle, uint16_t end_handle, bt_gatt_attr_func_t func, void *user_data)
 Attribute iterator.
 
struct bt_gatt_attrbt_gatt_attr_next (const struct bt_gatt_attr *attr)
 Iterate to the next attribute.
 
struct bt_gatt_attrbt_gatt_find_by_uuid (const struct bt_gatt_attr *attr, uint16_t attr_count, const struct bt_uuid *uuid)
 Find Attribute by UUID.
 
uint16_t bt_gatt_attr_get_handle (const struct bt_gatt_attr *attr)
 Get Attribute handle.
 
uint16_t bt_gatt_attr_value_handle (const struct bt_gatt_attr *attr)
 Get the handle of the characteristic value descriptor.
 
ssize_t bt_gatt_attr_read (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t buf_len, uint16_t offset, const void *value, uint16_t value_len)
 Generic Read Attribute value helper.
 
ssize_t bt_gatt_attr_read_service (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Service Attribute helper.
 
ssize_t bt_gatt_attr_read_included (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Include Attribute helper.
 
ssize_t bt_gatt_attr_read_chrc (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Characteristic Attribute helper.
 
ssize_t bt_gatt_attr_read_ccc (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Client Characteristic Configuration Attribute helper.
 
ssize_t bt_gatt_attr_write_ccc (struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
 Write Client Characteristic Configuration Attribute helper.
 
ssize_t bt_gatt_attr_read_cep (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Characteristic Extended Properties Attribute helper.
 
ssize_t bt_gatt_attr_read_cud (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Characteristic User Description Descriptor Attribute helper.
 
ssize_t bt_gatt_attr_read_cpf (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Read Characteristic Presentation format Descriptor Attribute helper.
 
int bt_gatt_notify_cb (struct bt_conn *conn, struct bt_gatt_notify_params *params)
 Notify attribute value change.
 
int bt_gatt_notify_multiple (struct bt_conn *conn, uint16_t num_params, struct bt_gatt_notify_params params[])
 Send multiple notifications in a single PDU.
 
static int bt_gatt_notify (struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *data, uint16_t len)
 Notify attribute value change.
 
static int bt_gatt_notify_uuid (struct bt_conn *conn, const struct bt_uuid *uuid, const struct bt_gatt_attr *attr, const void *data, uint16_t len)
 Notify attribute value change by UUID.
 
int bt_gatt_indicate (struct bt_conn *conn, struct bt_gatt_indicate_params *params)
 Indicate attribute value change.
 
bool bt_gatt_is_subscribed (struct bt_conn *conn, const struct bt_gatt_attr *attr, uint16_t ccc_type)
 Check if connection have subscribed to attribute.
 
uint16_t bt_gatt_get_mtu (struct bt_conn *conn)
 Get ATT MTU for a connection.
 

Detailed Description

Macro Definition Documentation

◆ BT_GATT_ATTRIBUTE

#define BT_GATT_ATTRIBUTE (   _uuid,
  _perm,
  _read,
  _write,
  _user_data 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
{ \
.uuid = _uuid, \
.read = _read, \
.write = _write, \
.user_data = _user_data, \
.handle = 0, \
.perm = _perm, \
}

Attribute Declaration Macro.

Helper macro to declare an attribute.

Parameters
_uuidAttribute uuid.
_permAttribute access permissions, a bitmap of bt_gatt_perm values.
_readAttribute read callback (bt_gatt_attr_read_func_t).
_writeAttribute write callback (bt_gatt_attr_write_func_t).
_user_dataAttribute user data.

◆ BT_GATT_CCC

#define BT_GATT_CCC (   _changed,
  _perm 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
{BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match)
Initialize Client Characteristic Configuration Declaration Macro.
Definition gatt.h:909
#define BT_GATT_CCC_MANAGED(_ccc, _perm)
Managed Client Characteristic Configuration Declaration Macro.
Definition gatt.h:926

Client Characteristic Configuration Declaration Macro.

Helper macro to declare a CCC attribute.

Parameters
_changedConfiguration changed callback.
_permCCC access permissions, a bitmap of bt_gatt_perm values.

◆ BT_GATT_CCC_INITIALIZER

#define BT_GATT_CCC_INITIALIZER (   _changed,
  _write,
  _match 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
{ \
.cfg = {}, \
.cfg_changed = _changed, \
.cfg_write = _write, \
.cfg_match = _match, \
}

Initialize Client Characteristic Configuration Declaration Macro.

Helper macro to initialize a Managed CCC attribute value.

Parameters
_changedConfiguration changed callback.
_writeConfiguration write callback.
_matchConfiguration match callback.

◆ BT_GATT_CCC_MANAGED

#define BT_GATT_CCC_MANAGED (   _ccc,
  _perm 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
_ccc)
ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Client Characteristic Configuration Attribute helper.
ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
Write Client Characteristic Configuration Attribute helper.
#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
Attribute Declaration Macro.
Definition gatt.h:1069
#define BT_UUID_GATT_CCC
GATT Client Characteristic Configuration.
Definition uuid.h:886

Managed Client Characteristic Configuration Declaration Macro.

Helper macro to declare a Managed CCC attribute.

Parameters
_cccCCC attribute user data, shall point to a _bt_gatt_ccc.
_permCCC access permissions, a bitmap of bt_gatt_perm values.

◆ BT_GATT_CCC_MAX

#define BT_GATT_CCC_MAX   0

◆ BT_GATT_CEP

#define BT_GATT_CEP (   _value)

#include <include/zephyr/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_cep, NULL, (void *)_value)
ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Characteristic Extended Properties Attribute helper.
#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data)
Descriptor Declaration Macro.
Definition gatt.h:1054
@ BT_GATT_PERM_READ
Attribute read permission.
Definition gatt.h:42
#define BT_UUID_GATT_CEP
GATT Characteristic Extended Properties.
Definition uuid.h:868

Characteristic Extended Properties Declaration Macro.

Helper macro to declare a CEP attribute.

Parameters
_valuePointer to a struct bt_gatt_cep.

◆ BT_GATT_CHARACTERISTIC

#define BT_GATT_CHARACTERISTIC (   _uuid,
  _props,
  _perm,
  _read,
  _write,
  _user_data 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
((struct bt_gatt_chrc[]) { \
BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
})), \
BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Characteristic Attribute helper.
#define BT_UUID_GATT_CHRC
GATT Characteristic.
Definition uuid.h:859
Characteristic Attribute Value.
Definition gatt.h:325

Characteristic and Value Declaration Macro.

Helper macro to declare a characteristic attribute along with its attribute value.

Parameters
_uuidCharacteristic attribute uuid.
_propsCharacteristic attribute properties, a bitmap of BT_GATT_CHRC_* macros.
_permCharacteristic Attribute access permissions, a bitmap of bt_gatt_perm values.
_readCharacteristic Attribute read callback (bt_gatt_attr_read_func_t).
_writeCharacteristic Attribute write callback (bt_gatt_attr_write_func_t).
_user_dataCharacteristic Attribute user data.

◆ BT_GATT_CHRC_INIT

#define BT_GATT_CHRC_INIT (   _uuid,
  _handle,
  _props 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
{ \
.uuid = _uuid, \
.value_handle = _handle, \
.properties = _props, \
}

◆ BT_GATT_CPF

#define BT_GATT_CPF (   _value)

#include <include/zephyr/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_cpf, NULL, (void *)_value)
ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Characteristic Presentation format Descriptor Attribute helper.
#define BT_UUID_GATT_CPF
GATT Characteristic Presentation Format.
Definition uuid.h:904

Characteristic Presentation Format Descriptor Declaration Macro.

Helper macro to declare a CPF attribute.

Parameters
_valuePointer to a struct bt_gatt_cpf.

◆ BT_GATT_CUD

#define BT_GATT_CUD (   _value,
  _perm 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
NULL, (void *)_value)
ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Characteristic User Description Descriptor Attribute helper.
#define BT_UUID_GATT_CUD
GATT Characteristic User Description.
Definition uuid.h:877

Characteristic User Format Descriptor Declaration Macro.

Helper macro to declare a CUD attribute.

Parameters
_valueUser description NULL-terminated C string.
_permDescriptor attribute access permissions, a bitmap of bt_gatt_perm values.

◆ BT_GATT_DESCRIPTOR

#define BT_GATT_DESCRIPTOR (   _uuid,
  _perm,
  _read,
  _write,
  _user_data 
)     BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)

#include <include/zephyr/bluetooth/gatt.h>

Descriptor Declaration Macro.

Helper macro to declare a descriptor attribute.

Parameters
_uuidDescriptor attribute uuid.
_permDescriptor attribute access permissions, a bitmap of bt_gatt_perm values.
_readDescriptor attribute read callback (bt_gatt_attr_read_func_t).
_writeDescriptor attribute write callback (bt_gatt_attr_write_func_t).
_user_dataDescriptor attribute user data.

◆ BT_GATT_INCLUDE_SERVICE

#define BT_GATT_INCLUDE_SERVICE (   _service_incl)

#include <include/zephyr/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_included, NULL, _service_incl)
ssize_t bt_gatt_attr_read_included(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Include Attribute helper.
#define BT_UUID_GATT_INCLUDE
GATT Include Service.
Definition uuid.h:850

Include Service Declaration Macro.

Helper macro to declare database internal include service attribute.

Parameters
_service_inclthe first service attribute of service to include

◆ BT_GATT_PRIMARY_SERVICE

#define BT_GATT_PRIMARY_SERVICE (   _service)

#include <include/zephyr/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_service, NULL, (void *)_service)
ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Service Attribute helper.
#define BT_UUID_GATT_PRIMARY
GATT Primary Service.
Definition uuid.h:832

Primary Service Declaration Macro.

Helper macro to declare a primary service attribute.

Parameters
_serviceService attribute value.

◆ BT_GATT_SECONDARY_SERVICE

#define BT_GATT_SECONDARY_SERVICE (   _service)

#include <include/zephyr/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_service, NULL, (void *)_service)
#define BT_UUID_GATT_SECONDARY
GATT Secondary Service.
Definition uuid.h:841

Secondary Service Declaration Macro.

Helper macro to declare a secondary service attribute.

Note
A secondary service is only intended to be included from a primary service or another secondary service or other higher layer specification.
Parameters
_serviceService attribute value.

◆ BT_GATT_SERVICE

#define BT_GATT_SERVICE (   _attrs)

#include <include/zephyr/bluetooth/gatt.h>

Value:
{ \
.attrs = _attrs, \
.attr_count = ARRAY_SIZE(_attrs), \
}
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition util.h:127

Service Structure Declaration Macro.

Helper macro to declare a service structure.

Parameters
_attrsService attributes.

◆ BT_GATT_SERVICE_DEFINE

#define BT_GATT_SERVICE_DEFINE (   _name,
  ... 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
BT_GATT_SERVICE(attr_##_name)
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition iterable_sections.h:216
GATT Attribute structure.
Definition gatt.h:169
GATT Service structure.
Definition gatt.h:188

Statically define and register a service.

Helper macro to statically define and register a service.

Parameters
_nameService name.

◆ BT_GATT_SERVICE_INSTANCE_DEFINE

#define BT_GATT_SERVICE_INSTANCE_DEFINE (   _name,
  _instances,
  _instance_num,
  _attrs_def 
)

#include <include/zephyr/bluetooth/gatt.h>

Value:
BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
"The number of array elements does not match its size"); \
LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
_instances, _attrs_def); \
static struct bt_gatt_service _name[] = { \
LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
}
GATT Service structure.
Definition gatt.h:196

Statically define service structure array.

Helper macro to statically define service structure array. Each element of the array is linked to the service attribute array which is also defined in this scope using _attrs_def macro.

Parameters
_nameName of service structure array.
_instancesArray of instances to pass as user context to the attribute callbacks.
_instance_numNumber of elements in instance array.
_attrs_defMacro provided by the user that defines attribute array for the service. This macro should accept single parameter which is the instance context.

Typedef Documentation

◆ bt_gatt_attr_func_t

bt_gatt_attr_func_t

#include <include/zephyr/bluetooth/gatt.h>

Attribute iterator callback.

Parameters
attrAttribute found.
handleAttribute handle found.
user_dataData given.
Returns
BT_GATT_ITER_CONTINUE if should continue to the next attribute.
BT_GATT_ITER_STOP to stop.

◆ bt_gatt_complete_func_t

typedef void(* bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data)

#include <include/zephyr/bluetooth/gatt.h>

Notification complete result callback.

Parameters
connConnection object.
user_dataData passed in by the user.

◆ bt_gatt_indicate_func_t

bt_gatt_indicate_func_t

#include <include/zephyr/bluetooth/gatt.h>

Indication complete result callback.

Parameters
connConnection object.
paramsIndication params object.
errATT error code

◆ bt_gatt_indicate_params_destroy_t

typedef void(* bt_gatt_indicate_params_destroy_t) (struct bt_gatt_indicate_params *params)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

#include <include/zephyr/bluetooth/gatt.h>

Enumerator
BT_GATT_ITER_STOP 
BT_GATT_ITER_CONTINUE 

Function Documentation

◆ bt_gatt_attr_get_handle()

uint16_t bt_gatt_attr_get_handle ( const struct bt_gatt_attr attr)

#include <include/zephyr/bluetooth/gatt.h>

Get Attribute handle.

Parameters
attrAttribute object.
Returns
Handle of the corresponding attribute or zero if the attribute could not be found.

◆ bt_gatt_attr_next()

struct bt_gatt_attr * bt_gatt_attr_next ( const struct bt_gatt_attr attr)

#include <include/zephyr/bluetooth/gatt.h>

Iterate to the next attribute.

Iterate to the next attribute following a given attribute.

Parameters
attrCurrent Attribute.
Returns
The next attribute or NULL if it cannot be found.

◆ bt_gatt_attr_read()

ssize_t bt_gatt_attr_read ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  buf_len,
uint16_t  offset,
const void *  value,
uint16_t  value_len 
)

#include <include/zephyr/bluetooth/gatt.h>

Generic Read Attribute value helper.

Read attribute value from local database storing the result into buffer.

Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value.
buf_lenBuffer length.
offsetStart offset.
valueAttribute value.
value_lenLength of the attribute value.
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_ccc()

ssize_t bt_gatt_attr_read_ccc ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Client Characteristic Configuration Attribute helper.

Read CCC attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a _bt_gatt_ccc.
Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value read.
lenBuffer length.
offsetStart offset.
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_cep()

ssize_t bt_gatt_attr_read_cep ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Characteristic Extended Properties Attribute helper.

Read CEP attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a bt_gatt_cep.
Parameters
connConnection object
attrAttribute to read
bufBuffer to store the value read
lenBuffer length
offsetStart offset
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_chrc()

ssize_t bt_gatt_attr_read_chrc ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Characteristic Attribute helper.

Read characteristic attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a bt_gatt_chrc.
Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value read.
lenBuffer length.
offsetStart offset.
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_cpf()

ssize_t bt_gatt_attr_read_cpf ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Characteristic Presentation format Descriptor Attribute helper.

Read CPF attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a bt_gatt_pf.
Parameters
connConnection object
attrAttribute to read
bufBuffer to store the value read
lenBuffer length
offsetStart offset
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_cud()

ssize_t bt_gatt_attr_read_cud ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Characteristic User Description Descriptor Attribute helper.

Read CUD attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a NULL-terminated C string.
Parameters
connConnection object
attrAttribute to read
bufBuffer to store the value read
lenBuffer length
offsetStart offset
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_included()

ssize_t bt_gatt_attr_read_included ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Include Attribute helper.

Read include service attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a bt_gatt_include.
Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value read.
lenBuffer length.
offsetStart offset.
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_read_service()

ssize_t bt_gatt_attr_read_service ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
void *  buf,
uint16_t  len,
uint16_t  offset 
)

#include <include/zephyr/bluetooth/gatt.h>

Read Service Attribute helper.

Read service attribute value from local database storing the result into buffer after encoding it.

Note
Only use this with attributes which user_data is a bt_uuid.
Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value read.
lenBuffer length.
offsetStart offset.
Returns
number of bytes read in case of success or negative values in case of error.

◆ bt_gatt_attr_value_handle()

uint16_t bt_gatt_attr_value_handle ( const struct bt_gatt_attr attr)

#include <include/zephyr/bluetooth/gatt.h>

Get the handle of the characteristic value descriptor.

Parameters
attrA Characteristic Attribute.
Note
The user_data of the attribute must of type bt_gatt_chrc.
Returns
the handle of the corresponding Characteristic Value. The value will be zero (the invalid handle) if attr was not a characteristic attribute.

◆ bt_gatt_attr_write_ccc()

ssize_t bt_gatt_attr_write_ccc ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
const void *  buf,
uint16_t  len,
uint16_t  offset,
uint8_t  flags 
)

#include <include/zephyr/bluetooth/gatt.h>

Write Client Characteristic Configuration Attribute helper.

Write value in the buffer into CCC attribute.

Note
Only use this with attributes which user_data is a _bt_gatt_ccc.
Parameters
connConnection object.
attrAttribute to read.
bufBuffer to store the value read.
lenBuffer length.
offsetStart offset.
flagsWrite flags.
Returns
number of bytes written in case of success or negative values in case of error.

◆ bt_gatt_authorization_cb_register()

int bt_gatt_authorization_cb_register ( const struct bt_gatt_authorization_cb cb)

#include <include/zephyr/bluetooth/gatt.h>

Register GATT authorization callbacks.

Register callbacks to perform application-specific authorization of GATT operations on all registered GATT attributes. The callback structure must remain valid throughout the entire duration of the Bluetooth subsys activity.

The CONFIG_BT_GATT_AUTHORIZATION_CUSTOM Kconfig must be enabled to make this API functional.

This API allows the user to register only one callback structure concurrently. Passing NULL unregisters the previous set of callbacks and makes it possible to register a new one.

Parameters
cbCallback struct.
Returns
Zero on success or negative error code otherwise

◆ bt_gatt_cb_register()

void bt_gatt_cb_register ( struct bt_gatt_cb cb)

#include <include/zephyr/bluetooth/gatt.h>

Register GATT callbacks.

Register callbacks to monitor the state of GATT. The callback struct must remain valid for the remainder of the program.

Parameters
cbCallback struct.

◆ bt_gatt_err_to_str()

static const char * bt_gatt_err_to_str ( int  gatt_err)
inlinestatic

#include <include/zephyr/bluetooth/gatt.h>

Converts a GATT error to string.

The GATT errors are created with BT_GATT_ERR.

The error codes are described in the Bluetooth Core specification, Vol 3, Part F, Section 3.4.1.1.

The ATT and GATT documentation found in Vol 4, Part F and Part G describe when the different error codes are used.

See also the defined BT_ATT_ERR_* macros.

Returns
The string representation of the GATT error code. If CONFIG_BT_ATT_ERR_TO_STR is not enabled, this just returns the empty string.

◆ bt_gatt_find_by_uuid()

struct bt_gatt_attr * bt_gatt_find_by_uuid ( const struct bt_gatt_attr attr,
uint16_t  attr_count,
const struct bt_uuid uuid 
)

#include <include/zephyr/bluetooth/gatt.h>

Find Attribute by UUID.

Find the attribute with the matching UUID. To limit the search to a service set the attr to the service attributes and the attr_count to the service attribute count .

Parameters
attrPointer to an attribute that serves as the starting point for the search of a match for the UUID. Passing NULL will search the entire range.
attr_countThe number of attributes from the starting point to search for a match for the UUID. Set to 0 to search until the end.
uuidUUID to match.

◆ bt_gatt_foreach_attr()

static void bt_gatt_foreach_attr ( uint16_t  start_handle,
uint16_t  end_handle,
bt_gatt_attr_func_t  func,
void *  user_data 
)
inlinestatic

#include <include/zephyr/bluetooth/gatt.h>

Attribute iterator.

Iterate attributes in the given range.

Parameters
start_handleStart handle.
end_handleEnd handle.
funcCallback function.
user_dataData to pass to the callback.

◆ bt_gatt_foreach_attr_type()

void bt_gatt_foreach_attr_type ( uint16_t  start_handle,
uint16_t  end_handle,
const struct bt_uuid uuid,
const void *  attr_data,
uint16_t  num_matches,
bt_gatt_attr_func_t  func,
void *  user_data 
)

#include <include/zephyr/bluetooth/gatt.h>

Attribute iterator by type.

Iterate attributes in the given range matching given UUID and/or data.

Parameters
start_handleStart handle.
end_handleEnd handle.
uuidUUID to match, passing NULL skips UUID matching.
attr_dataAttribute data to match, passing NULL skips data matching.
num_matchesNumber matches, passing 0 makes it unlimited.
funcCallback function.
user_dataData to pass to the callback.

◆ bt_gatt_get_mtu()

uint16_t bt_gatt_get_mtu ( struct bt_conn *  conn)

#include <include/zephyr/bluetooth/gatt.h>

Get ATT MTU for a connection.

Get negotiated ATT connection MTU, note that this does not equal the largest amount of attribute data that can be transferred within a single packet.

Parameters
connConnection object.
Returns
MTU in bytes

◆ bt_gatt_indicate()

int bt_gatt_indicate ( struct bt_conn *  conn,
struct bt_gatt_indicate_params params 
)

#include <include/zephyr/bluetooth/gatt.h>

Indicate attribute value change.

Send an indication of attribute value change. if connection is NULL indicate all peer that have notification enabled via CCC otherwise do a direct indication only the given connection.

The attribute object on the parameters can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC.

Alternatively it is possible to indicate by UUID by setting it on the parameters, when using this method the attribute if provided is used as the start range when looking up for possible matches.

Note
This procedure is asynchronous therefore the parameters need to remains valid while it is active. The procedure is active until the destroy callback is run.
Parameters
connConnection object.
paramsIndicate parameters.
Returns
0 in case of success or negative value in case of error.

◆ bt_gatt_is_subscribed()

bool bt_gatt_is_subscribed ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
uint16_t  ccc_type 
)

#include <include/zephyr/bluetooth/gatt.h>

Check if connection have subscribed to attribute.

Check if connection has subscribed to attribute value change.

The attribute object can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC, or the Client Characteristic Configuration Descriptor (CCCD) which is created by BT_GATT_CCC.

Parameters
connConnection object.
attrAttribute object.
ccc_typeThe subscription type, BT_GATT_CCC_NOTIFY and/or BT_GATT_CCC_INDICATE.
Returns
true if the attribute object has been subscribed.

◆ bt_gatt_notify()

static int bt_gatt_notify ( struct bt_conn *  conn,
const struct bt_gatt_attr attr,
const void *  data,
uint16_t  len 
)
inlinestatic

#include <include/zephyr/bluetooth/gatt.h>

Notify attribute value change.

Send notification of attribute value change, if connection is NULL notify all peer that have notification enabled via CCC otherwise do a direct notification only the given connection.

The attribute object on the parameters can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC.

Parameters
connConnection object.
attrCharacteristic or Characteristic Value attribute.
dataPointer to Attribute data.
lenAttribute value length.
Returns
0 in case of success or negative value in case of error.

◆ bt_gatt_notify_cb()

int bt_gatt_notify_cb ( struct bt_conn *  conn,
struct bt_gatt_notify_params params 
)

#include <include/zephyr/bluetooth/gatt.h>

Notify attribute value change.

This function works in the same way as bt_gatt_notify. With the addition that after sending the notification the callback function will be called.

The callback is run from System Workqueue context. When called from the System Workqueue context this API will not wait for resources for the callback but instead return an error. The number of pending callbacks can be increased with the CONFIG_BT_CONN_TX_MAX option.

Alternatively it is possible to notify by UUID by setting it on the parameters, when using this method the attribute if provided is used as the start range when looking up for possible matches.

Parameters
connConnection object.
paramsNotification parameters.
Returns
0 in case of success or negative value in case of error.

◆ bt_gatt_notify_multiple()

int bt_gatt_notify_multiple ( struct bt_conn *  conn,
uint16_t  num_params,
struct bt_gatt_notify_params  params[] 
)

#include <include/zephyr/bluetooth/gatt.h>

Send multiple notifications in a single PDU.

The GATT Server will send a single ATT_MULTIPLE_HANDLE_VALUE_NTF PDU containing all the notifications passed to this API.

All params must have the same func and user_data (due to implementation limitation). But func(user_data) will be invoked for each parameter.

As this API may block to wait for Bluetooth Host resources, it is not recommended to call it from a cooperative thread or a Bluetooth callback.

The peer's GATT Client must write to this device's Client Supported Features attribute and set the bit for Multiple Handle Value Notifications before this API can be used.

Only use this API to force the use of the ATT_MULTIPLE_HANDLE_VALUE_NTF PDU. For standard applications, bt_gatt_notify_cb is preferred, as it will use this PDU if supported and automatically fallback to ATT_HANDLE_VALUE_NTF when not supported by the peer.

This API has an additional limitation: it only accepts valid attribute references and not UUIDs like bt_gatt_notify and bt_gatt_notify_cb.

Parameters
connTarget client. Notifying all connected clients by passing NULL is not yet supported, please use bt_gatt_notify instead.
num_paramsElement count of params array. Has to be greater than 1.
paramsArray of notification parameters. It is okay to free this after calling this function.
Return values
0Success. The PDU is queued for sending.
-EINVAL
  • One of the attribute handles is invalid.
  • Only one parameter was passed. This API expects 2 or more.
  • Not all func were equal or not all user_data were equal.
  • One of the characteristics is not notifiable.
  • An UUID was passed in one of the parameters.
-ERANGE
  • The notifications cannot all fit in a single ATT_MULTIPLE_HANDLE_VALUE_NTF.
  • They exceed the MTU of all open ATT bearers.
-EPERMThe connection has a lower security level than required by one of the attributes.
-EOPNOTSUPPThe peer hasn't yet communicated that it supports this PDU type.

◆ bt_gatt_notify_uuid()

static int bt_gatt_notify_uuid ( struct bt_conn *  conn,
const struct bt_uuid uuid,
const struct bt_gatt_attr attr,
const void *  data,
uint16_t  len 
)
inlinestatic

#include <include/zephyr/bluetooth/gatt.h>

Notify attribute value change by UUID.

Send notification of attribute value change, if connection is NULL notify all peer that have notification enabled via CCC otherwise do a direct notification only on the given connection.

The attribute object is the starting point for the search of the UUID.

Parameters
connConnection object.
uuidThe UUID. If the server contains multiple services with the same UUID, then the first occurrence, starting from the attr given, is used.
attrPointer to an attribute that serves as the starting point for the search of a match for the UUID.
dataPointer to Attribute data.
lenAttribute value length.
Returns
0 in case of success or negative value in case of error.

◆ bt_gatt_service_is_registered()

bool bt_gatt_service_is_registered ( const struct bt_gatt_service svc)

#include <include/zephyr/bluetooth/gatt.h>

Check if GATT service is registered.

Parameters
svcService to be checked.
Returns
true if registered or false if not register.

◆ bt_gatt_service_register()

int bt_gatt_service_register ( struct bt_gatt_service svc)

#include <include/zephyr/bluetooth/gatt.h>

Register GATT service.

Register GATT service. Applications can make use of macros such as BT_GATT_PRIMARY_SERVICE, BT_GATT_CHARACTERISTIC, BT_GATT_DESCRIPTOR, etc.

When using CONFIG_BT_SETTINGS then all services that should have bond configuration loaded, i.e. CCC values, must be registered before calling settings_load.

When using CONFIG_BT_GATT_CACHING and CONFIG_BT_SETTINGS then all services that should be included in the GATT Database Hash calculation should be added before calling settings_load. All services registered after settings_load will trigger a new database hash calculation and a new hash stored.

There are two situations where this function can be called: either before bt_init() has been called, or after settings_load() has been called. Registering a service in the middle is not supported and will return an error.

Parameters
svcService containing the available attributes
Returns
0 in case of success or negative value in case of error.
-EAGAIN if bt_init() has been called but settings_load() hasn't yet.

◆ bt_gatt_service_unregister()

int bt_gatt_service_unregister ( struct bt_gatt_service svc)

#include <include/zephyr/bluetooth/gatt.h>

Unregister GATT service.

Parameters
svcService to be unregistered.
Returns
0 in case of success or negative value in case of error.