Zephyr Project API 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
237 const struct bt_uuid *uuid;
238
251
264
277
290
301
310 bool _auto_assigned_handle: 1;
312};
313
317 const struct bt_gatt_attr *attrs;
320};
321
331
339
349
361 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
362
364};
365
379 bool (*read_authorize)(struct bt_conn *conn,
380 const struct bt_gatt_attr *attr);
381
393 bool (*write_authorize)(struct bt_conn *conn,
394 const struct bt_gatt_attr *attr);
395};
396
405#define BT_GATT_CHRC_BROADCAST 0x01
411#define BT_GATT_CHRC_READ 0x02
417#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
423#define BT_GATT_CHRC_WRITE 0x08
430#define BT_GATT_CHRC_NOTIFY 0x10
436#define BT_GATT_CHRC_INDICATE 0x20
442#define BT_GATT_CHRC_AUTH 0x40
449#define BT_GATT_CHRC_EXT_PROP 0x80
450
460
462#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
463#define BT_GATT_CEP_WRITABLE_AUX 0x0002
464
470
478#define BT_GATT_CCC_NOTIFY 0x0001
484#define BT_GATT_CCC_INDICATE 0x0002
485
491
500#define BT_GATT_SCC_BROADCAST 0x0001
501
507
523
546static inline const char *bt_gatt_err_to_str(int gatt_err)
547{
548 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
549}
550
559
579
607
615
623
624enum {
627};
628
639typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
641 void *user_data);
642
655void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
656 const struct bt_uuid *uuid,
657 const void *attr_data, uint16_t num_matches,
659 void *user_data);
660
670static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
672 void *user_data)
673{
674 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
675 user_data);
676}
677
686struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
687
703 uint16_t attr_count,
704 const struct bt_uuid *uuid);
705
715
728
744ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
745 void *buf, uint16_t buf_len, uint16_t offset,
746 const void *value, uint16_t value_len);
747
764 const struct bt_gatt_attr *attr,
765 void *buf, uint16_t len, uint16_t offset);
766
774#define BT_GATT_SERVICE_DEFINE(_name, ...) \
775 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
776 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
777 BT_GATT_SERVICE(attr_##_name)
778
779#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
780 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
781
782#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
783
799#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
800 _name, _instances, _instance_num, _attrs_def) \
801 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
802 "The number of array elements does not match its size"); \
803 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
804 _instances, _attrs_def); \
805 static struct bt_gatt_service _name[] = { \
806 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
807 }
808
816#define BT_GATT_SERVICE(_attrs) \
817{ \
818 .attrs = _attrs, \
819 .attr_count = ARRAY_SIZE(_attrs), \
820}
821
829#define BT_GATT_PRIMARY_SERVICE(_service) \
830 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
831 bt_gatt_attr_read_service, NULL, (void *)_service)
832
843#define BT_GATT_SECONDARY_SERVICE(_service) \
844 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
845 bt_gatt_attr_read_service, NULL, (void *)_service)
846
863 const struct bt_gatt_attr *attr,
864 void *buf, uint16_t len, uint16_t offset);
865
873#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
874 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
875 bt_gatt_attr_read_included, NULL, _service_incl)
876
892ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
893 const struct bt_gatt_attr *attr, void *buf,
894 uint16_t len, uint16_t offset);
895
896#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
897{ \
898 .uuid = _uuid, \
899 .value_handle = _handle, \
900 .properties = _props, \
901}
902
920#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
921 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
922 bt_gatt_attr_read_chrc, NULL, \
923 ((struct bt_gatt_chrc[]) { \
924 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
925 })), \
926 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
927
928#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
929 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
930#elif defined(CONFIG_BT_CONN)
931 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
932#else
933 #define BT_GATT_CCC_MAX 0
934#endif
935
945
947struct _bt_gatt_ccc {
950
952 uint16_t value;
953
959 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
960
970 ssize_t (*cfg_write)(struct bt_conn *conn,
971 const struct bt_gatt_attr *attr, uint16_t value);
972
984 bool (*cfg_match)(struct bt_conn *conn,
985 const struct bt_gatt_attr *attr);
986};
987
1004ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
1005 const struct bt_gatt_attr *attr, void *buf,
1006 uint16_t len, uint16_t offset);
1007
1024ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
1025 const struct bt_gatt_attr *attr, const void *buf,
1026 uint16_t len, uint16_t offset, uint8_t flags);
1027
1028
1038#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match) \
1039 { \
1040 .cfg = {}, \
1041 .cfg_changed = _changed, \
1042 .cfg_write = _write, \
1043 .cfg_match = _match, \
1044 }
1045
1055#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1056 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1057 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1058 _ccc)
1059
1069#define BT_GATT_CCC(_changed, _perm) \
1070 BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
1071 {BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
1072
1089ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
1090 const struct bt_gatt_attr *attr, void *buf,
1091 uint16_t len, uint16_t offset);
1092
1100#define BT_GATT_CEP(_value) \
1101 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1102 bt_gatt_attr_read_cep, NULL, (void *)_value)
1103
1121ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
1122 const struct bt_gatt_attr *attr, void *buf,
1123 uint16_t len, uint16_t offset);
1124
1134#define BT_GATT_CUD(_value, _perm) \
1135 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1136 NULL, (void *)_value)
1137
1154ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1155 const struct bt_gatt_attr *attr, void *buf,
1156 uint16_t len, uint16_t offset);
1157
1165#define BT_GATT_CPF(_value) \
1166 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1167 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1168
1183#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1184 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1185
1198#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1199{ \
1200 .uuid = _uuid, \
1201 .read = _read, \
1202 .write = _write, \
1203 .user_data = _user_data, \
1204 .handle = 0, \
1205 .perm = _perm, \
1206}
1207
1213typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1214
1221 const struct bt_uuid *uuid;
1227 const struct bt_gatt_attr *attr;
1229 const void *data;
1236#if defined(CONFIG_BT_EATT)
1238#endif /* CONFIG_BT_EATT */
1239};
1240
1262int bt_gatt_notify_cb(struct bt_conn *conn,
1263 struct bt_gatt_notify_params *params);
1264
1316int bt_gatt_notify_multiple(struct bt_conn *conn,
1317 uint16_t num_params,
1318 struct bt_gatt_notify_params params[]);
1319
1339static inline int bt_gatt_notify(struct bt_conn *conn,
1340 const struct bt_gatt_attr *attr,
1341 const void *data, uint16_t len)
1342{
1343 struct bt_gatt_notify_params params;
1344
1345 memset(&params, 0, sizeof(params));
1346
1347 params.attr = attr;
1348 params.data = data;
1349 params.len = len;
1350#if defined(CONFIG_BT_EATT)
1352#endif /* CONFIG_BT_EATT */
1353
1354 return bt_gatt_notify_cb(conn, &params);
1355}
1356
1376static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1377 const struct bt_uuid *uuid,
1378 const struct bt_gatt_attr *attr,
1379 const void *data, uint16_t len)
1380{
1381 struct bt_gatt_notify_params params;
1382
1383 memset(&params, 0, sizeof(params));
1384
1385 params.uuid = uuid;
1386 params.attr = attr;
1387 params.data = data;
1388 params.len = len;
1389#if defined(CONFIG_BT_EATT)
1391#endif /* CONFIG_BT_EATT */
1392
1393 return bt_gatt_notify_cb(conn, &params);
1394}
1395
1396/* Forward declaration of the bt_gatt_indicate_params structure */
1398
1406typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1407 struct bt_gatt_indicate_params *params,
1408 uint8_t err);
1409
1411 struct bt_gatt_indicate_params *params);
1412
1420 const struct bt_uuid *uuid;
1426 const struct bt_gatt_attr *attr;
1432 const void *data;
1436 uint8_t _ref;
1437#if defined(CONFIG_BT_EATT)
1439#endif /* CONFIG_BT_EATT */
1440};
1441
1467int bt_gatt_indicate(struct bt_conn *conn,
1468 struct bt_gatt_indicate_params *params);
1469
1470
1489bool bt_gatt_is_subscribed(struct bt_conn *conn,
1490 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1491
1501uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1502
1518uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn);
1519
1531 void (*func)(struct bt_conn *conn, uint8_t err,
1532 struct bt_gatt_exchange_params *params);
1533};
1534
1562int bt_gatt_exchange_mtu(struct bt_conn *conn,
1563 struct bt_gatt_exchange_params *params);
1564
1566
1611typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1612 const struct bt_gatt_attr *attr,
1613 struct bt_gatt_discover_params *params);
1614
1616enum {
1657};
1658
1660#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1661
1665 const struct bt_uuid *uuid;
1668 union {
1669 struct {
1676 } _included;
1678 uint16_t start_handle;
1679 };
1684#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1687#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1688#if defined(CONFIG_BT_EATT)
1690#endif /* CONFIG_BT_EATT */
1691};
1692
1729int bt_gatt_discover(struct bt_conn *conn,
1730 struct bt_gatt_discover_params *params);
1731
1732struct bt_gatt_read_params;
1733
1749typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1750 struct bt_gatt_read_params *params,
1751 const void *data, uint16_t length);
1752
1762 union {
1763 struct {
1769 struct {
1786 struct {
1792 const struct bt_uuid *uuid;
1794 };
1795#if defined(CONFIG_BT_EATT)
1797#endif /* CONFIG_BT_EATT */
1799 uint16_t _att_mtu;
1800};
1801
1844int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
1845
1847
1855typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
1856 struct bt_gatt_write_params *params);
1857
1867 const void *data;
1870#if defined(CONFIG_BT_EATT)
1872#endif /* CONFIG_BT_EATT */
1873};
1874
1897int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
1898
1929int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
1930 const void *data, uint16_t length,
1931 bool sign, bt_gatt_complete_func_t func,
1932 void *user_data);
1933
1955static inline int bt_gatt_write_without_response(struct bt_conn *conn,
1956 uint16_t handle, const void *data,
1957 uint16_t length, bool sign)
1958{
1959 return bt_gatt_write_without_response_cb(conn, handle, data, length,
1960 sign, NULL, NULL);
1961}
1962
1964
1981typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
1982 struct bt_gatt_subscribe_params *params,
1983 const void *data, uint16_t length);
1984
1992typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
1993 struct bt_gatt_subscribe_params *params);
1994
1996enum {
2007
2021
2030
2042
2045
2054
2059#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2064#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2067#if defined(CONFIG_BT_SMP)
2073#endif
2076
2078#if defined(CONFIG_BT_EATT)
2080#endif /* CONFIG_BT_EATT */
2081};
2082
2120int bt_gatt_subscribe(struct bt_conn *conn,
2121 struct bt_gatt_subscribe_params *params);
2122
2140 struct bt_gatt_subscribe_params *params);
2141
2167int bt_gatt_unsubscribe(struct bt_conn *conn,
2168 struct bt_gatt_subscribe_params *params);
2169
2187void bt_gatt_cancel(struct bt_conn *conn, void *params);
2188
2191#ifdef __cplusplus
2192}
2193#endif
2194
2199#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:809
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_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:1611
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:1992
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.
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:1749
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:1955
int bt_gatt_discover(struct bt_conn *conn, struct bt_gatt_discover_params *params)
GATT Discover function.
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:1981
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:1855
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1636
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1620
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1627
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1622
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1656
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1618
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1645
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2020
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2043
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2041
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2006
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2029
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:1406
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:1376
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:1410
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
Register GATT authorization callbacks.
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:1339
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:670
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:933
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1213
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.
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:639
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:546
@ BT_GATT_ITER_STOP
Definition gatt.h:625
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:626
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
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
bt_gatt_perm
GATT attribute permission bit field values.
Definition gatt.h:37
@ 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
@ 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
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:97
#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:367
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:379
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:393
GATT callback structure.
Definition gatt.h:351
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:361
sys_snode_t node
Definition gatt.h:363
GATT CCC configuration entry.
Definition gatt.h:937
uint16_t value
Configuration value.
Definition gatt.h:943
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:941
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:939
Client Characteristic Configuration Attribute Value.
Definition gatt.h:487
uint16_t flags
Client Characteristic Configuration flags.
Definition gatt.h:489
Characteristic Extended Properties Attribute Value.
Definition gatt.h:466
uint16_t properties
Characteristic Extended properties.
Definition gatt.h:468
Characteristic Attribute Value.
Definition gatt.h:452
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:456
uint8_t properties
Characteristic properties.
Definition gatt.h:458
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:454
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:509
uint8_t name_space
Name space of the description.
Definition gatt.h:519
uint16_t unit
Unit of the characteristic.
Definition gatt.h:517
int8_t exponent
Exponent field to determine how the value of this characteristic is further formatted.
Definition gatt.h:515
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:521
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:511
GATT Discover Attributes parameters.
Definition gatt.h:1663
uint16_t start_handle
Included service start handle.
Definition gatt.h:1673
uint16_t end_handle
Included service end handle.
Definition gatt.h:1675
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1667
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1671
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1665
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1686
uint8_t type
Discover type.
Definition gatt.h:1683
enum bt_att_chan_opt chan_opt
Definition gatt.h:1689
GATT Exchange MTU parameters.
Definition gatt.h:1529
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Response callback.
Definition gatt.h:1531
Include Attribute Value.
Definition gatt.h:341
uint16_t end_handle
Service end handle.
Definition gatt.h:347
uint16_t start_handle
Service start handle.
Definition gatt.h:345
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:343
GATT Indicate Value parameters.
Definition gatt.h:1414
enum bt_att_chan_opt chan_opt
Definition gatt.h:1438
uint16_t len
Indicate Value length.
Definition gatt.h:1434
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1426
const void * data
Indicate Value data.
Definition gatt.h:1432
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1430
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1428
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1420
Definition gatt.h:1215
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1221
uint16_t len
Notification Value length.
Definition gatt.h:1231
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1227
enum bt_att_chan_opt chan_opt
Definition gatt.h:1237
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1233
void * user_data
Notification Value callback user data.
Definition gatt.h:1235
const void * data
Notification Value data.
Definition gatt.h:1229
GATT Read parameters.
Definition gatt.h:1754
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1761
enum bt_att_chan_opt chan_opt
Definition gatt.h:1796
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:1773
uint16_t offset
Attribute data offset.
Definition gatt.h:1767
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1756
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:1784
struct bt_gatt_read_params::@128::@131 multiple
uint16_t end_handle
Last requested handle number.
Definition gatt.h:1790
struct bt_gatt_read_params::@128::@132 by_uuid
uint16_t start_handle
First requested handle number.
Definition gatt.h:1788
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:1792
struct bt_gatt_read_params::@128::@130 single
uint16_t handle
Attribute handle.
Definition gatt.h:1765
Server Characteristic Configuration Attribute Value.
Definition gatt.h:503
uint16_t flags
Server Characteristic Configuration flags.
Definition gatt.h:505
GATT Service structure.
Definition gatt.h:315
const struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:317
size_t attr_count
Service Attribute count.
Definition gatt.h:319
Service Attribute Value.
Definition gatt.h:333
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:335
uint16_t end_handle
Service end handle.
Definition gatt.h:337
GATT Service structure.
Definition gatt.h:323
struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:325
size_t attr_count
Service Attribute count.
Definition gatt.h:327
sys_snode_t node
Definition gatt.h:329
GATT Subscribe parameters.
Definition gatt.h:2047
uint16_t value
Subscribe value.
Definition gatt.h:2066
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2072
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2058
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2053
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2056
sys_snode_t node
Definition gatt.h:2077
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2049
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2063
enum bt_att_chan_opt chan_opt
Definition gatt.h:2079
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition gatt.h:2061
GATT Write parameters.
Definition gatt.h:1859
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:1861
uint16_t handle
Attribute handle.
Definition gatt.h:1863
const void * data
Data to be written.
Definition gatt.h:1867
enum bt_att_chan_opt chan_opt
Definition gatt.h:1871
uint16_t offset
Attribute data offset.
Definition gatt.h:1865
uint16_t length
Length of the data.
Definition gatt.h:1869
This is a 'tentative' type and should be used as a pointer only.
Definition uuid.h:49
Misc utilities.
Bluetooth UUID handling.