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
122
130#define BT_GATT_ERR(_att_err) (-(_att_err))
131
160
161/* Forward declaration of GATT Attribute structure */
162struct bt_gatt_attr;
163
200 const struct bt_gatt_attr *attr,
201 void *buf, uint16_t len,
202 uint16_t offset);
203
248 const struct bt_gatt_attr *attr,
249 const void *buf, uint16_t len,
250 uint16_t offset, uint8_t flags);
251
276 const struct bt_uuid *uuid;
277
290
303
316
326
335
344 bool _auto_assigned_handle: 1;
346};
347
356 const struct bt_gatt_attr *attrs;
359};
360
375 sys_snode_t node;
377};
378
390
405
417 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
418
422 sys_snode_t node;
424};
425
439 bool (*read_authorize)(struct bt_conn *conn,
440 const struct bt_gatt_attr *attr);
441
453 bool (*write_authorize)(struct bt_conn *conn,
454 const struct bt_gatt_attr *attr);
455};
456
458
465#define BT_GATT_CHRC_BROADCAST 0x01
471#define BT_GATT_CHRC_READ 0x02
477#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
483#define BT_GATT_CHRC_WRITE 0x08
490#define BT_GATT_CHRC_NOTIFY 0x10
496#define BT_GATT_CHRC_INDICATE 0x20
504#define BT_GATT_CHRC_AUTH 0x40 __DEPRECATED_MACRO
511#define BT_GATT_CHRC_EXT_PROP 0x80
512
526
528
540#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
541
547#define BT_GATT_CEP_WRITABLE_AUX 0x0002
548
560
562
568#define BT_GATT_CCC_NOTIFY 0x0001
574#define BT_GATT_CCC_INDICATE 0x0002
575
584
586
593#define BT_GATT_SCC_BROADCAST 0x0001
594
603
643
649
666static inline const char *bt_gatt_err_to_str(int gatt_err)
667{
668 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
669}
670
679
690
710
738
746
754
762
773typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
775 void *user_data);
776
790void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
791 const struct bt_uuid *uuid,
792 const void *attr_data, uint16_t num_matches,
794 void *user_data);
795
805static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
807 void *user_data)
808{
809 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
810 user_data);
811}
812
821struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
822
838 uint16_t attr_count,
839 const struct bt_uuid *uuid);
840
850
863
879ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
880 void *buf, uint16_t buf_len, uint16_t offset,
881 const void *value, uint16_t value_len);
882
899 const struct bt_gatt_attr *attr,
900 void *buf, uint16_t len, uint16_t offset);
901
909#define BT_GATT_SERVICE_DEFINE(_name, ...) \
910 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
911 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
912 BT_GATT_SERVICE(attr_##_name)
913
914#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
915 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
916
917#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
918
934#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
935 _name, _instances, _instance_num, _attrs_def) \
936 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
937 "The number of array elements does not match its size"); \
938 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
939 _instances, _attrs_def); \
940 static struct bt_gatt_service _name[] = { \
941 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
942 }
943
951#define BT_GATT_SERVICE(_attrs) \
952{ \
953 .attrs = _attrs, \
954 .attr_count = ARRAY_SIZE(_attrs), \
955}
956
964#define BT_GATT_PRIMARY_SERVICE(_service) \
965 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
966 bt_gatt_attr_read_service, NULL, (void *)_service)
967
978#define BT_GATT_SECONDARY_SERVICE(_service) \
979 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
980 bt_gatt_attr_read_service, NULL, (void *)_service)
981
999 const struct bt_gatt_attr *attr,
1000 void *buf, uint16_t len, uint16_t offset);
1001
1009#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
1010 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
1011 bt_gatt_attr_read_included, NULL, _service_incl)
1012
1029 const struct bt_gatt_attr *attr, void *buf,
1030 uint16_t len, uint16_t offset);
1031
1042#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
1043{ \
1044 .uuid = _uuid, \
1045 .value_handle = _handle, \
1046 .properties = _props, \
1047}
1048
1066#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
1067 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
1068 bt_gatt_attr_read_chrc, NULL, \
1069 ((struct bt_gatt_chrc[]) { \
1070 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
1071 })), \
1072 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1073
1085#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
1086 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
1087#elif defined(CONFIG_BT_CONN)
1088 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
1089#else
1090 #define BT_GATT_CCC_MAX 0
1091#endif
1092
1110
1118
1121
1132 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
1133
1143 ssize_t (*cfg_write)(struct bt_conn *conn,
1144 const struct bt_gatt_attr *attr, uint16_t value);
1145
1157 bool (*cfg_match)(struct bt_conn *conn,
1158 const struct bt_gatt_attr *attr);
1159};
1160
1181 const struct bt_gatt_attr *attr, void *buf,
1182 uint16_t len, uint16_t offset);
1183
1204 const struct bt_gatt_attr *attr, const void *buf,
1205 uint16_t len, uint16_t offset, uint8_t flags);
1206
1216#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1217 { \
1218 .cfg = {}, \
1219 .cfg_changed = _changed, \
1220 .cfg_write = _write, \
1221 .cfg_match = _match, \
1222 }
1223
1236#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1237 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1238 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1239 _ccc)
1240
1250#define BT_GATT_CCC(_changed, _perm) \
1251 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1252 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1253 _perm)
1254
1265#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1266 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1267 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1268 _perm)
1269
1287 const struct bt_gatt_attr *attr, void *buf,
1288 uint16_t len, uint16_t offset);
1289
1297#define BT_GATT_CEP(_value) \
1298 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1299 bt_gatt_attr_read_cep, NULL, (void *)_value)
1300
1319 const struct bt_gatt_attr *attr, void *buf,
1320 uint16_t len, uint16_t offset);
1321
1331#define BT_GATT_CUD(_value, _perm) \
1332 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1333 NULL, (void *)_value)
1334
1352 const struct bt_gatt_attr *attr, void *buf,
1353 uint16_t len, uint16_t offset);
1354
1362#define BT_GATT_CPF(_value) \
1363 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1364 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1365
1380#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1381 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1382
1395#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1396{ \
1397 .uuid = _uuid, \
1398 .read = _read, \
1399 .write = _write, \
1400 .user_data = _user_data, \
1401 .handle = 0, \
1402 .perm = _perm, \
1403}
1404
1410typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1411
1422 const struct bt_uuid *uuid;
1428 const struct bt_gatt_attr *attr;
1430 const void *data;
1437#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1440#endif /* CONFIG_BT_EATT */
1441};
1442
1464 struct bt_gatt_notify_params *params);
1465
1518 uint16_t num_params,
1519 struct bt_gatt_notify_params params[]);
1520
1540static inline int bt_gatt_notify(struct bt_conn *conn,
1541 const struct bt_gatt_attr *attr,
1542 const void *data, uint16_t len)
1543{
1544 struct bt_gatt_notify_params params;
1545
1546 memset(&params, 0, sizeof(params));
1547
1548 params.attr = attr;
1549 params.data = data;
1550 params.len = len;
1551#if defined(CONFIG_BT_EATT)
1553#endif /* CONFIG_BT_EATT */
1554
1555 return bt_gatt_notify_cb(conn, &params);
1556}
1557
1577static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1578 const struct bt_uuid *uuid,
1579 const struct bt_gatt_attr *attr,
1580 const void *data, uint16_t len)
1581{
1582 struct bt_gatt_notify_params params;
1583
1584 memset(&params, 0, sizeof(params));
1585
1586 params.uuid = uuid;
1587 params.attr = attr;
1588 params.data = data;
1589 params.len = len;
1590#if defined(CONFIG_BT_EATT)
1592#endif /* CONFIG_BT_EATT */
1593
1594 return bt_gatt_notify_cb(conn, &params);
1595}
1596
1597/* Forward declaration of the bt_gatt_indicate_params structure */
1599
1607typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1608 struct bt_gatt_indicate_params *params,
1609 uint8_t err);
1610
1620 struct bt_gatt_indicate_params *params);
1621
1633 const struct bt_uuid *uuid;
1639 const struct bt_gatt_attr *attr;
1645 const void *data;
1649 uint8_t _ref;
1650#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1653#endif /* CONFIG_BT_EATT */
1654};
1655
1681int bt_gatt_indicate(struct bt_conn *conn,
1682 struct bt_gatt_indicate_params *params);
1683
1703 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1704
1715
1732
1734
1740
1752 void (*func)(struct bt_conn *conn, uint8_t err,
1753 struct bt_gatt_exchange_params *params);
1754};
1755
1782 struct bt_gatt_exchange_params *params);
1783
1785
1836 const struct bt_gatt_attr *attr,
1837 struct bt_gatt_discover_params *params);
1838
1882
1884#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1885
1889 const struct bt_uuid *uuid;
1892 union {
1894 struct {
1901 } _included;
1903 uint16_t start_handle;
1904 };
1914#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1917#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1918#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1921#endif /* CONFIG_BT_EATT */
1922};
1923
1959int bt_gatt_discover(struct bt_conn *conn,
1960 struct bt_gatt_discover_params *params);
1961
1962struct bt_gatt_read_params;
1963
1982typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1983 struct bt_gatt_read_params *params,
1984 const void *data, uint16_t length);
1985
1995 union {
1996 struct {
2002 struct {
2019 struct {
2043 const struct bt_uuid *uuid;
2045 };
2046#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2049#endif /* CONFIG_BT_EATT */
2051 uint16_t _att_mtu;
2052};
2053
2096int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
2097
2099
2107typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
2108 struct bt_gatt_write_params *params);
2109
2119 const void *data;
2122#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2125#endif /* CONFIG_BT_EATT */
2126};
2127
2146int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
2147
2175 const void *data, uint16_t length,
2176 bool sign, bt_gatt_complete_func_t func,
2177 void *user_data);
2178
2197static inline int bt_gatt_write_without_response(struct bt_conn *conn,
2198 uint16_t handle, const void *data,
2199 uint16_t length, bool sign)
2200{
2201 return bt_gatt_write_without_response_cb(conn, handle, data, length,
2202 sign, NULL, NULL);
2203}
2204
2206
2223typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
2224 struct bt_gatt_subscribe_params *params,
2225 const void *data, uint16_t length);
2226
2234typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
2235 struct bt_gatt_subscribe_params *params);
2236
2287
2296
2301#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2306#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2309#if defined(CONFIG_BT_SMP) || defined(__DOXYGEN__)
2315#endif /* CONFIG_BT_SMP */
2318
2322 sys_snode_t node;
2324#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2327#endif /* CONFIG_BT_EATT */
2328};
2329
2365 struct bt_gatt_subscribe_params *params);
2366
2384 struct bt_gatt_subscribe_params *params);
2385
2410 struct bt_gatt_subscribe_params *params);
2411
2429void bt_gatt_cancel(struct bt_conn *conn, void *params);
2430
2432
2433#ifdef __cplusplus
2434}
2435#endif
2436
2440
2441#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:122
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:1982
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:2107
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:2234
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:2197
bt_gatt_sub_flag
Subscription flags.
Definition gatt.h:2238
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:2223
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:1835
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:1840
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2262
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2285
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2283
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2248
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2271
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1860
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1844
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1851
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1846
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1880
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1842
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1869
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:1607
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:1577
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:1619
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:773
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:1540
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:805
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:758
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:1090
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1410
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:666
@ BT_GATT_ITER_STOP
Definition gatt.h:759
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:760
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:247
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:199
bt_gatt_attr_write_flag
GATT attribute write flags.
Definition gatt.h:133
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:143
@ BT_GATT_WRITE_FLAG_CMD
Attribute write command flag.
Definition gatt.h:150
@ BT_GATT_WRITE_FLAG_EXECUTE
Attribute write execute flag.
Definition gatt.h:158
@ 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:108
@ BT_GATT_PERM_WRITE_LESC
Attribute write permission with LE Secure Connection encryption.
Definition gatt.h:120
@ 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:114
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:262
bt_gatt_attr_read_func_t read
Attribute Value read method.
Definition gatt.h:289
uint16_t perm
Attribute Permissions.
Definition gatt.h:334
bt_gatt_attr_write_func_t write
Attribute Value write method.
Definition gatt.h:302
const struct bt_uuid * uuid
Attribute Type.
Definition gatt.h:276
void * user_data
Private data for read() and write() implementation.
Definition gatt.h:315
uint16_t handle
Attribute Handle.
Definition gatt.h:325
GATT authorization callback structure.
Definition gatt.h:427
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:439
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:453
GATT callback structure.
Definition gatt.h:407
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:417
GATT CCC configuration entry.
Definition gatt.h:1099
uint16_t value
Configuration value Value used to enable or disable notifications or indications for a specific chara...
Definition gatt.h:1108
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:1103
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:1101
Internal representation of CCC value.
Definition gatt.h:1115
void(* cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute changed callback.
Definition gatt.h:1132
struct bt_gatt_ccc_cfg cfg[0]
Configuration for each connection.
Definition gatt.h:1117
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:1143
uint16_t value
Highest value of all connected peer's subscriptions.
Definition gatt.h:1120
bool(* cfg_match)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
CCC attribute match handler.
Definition gatt.h:1157
Client Characteristic Configuration Attribute Value.
Definition gatt.h:580
uint16_t flags
Client Characteristic Configuration flags, a bitmap of BT_GATT_CCC_* macros.
Definition gatt.h:582
Characteristic Extended Properties Attribute Value.
Definition gatt.h:556
uint16_t properties
Characteristic Extended properties, a bitmap of BT_GATT_CEP_* macros.
Definition gatt.h:558
Attribute Value of a Characteristic Declaration.
Definition gatt.h:518
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:522
uint8_t properties
Characteristic properties, a bitmap of BT_GATT_CHRC_* macros.
Definition gatt.h:524
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:520
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:609
uint8_t name_space
Name space of the description.
Definition gatt.h:634
uint16_t unit
UUID of the unit of the characteristic.
Definition gatt.h:627
int8_t exponent
Exponent field for value formatting.
Definition gatt.h:621
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:641
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:615
GATT Discover Attributes parameters.
Definition gatt.h:1887
uint16_t start_handle
Starting attribute handle for included service.
Definition gatt.h:1898
uint16_t end_handle
Ending attribute handle for included service.
Definition gatt.h:1900
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1891
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1896
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1889
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1916
uint8_t type
Discover type.
Definition gatt.h:1913
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1920
GATT Exchange MTU parameters.
Definition gatt.h:1750
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Callback for MTU exchange response.
Definition gatt.h:1752
Include Attribute Value.
Definition gatt.h:397
uint16_t end_handle
Handle of the last attribute within the included service.
Definition gatt.h:403
uint16_t start_handle
Handle of the first attribute within the included service.
Definition gatt.h:401
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:399
GATT Indicate Value parameters.
Definition gatt.h:1627
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1652
uint16_t len
Indicate Value length.
Definition gatt.h:1647
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1639
const void * data
Indicate Value data.
Definition gatt.h:1645
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1643
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1641
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1633
GATT notification parameters.
Definition gatt.h:1416
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1422
uint16_t len
Notification Value length.
Definition gatt.h:1432
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1428
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1439
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1434
void * user_data
Notification Value callback user data.
Definition gatt.h:1436
const void * data
Notification Value data.
Definition gatt.h:1430
GATT Read parameters.
Definition gatt.h:1987
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:1994
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2048
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:2006
uint16_t offset
Attribute data offset.
Definition gatt.h:2000
struct bt_gatt_read_params::@230240255327025042252332200332350030123113157136::@052025354345216265352245024173042257041150041213 single
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:1989
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:2017
uint16_t end_handle
Requested end attribute handle number.
Definition gatt.h:2041
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:2031
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:2043
uint16_t handle
Attribute handle.
Definition gatt.h:1998
Server Characteristic Configuration Attribute Value.
Definition gatt.h:599
uint16_t flags
Server Characteristic Configuration flags, a bitmap of BT_GATT_SCC_* macros.
Definition gatt.h:601
Static GATT Service structure.
Definition gatt.h:354
const struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:356
size_t attr_count
Service Attribute count.
Definition gatt.h:358
Service Attribute Value.
Definition gatt.h:384
const struct bt_uuid * uuid
Service UUID.
Definition gatt.h:386
uint16_t end_handle
Handle of the last Attribute within the Service.
Definition gatt.h:388
GATT Service structure.
Definition gatt.h:367
struct bt_gatt_attr * attrs
Service Attributes.
Definition gatt.h:369
size_t attr_count
Service Attribute count.
Definition gatt.h:371
GATT Subscribe parameters.
Definition gatt.h:2289
uint16_t value
Subscribe value.
Definition gatt.h:2308
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2314
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2300
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2295
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2298
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2291
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2305
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2326
atomic_t flags[ATOMIC_BITMAP_SIZE(BT_GATT_SUBSCRIBE_NUM_FLAGS)]
Subscription flags, see bt_gatt_sub_flag.
Definition gatt.h:2317
uint16_t end_handle
Subscribe End handle (for automatic discovery).
Definition gatt.h:2303
GATT Write parameters.
Definition gatt.h:2111
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:2113
uint16_t handle
Attribute handle.
Definition gatt.h:2115
const void * data
Data to be written.
Definition gatt.h:2119
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2124
uint16_t offset
Attribute data offset.
Definition gatt.h:2117
uint16_t length
Length of the data.
Definition gatt.h:2121
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.