Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS

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

Typedefs

typedef uint8_t(* bt_gatt_attr_func_t) (const struct bt_gatt_attr *attr, uint16_t handle, void *user_data)
 Attribute iterator callback. More...
 
typedef void(* bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data)
 Notification complete result callback. More...
 
typedef void(* bt_gatt_indicate_func_t) (struct bt_conn *conn, struct bt_gatt_indicate_params *params, uint8_t err)
 Indication complete result callback. More...
 
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

void bt_gatt_cb_register (struct bt_gatt_cb *cb)
 Register GATT callbacks. More...
 
int bt_gatt_service_register (struct bt_gatt_service *svc)
 Register GATT service. More...
 
int bt_gatt_service_unregister (struct bt_gatt_service *svc)
 Unregister GATT service. *. More...
 
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. More...
 
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. More...
 
struct bt_gatt_attrbt_gatt_attr_next (const struct bt_gatt_attr *attr)
 Iterate to the next attribute. More...
 
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. More...
 
uint16_t bt_gatt_attr_get_handle (const struct bt_gatt_attr *attr)
 Get Attribute handle. More...
 
uint16_t bt_gatt_attr_value_handle (const struct bt_gatt_attr *attr)
 Get the handle of the characteristic value descriptor. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int bt_gatt_notify_cb (struct bt_conn *conn, struct bt_gatt_notify_params *params)
 Notify attribute value change. More...
 
int bt_gatt_notify_multiple (struct bt_conn *conn, uint16_t num_params, struct bt_gatt_notify_params *params)
 Notify multiple attribute value change. More...
 
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. More...
 
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. More...
 
int bt_gatt_indicate (struct bt_conn *conn, struct bt_gatt_indicate_params *params)
 Indicate attribute value change. More...
 
bool bt_gatt_is_subscribed (struct bt_conn *conn, const struct bt_gatt_attr *attr, uint16_t ccc_value)
 Check if connection have subscribed to attribute. More...
 
uint16_t bt_gatt_get_mtu (struct bt_conn *conn)
 Get ATT MTU for a connection. More...
 

Detailed Description

Macro Definition Documentation

◆ BT_GATT_ATTRIBUTE

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

#include <include/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.
_readAttribute read callback.
_writeAttribute write callback.
_user_dataAttribute user data.

◆ BT_GATT_CCC

#define BT_GATT_CCC (   _changed,
  _perm 
)

#include <include/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:778
#define BT_GATT_CCC_MANAGED(_ccc, _perm)
Managed Client Characteristic Configuration Declaration Macro.
Definition: gatt.h:794

Client Characteristic Configuration Declaration Macro.

Helper macro to declare a CCC attribute.

Parameters
_changedConfiguration changed callback.
_permCCC access permissions.

◆ BT_GATT_CCC_INITIALIZER

#define BT_GATT_CCC_INITIALIZER (   _changed,
  _write,
  _match 
)

#include <include/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/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:931
#define BT_UUID_GATT_CCC
GATT Client Characteristic Configuration.
Definition: uuid.h:519

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.

◆ BT_GATT_CCC_MAX

#define BT_GATT_CCC_MAX   0

◆ BT_GATT_CEP

#define BT_GATT_CEP (   _value)

#include <include/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:917
@ BT_GATT_PERM_READ
Definition: gatt.h:38
#define BT_UUID_GATT_CEP
GATT Characteristic Extended Properties.
Definition: uuid.h:501

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/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:492
Characteristic Attribute Value.
Definition: gatt.h:256

Characteristic and Value Declaration Macro.

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

Parameters
_uuidCharacteristic attribute uuid.
_propsCharacteristic attribute properties.
_permCharacteristic Attribute access permissions.
_readCharacteristic Attribute read callback.
_writeCharacteristic Attribute write callback.
_user_dataCharacteristic Attribute user data.

◆ BT_GATT_CHRC_INIT

#define BT_GATT_CHRC_INIT (   _uuid,
  _handle,
  _props 
)

#include <include/bluetooth/gatt.h>

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

◆ BT_GATT_CPF

#define BT_GATT_CPF (   _value)

#include <include/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:537

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/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:510

Characteristic User Format Descriptor Declaration Macro.

Helper macro to declare a CUD attribute.

Parameters
_valueUser description NULL-terminated C string.
_permDescriptor attribute access permissions.

◆ BT_GATT_DESCRIPTOR

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

#include <include/bluetooth/gatt.h>

Descriptor Declaration Macro.

Helper macro to declare a descriptor attribute.

Parameters
_uuidDescriptor attribute uuid.
_permDescriptor attribute access permissions.
_readDescriptor attribute read callback.
_writeDescriptor attribute write callback.
_user_dataDescriptor attribute user data.

◆ BT_GATT_INCLUDE_SERVICE

#define BT_GATT_INCLUDE_SERVICE (   _service_incl)

#include <include/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:483

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/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_service, NULL, _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:465

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/bluetooth/gatt.h>

Value:
bt_gatt_attr_read_service, NULL, _service)
#define BT_UUID_GATT_SECONDARY
GATT Secondary Service.
Definition: uuid.h:474

Secondary Service Declaration Macro.

Helper macro to declare a secondary service attribute.

Parameters
_serviceService attribute value.

◆ BT_GATT_SERVICE

#define BT_GATT_SERVICE (   _attrs)

#include <include/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:92

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/bluetooth/gatt.h>

Value:
const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
BT_GATT_SERVICE(attr_##_name)
#define STRUCT_SECTION_ITERABLE(struct_type, name)
Defines a new iterable section.
Definition: common.h:199
GATT Attribute structure.
Definition: gatt.h:104
GATT Service structure.
Definition: gatt.h:150

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/bluetooth/gatt.h>

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

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 serivce. 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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_cb_register()

void bt_gatt_cb_register ( struct bt_gatt_cb cb)

#include <include/bluetooth/gatt.h>

Register GATT callbacks.

Register callbacks to monitor the state of GATT.

Parameters
cbCallback struct.

◆ 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/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/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/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/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/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_value 
)

#include <include/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_valueThe subscription type, either notifications or indications.
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/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/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

embed:rst:inline :kconfig:`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/bluetooth/gatt.h>

Notify multiple attribute value change.

This function works in the same way as bt_gatt_notify_cb.

Parameters
connConnection object.
num_paramsNumber of notification parameters.
paramsArray of notification parameters.
Returns
0 in case of success or negative value in case of error.

◆ 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/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_register()

int bt_gatt_service_register ( struct bt_gatt_service svc)

#include <include/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

embed:rst:inline :kconfig:`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

embed:rst:inline :kconfig:`CONFIG_BT_GATT_CACHING` 

and

embed:rst:inline :kconfig:`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.

Parameters
svcService containing the available attributes
Returns
0 in case of success or negative value in case of error.

◆ bt_gatt_service_unregister()

int bt_gatt_service_unregister ( struct bt_gatt_service svc)

#include <include/bluetooth/gatt.h>

Unregister GATT service. *.

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