Zephyr API Documentation 4.5.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
424
436 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
437
459 void (*execute_write_ended)(struct bt_conn *conn,
460 enum bt_gatt_execute_write_outcome outcome, uint8_t att_err);
461
465 sys_snode_t node;
467};
468
482 bool (*read_authorize)(struct bt_conn *conn,
483 const struct bt_gatt_attr *attr);
484
496 bool (*write_authorize)(struct bt_conn *conn,
497 const struct bt_gatt_attr *attr);
498};
499
501
508#define BT_GATT_CHRC_BROADCAST 0x01
514#define BT_GATT_CHRC_READ 0x02
520#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
526#define BT_GATT_CHRC_WRITE 0x08
533#define BT_GATT_CHRC_NOTIFY 0x10
539#define BT_GATT_CHRC_INDICATE 0x20
547#define BT_GATT_CHRC_AUTH 0x40 __DEPRECATED_MACRO
554#define BT_GATT_CHRC_EXT_PROP 0x80
555
569
571
583#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
584
590#define BT_GATT_CEP_WRITABLE_AUX 0x0002
591
603
605
611#define BT_GATT_CCC_NOTIFY 0x0001
617#define BT_GATT_CCC_INDICATE 0x0002
618
627
629
636#define BT_GATT_SCC_BROADCAST 0x0001
637
646
686
692
709static inline const char *bt_gatt_err_to_str(int gatt_err)
710{
711 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
712}
713
722
733
753
781
789
797
805
816typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
818 void *user_data);
819
833void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
834 const struct bt_uuid *uuid,
835 const void *attr_data, uint16_t num_matches,
837 void *user_data);
838
848static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
850 void *user_data)
851{
852 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
853 user_data);
854}
855
864struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
865
881 uint16_t attr_count,
882 const struct bt_uuid *uuid);
883
893
906
922ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
923 void *buf, uint16_t buf_len, uint16_t offset,
924 const void *value, uint16_t value_len);
925
942 const struct bt_gatt_attr *attr,
943 void *buf, uint16_t len, uint16_t offset);
944
952#define BT_GATT_SERVICE_DEFINE(_name, ...) \
953 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
954 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
955 BT_GATT_SERVICE(attr_##_name)
956
957#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
958 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
959
960#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
961
977#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
978 _name, _instances, _instance_num, _attrs_def) \
979 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
980 "The number of array elements does not match its size"); \
981 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
982 _instances, _attrs_def); \
983 static struct bt_gatt_service _name[] = { \
984 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
985 }
986
994#define BT_GATT_SERVICE(_attrs) \
995{ \
996 .attrs = _attrs, \
997 .attr_count = ARRAY_SIZE(_attrs), \
998}
999
1007#define BT_GATT_PRIMARY_SERVICE(_service) \
1008 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
1009 bt_gatt_attr_read_service, NULL, (void *)_service)
1010
1021#define BT_GATT_SECONDARY_SERVICE(_service) \
1022 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
1023 bt_gatt_attr_read_service, NULL, (void *)_service)
1024
1042 const struct bt_gatt_attr *attr,
1043 void *buf, uint16_t len, uint16_t offset);
1044
1052#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
1053 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
1054 bt_gatt_attr_read_included, NULL, _service_incl)
1055
1072 const struct bt_gatt_attr *attr, void *buf,
1073 uint16_t len, uint16_t offset);
1074
1085#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
1086{ \
1087 .uuid = _uuid, \
1088 .value_handle = _handle, \
1089 .properties = _props, \
1090}
1091
1109#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
1110 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
1111 bt_gatt_attr_read_chrc, NULL, \
1112 ((struct bt_gatt_chrc[]) { \
1113 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
1114 })), \
1115 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1116
1128#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
1129 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
1130#elif defined(CONFIG_BT_CONN)
1131 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
1132#else
1133 #define BT_GATT_CCC_MAX 0
1134#endif
1135
1153
1161
1164
1175 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
1176
1186 ssize_t (*cfg_write)(struct bt_conn *conn,
1187 const struct bt_gatt_attr *attr, uint16_t value);
1188
1200 bool (*cfg_match)(struct bt_conn *conn,
1201 const struct bt_gatt_attr *attr);
1202};
1203
1224 const struct bt_gatt_attr *attr, void *buf,
1225 uint16_t len, uint16_t offset);
1226
1247 const struct bt_gatt_attr *attr, const void *buf,
1248 uint16_t len, uint16_t offset, uint8_t flags);
1249
1259#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1260 { \
1261 .cfg = {}, \
1262 .cfg_changed = _changed, \
1263 .cfg_write = _write, \
1264 .cfg_match = _match, \
1265 }
1266
1279#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
1280 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
1281 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
1282 _ccc)
1283
1293#define BT_GATT_CCC(_changed, _perm) \
1294 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1295 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1296 _perm)
1297
1308#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1309 BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1310 BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1311 _perm)
1312
1330 const struct bt_gatt_attr *attr, void *buf,
1331 uint16_t len, uint16_t offset);
1332
1340#define BT_GATT_CEP(_value) \
1341 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
1342 bt_gatt_attr_read_cep, NULL, (void *)_value)
1343
1362 const struct bt_gatt_attr *attr, void *buf,
1363 uint16_t len, uint16_t offset);
1364
1374#define BT_GATT_CUD(_value, _perm) \
1375 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1376 NULL, (void *)_value)
1377
1395 const struct bt_gatt_attr *attr, void *buf,
1396 uint16_t len, uint16_t offset);
1397
1405#define BT_GATT_CPF(_value) \
1406 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1407 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1408
1423#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1424 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1425
1438#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1439{ \
1440 .uuid = _uuid, \
1441 .read = _read, \
1442 .write = _write, \
1443 .user_data = _user_data, \
1444 .handle = 0, \
1445 .perm = _perm, \
1446}
1447
1453typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1454
1465 const struct bt_uuid *uuid;
1471 const struct bt_gatt_attr *attr;
1473 const void *data;
1480#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1483#endif /* CONFIG_BT_EATT */
1484};
1485
1507 struct bt_gatt_notify_params *params);
1508
1561 uint16_t num_params,
1562 struct bt_gatt_notify_params params[]);
1563
1587static inline int bt_gatt_notify(struct bt_conn *conn,
1588 const struct bt_gatt_attr *attr,
1589 const void *data, uint16_t len)
1590{
1591 struct bt_gatt_notify_params params;
1592
1593 memset(&params, 0, sizeof(params));
1594
1595 params.attr = attr;
1596 params.data = data;
1597 params.len = len;
1598#if defined(CONFIG_BT_EATT)
1600#endif /* CONFIG_BT_EATT */
1601
1602 return bt_gatt_notify_cb(conn, &params);
1603}
1604
1624static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1625 const struct bt_uuid *uuid,
1626 const struct bt_gatt_attr *attr,
1627 const void *data, uint16_t len)
1628{
1629 struct bt_gatt_notify_params params;
1630
1631 memset(&params, 0, sizeof(params));
1632
1633 params.uuid = uuid;
1634 params.attr = attr;
1635 params.data = data;
1636 params.len = len;
1637#if defined(CONFIG_BT_EATT)
1639#endif /* CONFIG_BT_EATT */
1640
1641 return bt_gatt_notify_cb(conn, &params);
1642}
1643
1644/* Forward declaration of the bt_gatt_indicate_params structure */
1646
1654typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1655 struct bt_gatt_indicate_params *params,
1656 uint8_t err);
1657
1667 struct bt_gatt_indicate_params *params);
1668
1680 const struct bt_uuid *uuid;
1686 const struct bt_gatt_attr *attr;
1692 const void *data;
1696 uint8_t _ref;
1697#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1700#endif /* CONFIG_BT_EATT */
1701};
1702
1732int bt_gatt_indicate(struct bt_conn *conn,
1733 struct bt_gatt_indicate_params *params);
1734
1754 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1755
1766
1783
1785
1791
1803 void (*func)(struct bt_conn *conn, uint8_t err,
1804 struct bt_gatt_exchange_params *params);
1805};
1806
1833 struct bt_gatt_exchange_params *params);
1834
1836
1887 const struct bt_gatt_attr *attr,
1888 struct bt_gatt_discover_params *params);
1889
1933
1935#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1936
1940 const struct bt_uuid *uuid;
1943 union {
1945 struct {
1952 } _included;
1954 uint16_t start_handle;
1955 };
1965#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1968#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1969#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1972#endif /* CONFIG_BT_EATT */
1973};
1974
2010int bt_gatt_discover(struct bt_conn *conn,
2011 struct bt_gatt_discover_params *params);
2012
2013struct bt_gatt_read_params;
2014
2033typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
2034 struct bt_gatt_read_params *params,
2035 const void *data, uint16_t length);
2036
2046 union {
2047 struct {
2053 struct {
2070 struct {
2094 const struct bt_uuid *uuid;
2096 };
2097#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2100#endif /* CONFIG_BT_EATT */
2102 uint16_t _att_mtu;
2103};
2104
2147int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
2148
2150
2158typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
2159 struct bt_gatt_write_params *params);
2160
2170 const void *data;
2173#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2176#endif /* CONFIG_BT_EATT */
2177};
2178
2197int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
2198
2226 const void *data, uint16_t length,
2227 bool sign, bt_gatt_complete_func_t func,
2228 void *user_data);
2229
2248static inline int bt_gatt_write_without_response(struct bt_conn *conn,
2249 uint16_t handle, const void *data,
2250 uint16_t length, bool sign)
2251{
2252 return bt_gatt_write_without_response_cb(conn, handle, data, length,
2253 sign, NULL, NULL);
2254}
2255
2257
2274typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
2275 struct bt_gatt_subscribe_params *params,
2276 const void *data, uint16_t length);
2277
2285typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
2286 struct bt_gatt_subscribe_params *params);
2287
2338
2347
2352#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
2357#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
2360#if defined(CONFIG_BT_SMP) || defined(__DOXYGEN__)
2366#endif /* CONFIG_BT_SMP */
2369
2373 sys_snode_t node;
2375#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2378#endif /* CONFIG_BT_EATT */
2379};
2380
2416 struct bt_gatt_subscribe_params *params);
2417
2435 struct bt_gatt_subscribe_params *params);
2436
2461 struct bt_gatt_subscribe_params *params);
2462
2480void bt_gatt_cancel(struct bt_conn *conn, void *params);
2481
2483
2484#ifdef __cplusplus
2485}
2486#endif
2487
2491
2492#endif /* ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_ */
Bluetooth device address definitions and utilities.
Header file for the Atomic operations API.
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:204
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:206
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:2033
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:2158
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:2285
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:2248
bt_gatt_sub_flag
Subscription flags.
Definition gatt.h:2289
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:2274
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:1886
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:1891
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition gatt.h:2313
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition gatt.h:2336
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition gatt.h:2334
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition gatt.h:2299
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition gatt.h:2322
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition gatt.h:1911
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition gatt.h:1895
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition gatt.h:1902
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition gatt.h:1897
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition gatt.h:1931
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition gatt.h:1893
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition gatt.h:1920
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:1654
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:1624
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:1666
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:816
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:1587
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:848
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:801
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 <code class='doxyxref' data-stype='kconfig:option' d...
Definition gatt.h:1133
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition gatt.h:1453
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:709
@ BT_GATT_ITER_STOP
Definition gatt.h:802
@ BT_GATT_ITER_CONTINUE
Definition gatt.h:803
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_execute_write_outcome
Outcome of an Execute Write Request, see bt_gatt_cb::execute_write_ended.
Definition gatt.h:407
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_EXECUTE_WRITE_WRITTEN
All the prepared values were written.
Definition gatt.h:409
@ BT_GATT_EXECUTE_WRITE_FAILED
Writing a value failed and the values after it were discarded (Core Specification 7....
Definition gatt.h:422
@ BT_GATT_EXECUTE_WRITE_CANCELLED
The client cancelled the prepared values, so none was written.
Definition gatt.h:411
@ 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
__SIZE_TYPE__ ssize_t
Definition types.h:28
flags
Definition parser.h:86
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:470
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition gatt.h:482
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition gatt.h:496
GATT callback structure.
Definition gatt.h:426
void(* execute_write_ended)(struct bt_conn *conn, enum bt_gatt_execute_write_outcome outcome, uint8_t att_err)
An Execute Write Request of the client ended.
Definition gatt.h:459
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:436
GATT CCC configuration entry.
Definition gatt.h:1142
uint16_t value
Configuration value Value used to enable or disable notifications or indications for a specific chara...
Definition gatt.h:1151
bt_addr_le_t peer
Remote peer address.
Definition gatt.h:1146
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition gatt.h:1144
Internal representation of CCC value.
Definition gatt.h:1158
void(* cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value)
CCC attribute changed callback.
Definition gatt.h:1175
struct bt_gatt_ccc_cfg cfg[0]
Configuration for each connection.
Definition gatt.h:1160
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:1186
uint16_t value
Highest value of all connected peer's subscriptions, Reserved bits excluded.
Definition gatt.h:1163
bool(* cfg_match)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
CCC attribute match handler.
Definition gatt.h:1200
Client Characteristic Configuration Attribute Value.
Definition gatt.h:623
uint16_t flags
Client Characteristic Configuration flags, a bitmap of BT_GATT_CCC_* macros.
Definition gatt.h:625
Characteristic Extended Properties Attribute Value.
Definition gatt.h:599
uint16_t properties
Characteristic Extended properties, a bitmap of BT_GATT_CEP_* macros.
Definition gatt.h:601
Attribute Value of a Characteristic Declaration.
Definition gatt.h:561
uint16_t value_handle
Characteristic Value handle.
Definition gatt.h:565
uint8_t properties
Characteristic properties, a bitmap of BT_GATT_CHRC_* macros.
Definition gatt.h:567
const struct bt_uuid * uuid
Characteristic UUID.
Definition gatt.h:563
GATT Characteristic Presentation Format Attribute Value.
Definition gatt.h:652
uint8_t name_space
Name space of the description.
Definition gatt.h:677
uint16_t unit
UUID of the unit of the characteristic.
Definition gatt.h:670
int8_t exponent
Exponent field for value formatting.
Definition gatt.h:664
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition gatt.h:684
uint8_t format
Format of the value of the characteristic.
Definition gatt.h:658
GATT Discover Attributes parameters.
Definition gatt.h:1938
uint16_t start_handle
Starting attribute handle for included service.
Definition gatt.h:1949
uint16_t end_handle
Ending attribute handle for included service.
Definition gatt.h:1951
bt_gatt_discover_func_t func
Discover attribute callback.
Definition gatt.h:1942
uint16_t attr_handle
Include service attribute declaration handle.
Definition gatt.h:1947
const struct bt_uuid * uuid
Discover UUID type.
Definition gatt.h:1940
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition gatt.h:1967
uint8_t type
Discover type.
Definition gatt.h:1964
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1971
GATT Exchange MTU parameters.
Definition gatt.h:1801
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Callback for MTU exchange response.
Definition gatt.h:1803
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:1674
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1699
uint16_t len
Indicate Value length.
Definition gatt.h:1694
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition gatt.h:1686
const void * data
Indicate Value data.
Definition gatt.h:1692
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition gatt.h:1690
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition gatt.h:1688
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition gatt.h:1680
GATT notification parameters.
Definition gatt.h:1459
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition gatt.h:1465
uint16_t len
Notification Value length.
Definition gatt.h:1475
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition gatt.h:1471
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:1482
bt_gatt_complete_func_t func
Notification Value callback.
Definition gatt.h:1477
void * user_data
Notification Value callback user data.
Definition gatt.h:1479
const void * data
Notification Value data.
Definition gatt.h:1473
GATT Read parameters.
Definition gatt.h:2038
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition gatt.h:2045
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2099
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition gatt.h:2057
uint16_t offset
Attribute data offset.
Definition gatt.h:2051
bt_gatt_read_func_t func
Read attribute callback.
Definition gatt.h:2040
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@372352161252260236002106024214036013303007152222 single
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@371162354121151156017205063160212333251365073232 multiple
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition gatt.h:2068
struct bt_gatt_read_params::@172336054125152351005356152301225305321016010030::@261011265054333145327063036013076000041270205077 by_uuid
uint16_t end_handle
Requested end attribute handle number.
Definition gatt.h:2092
uint16_t start_handle
Requested start attribute handle number.
Definition gatt.h:2082
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition gatt.h:2094
uint16_t handle
Attribute handle.
Definition gatt.h:2049
Server Characteristic Configuration Attribute Value.
Definition gatt.h:642
uint16_t flags
Server Characteristic Configuration flags, a bitmap of BT_GATT_SCC_* macros.
Definition gatt.h:644
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:2340
uint16_t value
Subscribe value.
Definition gatt.h:2359
bt_security_t min_security
Minimum required security for received notification.
Definition gatt.h:2365
uint16_t ccc_handle
Subscribe CCC handle.
Definition gatt.h:2351
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition gatt.h:2346
uint16_t value_handle
Subscribe value handle.
Definition gatt.h:2349
bt_gatt_notify_func_t notify
Notification value callback.
Definition gatt.h:2342
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE.
Definition gatt.h:2356
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2377
atomic_t flags[ATOMIC_BITMAP_SIZE(BT_GATT_SUBSCRIBE_NUM_FLAGS)]
Subscription flags, see bt_gatt_sub_flag.
Definition gatt.h:2368
uint16_t end_handle
Subscribe End handle (for automatic discovery).
Definition gatt.h:2354
GATT Write parameters.
Definition gatt.h:2162
bt_gatt_write_func_t func
Response callback.
Definition gatt.h:2164
uint16_t handle
Attribute handle.
Definition gatt.h:2166
const void * data
Data to be written.
Definition gatt.h:2170
enum bt_att_chan_opt chan_opt
Att channel options.
Definition gatt.h:2175
uint16_t offset
Attribute data offset.
Definition gatt.h:2168
uint16_t length
Length of the data.
Definition gatt.h:2172
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
Iterable sections helpers.
Misc utilities.
Macros to abstract toolchain specific capabilities.
Macro utilities.