Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gatt.h
Go to the documentation of this file.
1
4
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
22
23#include <stdint.h>
24#include <stddef.h>
25#include <string.h>
26
27#include <sys/types.h>
28
29#include <zephyr/autoconf.h>
34#include <zephyr/sys/atomic.h>
36#include <zephyr/sys/slist.h>
37#include <zephyr/sys/util.h>
39#include <zephyr/toolchain.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
101
109#define BT_GATT_ERR(_att_err) (-(_att_err))
110
135
136/* Forward declaration of GATT Attribute structure */
137struct bt_gatt_attr;
138
169typedef ssize_t (*bt_gatt_attr_read_func_t)(struct bt_conn *conn,
170 const struct bt_gatt_attr *attr,
171 void *buf, uint16_t len,
172 uint16_t offset);
173
212typedef ssize_t (*bt_gatt_attr_write_func_t)(struct bt_conn *conn,
213 const struct bt_gatt_attr *attr,
214 const void *buf, uint16_t len,
215 uint16_t offset, uint8_t flags);
216
241 const struct bt_uuid *uuid;
242
255
268
281
291
300
309 bool _auto_assigned_handle: 1;
311};
312
321 const struct bt_gatt_attr *attrs;
324};
325
340 sys_snode_t node;
342};
343
355
370
382 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
383
387 sys_snode_t node;
389};
390
404 bool (*read_authorize)(struct bt_conn *conn,
405 const struct bt_gatt_attr *attr);
406
418 bool (*write_authorize)(struct bt_conn *conn,
419 const struct bt_gatt_attr *attr);
420};
421
423
430#define BT_GATT_CHRC_BROADCAST 0x01
436#define BT_GATT_CHRC_READ 0x02
442#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
448#define BT_GATT_CHRC_WRITE 0x08
455#define BT_GATT_CHRC_NOTIFY 0x10
461#define BT_GATT_CHRC_INDICATE 0x20
469#define BT_GATT_CHRC_AUTH 0x40 __DEPRECATED_MACRO
476#define BT_GATT_CHRC_EXT_PROP 0x80
477
491
493#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
494#define BT_GATT_CEP_WRITABLE_AUX 0x0002
495
507
509
515#define BT_GATT_CCC_NOTIFY 0x0001
521#define BT_GATT_CCC_INDICATE 0x0002
522
531
533
540#define BT_GATT_SCC_BROADCAST 0x0001
541
550
590
596
613static inline const char *bt_gatt_err_to_str(int gatt_err)
614{
615 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
616}
617
626
637
657
685
693
701
709
720typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
722 void *user_data);
723
737void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
738 const struct bt_uuid *uuid,
739 const void *attr_data, uint16_t num_matches,
741 void *user_data);
742
752static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
754 void *user_data)
755{
756 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
757 user_data);
758}
759
768struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
769
785 uint16_t attr_count,
786 const struct bt_uuid *uuid);
787
797
810
826ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
827 void *buf, uint16_t buf_len, uint16_t offset,
828 const void *value, uint16_t value_len);
829
846 const struct bt_gatt_attr *attr,
847 void *buf, uint16_t len, uint16_t offset);
848
856#define BT_GATT_SERVICE_DEFINE(_name, ...) \
857 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
858 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
859 BT_GATT_SERVICE(attr_##_name)
860
861#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
862 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
863
864#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
865
881#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
882 _name, _instances, _instance_num, _attrs_def) \
883 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
884 "The number of array elements does not match its size"); \
885 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
886 _instances, _attrs_def); \
887 static struct bt_gatt_service _name[] = { \
888 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
889 }
890
898#define BT_GATT_SERVICE(_attrs) \
899{ \
900 .attrs = _attrs, \
901 .attr_count = ARRAY_SIZE(_attrs), \
902}
903
911#define BT_GATT_PRIMARY_SERVICE(_service) \
912 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
913 bt_gatt_attr_read_service, NULL, (void *)_service)
914
925#define BT_GATT_SECONDARY_SERVICE(_service) \
926 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
927 bt_gatt_attr_read_service, NULL, (void *)_service)
928
946 const struct bt_gatt_attr *attr,
947 void *buf, uint16_t len, uint16_t offset);
948
956#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
957 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
958 bt_gatt_attr_read_included, NULL, _service_incl)
959
975ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
976 const struct bt_gatt_attr *attr, void *buf,
977 uint16_t len, uint16_t offset);
978
989#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
990{ \
991 .uuid = _uuid, \
992 .value_handle = _handle, \
993 .properties = _props, \
994}
995
1013#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
1014 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
1015 bt_gatt_attr_read_chrc, NULL, \
1016 ((struct bt_gatt_chrc[]) { \
1017 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
1018 })), \
1019 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1020
1032#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
1033 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
1034#elif defined(CONFIG_BT_CONN)
1035 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
1036#else
1037 #define BT_GATT_CCC_MAX 0
1038#endif
1039
1057
1059#define _bt_gatt_ccc bt_gatt_ccc_managed_user_data __DEPRECATED_MACRO
1060
1068
1071
1077 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
1078
1088 ssize_t (*cfg_write)(struct bt_conn *conn,
1089 const struct bt_gatt_attr *attr, uint16_t value);
1090
1102 bool (*cfg_match)(struct bt_conn *conn,
1103 const struct bt_gatt_attr *attr);
1104};
1105
1125ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
1126 const struct bt_gatt_attr *attr, void *buf,
1127 uint16_t len, uint16_t offset);
1128
1148ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
1149 const struct bt_gatt_attr *attr, const void *buf,
1150 uint16_t len, uint16_t offset, uint8_t flags);
1151
1153#define BT_GATT_CCC_INITIALIZER BT_GATT_CCC_MANAGED_USER_DATA_INIT __DEPRECATED_MACRO
1154
1164#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1165 { \
1166 .cfg = {}, \
1167 .cfg_changed = _changed, \
1168 .cfg_write = _write, \
1169 .cfg_match = _match, \
1170 }
1171
1184#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1185 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1186 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1187 _ccc)
1188
1198#define BT_GATT_CCC(_changed, _perm) \
1199 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1200 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1201 _perm)
1202
1213#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1214 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1215 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1216 _perm)
1217
1234ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
1235 const struct bt_gatt_attr *attr, void *buf,
1236 uint16_t len, uint16_t offset);
1237
1245#define BT_GATT_CEP(_value) \
1246 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1247 bt_gatt_attr_read_cep, NULL, (void *)_value)
1248
1266ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
1267 const struct bt_gatt_attr *attr, void *buf,
1268 uint16_t len, uint16_t offset);
1269
1279#define BT_GATT_CUD(_value, _perm) \
1280 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1281 NULL, (void *)_value)
1282
1299ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1300 const struct bt_gatt_attr *attr, void *buf,
1301 uint16_t len, uint16_t offset);
1302
1310#define BT_GATT_CPF(_value) \
1311 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1312 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1313
1328#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1329 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1330
1343#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1344{ \
1345 .uuid = _uuid, \
1346 .read = _read, \
1347 .write = _write, \
1348 .user_data = _user_data, \
1349 .handle = 0, \
1350 .perm = _perm, \
1351}
1352
1358typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1359
1370 const struct bt_uuid *uuid;
1376 const struct bt_gatt_attr *attr;
1378 const void *data;
1385#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1388#endif /* CONFIG_BT_EATT */
1389};
1390
1410int bt_gatt_notify_cb(struct bt_conn *conn,
1411 struct bt_gatt_notify_params *params);
1412
1464int bt_gatt_notify_multiple(struct bt_conn *conn,
1465 uint16_t num_params,
1466 struct bt_gatt_notify_params params[]);
1467
1487static inline int bt_gatt_notify(struct bt_conn *conn,
1488 const struct bt_gatt_attr *attr,
1489 const void *data, uint16_t len)
1490{
1491 struct bt_gatt_notify_params params;
1492
1493 memset(&params, 0, sizeof(params));
1494
1495 params.attr = attr;
1496 params.data = data;
1497 params.len = len;
1498#if defined(CONFIG_BT_EATT)
1500#endif /* CONFIG_BT_EATT */
1501
1502 return bt_gatt_notify_cb(conn, &params);
1503}
1504
1524static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1525 const struct bt_uuid *uuid,
1526 const struct bt_gatt_attr *attr,
1527 const void *data, uint16_t len)
1528{
1529 struct bt_gatt_notify_params params;
1530
1531 memset(&params, 0, sizeof(params));
1532
1533 params.uuid = uuid;
1534 params.attr = attr;
1535 params.data = data;
1536 params.len = len;
1537#if defined(CONFIG_BT_EATT)
1539#endif /* CONFIG_BT_EATT */
1540
1541 return bt_gatt_notify_cb(conn, &params);
1542}
1543
1544/* Forward declaration of the bt_gatt_indicate_params structure */
1546
1554typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1555 struct bt_gatt_indicate_params *params,
1556 uint8_t err);
1557
1567 struct bt_gatt_indicate_params *params);
1568
1580 const struct bt_uuid *uuid;
1586 const struct bt_gatt_attr *attr;
1592 const void *data;
1596 uint8_t _ref;
1597#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1600#endif /* CONFIG_BT_EATT */
1601};
1602
1628int bt_gatt_indicate(struct bt_conn *conn,
1629 struct bt_gatt_indicate_params *params);
1630
1649bool bt_gatt_is_subscribed(struct bt_conn *conn,
1650 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1651
1661uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1662
1678uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn);
1679
1681
1687
1698 void (*func)(struct bt_conn *conn, uint8_t err,
1699 struct bt_gatt_exchange_params *params);
1700};
1701
1726int bt_gatt_exchange_mtu(struct bt_conn *conn,
1727 struct bt_gatt_exchange_params *params);
1728
1730
1780typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1781 const struct bt_gatt_attr *attr,
1782 struct bt_gatt_discover_params *params);
1783
1827
1829#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1830
1834 const struct bt_uuid *uuid;
1837 union {
1839 struct {
1846 } _included;
1848 uint16_t start_handle;
1849 };
1859#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1862#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1863#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1866#endif /* CONFIG_BT_EATT */
1867};
1868
1902int bt_gatt_discover(struct bt_conn *conn,
1903 struct bt_gatt_discover_params *params);
1904
1905struct bt_gatt_read_params;
1906
1925typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1926 struct bt_gatt_read_params *params,
1927 const void *data, uint16_t length);
1928
1938 union {
1939 struct {
1945 struct {
1962 struct {
1986 const struct bt_uuid *uuid;
1988 };
1989#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1992#endif /* CONFIG_BT_EATT */
1994 uint16_t _att_mtu;
1995};
1996
2038int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
2039
2041
2049typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
2050 struct bt_gatt_write_params *params);
2051
2061 const void *data;
2064#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2067#endif /* CONFIG_BT_EATT */
2068};
2069
2087int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
2088
2114int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
2115 const void *data, uint16_t length,
2116 bool sign, bt_gatt_complete_func_t func,
2117 void *user_data);
2118
2137static inline int bt_gatt_write_without_response(struct bt_conn *conn,
2138 uint16_t handle, const void *data,
2139 uint16_t length, bool sign)
2140{
2141 return bt_gatt_write_without_response_cb(conn, handle, data, length,
2142 sign, NULL, NULL);
2143}
2144
2146
2163typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
2164 struct bt_gatt_subscribe_params *params,
2165 const void *data, uint16_t length);
2166
2174typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
2175 struct bt_gatt_subscribe_params *params);
2176
2227
2236
2241#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2246#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2249#if defined(CONFIG_BT_SMP)
2255#endif
2258
2262 sys_snode_t node;
2264#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2267#endif /* CONFIG_BT_EATT */
2268};
2269
2304int bt_gatt_subscribe(struct bt_conn *conn,
2305 struct bt_gatt_subscribe_params *params);
2306
2324 struct bt_gatt_subscribe_params *params);
2325
2348int bt_gatt_unsubscribe(struct bt_conn *conn,
2349 struct bt_gatt_subscribe_params *params);
2350
2368void bt_gatt_cancel(struct bt_conn *conn, void *params);
2369
2371
2372#ifdef __cplusplus
2373}
2374#endif
2375
2379
2380#endif /* ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_ */
Bluetooth device address definitions and utilities.
Attribute Protocol handling.
Bluetooth UUID handling.
Bluetooth connection handling.
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition atomic.h:113
bt_att_chan_opt
ATT channel option bit field values.
Definition att.h:177
static const char * bt_att_err_to_str(uint8_t att_err)
Converts a ATT error to string.
Definition att.h:127
@ BT_ATT_CHAN_OPT_NONE
Both Enhanced and Unenhanced channels can be used.
Definition att.h:179
bt_security_t
Security level.
Definition conn.h:1139
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:1925
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:2049
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:2174
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:2137
bt_gatt_sub_flag
Subscription flags.
Definition gatt.h:2178
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:2163
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:1780
int bt_gatt_discover(struct bt_conn *conn, struct bt_gatt_discover_params *params)
GATT Discover function.
bt_gatt_discover_type
GATT Discover types.
Definition gatt.h:1785
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2202
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2225
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2223
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2188
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2211
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1805
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1789
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1796
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1791
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1825
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1787
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1814
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:1554
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:1524
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)
Callback to destroy or clean up the GATT Indicate Value parameters.
Definition gatt.h:1566
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
Register GATT authorization callbacks.
int bt_gatt_cb_unregister(struct bt_gatt_cb *cb)
Unregister GATT 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:720
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:1487
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:752
bt_gatt_iter
to be used as return values for bt_gatt_attr_func_t and bt_gatt_read_func_t type callbacks.
Definition gatt.h:705
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
BT_GATT_CCC_MAX is defined depending on whether CONFIG_BT_SETTINGS_CCC_LAZY_LOADING or CONFIG_BT_CONN...
Definition gatt.h:1037
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1358
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:613
@ BT_GATT_ITER_STOP
Definition gatt.h:706
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:707
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:212
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:169
bt_gatt_attr_write_flag
GATT attribute write flags.
Definition gatt.h:112
bt_gatt_perm
GATT attribute permission bit field values.
Definition gatt.h:46
@ BT_GATT_WRITE_FLAG_PREPARE
Attribute prepare write flag.
Definition gatt.h:118
@ BT_GATT_WRITE_FLAG_CMD
Attribute write command flag.
Definition gatt.h:125
@ BT_GATT_WRITE_FLAG_EXECUTE
Attribute write execute flag.
Definition gatt.h:133
@ BT_GATT_PERM_READ_ENCRYPT
Attribute read permission with encryption.
Definition gatt.h:60
@ BT_GATT_PERM_WRITE
Attribute write permission.
Definition gatt.h:54
@ BT_GATT_PERM_WRITE_ENCRYPT
Attribute write permission with encryption.
Definition gatt.h:66
@ BT_GATT_PERM_NONE
No operations supported, e.g.
Definition gatt.h:48
@ BT_GATT_PERM_READ
Attribute read permission.
Definition gatt.h:51
@ BT_GATT_PERM_PREPARE_WRITE
Attribute prepare write permission.
Definition gatt.h:87
@ BT_GATT_PERM_WRITE_LESC
Attribute write permission with LE Secure Connection encryption.
Definition gatt.h:99
@ BT_GATT_PERM_READ_AUTHEN
Attribute read permission with authentication.
Definition gatt.h:73
@ BT_GATT_PERM_WRITE_AUTHEN
Attribute write permission with authentication.
Definition gatt.h:80
@ BT_GATT_PERM_READ_LESC
Attribute read permission with LE Secure Connection encryption.
Definition gatt.h:93
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
#define NULL
Definition iar_missing_defs.h:20
__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:227
bt_gatt_attr_read_func_t read
Attribute Value read method.
Definition gatt.h:254
uint16_t perm
Attribute Permissions.
Definition gatt.h:299
bt_gatt_attr_write_func_t write
Attribute Value write method.
Definition gatt.h:267
const struct bt_uuid * uuid
Attribute Type.
Definition gatt.h:241
void * user_data
Private data for read() and write() implementation.
Definition gatt.h:280
uint16_t handle
Attribute Handle.
Definition gatt.h:290
GATT authorization callback structure.
Definition gatt.h:392
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:404
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:418
GATT callback structure.
Definition gatt.h:372
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:382
GATT CCC configuration entry.
Definition gatt.h:1046
uint16_t value
Configuration value Value used to enable or disable notifications or indications for a specific chara...
Definition gatt.h:1055
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:1050
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:1048
Internal representation of CCC value.
Definition gatt.h:1065
void(* cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute changed callback.
Definition gatt.h:1077
struct bt_gatt_ccc_cfg cfg[0]
Configuration for each connection.
Definition gatt.h:1067
ssize_t(* cfg_write)(struct bt_conn *conn, const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute write validation callback.
Definition gatt.h:1088
uint16_t value
Highest value of all connected peer's subscriptions.
Definition gatt.h:1070
bool(* cfg_match)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
CCC attribute match handler.
Definition gatt.h:1102
Client Characteristic Configuration Attribute Value.
Definition gatt.h:527
uint16_t flags
Client Characteristic Configuration flags, a bitmap of BT_GATT_CCC_* macros.
Definition gatt.h:529
Characteristic Extended Properties Attribute Value.
Definition gatt.h:503
uint16_t properties
Characteristic Extended properties, a bitmap of BT_GATT_CEP_* macros.
Definition gatt.h:505
Attribute Value of a Characteristic Declaration.
Definition gatt.h:483
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:487
uint8_t properties
Characteristic properties, a bitmap of BT_GATT_CHRC_* macros.
Definition gatt.h:489
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:485
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:556
uint8_t name_space
Name space of the description.
Definition gatt.h:581
uint16_t unit
UUID of the unit of the characteristic.
Definition gatt.h:574
int8_t exponent
Exponent field for value formatting.
Definition gatt.h:568
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:588
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:562
GATT Discover Attributes parameters.
Definition gatt.h:1832
uint16_t start_handle
Starting attribute handle for included service.
Definition gatt.h:1843
uint16_t end_handle
Ending attribute handle for included service.
Definition gatt.h:1845
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1836
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1841
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1834
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1861
uint8_t type
Discover type.
Definition gatt.h:1858
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1865
GATT Exchange MTU parameters.
Definition gatt.h:1696
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Callback for MTU exchange response.
Definition gatt.h:1698
Include Attribute Value.
Definition gatt.h:362
uint16_t end_handle
Handle of the last attribute within the included service.
Definition gatt.h:368
uint16_t start_handle
Handle of the first attribute within the included service.
Definition gatt.h:366
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:364
GATT Indicate Value parameters.
Definition gatt.h:1574
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1599
uint16_t len
Indicate Value length.
Definition gatt.h:1594
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1586
const void * data
Indicate Value data.
Definition gatt.h:1592
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1590
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1588
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1580
GATT notification parameters.
Definition gatt.h:1364
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1370
uint16_t len
Notification Value length.
Definition gatt.h:1380
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1376
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1387
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1382
void * user_data
Notification Value callback user data.
Definition gatt.h:1384
const void * data
Notification Value data.
Definition gatt.h:1378
GATT Read parameters.
Definition gatt.h:1930
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1937
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1991
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:1949
uint16_t offset
Attribute data offset.
Definition gatt.h:1943
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1932
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@372352161252260236002106024214036013303007152222 single
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@371162354121151156017205063160212333251365073232 multiple
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:1960
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@261011265054333145327063036013076000041270205077 by_uuid
uint16_t end_handle
Requested end attribute handle number.
Definition gatt.h:1984
uint16_t start_handle
Requested start attribute handle number.
Definition gatt.h:1974
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:1986
uint16_t handle
Attribute handle.
Definition gatt.h:1941
Server Characteristic Configuration Attribute Value.
Definition gatt.h:546
uint16_t flags
Server Characteristic Configuration flags, a bitmap of BT_GATT_SCC_* macros.
Definition gatt.h:548
Static GATT Service structure.
Definition gatt.h:319
const struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:321
size_t attr_count
Service Attribute count.
Definition gatt.h:323
Service Attribute Value.
Definition gatt.h:349
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:351
uint16_t end_handle
Handle of the last Attribute within the Service.
Definition gatt.h:353
GATT Service structure.
Definition gatt.h:332
struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:334
size_t attr_count
Service Attribute count.
Definition gatt.h:336
GATT Subscribe parameters.
Definition gatt.h:2229
uint16_t value
Subscribe value.
Definition gatt.h:2248
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2254
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2240
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2235
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2238
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2231
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2245
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2266
atomic_t flags[ATOMIC_BITMAP_SIZE(BT_GATT_SUBSCRIBE_NUM_FLAGS)]
Subscription flags, see bt_gatt_sub_flag.
Definition gatt.h:2257
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition gatt.h:2243
GATT Write parameters.
Definition gatt.h:2053
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:2055
uint16_t handle
Attribute handle.
Definition gatt.h:2057
const void * data
Data to be written.
Definition gatt.h:2061
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2066
uint16_t offset
Attribute data offset.
Definition gatt.h:2059
uint16_t length
Length of the data.
Definition gatt.h:2063
This is a 'tentative' type and should be used as a pointer only.
Definition uuid.h:50
Binary representation of a UUID.
Definition uuid.h:48
Misc utilities.
Macros to abstract toolchain specific capabilities.
Macro utilities.