Zephyr Project API 4.1.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
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
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
467#define BT_GATT_CHRC_AUTH 0x40
474#define BT_GATT_CHRC_EXT_PROP 0x80
475
489
491#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
492#define BT_GATT_CEP_WRITABLE_AUX 0x0002
493
505
513#define BT_GATT_CCC_NOTIFY 0x0001
519#define BT_GATT_CCC_INDICATE 0x0002
520
529
538#define BT_GATT_SCC_BROADCAST 0x0001
539
548
588
611static inline const char *bt_gatt_err_to_str(int gatt_err)
612{
613 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
614}
615
624
644
672
680
688
696
707typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
709 void *user_data);
710
724void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
725 const struct bt_uuid *uuid,
726 const void *attr_data, uint16_t num_matches,
728 void *user_data);
729
739static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
741 void *user_data)
742{
743 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
744 user_data);
745}
746
755struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
756
772 uint16_t attr_count,
773 const struct bt_uuid *uuid);
774
784
797
813ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
814 void *buf, uint16_t buf_len, uint16_t offset,
815 const void *value, uint16_t value_len);
816
833 const struct bt_gatt_attr *attr,
834 void *buf, uint16_t len, uint16_t offset);
835
843#define BT_GATT_SERVICE_DEFINE(_name, ...) \
844 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
845 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
846 BT_GATT_SERVICE(attr_##_name)
847
848#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
849 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
850
851#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
852
868#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
869 _name, _instances, _instance_num, _attrs_def) \
870 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
871 "The number of array elements does not match its size"); \
872 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
873 _instances, _attrs_def); \
874 static struct bt_gatt_service _name[] = { \
875 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
876 }
877
885#define BT_GATT_SERVICE(_attrs) \
886{ \
887 .attrs = _attrs, \
888 .attr_count = ARRAY_SIZE(_attrs), \
889}
890
898#define BT_GATT_PRIMARY_SERVICE(_service) \
899 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
900 bt_gatt_attr_read_service, NULL, (void *)_service)
901
912#define BT_GATT_SECONDARY_SERVICE(_service) \
913 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
914 bt_gatt_attr_read_service, NULL, (void *)_service)
915
932 const struct bt_gatt_attr *attr,
933 void *buf, uint16_t len, uint16_t offset);
934
942#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
943 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
944 bt_gatt_attr_read_included, NULL, _service_incl)
945
961ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
962 const struct bt_gatt_attr *attr, void *buf,
963 uint16_t len, uint16_t offset);
964
975#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
976{ \
977 .uuid = _uuid, \
978 .value_handle = _handle, \
979 .properties = _props, \
980}
981
999#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
1000 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
1001 bt_gatt_attr_read_chrc, NULL, \
1002 ((struct bt_gatt_chrc[]) { \
1003 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
1004 })), \
1005 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1006
1018#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
1019 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
1020#elif defined(CONFIG_BT_CONN)
1021 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
1022#else
1023 #define BT_GATT_CCC_MAX 0
1024#endif
1025
1043
1045#define _bt_gatt_ccc bt_gatt_ccc_managed_user_data __DEPRECATED_MACRO
1046
1054
1057
1063 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
1064
1074 ssize_t (*cfg_write)(struct bt_conn *conn,
1075 const struct bt_gatt_attr *attr, uint16_t value);
1076
1088 bool (*cfg_match)(struct bt_conn *conn,
1089 const struct bt_gatt_attr *attr);
1090};
1091
1111ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
1112 const struct bt_gatt_attr *attr, void *buf,
1113 uint16_t len, uint16_t offset);
1114
1134ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
1135 const struct bt_gatt_attr *attr, const void *buf,
1136 uint16_t len, uint16_t offset, uint8_t flags);
1137
1139#define BT_GATT_CCC_INITIALIZER BT_GATT_CCC_MANAGED_USER_DATA_INIT __DEPRECATED_MACRO
1140
1150#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1151 { \
1152 .cfg = {}, \
1153 .cfg_changed = _changed, \
1154 .cfg_write = _write, \
1155 .cfg_match = _match, \
1156 }
1157
1170#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1171 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1172 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1173 _ccc)
1174
1184#define BT_GATT_CCC(_changed, _perm) \
1185 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1186 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1187 _perm)
1188
1199#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1200 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1201 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1202 _perm)
1203
1220ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
1221 const struct bt_gatt_attr *attr, void *buf,
1222 uint16_t len, uint16_t offset);
1223
1231#define BT_GATT_CEP(_value) \
1232 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1233 bt_gatt_attr_read_cep, NULL, (void *)_value)
1234
1252ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
1253 const struct bt_gatt_attr *attr, void *buf,
1254 uint16_t len, uint16_t offset);
1255
1265#define BT_GATT_CUD(_value, _perm) \
1266 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1267 NULL, (void *)_value)
1268
1285ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1286 const struct bt_gatt_attr *attr, void *buf,
1287 uint16_t len, uint16_t offset);
1288
1296#define BT_GATT_CPF(_value) \
1297 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1298 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1299
1314#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1315 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1316
1329#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1330{ \
1331 .uuid = _uuid, \
1332 .read = _read, \
1333 .write = _write, \
1334 .user_data = _user_data, \
1335 .handle = 0, \
1336 .perm = _perm, \
1337}
1338
1344typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1345
1356 const struct bt_uuid *uuid;
1362 const struct bt_gatt_attr *attr;
1364 const void *data;
1371#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1374#endif /* CONFIG_BT_EATT */
1375};
1376
1398int bt_gatt_notify_cb(struct bt_conn *conn,
1399 struct bt_gatt_notify_params *params);
1400
1452int bt_gatt_notify_multiple(struct bt_conn *conn,
1453 uint16_t num_params,
1454 struct bt_gatt_notify_params params[]);
1455
1475static inline int bt_gatt_notify(struct bt_conn *conn,
1476 const struct bt_gatt_attr *attr,
1477 const void *data, uint16_t len)
1478{
1479 struct bt_gatt_notify_params params;
1480
1481 memset(&params, 0, sizeof(params));
1482
1483 params.attr = attr;
1484 params.data = data;
1485 params.len = len;
1486#if defined(CONFIG_BT_EATT)
1488#endif /* CONFIG_BT_EATT */
1489
1490 return bt_gatt_notify_cb(conn, &params);
1491}
1492
1512static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1513 const struct bt_uuid *uuid,
1514 const struct bt_gatt_attr *attr,
1515 const void *data, uint16_t len)
1516{
1517 struct bt_gatt_notify_params params;
1518
1519 memset(&params, 0, sizeof(params));
1520
1521 params.uuid = uuid;
1522 params.attr = attr;
1523 params.data = data;
1524 params.len = len;
1525#if defined(CONFIG_BT_EATT)
1527#endif /* CONFIG_BT_EATT */
1528
1529 return bt_gatt_notify_cb(conn, &params);
1530}
1531
1532/* Forward declaration of the bt_gatt_indicate_params structure */
1534
1542typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1543 struct bt_gatt_indicate_params *params,
1544 uint8_t err);
1545
1555 struct bt_gatt_indicate_params *params);
1556
1568 const struct bt_uuid *uuid;
1574 const struct bt_gatt_attr *attr;
1580 const void *data;
1584 uint8_t _ref;
1585#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1588#endif /* CONFIG_BT_EATT */
1589};
1590
1616int bt_gatt_indicate(struct bt_conn *conn,
1617 struct bt_gatt_indicate_params *params);
1618
1637bool bt_gatt_is_subscribed(struct bt_conn *conn,
1638 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1639
1649uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1650
1666uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn);
1667
1686 void (*func)(struct bt_conn *conn, uint8_t err,
1687 struct bt_gatt_exchange_params *params);
1688};
1689
1714int bt_gatt_exchange_mtu(struct bt_conn *conn,
1715 struct bt_gatt_exchange_params *params);
1716
1718
1768typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1769 const struct bt_gatt_attr *attr,
1770 struct bt_gatt_discover_params *params);
1771
1815
1817#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1818
1822 const struct bt_uuid *uuid;
1825 union {
1827 struct {
1834 } _included;
1836 uint16_t start_handle;
1837 };
1847#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1850#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1851#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1854#endif /* CONFIG_BT_EATT */
1855};
1856
1890int bt_gatt_discover(struct bt_conn *conn,
1891 struct bt_gatt_discover_params *params);
1892
1893struct bt_gatt_read_params;
1894
1910typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1911 struct bt_gatt_read_params *params,
1912 const void *data, uint16_t length);
1913
1923 union {
1924 struct {
1930 struct {
1947 struct {
1971 const struct bt_uuid *uuid;
1973 };
1974#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1977#endif /* CONFIG_BT_EATT */
1979 uint16_t _att_mtu;
1980};
1981
2021int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
2022
2024
2032typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
2033 struct bt_gatt_write_params *params);
2034
2044 const void *data;
2047#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2050#endif /* CONFIG_BT_EATT */
2051};
2052
2070int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
2071
2099int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
2100 const void *data, uint16_t length,
2101 bool sign, bt_gatt_complete_func_t func,
2102 void *user_data);
2103
2122static inline int bt_gatt_write_without_response(struct bt_conn *conn,
2123 uint16_t handle, const void *data,
2124 uint16_t length, bool sign)
2125{
2126 return bt_gatt_write_without_response_cb(conn, handle, data, length,
2127 sign, NULL, NULL);
2128}
2129
2131
2148typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
2149 struct bt_gatt_subscribe_params *params,
2150 const void *data, uint16_t length);
2151
2159typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
2160 struct bt_gatt_subscribe_params *params);
2161
2212
2221
2226#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2231#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2234#if defined(CONFIG_BT_SMP)
2240#endif
2243
2247 sys_snode_t node;
2249#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2252#endif /* CONFIG_BT_EATT */
2253};
2254
2289int bt_gatt_subscribe(struct bt_conn *conn,
2290 struct bt_gatt_subscribe_params *params);
2291
2309 struct bt_gatt_subscribe_params *params);
2310
2333int bt_gatt_unsubscribe(struct bt_conn *conn,
2334 struct bt_gatt_subscribe_params *params);
2335
2353void bt_gatt_cancel(struct bt_conn *conn, void *params);
2354
2357#ifdef __cplusplus
2358}
2359#endif
2360
2365#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:111
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:814
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:1768
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:2159
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:1910
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:2122
bt_gatt_sub_flag
Subscription flags.
Definition gatt.h:2163
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:2148
bt_gatt_discover_type
GATT Discover types.
Definition gatt.h:1773
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:2032
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2187
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2210
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2208
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2173
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2196
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1793
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1777
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1784
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1779
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1813
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1775
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1802
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:1554
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:1542
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:1512
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.
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:1475
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:739
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:692
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.
Definition gatt.h:1023
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1344
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:707
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:611
@ BT_GATT_ITER_STOP
Definition gatt.h:693
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:694
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
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
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:1032
uint16_t value
Configuration value Value used to enable or disable notifications or indications for a specific chara...
Definition gatt.h:1041
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:1036
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:1034
Internal representation of CCC value.
Definition gatt.h:1051
void(* cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute changed callback.
Definition gatt.h:1063
struct bt_gatt_ccc_cfg cfg[0]
Configuration for each connection.
Definition gatt.h:1053
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:1074
uint16_t value
Highest value of all connected peer's subscriptions.
Definition gatt.h:1056
bool(* cfg_match)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
CCC attribute match handler.
Definition gatt.h:1088
Client Characteristic Configuration Attribute Value.
Definition gatt.h:525
uint16_t flags
Client Characteristic Configuration flags, a bitmap of BT_GATT_CCC_* macros.
Definition gatt.h:527
Characteristic Extended Properties Attribute Value.
Definition gatt.h:501
uint16_t properties
Characteristic Extended properties, a bitmap of BT_GATT_CEP_* macros.
Definition gatt.h:503
Attribute Value of a Characteristic Declaration.
Definition gatt.h:481
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:485
uint8_t properties
Characteristic properties, a bitmap of BT_GATT_CHRC_* macros.
Definition gatt.h:487
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:483
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:554
uint8_t name_space
Name space of the description.
Definition gatt.h:579
uint16_t unit
UUID of the unit of the characteristic.
Definition gatt.h:572
int8_t exponent
Exponent field for value formatting.
Definition gatt.h:566
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:586
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:560
GATT Discover Attributes parameters.
Definition gatt.h:1820
uint16_t start_handle
Starting attribute handle for included service.
Definition gatt.h:1831
uint16_t end_handle
Ending attribute handle for included service.
Definition gatt.h:1833
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1824
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1829
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1822
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1849
uint8_t type
Discover type.
Definition gatt.h:1846
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1853
GATT Exchange MTU parameters.
Definition gatt.h:1684
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Callback for MTU exchange response.
Definition gatt.h:1686
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:1562
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1587
uint16_t len
Indicate Value length.
Definition gatt.h:1582
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1574
const void * data
Indicate Value data.
Definition gatt.h:1580
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1578
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1576
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1568
GATT notification parameters.
Definition gatt.h:1350
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1356
uint16_t len
Notification Value length.
Definition gatt.h:1366
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1362
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1373
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1368
void * user_data
Notification Value callback user data.
Definition gatt.h:1370
const void * data
Notification Value data.
Definition gatt.h:1364
GATT Read parameters.
Definition gatt.h:1915
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1922
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1976
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:1934
uint16_t offset
Attribute data offset.
Definition gatt.h:1928
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1917
struct bt_gatt_read_params::@117::@121 by_uuid
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:1945
uint16_t end_handle
Requested end attribute handle number.
Definition gatt.h:1969
struct bt_gatt_read_params::@117::@120 multiple
uint16_t start_handle
Requested start attribute handle number.
Definition gatt.h:1959
struct bt_gatt_read_params::@117::@119 single
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:1971
uint16_t handle
Attribute handle.
Definition gatt.h:1926
Server Characteristic Configuration Attribute Value.
Definition gatt.h:544
uint16_t flags
Server Characteristic Configuration flags, a bitmap of BT_GATT_SCC_* macros.
Definition gatt.h:546
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:2214
uint16_t value
Subscribe value.
Definition gatt.h:2233
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2239
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2225
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2220
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2223
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2216
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2230
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2251
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition gatt.h:2228
GATT Write parameters.
Definition gatt.h:2036
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:2038
uint16_t handle
Attribute handle.
Definition gatt.h:2040
const void * data
Data to be written.
Definition gatt.h:2044
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2049
uint16_t offset
Attribute data offset.
Definition gatt.h:2042
uint16_t length
Length of the data.
Definition gatt.h:2046
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.