Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gatt.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-2016 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_
12
20#include <stdint.h>
21#include <stddef.h>
22
23#include <sys/types.h>
24
25#include <zephyr/sys/slist.h>
26#include <zephyr/sys/util.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
40
43
46
52
58
65
72
79
85
91};
92
100#define BT_GATT_ERR(_att_err) (-(_att_err))
101
103enum {
110
117
125};
126
127/* Forward declaration of GATT Attribute structure */
128struct bt_gatt_attr;
129
145typedef ssize_t (*bt_gatt_attr_read_func_t)(struct bt_conn *conn,
146 const struct bt_gatt_attr *attr,
147 void *buf, uint16_t len,
148 uint16_t offset);
149
163typedef ssize_t (*bt_gatt_attr_write_func_t)(struct bt_conn *conn,
164 const struct bt_gatt_attr *attr,
165 const void *buf, uint16_t len,
166 uint16_t offset, uint8_t flags);
167
171 const struct bt_uuid *uuid;
185};
186
190 const struct bt_gatt_attr *attrs;
193};
194
201
203};
204
208 const struct bt_uuid *uuid;
211};
212
216 const struct bt_uuid *uuid;
221};
222
234 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
235
237};
238
252 bool (*read_authorize)(struct bt_conn *conn,
253 const struct bt_gatt_attr *attr);
254
266 bool (*write_authorize)(struct bt_conn *conn,
267 const struct bt_gatt_attr *attr);
268};
269
278#define BT_GATT_CHRC_BROADCAST 0x01
284#define BT_GATT_CHRC_READ 0x02
290#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
296#define BT_GATT_CHRC_WRITE 0x08
303#define BT_GATT_CHRC_NOTIFY 0x10
309#define BT_GATT_CHRC_INDICATE 0x20
315#define BT_GATT_CHRC_AUTH 0x40
322#define BT_GATT_CHRC_EXT_PROP 0x80
323
327 const struct bt_uuid *uuid;
332};
333
335#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
336#define BT_GATT_CEP_WRITABLE_AUX 0x0002
337
342};
343
351#define BT_GATT_CCC_NOTIFY 0x0001
357#define BT_GATT_CCC_INDICATE 0x0002
358
363};
364
373#define BT_GATT_SCC_BROADCAST 0x0001
374
379};
380
395};
396
419static inline const char *bt_gatt_err_to_str(int gatt_err)
420{
421 return bt_att_err_to_str((gatt_err) < 0 ? -(gatt_err) : (gatt_err));
422}
423
432
452
480
488
496
497enum {
500};
501
512typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
514 void *user_data);
515
528void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
529 const struct bt_uuid *uuid,
530 const void *attr_data, uint16_t num_matches,
532 void *user_data);
533
543static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
545 void *user_data)
546{
547 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
548 user_data);
549}
550
559struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
560
576 uint16_t attr_count,
577 const struct bt_uuid *uuid);
578
587
599
615ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
616 void *buf, uint16_t buf_len, uint16_t offset,
617 const void *value, uint16_t value_len);
618
635 const struct bt_gatt_attr *attr,
636 void *buf, uint16_t len, uint16_t offset);
637
645#define BT_GATT_SERVICE_DEFINE(_name, ...) \
646 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
647 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
648 BT_GATT_SERVICE(attr_##_name)
649
650#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
651 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
652
653#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
654
670#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
671 _name, _instances, _instance_num, _attrs_def) \
672 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
673 "The number of array elements does not match its size"); \
674 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
675 _instances, _attrs_def); \
676 static struct bt_gatt_service _name[] = { \
677 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
678 }
679
687#define BT_GATT_SERVICE(_attrs) \
688{ \
689 .attrs = _attrs, \
690 .attr_count = ARRAY_SIZE(_attrs), \
691}
692
700#define BT_GATT_PRIMARY_SERVICE(_service) \
701 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
702 bt_gatt_attr_read_service, NULL, (void *)_service)
703
714#define BT_GATT_SECONDARY_SERVICE(_service) \
715 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
716 bt_gatt_attr_read_service, NULL, (void *)_service)
717
734 const struct bt_gatt_attr *attr,
735 void *buf, uint16_t len, uint16_t offset);
736
744#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
745 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
746 bt_gatt_attr_read_included, NULL, _service_incl)
747
763ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
764 const struct bt_gatt_attr *attr, void *buf,
765 uint16_t len, uint16_t offset);
766
767#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
768{ \
769 .uuid = _uuid, \
770 .value_handle = _handle, \
771 .properties = _props, \
772}
773
791#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
792 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
793 bt_gatt_attr_read_chrc, NULL, \
794 ((struct bt_gatt_chrc[]) { \
795 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
796 })), \
797 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
798
799#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
800 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
801#elif defined(CONFIG_BT_CONN)
802 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
803#else
804 #define BT_GATT_CCC_MAX 0
805#endif
806
815};
816
818struct _bt_gatt_ccc {
821
823 uint16_t value;
824
830 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
831
841 ssize_t (*cfg_write)(struct bt_conn *conn,
842 const struct bt_gatt_attr *attr, uint16_t value);
843
855 bool (*cfg_match)(struct bt_conn *conn,
856 const struct bt_gatt_attr *attr);
857};
858
875ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
876 const struct bt_gatt_attr *attr, void *buf,
877 uint16_t len, uint16_t offset);
878
895ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
896 const struct bt_gatt_attr *attr, const void *buf,
897 uint16_t len, uint16_t offset, uint8_t flags);
898
899
909#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match) \
910 { \
911 .cfg = {}, \
912 .cfg_changed = _changed, \
913 .cfg_write = _write, \
914 .cfg_match = _match, \
915 }
916
926#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
927 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
928 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
929 _ccc)
930
940#define BT_GATT_CCC(_changed, _perm) \
941 BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
942 {BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
943
960ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
961 const struct bt_gatt_attr *attr, void *buf,
962 uint16_t len, uint16_t offset);
963
971#define BT_GATT_CEP(_value) \
972 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
973 bt_gatt_attr_read_cep, NULL, (void *)_value)
974
992ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
993 const struct bt_gatt_attr *attr, void *buf,
994 uint16_t len, uint16_t offset);
995
1005#define BT_GATT_CUD(_value, _perm) \
1006 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
1007 NULL, (void *)_value)
1008
1025ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1026 const struct bt_gatt_attr *attr, void *buf,
1027 uint16_t len, uint16_t offset);
1028
1036#define BT_GATT_CPF(_value) \
1037 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1038 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1039
1054#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1055 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1056
1069#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1070{ \
1071 .uuid = _uuid, \
1072 .read = _read, \
1073 .write = _write, \
1074 .user_data = _user_data, \
1075 .handle = 0, \
1076 .perm = _perm, \
1077}
1078
1084typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1085
1092 const struct bt_uuid *uuid;
1098 const struct bt_gatt_attr *attr;
1100 const void *data;
1107#if defined(CONFIG_BT_EATT)
1109#endif /* CONFIG_BT_EATT */
1110};
1111
1133int bt_gatt_notify_cb(struct bt_conn *conn,
1134 struct bt_gatt_notify_params *params);
1135
1187int bt_gatt_notify_multiple(struct bt_conn *conn,
1188 uint16_t num_params,
1189 struct bt_gatt_notify_params params[]);
1190
1210static inline int bt_gatt_notify(struct bt_conn *conn,
1211 const struct bt_gatt_attr *attr,
1212 const void *data, uint16_t len)
1213{
1214 struct bt_gatt_notify_params params;
1215
1216 memset(&params, 0, sizeof(params));
1217
1218 params.attr = attr;
1219 params.data = data;
1220 params.len = len;
1221#if defined(CONFIG_BT_EATT)
1223#endif /* CONFIG_BT_EATT */
1224
1225 return bt_gatt_notify_cb(conn, &params);
1226}
1227
1247static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1248 const struct bt_uuid *uuid,
1249 const struct bt_gatt_attr *attr,
1250 const void *data, uint16_t len)
1251{
1252 struct bt_gatt_notify_params params;
1253
1254 memset(&params, 0, sizeof(params));
1255
1256 params.uuid = uuid;
1257 params.attr = attr;
1258 params.data = data;
1259 params.len = len;
1260#if defined(CONFIG_BT_EATT)
1262#endif /* CONFIG_BT_EATT */
1263
1264 return bt_gatt_notify_cb(conn, &params);
1265}
1266
1267/* Forward declaration of the bt_gatt_indicate_params structure */
1269
1277typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1278 struct bt_gatt_indicate_params *params,
1279 uint8_t err);
1280
1282 struct bt_gatt_indicate_params *params);
1283
1291 const struct bt_uuid *uuid;
1297 const struct bt_gatt_attr *attr;
1303 const void *data;
1307 uint8_t _ref;
1308#if defined(CONFIG_BT_EATT)
1310#endif /* CONFIG_BT_EATT */
1311};
1312
1338int bt_gatt_indicate(struct bt_conn *conn,
1339 struct bt_gatt_indicate_params *params);
1340
1341
1360bool bt_gatt_is_subscribed(struct bt_conn *conn,
1361 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1362
1372uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1373
1385 void (*func)(struct bt_conn *conn, uint8_t err,
1386 struct bt_gatt_exchange_params *params);
1387};
1388
1416int bt_gatt_exchange_mtu(struct bt_conn *conn,
1417 struct bt_gatt_exchange_params *params);
1418
1420
1465typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1466 const struct bt_gatt_attr *attr,
1467 struct bt_gatt_discover_params *params);
1468
1470enum {
1511};
1512
1516 const struct bt_uuid *uuid;
1519 union {
1520 struct {
1527 } _included;
1529 uint16_t start_handle;
1530 };
1535#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1538#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1539#if defined(CONFIG_BT_EATT)
1541#endif /* CONFIG_BT_EATT */
1542};
1543
1580int bt_gatt_discover(struct bt_conn *conn,
1581 struct bt_gatt_discover_params *params);
1582
1583struct bt_gatt_read_params;
1584
1600typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1601 struct bt_gatt_read_params *params,
1602 const void *data, uint16_t length);
1603
1613 union {
1614 struct {
1620 struct {
1637 struct {
1643 const struct bt_uuid *uuid;
1645 };
1646#if defined(CONFIG_BT_EATT)
1648#endif /* CONFIG_BT_EATT */
1650 uint16_t _att_mtu;
1651};
1652
1695int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
1696
1698
1706typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
1707 struct bt_gatt_write_params *params);
1708
1718 const void *data;
1721#if defined(CONFIG_BT_EATT)
1723#endif /* CONFIG_BT_EATT */
1724};
1725
1748int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
1749
1785int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
1786 const void *data, uint16_t length,
1787 bool sign, bt_gatt_complete_func_t func,
1788 void *user_data);
1789
1811static inline int bt_gatt_write_without_response(struct bt_conn *conn,
1812 uint16_t handle, const void *data,
1813 uint16_t length, bool sign)
1814{
1815 return bt_gatt_write_without_response_cb(conn, handle, data, length,
1816 sign, NULL, NULL);
1817}
1818
1820
1837typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
1838 struct bt_gatt_subscribe_params *params,
1839 const void *data, uint16_t length);
1840
1848typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
1849 struct bt_gatt_subscribe_params *params);
1850
1852enum {
1863
1877
1886
1898
1901
1910
1917#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1922#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1925#if defined(CONFIG_BT_SMP)
1931#endif
1934
1936#if defined(CONFIG_BT_EATT)
1938#endif /* CONFIG_BT_EATT */
1939};
1940
1978int bt_gatt_subscribe(struct bt_conn *conn,
1979 struct bt_gatt_subscribe_params *params);
1980
1998 struct bt_gatt_subscribe_params *params);
1999
2024int bt_gatt_unsubscribe(struct bt_conn *conn,
2025 struct bt_gatt_subscribe_params *params);
2026
2044void bt_gatt_cancel(struct bt_conn *conn, void *params);
2045
2048#ifdef __cplusplus
2049}
2050#endif
2051
2056#endif /* ZEPHYR_INCLUDE_BLUETOOTH_GATT_H_ */
Attribute Protocol handling.
Bluetooth connection handling.
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition: atomic.h:111
bt_att_chan_opt
ATT channel option bit field values.
Definition: att.h:173
static const char * bt_att_err_to_str(uint8_t att_err)
Converts a ATT error to string.
Definition: att.h:123
@ BT_ATT_CHAN_OPT_NONE
Both Enhanced and Unenhanced channels can be used
Definition: att.h:175
bt_security_t
Security level.
Definition: conn.h:408
int bt_gatt_exchange_mtu(struct bt_conn *conn, struct bt_gatt_exchange_params *params)
Exchange MTU.
int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)
Read Attribute Value by handle.
uint8_t(* bt_gatt_discover_func_t)(struct bt_conn *conn, const struct bt_gatt_attr *attr, struct bt_gatt_discover_params *params)
Discover attribute callback function.
Definition: gatt.h:1465
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:1848
int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle, const void *data, uint16_t length, bool sign, bt_gatt_complete_func_t func, void *user_data)
Write Attribute Value by handle without response with callback.
void bt_gatt_cancel(struct bt_conn *conn, void *params)
Try to cancel the first pending request identified by params.
int bt_gatt_unsubscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params)
Unsubscribe Attribute Value Notification.
uint8_t(* bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err, struct bt_gatt_read_params *params, const void *data, uint16_t length)
Read callback function.
Definition: gatt.h:1600
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:1811
int bt_gatt_discover(struct bt_conn *conn, struct bt_gatt_discover_params *params)
GATT Discover function.
uint8_t(* bt_gatt_notify_func_t)(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length)
Notification callback function.
Definition: gatt.h:1837
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:1706
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition: gatt.h:1490
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition: gatt.h:1474
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition: gatt.h:1481
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition: gatt.h:1476
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition: gatt.h:1510
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition: gatt.h:1472
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition: gatt.h:1499
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition: gatt.h:1876
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition: gatt.h:1899
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition: gatt.h:1897
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition: gatt.h:1862
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition: gatt.h:1885
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:1277
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:1247
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)
Definition: gatt.h:1281
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
Register GATT authorization callbacks.
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:1210
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:543
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
Definition: gatt.h:804
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition: gatt.h:1084
ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Service Attribute helper.
struct bt_gatt_attr * bt_gatt_find_by_uuid(const struct bt_gatt_attr *attr, uint16_t attr_count, const struct bt_uuid *uuid)
Find Attribute by UUID.
ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
Read Characteristic Attribute helper.
void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle, const struct bt_uuid *uuid, const void *attr_data, uint16_t num_matches, bt_gatt_attr_func_t func, void *user_data)
Attribute iterator by type.
bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc)
Check if GATT service is registered.
uint8_t(* bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr, uint16_t handle, void *user_data)
Attribute iterator callback.
Definition: gatt.h:512
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:419
@ BT_GATT_ITER_STOP
Definition: gatt.h:498
@ BT_GATT_ITER_CONTINUE
Definition: gatt.h:499
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:145
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 write callback.
Definition: gatt.h:163
bt_gatt_perm
GATT attribute permission bit field values.
Definition: gatt.h:37
@ BT_GATT_PERM_READ_ENCRYPT
Attribute read permission with encryption.
Definition: gatt.h:51
@ BT_GATT_PERM_WRITE
Attribute write permission.
Definition: gatt.h:45
@ BT_GATT_PERM_WRITE_ENCRYPT
Attribute write permission with encryption.
Definition: gatt.h:57
@ BT_GATT_PERM_NONE
No operations supported, e.g.
Definition: gatt.h:39
@ BT_GATT_PERM_READ
Attribute read permission.
Definition: gatt.h:42
@ BT_GATT_PERM_PREPARE_WRITE
Attribute prepare write permission.
Definition: gatt.h:78
@ BT_GATT_PERM_WRITE_LESC
Attribute write permission with LE Secure Connection encryption.
Definition: gatt.h:90
@ BT_GATT_PERM_READ_AUTHEN
Attribute read permission with authentication.
Definition: gatt.h:64
@ BT_GATT_PERM_WRITE_AUTHEN
Attribute write permission with authentication.
Definition: gatt.h:71
@ BT_GATT_PERM_READ_LESC
Attribute read permission with LE Secure Connection encryption.
Definition: gatt.h:84
@ BT_GATT_WRITE_FLAG_PREPARE
Attribute prepare write flag.
Definition: gatt.h:109
@ BT_GATT_WRITE_FLAG_CMD
Attribute write command flag.
Definition: gatt.h:116
@ BT_GATT_WRITE_FLAG_EXECUTE
Attribute write execute flag.
Definition: gatt.h:124
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
__SIZE_TYPE__ ssize_t
Definition: types.h:28
flags
Definition: parser.h:96
#define bool
Definition: stdbool.h:13
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT8_TYPE__ int8_t
Definition: stdint.h:72
void * memset(void *buf, int c, size_t n)
Bluetooth LE Device Address.
Definition: addr.h:49
GATT Attribute structure.
Definition: gatt.h:169
bt_gatt_attr_read_func_t read
Attribute read callback.
Definition: gatt.h:173
uint16_t perm
Attribute permissions.
Definition: gatt.h:184
bt_gatt_attr_write_func_t write
Attribute write callback.
Definition: gatt.h:175
const struct bt_uuid * uuid
Attribute UUID.
Definition: gatt.h:171
void * user_data
Attribute user data.
Definition: gatt.h:177
uint16_t handle
Attribute handle.
Definition: gatt.h:179
GATT authorization callback structure.
Definition: gatt.h:240
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition: gatt.h:252
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition: gatt.h:266
GATT callback structure.
Definition: gatt.h:224
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:234
sys_snode_t node
Definition: gatt.h:236
GATT CCC configuration entry.
Definition: gatt.h:808
uint16_t value
Configuration value.
Definition: gatt.h:814
bt_addr_le_t peer
Remote peer address.
Definition: gatt.h:812
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition: gatt.h:810
Client Characteristic Configuration Attribute Value.
Definition: gatt.h:360
uint16_t flags
Client Characteristic Configuration flags.
Definition: gatt.h:362
Characteristic Extended Properties Attribute Value.
Definition: gatt.h:339
uint16_t properties
Characteristic Extended properties.
Definition: gatt.h:341
Characteristic Attribute Value.
Definition: gatt.h:325
uint16_t value_handle
Characteristic Value handle.
Definition: gatt.h:329
uint8_t properties
Characteristic properties.
Definition: gatt.h:331
const struct bt_uuid * uuid
Characteristic UUID.
Definition: gatt.h:327
GATT Characteristic Presentation Format Attribute Value.
Definition: gatt.h:382
uint8_t name_space
Name space of the description.
Definition: gatt.h:392
uint16_t unit
Unit of the characteristic.
Definition: gatt.h:390
int8_t exponent
Exponent field to determine how the value of this characteristic is further formatted.
Definition: gatt.h:388
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition: gatt.h:394
uint8_t format
Format of the value of the characteristic.
Definition: gatt.h:384
GATT Discover Attributes parameters.
Definition: gatt.h:1514
uint16_t start_handle
Included service start handle.
Definition: gatt.h:1524
uint16_t end_handle
Included service end handle.
Definition: gatt.h:1526
bt_gatt_discover_func_t func
Discover attribute callback.
Definition: gatt.h:1518
uint16_t attr_handle
Include service attribute declaration handle.
Definition: gatt.h:1522
const struct bt_uuid * uuid
Discover UUID type.
Definition: gatt.h:1516
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition: gatt.h:1537
uint8_t type
Discover type.
Definition: gatt.h:1534
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1540
GATT Exchange MTU parameters.
Definition: gatt.h:1383
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Response callback.
Definition: gatt.h:1385
Include Attribute Value.
Definition: gatt.h:214
uint16_t end_handle
Service end handle.
Definition: gatt.h:220
uint16_t start_handle
Service start handle.
Definition: gatt.h:218
const struct bt_uuid * uuid
Service UUID.
Definition: gatt.h:216
GATT Indicate Value parameters.
Definition: gatt.h:1285
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1309
uint16_t len
Indicate Value length.
Definition: gatt.h:1305
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition: gatt.h:1297
const void * data
Indicate Value data.
Definition: gatt.h:1303
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition: gatt.h:1301
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition: gatt.h:1299
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition: gatt.h:1291
Definition: gatt.h:1086
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition: gatt.h:1092
uint16_t len
Notification Value length.
Definition: gatt.h:1102
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition: gatt.h:1098
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1108
bt_gatt_complete_func_t func
Notification Value callback.
Definition: gatt.h:1104
void * user_data
Notification Value callback user data.
Definition: gatt.h:1106
const void * data
Notification Value data.
Definition: gatt.h:1100
GATT Read parameters.
Definition: gatt.h:1605
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition: gatt.h:1612
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1647
struct bt_gatt_read_params::@80::@84 by_uuid
struct bt_gatt_read_params::@80::@83 multiple
uint16_t * handles
Attribute handles to read with Read Multiple Characteristic Values.
Definition: gatt.h:1624
uint16_t offset
Attribute data offset.
Definition: gatt.h:1618
bt_gatt_read_func_t func
Read attribute callback.
Definition: gatt.h:1607
struct bt_gatt_read_params::@80::@82 single
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition: gatt.h:1635
uint16_t end_handle
Last requested handle number.
Definition: gatt.h:1641
uint16_t start_handle
First requested handle number.
Definition: gatt.h:1639
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition: gatt.h:1643
uint16_t handle
Attribute handle.
Definition: gatt.h:1616
Server Characteristic Configuration Attribute Value.
Definition: gatt.h:376
uint16_t flags
Server Characteristic Configuration flags.
Definition: gatt.h:378
GATT Service structure.
Definition: gatt.h:188
const struct bt_gatt_attr * attrs
Service Attributes.
Definition: gatt.h:190
size_t attr_count
Service Attribute count.
Definition: gatt.h:192
Service Attribute Value.
Definition: gatt.h:206
const struct bt_uuid * uuid
Service UUID.
Definition: gatt.h:208
uint16_t end_handle
Service end handle.
Definition: gatt.h:210
GATT Service structure.
Definition: gatt.h:196
struct bt_gatt_attr * attrs
Service Attributes.
Definition: gatt.h:198
size_t attr_count
Service Attribute count.
Definition: gatt.h:200
sys_snode_t node
Definition: gatt.h:202
GATT Subscribe parameters.
Definition: gatt.h:1903
bt_gatt_write_func_t write
Definition: gatt.h:1912
uint16_t value
Subscribe value.
Definition: gatt.h:1924
bt_security_t min_security
Minimum required security for received notification.
Definition: gatt.h:1930
uint16_t ccc_handle
Subscribe CCC handle.
Definition: gatt.h:1916
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition: gatt.h:1909
uint16_t value_handle
Subscribe value handle.
Definition: gatt.h:1914
sys_snode_t node
Definition: gatt.h:1935
bt_gatt_notify_func_t notify
Notification value callback.
Definition: gatt.h:1905
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = 0.
Definition: gatt.h:1921
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1937
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition: gatt.h:1919
GATT Write parameters.
Definition: gatt.h:1710
bt_gatt_write_func_t func
Response callback.
Definition: gatt.h:1712
uint16_t handle
Attribute handle.
Definition: gatt.h:1714
const void * data
Data to be written.
Definition: gatt.h:1718
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1722
uint16_t offset
Attribute data offset.
Definition: gatt.h:1716
uint16_t length
Length of the data.
Definition: gatt.h:1720
This is a 'tentative' type and should be used as a pointer only.
Definition: uuid.h:49
Misc utilities.
Bluetooth UUID handling.