Zephyr Project API 4.4.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
24
25#include <stdint.h>
26#include <stddef.h>
27#include <string.h>
28
29#include <sys/types.h>
30
31#include <zephyr/autoconf.h>
36#include <zephyr/sys/atomic.h>
38#include <zephyr/sys/slist.h>
39#include <zephyr/sys/util.h>
41#include <zephyr/toolchain.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
114
122#define BT_GATT_ERR(_att_err) (-(_att_err))
123
148
149/* Forward declaration of GATT Attribute structure */
150struct bt_gatt_attr;
151
183 const struct bt_gatt_attr *attr,
184 void *buf, uint16_t len,
185 uint16_t offset);
186
226 const struct bt_gatt_attr *attr,
227 const void *buf, uint16_t len,
228 uint16_t offset, uint8_t flags);
229
254 const struct bt_uuid *uuid;
255
268
281
294
304
313
322 bool _auto_assigned_handle: 1;
324};
325
334 const struct bt_gatt_attr *attrs;
337};
338
353 sys_snode_t node;
355};
356
368
383
395 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
396
400 sys_snode_t node;
402};
403
417 bool (*read_authorize)(struct bt_conn *conn,
418 const struct bt_gatt_attr *attr);
419
431 bool (*write_authorize)(struct bt_conn *conn,
432 const struct bt_gatt_attr *attr);
433};
434
436
443#define BT_GATT_CHRC_BROADCAST 0x01
449#define BT_GATT_CHRC_READ 0x02
455#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
461#define BT_GATT_CHRC_WRITE 0x08
468#define BT_GATT_CHRC_NOTIFY 0x10
474#define BT_GATT_CHRC_INDICATE 0x20
482#define BT_GATT_CHRC_AUTH 0x40 __DEPRECATED_MACRO
489#define BT_GATT_CHRC_EXT_PROP 0x80
490
504
506
518#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
519
525#define BT_GATT_CEP_WRITABLE_AUX 0x0002
526
538
540
546#define BT_GATT_CCC_NOTIFY 0x0001
552#define BT_GATT_CCC_INDICATE 0x0002
553
562
564
571#define BT_GATT_SCC_BROADCAST 0x0001
572
581
621
627
644static inline const char *bt_gatt_err_to_str(int gatt_err)
645{
646 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
647}
648
657
668
688
716
724
732
740
751typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
753 void *user_data);
754
768void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
769 const struct bt_uuid *uuid,
770 const void *attr_data, uint16_t num_matches,
772 void *user_data);
773
783static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
785 void *user_data)
786{
787 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
788 user_data);
789}
790
799struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
800
816 uint16_t attr_count,
817 const struct bt_uuid *uuid);
818
828
841
857ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
858 void *buf, uint16_t buf_len, uint16_t offset,
859 const void *value, uint16_t value_len);
860
877 const struct bt_gatt_attr *attr,
878 void *buf, uint16_t len, uint16_t offset);
879
887#define BT_GATT_SERVICE_DEFINE(_name, ...) \
888 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
889 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
890 BT_GATT_SERVICE(attr_##_name)
891
892#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
893 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
894
895#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
896
912#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
913 _name, _instances, _instance_num, _attrs_def) \
914 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
915 "The number of array elements does not match its size"); \
916 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
917 _instances, _attrs_def); \
918 static struct bt_gatt_service _name[] = { \
919 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
920 }
921
929#define BT_GATT_SERVICE(_attrs) \
930{ \
931 .attrs = _attrs, \
932 .attr_count = ARRAY_SIZE(_attrs), \
933}
934
942#define BT_GATT_PRIMARY_SERVICE(_service) \
943 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
944 bt_gatt_attr_read_service, NULL, (void *)_service)
945
956#define BT_GATT_SECONDARY_SERVICE(_service) \
957 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
958 bt_gatt_attr_read_service, NULL, (void *)_service)
959
977 const struct bt_gatt_attr *attr,
978 void *buf, uint16_t len, uint16_t offset);
979
987#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
988 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
989 bt_gatt_attr_read_included, NULL, _service_incl)
990
1007 const struct bt_gatt_attr *attr, void *buf,
1008 uint16_t len, uint16_t offset);
1009
1020#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
1021{ \
1022 .uuid = _uuid, \
1023 .value_handle = _handle, \
1024 .properties = _props, \
1025}
1026
1044#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
1045 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
1046 bt_gatt_attr_read_chrc, NULL, \
1047 ((struct bt_gatt_chrc[]) { \
1048 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
1049 })), \
1050 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1051
1063#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
1064 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
1065#elif defined(CONFIG_BT_CONN)
1066 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
1067#else
1068 #define BT_GATT_CCC_MAX 0
1069#endif
1070
1088
1090#define _bt_gatt_ccc bt_gatt_ccc_managed_user_data __DEPRECATED_MACRO
1091
1099
1102
1108 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
1109
1119 ssize_t (*cfg_write)(struct bt_conn *conn,
1120 const struct bt_gatt_attr *attr, uint16_t value);
1121
1133 bool (*cfg_match)(struct bt_conn *conn,
1134 const struct bt_gatt_attr *attr);
1135};
1136
1157 const struct bt_gatt_attr *attr, void *buf,
1158 uint16_t len, uint16_t offset);
1159
1180 const struct bt_gatt_attr *attr, const void *buf,
1181 uint16_t len, uint16_t offset, uint8_t flags);
1182
1184#define BT_GATT_CCC_INITIALIZER BT_GATT_CCC_MANAGED_USER_DATA_INIT __DEPRECATED_MACRO
1185
1195#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1196 { \
1197 .cfg = {}, \
1198 .cfg_changed = _changed, \
1199 .cfg_write = _write, \
1200 .cfg_match = _match, \
1201 }
1202
1215#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1216 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1217 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1218 _ccc)
1219
1229#define BT_GATT_CCC(_changed, _perm) \
1230 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1231 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1232 _perm)
1233
1244#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1245 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1246 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1247 _perm)
1248
1266 const struct bt_gatt_attr *attr, void *buf,
1267 uint16_t len, uint16_t offset);
1268
1276#define BT_GATT_CEP(_value) \
1277 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1278 bt_gatt_attr_read_cep, NULL, (void *)_value)
1279
1298 const struct bt_gatt_attr *attr, void *buf,
1299 uint16_t len, uint16_t offset);
1300
1310#define BT_GATT_CUD(_value, _perm) \
1311 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1312 NULL, (void *)_value)
1313
1331 const struct bt_gatt_attr *attr, void *buf,
1332 uint16_t len, uint16_t offset);
1333
1341#define BT_GATT_CPF(_value) \
1342 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1343 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1344
1359#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1360 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1361
1374#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1375{ \
1376 .uuid = _uuid, \
1377 .read = _read, \
1378 .write = _write, \
1379 .user_data = _user_data, \
1380 .handle = 0, \
1381 .perm = _perm, \
1382}
1383
1389typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1390
1401 const struct bt_uuid *uuid;
1407 const struct bt_gatt_attr *attr;
1409 const void *data;
1416#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1419#endif /* CONFIG_BT_EATT */
1420};
1421
1442 struct bt_gatt_notify_params *params);
1443
1496 uint16_t num_params,
1497 struct bt_gatt_notify_params params[]);
1498
1518static inline int bt_gatt_notify(struct bt_conn *conn,
1519 const struct bt_gatt_attr *attr,
1520 const void *data, uint16_t len)
1521{
1522 struct bt_gatt_notify_params params;
1523
1524 memset(&params, 0, sizeof(params));
1525
1526 params.attr = attr;
1527 params.data = data;
1528 params.len = len;
1529#if defined(CONFIG_BT_EATT)
1531#endif /* CONFIG_BT_EATT */
1532
1533 return bt_gatt_notify_cb(conn, &params);
1534}
1535
1555static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1556 const struct bt_uuid *uuid,
1557 const struct bt_gatt_attr *attr,
1558 const void *data, uint16_t len)
1559{
1560 struct bt_gatt_notify_params params;
1561
1562 memset(&params, 0, sizeof(params));
1563
1564 params.uuid = uuid;
1565 params.attr = attr;
1566 params.data = data;
1567 params.len = len;
1568#if defined(CONFIG_BT_EATT)
1570#endif /* CONFIG_BT_EATT */
1571
1572 return bt_gatt_notify_cb(conn, &params);
1573}
1574
1575/* Forward declaration of the bt_gatt_indicate_params structure */
1577
1585typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1586 struct bt_gatt_indicate_params *params,
1587 uint8_t err);
1588
1598 struct bt_gatt_indicate_params *params);
1599
1611 const struct bt_uuid *uuid;
1617 const struct bt_gatt_attr *attr;
1623 const void *data;
1627 uint8_t _ref;
1628#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1631#endif /* CONFIG_BT_EATT */
1632};
1633
1659int bt_gatt_indicate(struct bt_conn *conn,
1660 struct bt_gatt_indicate_params *params);
1661
1681 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1682
1693
1710
1712
1718
1729 void (*func)(struct bt_conn *conn, uint8_t err,
1730 struct bt_gatt_exchange_params *params);
1731};
1732
1758 struct bt_gatt_exchange_params *params);
1759
1761
1812 const struct bt_gatt_attr *attr,
1813 struct bt_gatt_discover_params *params);
1814
1858
1860#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1861
1865 const struct bt_uuid *uuid;
1868 union {
1870 struct {
1877 } _included;
1879 uint16_t start_handle;
1880 };
1890#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1893#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1894#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1897#endif /* CONFIG_BT_EATT */
1898};
1899
1933int bt_gatt_discover(struct bt_conn *conn,
1934 struct bt_gatt_discover_params *params);
1935
1936struct bt_gatt_read_params;
1937
1956typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1957 struct bt_gatt_read_params *params,
1958 const void *data, uint16_t length);
1959
1969 union {
1970 struct {
1976 struct {
1993 struct {
2017 const struct bt_uuid *uuid;
2019 };
2020#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2023#endif /* CONFIG_BT_EATT */
2025 uint16_t _att_mtu;
2026};
2027
2069int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
2070
2072
2080typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
2081 struct bt_gatt_write_params *params);
2082
2092 const void *data;
2095#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2098#endif /* CONFIG_BT_EATT */
2099};
2100
2118int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
2119
2146 const void *data, uint16_t length,
2147 bool sign, bt_gatt_complete_func_t func,
2148 void *user_data);
2149
2168static inline int bt_gatt_write_without_response(struct bt_conn *conn,
2169 uint16_t handle, const void *data,
2170 uint16_t length, bool sign)
2171{
2172 return bt_gatt_write_without_response_cb(conn, handle, data, length,
2173 sign, NULL, NULL);
2174}
2175
2177
2194typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
2195 struct bt_gatt_subscribe_params *params,
2196 const void *data, uint16_t length);
2197
2205typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
2206 struct bt_gatt_subscribe_params *params);
2207
2258
2267
2272#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2277#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2280#if defined(CONFIG_BT_SMP) || defined(__DOXYGEN__)
2286#endif /* CONFIG_BT_SMP */
2289
2293 sys_snode_t node;
2295#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2298#endif /* CONFIG_BT_EATT */
2299};
2300
2336 struct bt_gatt_subscribe_params *params);
2337
2355 struct bt_gatt_subscribe_params *params);
2356
2380 struct bt_gatt_subscribe_params *params);
2381
2399void bt_gatt_cancel(struct bt_conn *conn, void *params);
2400
2402
2403#ifdef __cplusplus
2404}
2405#endif
2406
2410
2411#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:119
bt_att_chan_opt
ATT channel option bit field values.
Definition att.h:193
static const char * bt_att_err_to_str(uint8_t att_err)
Converts a ATT error to string.
Definition att.h:129
@ BT_ATT_CHAN_OPT_NONE
Both Enhanced and Unenhanced channels can be used.
Definition att.h:195
bt_security_t
Security level.
Definition conn.h:1201
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:1956
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:2080
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:2205
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:2168
bt_gatt_sub_flag
Subscription flags.
Definition gatt.h:2209
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:2194
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:1811
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:1816
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2233
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2256
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2254
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2219
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2242
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1836
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1820
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1827
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1822
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1856
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1818
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1845
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:1585
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:1555
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:1597
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:751
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:1518
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:783
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:736
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:1068
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1389
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:644
@ BT_GATT_ITER_STOP
Definition gatt.h:737
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:738
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:225
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:182
bt_gatt_attr_write_flag
GATT attribute write flags.
Definition gatt.h:125
bt_gatt_perm
GATT attribute permission bit field values.
Definition gatt.h:48
@ BT_GATT_WRITE_FLAG_PREPARE
Attribute prepare write flag.
Definition gatt.h:131
@ BT_GATT_WRITE_FLAG_CMD
Attribute write command flag.
Definition gatt.h:138
@ BT_GATT_WRITE_FLAG_EXECUTE
Attribute write execute flag.
Definition gatt.h:146
@ BT_GATT_PERM_READ_ENCRYPT
Attribute read permission with encryption.
Definition gatt.h:62
@ BT_GATT_PERM_WRITE
Attribute write permission.
Definition gatt.h:56
@ BT_GATT_PERM_WRITE_ENCRYPT
Attribute write permission with encryption.
Definition gatt.h:68
@ BT_GATT_PERM_NONE
No operations supported, e.g.
Definition gatt.h:50
@ BT_GATT_PERM_READ
Attribute read permission.
Definition gatt.h:53
@ BT_GATT_PERM_PREPARE_WRITE
Attribute prepare write permission.
Definition gatt.h:100
@ BT_GATT_PERM_WRITE_LESC
Attribute write permission with LE Secure Connection encryption.
Definition gatt.h:112
@ BT_GATT_PERM_READ_AUTHEN
Attribute read permission with authentication.
Definition gatt.h:75
@ BT_GATT_PERM_WRITE_AUTHEN
Attribute write permission with authentication.
Definition gatt.h:82
@ BT_GATT_PERM_READ_LESC
Attribute read permission with LE Secure Connection encryption.
Definition gatt.h:106
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
#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
Header file for the single-linked list API.
#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:51
Opaque type representing a connection to a remote device.
GATT Attribute.
Definition gatt.h:240
bt_gatt_attr_read_func_t read
Attribute Value read method.
Definition gatt.h:267
uint16_t perm
Attribute Permissions.
Definition gatt.h:312
bt_gatt_attr_write_func_t write
Attribute Value write method.
Definition gatt.h:280
const struct bt_uuid * uuid
Attribute Type.
Definition gatt.h:254
void * user_data
Private data for read() and write() implementation.
Definition gatt.h:293
uint16_t handle
Attribute Handle.
Definition gatt.h:303
GATT authorization callback structure.
Definition gatt.h:405
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:417
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:431
GATT callback structure.
Definition gatt.h:385
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:395
GATT CCC configuration entry.
Definition gatt.h:1077
uint16_t value
Configuration value Value used to enable or disable notifications or indications for a specific chara...
Definition gatt.h:1086
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:1081
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:1079
Internal representation of CCC value.
Definition gatt.h:1096
void(* cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute changed callback.
Definition gatt.h:1108
struct bt_gatt_ccc_cfg cfg[0]
Configuration for each connection.
Definition gatt.h:1098
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:1119
uint16_t value
Highest value of all connected peer's subscriptions.
Definition gatt.h:1101
bool(* cfg_match)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
CCC attribute match handler.
Definition gatt.h:1133
Client Characteristic Configuration Attribute Value.
Definition gatt.h:558
uint16_t flags
Client Characteristic Configuration flags, a bitmap of BT_GATT_CCC_* macros.
Definition gatt.h:560
Characteristic Extended Properties Attribute Value.
Definition gatt.h:534
uint16_t properties
Characteristic Extended properties, a bitmap of BT_GATT_CEP_* macros.
Definition gatt.h:536
Attribute Value of a Characteristic Declaration.
Definition gatt.h:496
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:500
uint8_t properties
Characteristic properties, a bitmap of BT_GATT_CHRC_* macros.
Definition gatt.h:502
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:498
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:587
uint8_t name_space
Name space of the description.
Definition gatt.h:612
uint16_t unit
UUID of the unit of the characteristic.
Definition gatt.h:605
int8_t exponent
Exponent field for value formatting.
Definition gatt.h:599
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:619
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:593
GATT Discover Attributes parameters.
Definition gatt.h:1863
uint16_t start_handle
Starting attribute handle for included service.
Definition gatt.h:1874
uint16_t end_handle
Ending attribute handle for included service.
Definition gatt.h:1876
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1867
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1872
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1865
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1892
uint8_t type
Discover type.
Definition gatt.h:1889
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1896
GATT Exchange MTU parameters.
Definition gatt.h:1727
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Callback for MTU exchange response.
Definition gatt.h:1729
Include Attribute Value.
Definition gatt.h:375
uint16_t end_handle
Handle of the last attribute within the included service.
Definition gatt.h:381
uint16_t start_handle
Handle of the first attribute within the included service.
Definition gatt.h:379
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:377
GATT Indicate Value parameters.
Definition gatt.h:1605
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1630
uint16_t len
Indicate Value length.
Definition gatt.h:1625
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1617
const void * data
Indicate Value data.
Definition gatt.h:1623
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1621
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1619
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1611
GATT notification parameters.
Definition gatt.h:1395
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1401
uint16_t len
Notification Value length.
Definition gatt.h:1411
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1407
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1418
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1413
void * user_data
Notification Value callback user data.
Definition gatt.h:1415
const void * data
Notification Value data.
Definition gatt.h:1409
GATT Read parameters.
Definition gatt.h:1961
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1968
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2022
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:1980
uint16_t offset
Attribute data offset.
Definition gatt.h:1974
struct bt_gatt_read_params::@230240255327025042252332200332350030123113157136::@052025354345216265352245024173042257041150041213 single
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1963
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:1991
uint16_t end_handle
Requested end attribute handle number.
Definition gatt.h:2015
struct bt_gatt_read_params::@230240255327025042252332200332350030123113157136::@072321356235326155162354137272253273261365034225 by_uuid
struct bt_gatt_read_params::@230240255327025042252332200332350030123113157136::@373223246131242154106164053123060336264140334012 multiple
uint16_t start_handle
Requested start attribute handle number.
Definition gatt.h:2005
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:2017
uint16_t handle
Attribute handle.
Definition gatt.h:1972
Server Characteristic Configuration Attribute Value.
Definition gatt.h:577
uint16_t flags
Server Characteristic Configuration flags, a bitmap of BT_GATT_SCC_* macros.
Definition gatt.h:579
Static GATT Service structure.
Definition gatt.h:332
const struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:334
size_t attr_count
Service Attribute count.
Definition gatt.h:336
Service Attribute Value.
Definition gatt.h:362
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:364
uint16_t end_handle
Handle of the last Attribute within the Service.
Definition gatt.h:366
GATT Service structure.
Definition gatt.h:345
struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:347
size_t attr_count
Service Attribute count.
Definition gatt.h:349
GATT Subscribe parameters.
Definition gatt.h:2260
uint16_t value
Subscribe value.
Definition gatt.h:2279
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2285
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2271
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2266
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2269
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2262
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2276
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2297
atomic_t flags[ATOMIC_BITMAP_SIZE(BT_GATT_SUBSCRIBE_NUM_FLAGS)]
Subscription flags, see bt_gatt_sub_flag.
Definition gatt.h:2288
uint16_t end_handle
Subscribe End handle (for automatic discovery).
Definition gatt.h:2274
GATT Write parameters.
Definition gatt.h:2084
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:2086
uint16_t handle
Attribute handle.
Definition gatt.h:2088
const void * data
Data to be written.
Definition gatt.h:2092
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2097
uint16_t offset
Attribute data offset.
Definition gatt.h:2090
uint16_t length
Length of the data.
Definition gatt.h:2094
This is a 'tentative' type and should be used as a pointer only.
Definition uuid.h:52
Binary representation of a UUID.
Definition uuid.h:48
Header file for the Atomic operations API.
Iterable sections helpers.
Misc utilities.
Macros to abstract toolchain specific capabilities.
Macro utilities.