Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gatt.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-2016 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_
12
20#include <stdint.h>
21#include <stddef.h>
22
23#include <sys/types.h>
24
25#include <zephyr/sys/slist.h>
26#include <zephyr/sys/util.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
92
100#define BT_GATT_ERR(_att_err) (-(_att_err))
101
103enum {
110
117
125};
126
127/* Forward declaration of GATT Attribute structure */
128struct bt_gatt_attr;
129
160typedef ssize_t (*bt_gatt_attr_read_func_t)(struct bt_conn *conn,
161 const struct bt_gatt_attr *attr,
162 void *buf, uint16_t len,
163 uint16_t offset);
164
203typedef ssize_t (*bt_gatt_attr_write_func_t)(struct bt_conn *conn,
204 const struct bt_gatt_attr *attr,
205 const void *buf, uint16_t len,
206 uint16_t offset, uint8_t flags);
207
302
306 const struct bt_gatt_attr *attrs;
309};
310
320
328
338
350 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
351
353};
354
368 bool (*read_authorize)(struct bt_conn *conn,
369 const struct bt_gatt_attr *attr);
370
382 bool (*write_authorize)(struct bt_conn *conn,
383 const struct bt_gatt_attr *attr);
384};
385
394#define BT_GATT_CHRC_BROADCAST 0x01
400#define BT_GATT_CHRC_READ 0x02
406#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
412#define BT_GATT_CHRC_WRITE 0x08
419#define BT_GATT_CHRC_NOTIFY 0x10
425#define BT_GATT_CHRC_INDICATE 0x20
431#define BT_GATT_CHRC_AUTH 0x40
438#define BT_GATT_CHRC_EXT_PROP 0x80
439
449
451#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
452#define BT_GATT_CEP_WRITABLE_AUX 0x0002
453
459
467#define BT_GATT_CCC_NOTIFY 0x0001
473#define BT_GATT_CCC_INDICATE 0x0002
474
480
489#define BT_GATT_SCC_BROADCAST 0x0001
490
496
512
535static inline const char *bt_gatt_err_to_str(int gatt_err)
536{
537 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
538}
539
548
568
596
604
612
613enum {
616};
617
628typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
630 void *user_data);
631
644void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
645 const struct bt_uuid *uuid,
646 const void *attr_data, uint16_t num_matches,
648 void *user_data);
649
659static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
661 void *user_data)
662{
663 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
664 user_data);
665}
666
675struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
676
692 uint16_t attr_count,
693 const struct bt_uuid *uuid);
694
704
716
732ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
733 void *buf, uint16_t buf_len, uint16_t offset,
734 const void *value, uint16_t value_len);
735
752 const struct bt_gatt_attr *attr,
753 void *buf, uint16_t len, uint16_t offset);
754
762#define BT_GATT_SERVICE_DEFINE(_name, ...) \
763 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
764 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
765 BT_GATT_SERVICE(attr_##_name)
766
767#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
768 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
769
770#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
771
787#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
788 _name, _instances, _instance_num, _attrs_def) \
789 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
790 "The number of array elements does not match its size"); \
791 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
792 _instances, _attrs_def); \
793 static struct bt_gatt_service _name[] = { \
794 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
795 }
796
804#define BT_GATT_SERVICE(_attrs) \
805{ \
806 .attrs = _attrs, \
807 .attr_count = ARRAY_SIZE(_attrs), \
808}
809
817#define BT_GATT_PRIMARY_SERVICE(_service) \
818 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
819 bt_gatt_attr_read_service, NULL, (void *)_service)
820
831#define BT_GATT_SECONDARY_SERVICE(_service) \
832 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
833 bt_gatt_attr_read_service, NULL, (void *)_service)
834
851 const struct bt_gatt_attr *attr,
852 void *buf, uint16_t len, uint16_t offset);
853
861#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
862 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
863 bt_gatt_attr_read_included, NULL, _service_incl)
864
880ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
881 const struct bt_gatt_attr *attr, void *buf,
882 uint16_t len, uint16_t offset);
883
884#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
885{ \
886 .uuid = _uuid, \
887 .value_handle = _handle, \
888 .properties = _props, \
889}
890
908#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
909 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
910 bt_gatt_attr_read_chrc, NULL, \
911 ((struct bt_gatt_chrc[]) { \
912 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
913 })), \
914 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
915
916#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
917 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
918#elif defined(CONFIG_BT_CONN)
919 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
920#else
921 #define BT_GATT_CCC_MAX 0
922#endif
923
933
935struct _bt_gatt_ccc {
938
940 uint16_t value;
941
947 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
948
958 ssize_t (*cfg_write)(struct bt_conn *conn,
959 const struct bt_gatt_attr *attr, uint16_t value);
960
972 bool (*cfg_match)(struct bt_conn *conn,
973 const struct bt_gatt_attr *attr);
974};
975
992ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
993 const struct bt_gatt_attr *attr, void *buf,
994 uint16_t len, uint16_t offset);
995
1012ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
1013 const struct bt_gatt_attr *attr, const void *buf,
1014 uint16_t len, uint16_t offset, uint8_t flags);
1015
1016
1026#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match) \
1027 { \
1028 .cfg = {}, \
1029 .cfg_changed = _changed, \
1030 .cfg_write = _write, \
1031 .cfg_match = _match, \
1032 }
1033
1043#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1044 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1045 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1046 _ccc)
1047
1057#define BT_GATT_CCC(_changed, _perm) \
1058 BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
1059 {BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
1060
1077ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
1078 const struct bt_gatt_attr *attr, void *buf,
1079 uint16_t len, uint16_t offset);
1080
1088#define BT_GATT_CEP(_value) \
1089 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1090 bt_gatt_attr_read_cep, NULL, (void *)_value)
1091
1109ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
1110 const struct bt_gatt_attr *attr, void *buf,
1111 uint16_t len, uint16_t offset);
1112
1122#define BT_GATT_CUD(_value, _perm) \
1123 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1124 NULL, (void *)_value)
1125
1142ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1143 const struct bt_gatt_attr *attr, void *buf,
1144 uint16_t len, uint16_t offset);
1145
1153#define BT_GATT_CPF(_value) \
1154 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1155 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1156
1171#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1172 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1173
1186#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1187{ \
1188 .uuid = _uuid, \
1189 .read = _read, \
1190 .write = _write, \
1191 .user_data = _user_data, \
1192 .handle = 0, \
1193 .perm = _perm, \
1194}
1195
1201typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1202
1209 const struct bt_uuid *uuid;
1215 const struct bt_gatt_attr *attr;
1217 const void *data;
1224#if defined(CONFIG_BT_EATT)
1226#endif /* CONFIG_BT_EATT */
1227};
1228
1250int bt_gatt_notify_cb(struct bt_conn *conn,
1251 struct bt_gatt_notify_params *params);
1252
1304int bt_gatt_notify_multiple(struct bt_conn *conn,
1305 uint16_t num_params,
1306 struct bt_gatt_notify_params params[]);
1307
1327static inline int bt_gatt_notify(struct bt_conn *conn,
1328 const struct bt_gatt_attr *attr,
1329 const void *data, uint16_t len)
1330{
1331 struct bt_gatt_notify_params params;
1332
1333 memset(&params, 0, sizeof(params));
1334
1335 params.attr = attr;
1336 params.data = data;
1337 params.len = len;
1338#if defined(CONFIG_BT_EATT)
1340#endif /* CONFIG_BT_EATT */
1341
1342 return bt_gatt_notify_cb(conn, &params);
1343}
1344
1364static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1365 const struct bt_uuid *uuid,
1366 const struct bt_gatt_attr *attr,
1367 const void *data, uint16_t len)
1368{
1369 struct bt_gatt_notify_params params;
1370
1371 memset(&params, 0, sizeof(params));
1372
1373 params.uuid = uuid;
1374 params.attr = attr;
1375 params.data = data;
1376 params.len = len;
1377#if defined(CONFIG_BT_EATT)
1379#endif /* CONFIG_BT_EATT */
1380
1381 return bt_gatt_notify_cb(conn, &params);
1382}
1383
1384/* Forward declaration of the bt_gatt_indicate_params structure */
1386
1394typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1395 struct bt_gatt_indicate_params *params,
1396 uint8_t err);
1397
1399 struct bt_gatt_indicate_params *params);
1400
1408 const struct bt_uuid *uuid;
1414 const struct bt_gatt_attr *attr;
1420 const void *data;
1424 uint8_t _ref;
1425#if defined(CONFIG_BT_EATT)
1427#endif /* CONFIG_BT_EATT */
1428};
1429
1455int bt_gatt_indicate(struct bt_conn *conn,
1456 struct bt_gatt_indicate_params *params);
1457
1458
1477bool bt_gatt_is_subscribed(struct bt_conn *conn,
1478 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1479
1489uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1490
1506uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn);
1507
1519 void (*func)(struct bt_conn *conn, uint8_t err,
1520 struct bt_gatt_exchange_params *params);
1521};
1522
1550int bt_gatt_exchange_mtu(struct bt_conn *conn,
1551 struct bt_gatt_exchange_params *params);
1552
1554
1599typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1600 const struct bt_gatt_attr *attr,
1601 struct bt_gatt_discover_params *params);
1602
1604enum {
1645};
1646
1648#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1649
1653 const struct bt_uuid *uuid;
1656 union {
1657 struct {
1664 } _included;
1666 uint16_t start_handle;
1667 };
1672#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1675#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1676#if defined(CONFIG_BT_EATT)
1678#endif /* CONFIG_BT_EATT */
1679};
1680
1717int bt_gatt_discover(struct bt_conn *conn,
1718 struct bt_gatt_discover_params *params);
1719
1720struct bt_gatt_read_params;
1721
1737typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1738 struct bt_gatt_read_params *params,
1739 const void *data, uint16_t length);
1740
1750 union {
1751 struct {
1757 struct {
1774 struct {
1780 const struct bt_uuid *uuid;
1782 };
1783#if defined(CONFIG_BT_EATT)
1785#endif /* CONFIG_BT_EATT */
1787 uint16_t _att_mtu;
1788};
1789
1832int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
1833
1835
1843typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
1844 struct bt_gatt_write_params *params);
1845
1855 const void *data;
1858#if defined(CONFIG_BT_EATT)
1860#endif /* CONFIG_BT_EATT */
1861};
1862
1885int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
1886
1917int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
1918 const void *data, uint16_t length,
1919 bool sign, bt_gatt_complete_func_t func,
1920 void *user_data);
1921
1943static inline int bt_gatt_write_without_response(struct bt_conn *conn,
1944 uint16_t handle, const void *data,
1945 uint16_t length, bool sign)
1946{
1947 return bt_gatt_write_without_response_cb(conn, handle, data, length,
1948 sign, NULL, NULL);
1949}
1950
1952
1969typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
1970 struct bt_gatt_subscribe_params *params,
1971 const void *data, uint16_t length);
1972
1980typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
1981 struct bt_gatt_subscribe_params *params);
1982
1984enum {
1995
2009
2018
2030
2033
2042
2047#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2052#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2055#if defined(CONFIG_BT_SMP)
2061#endif
2064
2066#if defined(CONFIG_BT_EATT)
2068#endif /* CONFIG_BT_EATT */
2069};
2070
2108int bt_gatt_subscribe(struct bt_conn *conn,
2109 struct bt_gatt_subscribe_params *params);
2110
2128 struct bt_gatt_subscribe_params *params);
2129
2155int bt_gatt_unsubscribe(struct bt_conn *conn,
2156 struct bt_gatt_subscribe_params *params);
2157
2175void bt_gatt_cancel(struct bt_conn *conn, void *params);
2176
2179#ifdef __cplusplus
2180}
2181#endif
2182
2187#endif /* ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_ */
Attribute Protocol handling.
Bluetooth connection handling.
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition atomic.h:111
bt_att_chan_opt
ATT channel option bit field values.
Definition att.h:171
static const char * bt_att_err_to_str(uint8_t att_err)
Converts a ATT error to string.
Definition att.h:121
@ BT_ATT_CHAN_OPT_NONE
Both Enhanced and Unenhanced channels can be used
Definition att.h:173
bt_security_t
Security level.
Definition conn.h:806
int bt_gatt_exchange_mtu(struct bt_conn *conn, struct bt_gatt_exchange_params *params)
Exchange MTU.
int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)
Read Attribute Value by handle.
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.
Definition gatt.h:1737
void(* bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params)
Write callback function.
Definition gatt.h:1843
void(* bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err, struct bt_gatt_subscribe_params *params)
Subscription callback function.
Definition gatt.h:1980
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.
void bt_gatt_cancel(struct bt_conn *conn, void *params)
Try to cancel the first pending request identified by params.
int bt_gatt_unsubscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params)
Unsubscribe 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_subscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params)
Subscribe Attribute Value Notification.
int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params)
Write Attribute Value by handle.
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.
Definition gatt.h:1943
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.
Definition gatt.h:1969
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.
Definition gatt.h:1599
int bt_gatt_discover(struct bt_conn *conn, struct bt_gatt_discover_params *params)
GATT Discover function.
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2008
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2031
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2029
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:1994
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2017
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1624
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1608
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1615
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1610
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1644
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1606
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1633
void(* bt_gatt_indicate_func_t)(struct bt_conn *conn, struct bt_gatt_indicate_params *params, uint8_t err)
Indication complete result callback.
Definition gatt.h:1394
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.
Definition gatt.h:1364
void bt_gatt_cb_register(struct bt_gatt_cb *cb)
Register GATT callbacks.
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.
uint16_t bt_gatt_attr_get_handle(const struct bt_gatt_attr *attr)
Get Attribute handle.
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.
uint16_t bt_gatt_get_mtu(struct bt_conn *conn)
Get ATT MTU for a connection.
struct bt_gatt_attr * bt_gatt_attr_next(const struct bt_gatt_attr *attr)
Iterate to the next attribute.
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.
int bt_gatt_indicate(struct bt_conn *conn, struct bt_gatt_indicate_params *params)
Indicate attribute value change.
int bt_gatt_notify_cb(struct bt_conn *conn, struct bt_gatt_notify_params *params)
Notify attribute value change.
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_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.
void(* bt_gatt_indicate_params_destroy_t)(struct bt_gatt_indicate_params *params)
Definition gatt.h:1398
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
Register GATT authorization callbacks.
uint8_t(* bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr, uint16_t handle, void *user_data)
Attribute iterator callback.
Definition gatt.h:628
uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn)
Get Unenhanced ATT (UATT) MTU for a connection.
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.
Definition gatt.h:1327
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.
uint16_t bt_gatt_attr_value_handle(const struct bt_gatt_attr *attr)
Get the handle of the characteristic value descriptor.
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.
Definition gatt.h:659
int bt_gatt_service_register(struct bt_gatt_service *svc)
Register GATT service.
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.
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.
#define BT_GATT_CCC_MAX
Definition gatt.h:921
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1201
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.
struct bt_gatt_attr * bt_gatt_find_by_uuid(const struct bt_gatt_attr *attr, uint16_t attr_count, const struct bt_uuid *uuid)
Find Attribute by UUID.
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.
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.
bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc)
Check if GATT service is registered.
int bt_gatt_service_unregister(struct bt_gatt_service *svc)
Unregister GATT service.
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.
static const char * bt_gatt_err_to_str(int gatt_err)
Converts a GATT error to string.
Definition gatt.h:535
@ BT_GATT_ITER_STOP
Definition gatt.h:614
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:615
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 Value write implementation.
Definition gatt.h:203
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.
Definition gatt.h:160
bt_gatt_perm
GATT attribute permission bit field values.
Definition gatt.h:37
@ BT_GATT_WRITE_FLAG_PREPARE
Attribute prepare write flag.
Definition gatt.h:109
@ BT_GATT_WRITE_FLAG_CMD
Attribute write command flag.
Definition gatt.h:116
@ BT_GATT_WRITE_FLAG_EXECUTE
Attribute write execute flag.
Definition gatt.h:124
@ BT_GATT_PERM_READ_ENCRYPT
Attribute read permission with encryption.
Definition gatt.h:51
@ BT_GATT_PERM_WRITE
Attribute write permission.
Definition gatt.h:45
@ BT_GATT_PERM_WRITE_ENCRYPT
Attribute write permission with encryption.
Definition gatt.h:57
@ BT_GATT_PERM_NONE
No operations supported, e.g.
Definition gatt.h:39
@ BT_GATT_PERM_READ
Attribute read permission.
Definition gatt.h:42
@ BT_GATT_PERM_PREPARE_WRITE
Attribute prepare write permission.
Definition gatt.h:78
@ BT_GATT_PERM_WRITE_LESC
Attribute write permission with LE Secure Connection encryption.
Definition gatt.h:90
@ BT_GATT_PERM_READ_AUTHEN
Attribute read permission with authentication.
Definition gatt.h:64
@ BT_GATT_PERM_WRITE_AUTHEN
Attribute write permission with authentication.
Definition gatt.h:71
@ BT_GATT_PERM_READ_LESC
Attribute read permission with LE Secure Connection encryption.
Definition gatt.h:84
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
__SIZE_TYPE__ ssize_t
Definition types.h:28
flags
Definition parser.h:96
#define bool
Definition stdbool.h:13
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
void * memset(void *buf, int c, size_t n)
Bluetooth LE Device Address.
Definition addr.h:49
GATT Attribute.
Definition gatt.h:224
bt_gatt_attr_read_func_t read
Attribute Value read method.
Definition gatt.h:250
uint16_t perm
Attribute Permissions.
Definition gatt.h:300
bt_gatt_attr_write_func_t write
Attribute Value write method.
Definition gatt.h:263
const struct bt_uuid * uuid
Attribute Type, aka.
Definition gatt.h:237
void * user_data
Private data for read() and write() implementation.
Definition gatt.h:276
uint16_t handle
Attribute Handle or zero, maybe?
Definition gatt.h:289
GATT authorization callback structure.
Definition gatt.h:356
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:368
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:382
GATT callback structure.
Definition gatt.h:340
void(* att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx)
The maximum ATT MTU on a connection has changed.
Definition gatt.h:350
sys_snode_t node
Definition gatt.h:352
GATT CCC configuration entry.
Definition gatt.h:925
uint16_t value
Configuration value.
Definition gatt.h:931
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:929
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:927
Client Characteristic Configuration Attribute Value.
Definition gatt.h:476
uint16_t flags
Client Characteristic Configuration flags.
Definition gatt.h:478
Characteristic Extended Properties Attribute Value.
Definition gatt.h:455
uint16_t properties
Characteristic Extended properties.
Definition gatt.h:457
Characteristic Attribute Value.
Definition gatt.h:441
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:445
uint8_t properties
Characteristic properties.
Definition gatt.h:447
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:443
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:498
uint8_t name_space
Name space of the description.
Definition gatt.h:508
uint16_t unit
Unit of the characteristic.
Definition gatt.h:506
int8_t exponent
Exponent field to determine how the value of this characteristic is further formatted.
Definition gatt.h:504
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:510
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:500
GATT Discover Attributes parameters.
Definition gatt.h:1651
uint16_t start_handle
Included service start handle.
Definition gatt.h:1661
uint16_t end_handle
Included service end handle.
Definition gatt.h:1663
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1655
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1659
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1653
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1674
uint8_t type
Discover type.
Definition gatt.h:1671
enum bt_att_chan_opt chan_opt
Definition gatt.h:1677
GATT Exchange MTU parameters.
Definition gatt.h:1517
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Response callback.
Definition gatt.h:1519
Include Attribute Value.
Definition gatt.h:330
uint16_t end_handle
Service end handle.
Definition gatt.h:336
uint16_t start_handle
Service start handle.
Definition gatt.h:334
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:332
GATT Indicate Value parameters.
Definition gatt.h:1402
enum bt_att_chan_opt chan_opt
Definition gatt.h:1426
uint16_t len
Indicate Value length.
Definition gatt.h:1422
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1414
const void * data
Indicate Value data.
Definition gatt.h:1420
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1418
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1416
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1408
Definition gatt.h:1203
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1209
uint16_t len
Notification Value length.
Definition gatt.h:1219
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1215
enum bt_att_chan_opt chan_opt
Definition gatt.h:1225
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1221
void * user_data
Notification Value callback user data.
Definition gatt.h:1223
const void * data
Notification Value data.
Definition gatt.h:1217
GATT Read parameters.
Definition gatt.h:1742
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1749
enum bt_att_chan_opt chan_opt
Definition gatt.h:1784
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:1761
uint16_t offset
Attribute data offset.
Definition gatt.h:1755
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1744
struct bt_gatt_read_params::@125::@127 single
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:1772
uint16_t end_handle
Last requested handle number.
Definition gatt.h:1778
struct bt_gatt_read_params::@125::@128 multiple
struct bt_gatt_read_params::@125::@129 by_uuid
uint16_t start_handle
First requested handle number.
Definition gatt.h:1776
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:1780
uint16_t handle
Attribute handle.
Definition gatt.h:1753
Server Characteristic Configuration Attribute Value.
Definition gatt.h:492
uint16_t flags
Server Characteristic Configuration flags.
Definition gatt.h:494
GATT Service structure.
Definition gatt.h:304
const struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:306
size_t attr_count
Service Attribute count.
Definition gatt.h:308
Service Attribute Value.
Definition gatt.h:322
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:324
uint16_t end_handle
Service end handle.
Definition gatt.h:326
GATT Service structure.
Definition gatt.h:312
struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:314
size_t attr_count
Service Attribute count.
Definition gatt.h:316
sys_snode_t node
Definition gatt.h:318
GATT Subscribe parameters.
Definition gatt.h:2035
uint16_t value
Subscribe value.
Definition gatt.h:2054
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2060
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2046
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2041
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2044
sys_snode_t node
Definition gatt.h:2065
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2037
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2051
enum bt_att_chan_opt chan_opt
Definition gatt.h:2067
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition gatt.h:2049
GATT Write parameters.
Definition gatt.h:1847
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:1849
uint16_t handle
Attribute handle.
Definition gatt.h:1851
const void * data
Data to be written.
Definition gatt.h:1855
enum bt_att_chan_opt chan_opt
Definition gatt.h:1859
uint16_t offset
Attribute data offset.
Definition gatt.h:1853
uint16_t length
Length of the data.
Definition gatt.h:1857
This is a 'tentative' type and should be used as a pointer only.
Definition uuid.h:49
Misc utilities.
Bluetooth UUID handling.