Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gatt.h File Reference

Generic Attribute Profile handling. More...

#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/att.h>
#include <zephyr/sys/iterable_sections.h>

Go to the source code of this file.

Data Structures

struct  bt_gatt_attr
 GATT Attribute structure. More...
 
struct  bt_gatt_service_static
 GATT Service structure. More...
 
struct  bt_gatt_service
 GATT Service structure. More...
 
struct  bt_gatt_service_val
 Service Attribute Value. More...
 
struct  bt_gatt_include
 Include Attribute Value. More...
 
struct  bt_gatt_cb
 GATT callback structure. More...
 
struct  bt_gatt_authorization_cb
 GATT authorization callback structure. More...
 
struct  bt_gatt_chrc
 Characteristic Attribute Value. More...
 
struct  bt_gatt_cep
 Characteristic Extended Properties Attribute Value. More...
 
struct  bt_gatt_ccc
 Client Characteristic Configuration Attribute Value. More...
 
struct  bt_gatt_scc
 Server Characteristic Configuration Attribute Value. More...
 
struct  bt_gatt_cpf
 GATT Characteristic Presentation Format Attribute Value. More...
 
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...
 
struct  bt_gatt_exchange_params
 GATT Exchange MTU parameters. More...
 
struct  bt_gatt_discover_params
 GATT Discover Attributes parameters. More...
 
struct  bt_gatt_read_params
 GATT Read parameters. More...
 
struct  bt_gatt_write_params
 GATT Write parameters. More...
 
struct  bt_gatt_subscribe_params
 GATT Subscribe parameters. More...
 

Macros

#define BT_GATT_ERR(_att_err)   (-(_att_err))
 Construct error return value for attribute read and write callbacks.
 
#define BT_GATT_CHRC_BROADCAST   0x01
 Characteristic Properties Bit field values.
 
#define BT_GATT_CHRC_READ   0x02
 Characteristic read property.
 
#define BT_GATT_CHRC_WRITE_WITHOUT_RESP   0x04
 Characteristic write without response property.
 
#define BT_GATT_CHRC_WRITE   0x08
 Characteristic write with response property.
 
#define BT_GATT_CHRC_NOTIFY   0x10
 Characteristic notify property.
 
#define BT_GATT_CHRC_INDICATE   0x20
 Characteristic indicate property.
 
#define BT_GATT_CHRC_AUTH   0x40
 Characteristic Authenticated Signed Writes property.
 
#define BT_GATT_CHRC_EXT_PROP   0x80
 Characteristic Extended Properties property.
 
#define BT_GATT_CEP_RELIABLE_WRITE   0x0001
 Characteristic Extended Properties Bit field values.
 
#define BT_GATT_CEP_WRITABLE_AUX   0x0002
 
#define BT_GATT_CCC_NOTIFY   0x0001
 Client Characteristic Configuration Values.
 
#define BT_GATT_CCC_INDICATE   0x0002
 Client Characteristic Configuration Indication.
 
#define BT_GATT_SCC_BROADCAST   0x0001
 Server Characteristic Configuration Values.
 
#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 ssize_t(* bt_gatt_attr_read_func_t) (struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
 Attribute read callback.
 
typedef ssize_t(* bt_gatt_attr_write_func_t) (struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
 Attribute write callback.
 
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)
 
typedef uint8_t(* bt_gatt_discover_func_t) (struct bt_conn *conn, const struct bt_gatt_attr *attr, struct bt_gatt_discover_params *params)
 Discover attribute callback function.
 
typedef uint8_t(* bt_gatt_read_func_t) (struct bt_conn *conn, uint8_t err, struct bt_gatt_read_params *params, const void *data, uint16_t length)
 Read callback function.
 
typedef void(* bt_gatt_write_func_t) (struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params)
 Write callback function.
 
typedef uint8_t(* bt_gatt_notify_func_t) (struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length)
 Notification callback function.
 
typedef void(* bt_gatt_subscribe_func_t) (struct bt_conn *conn, uint8_t err, struct bt_gatt_subscribe_params *params)
 Subscription callback function.
 

Enumerations

enum  bt_gatt_perm {
  BT_GATT_PERM_NONE = 0 , BT_GATT_PERM_READ = BIT(0) , BT_GATT_PERM_WRITE = BIT(1) , BT_GATT_PERM_READ_ENCRYPT = BIT(2) ,
  BT_GATT_PERM_WRITE_ENCRYPT = BIT(3) , BT_GATT_PERM_READ_AUTHEN = BIT(4) , BT_GATT_PERM_WRITE_AUTHEN = BIT(5) , BT_GATT_PERM_PREPARE_WRITE = BIT(6) ,
  BT_GATT_PERM_READ_LESC = BIT(7) , BT_GATT_PERM_WRITE_LESC = BIT(8)
}
 GATT attribute permission bit field values. More...
 
enum  { BT_GATT_WRITE_FLAG_PREPARE = BIT(0) , BT_GATT_WRITE_FLAG_CMD = BIT(1) , BT_GATT_WRITE_FLAG_EXECUTE = BIT(2) }
 GATT attribute write flags. More...
 
enum  { BT_GATT_ITER_STOP = 0 , BT_GATT_ITER_CONTINUE }
 
enum  {
  BT_GATT_DISCOVER_PRIMARY , BT_GATT_DISCOVER_SECONDARY , BT_GATT_DISCOVER_INCLUDE , BT_GATT_DISCOVER_CHARACTERISTIC ,
  BT_GATT_DISCOVER_DESCRIPTOR , BT_GATT_DISCOVER_ATTRIBUTE , BT_GATT_DISCOVER_STD_CHAR_DESC
}
 GATT Discover types. More...
 
enum  {
  BT_GATT_SUBSCRIBE_FLAG_VOLATILE , BT_GATT_SUBSCRIBE_FLAG_NO_RESUB , BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING , BT_GATT_SUBSCRIBE_FLAG_SENT ,
  BT_GATT_SUBSCRIBE_NUM_FLAGS
}
 Subscription flags. More...
 

Functions

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.
 
int bt_gatt_exchange_mtu (struct bt_conn *conn, struct bt_gatt_exchange_params *params)
 Exchange MTU.
 
int bt_gatt_discover (struct bt_conn *conn, struct bt_gatt_discover_params *params)
 GATT Discover function.
 
int bt_gatt_read (struct bt_conn *conn, struct bt_gatt_read_params *params)
 Read Attribute Value by handle.
 
int bt_gatt_write (struct bt_conn *conn, struct bt_gatt_write_params *params)
 Write Attribute Value by handle.
 
int bt_gatt_write_without_response_cb (struct bt_conn *conn, uint16_t handle, const void *data, uint16_t length, bool sign, bt_gatt_complete_func_t func, void *user_data)
 Write Attribute Value by handle without response with callback.
 
static int bt_gatt_write_without_response (struct bt_conn *conn, uint16_t handle, const void *data, uint16_t length, bool sign)
 Write Attribute Value by handle without response.
 
int bt_gatt_subscribe (struct bt_conn *conn, struct bt_gatt_subscribe_params *params)
 Subscribe Attribute Value Notification.
 
int bt_gatt_resubscribe (uint8_t id, const bt_addr_le_t *peer, struct bt_gatt_subscribe_params *params)
 Resubscribe Attribute Value Notification subscription.
 
int bt_gatt_unsubscribe (struct bt_conn *conn, struct bt_gatt_subscribe_params *params)
 Unsubscribe Attribute Value Notification.
 
void bt_gatt_cancel (struct bt_conn *conn, void *params)
 Try to cancel the first pending request identified by params.
 

Detailed Description

Generic Attribute Profile handling.