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;
184};
185
189 const struct bt_gatt_attr *attrs;
192};
193
200
202};
203
207 const struct bt_uuid *uuid;
210};
211
215 const struct bt_uuid *uuid;
220};
221
233 void (*att_mtu_updated)(struct bt_conn *conn, uint16_t tx, uint16_t rx);
234
236};
237
251 bool (*read_authorize)(struct bt_conn *conn,
252 const struct bt_gatt_attr *attr);
253
265 bool (*write_authorize)(struct bt_conn *conn,
266 const struct bt_gatt_attr *attr);
267};
268
277#define BT_GATT_CHRC_BROADCAST 0x01
283#define BT_GATT_CHRC_READ 0x02
289#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
295#define BT_GATT_CHRC_WRITE 0x08
302#define BT_GATT_CHRC_NOTIFY 0x10
308#define BT_GATT_CHRC_INDICATE 0x20
314#define BT_GATT_CHRC_AUTH 0x40
321#define BT_GATT_CHRC_EXT_PROP 0x80
322
326 const struct bt_uuid *uuid;
331};
332
334#define BT_GATT_CEP_RELIABLE_WRITE 0x0001
335#define BT_GATT_CEP_WRITABLE_AUX 0x0002
336
341};
342
350#define BT_GATT_CCC_NOTIFY 0x0001
356#define BT_GATT_CCC_INDICATE 0x0002
357
362};
363
372#define BT_GATT_SCC_BROADCAST 0x0001
373
378};
379
394};
395
410
430
458
466
474
475enum {
478};
479
490typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
492 void *user_data);
493
506void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
507 const struct bt_uuid *uuid,
508 const void *attr_data, uint16_t num_matches,
510 void *user_data);
511
521static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_handle,
523 void *user_data)
524{
525 bt_gatt_foreach_attr_type(start_handle, end_handle, NULL, NULL, 0, func,
526 user_data);
527}
528
537struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
538
554 uint16_t attr_count,
555 const struct bt_uuid *uuid);
556
565
577
593ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
594 void *buf, uint16_t buf_len, uint16_t offset,
595 const void *value, uint16_t value_len);
596
613 const struct bt_gatt_attr *attr,
614 void *buf, uint16_t len, uint16_t offset);
615
623#define BT_GATT_SERVICE_DEFINE(_name, ...) \
624 const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
625 const STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) = \
626 BT_GATT_SERVICE(attr_##_name)
627
628#define _BT_GATT_ATTRS_ARRAY_DEFINE(n, _instances, _attrs_def) \
629 static struct bt_gatt_attr attrs_##n[] = _attrs_def(_instances[n])
630
631#define _BT_GATT_SERVICE_ARRAY_ITEM(_n, _) BT_GATT_SERVICE(attrs_##_n)
632
648#define BT_GATT_SERVICE_INSTANCE_DEFINE( \
649 _name, _instances, _instance_num, _attrs_def) \
650 BUILD_ASSERT(ARRAY_SIZE(_instances) == _instance_num, \
651 "The number of array elements does not match its size"); \
652 LISTIFY(_instance_num, _BT_GATT_ATTRS_ARRAY_DEFINE, (;), \
653 _instances, _attrs_def); \
654 static struct bt_gatt_service _name[] = { \
655 LISTIFY(_instance_num, _BT_GATT_SERVICE_ARRAY_ITEM, (,)) \
656 }
657
665#define BT_GATT_SERVICE(_attrs) \
666{ \
667 .attrs = _attrs, \
668 .attr_count = ARRAY_SIZE(_attrs), \
669}
670
678#define BT_GATT_PRIMARY_SERVICE(_service) \
679 BT_GATT_ATTRIBUTE(BT_UUID_GATT_PRIMARY, BT_GATT_PERM_READ, \
680 bt_gatt_attr_read_service, NULL, (void *)_service)
681
692#define BT_GATT_SECONDARY_SERVICE(_service) \
693 BT_GATT_ATTRIBUTE(BT_UUID_GATT_SECONDARY, BT_GATT_PERM_READ, \
694 bt_gatt_attr_read_service, NULL, (void *)_service)
695
712 const struct bt_gatt_attr *attr,
713 void *buf, uint16_t len, uint16_t offset);
714
722#define BT_GATT_INCLUDE_SERVICE(_service_incl) \
723 BT_GATT_ATTRIBUTE(BT_UUID_GATT_INCLUDE, BT_GATT_PERM_READ, \
724 bt_gatt_attr_read_included, NULL, _service_incl)
725
741ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
742 const struct bt_gatt_attr *attr, void *buf,
743 uint16_t len, uint16_t offset);
744
745#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
746{ \
747 .uuid = _uuid, \
748 .value_handle = _handle, \
749 .properties = _props, \
750}
751
769#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _user_data) \
770 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \
771 bt_gatt_attr_read_chrc, NULL, \
772 ((struct bt_gatt_chrc[]) { \
773 BT_GATT_CHRC_INIT(_uuid, 0U, _props), \
774 })), \
775 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
776
777#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
778 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
779#elif defined(CONFIG_BT_CONN)
780 #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN)
781#else
782 #define BT_GATT_CCC_MAX 0
783#endif
784
793};
794
796struct _bt_gatt_ccc {
799
801 uint16_t value;
802
808 void (*cfg_changed)(const struct bt_gatt_attr *attr, uint16_t value);
809
819 ssize_t (*cfg_write)(struct bt_conn *conn,
820 const struct bt_gatt_attr *attr, uint16_t value);
821
833 bool (*cfg_match)(struct bt_conn *conn,
834 const struct bt_gatt_attr *attr);
835};
836
853ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
854 const struct bt_gatt_attr *attr, void *buf,
855 uint16_t len, uint16_t offset);
856
873ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
874 const struct bt_gatt_attr *attr, const void *buf,
875 uint16_t len, uint16_t offset, uint8_t flags);
876
877
887#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match) \
888 { \
889 .cfg = {}, \
890 .cfg_changed = _changed, \
891 .cfg_write = _write, \
892 .cfg_match = _match, \
893 }
894
904#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
905 BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
906 bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
907 _ccc)
908
918#define BT_GATT_CCC(_changed, _perm) \
919 BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
920 {BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
921
938ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
939 const struct bt_gatt_attr *attr, void *buf,
940 uint16_t len, uint16_t offset);
941
949#define BT_GATT_CEP(_value) \
950 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
951 bt_gatt_attr_read_cep, NULL, (void *)_value)
952
970ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
971 const struct bt_gatt_attr *attr, void *buf,
972 uint16_t len, uint16_t offset);
973
983#define BT_GATT_CUD(_value, _perm) \
984 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
985 NULL, (void *)_value)
986
1003ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
1004 const struct bt_gatt_attr *attr, void *buf,
1005 uint16_t len, uint16_t offset);
1006
1014#define BT_GATT_CPF(_value) \
1015 BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
1016 bt_gatt_attr_read_cpf, NULL, (void *)_value)
1017
1032#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _user_data) \
1033 BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
1034
1047#define BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data) \
1048{ \
1049 .uuid = _uuid, \
1050 .read = _read, \
1051 .write = _write, \
1052 .user_data = _user_data, \
1053 .handle = 0, \
1054 .perm = _perm, \
1055}
1056
1062typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
1063
1070 const struct bt_uuid *uuid;
1076 const struct bt_gatt_attr *attr;
1078 const void *data;
1085#if defined(CONFIG_BT_EATT)
1087#endif /* CONFIG_BT_EATT */
1088};
1089
1111int bt_gatt_notify_cb(struct bt_conn *conn,
1112 struct bt_gatt_notify_params *params);
1113
1165int bt_gatt_notify_multiple(struct bt_conn *conn,
1166 uint16_t num_params,
1167 struct bt_gatt_notify_params params[]);
1168
1188static inline int bt_gatt_notify(struct bt_conn *conn,
1189 const struct bt_gatt_attr *attr,
1190 const void *data, uint16_t len)
1191{
1192 struct bt_gatt_notify_params params;
1193
1194 memset(&params, 0, sizeof(params));
1195
1196 params.attr = attr;
1197 params.data = data;
1198 params.len = len;
1199#if defined(CONFIG_BT_EATT)
1201#endif /* CONFIG_BT_EATT */
1202
1203 return bt_gatt_notify_cb(conn, &params);
1204}
1205
1225static inline int bt_gatt_notify_uuid(struct bt_conn *conn,
1226 const struct bt_uuid *uuid,
1227 const struct bt_gatt_attr *attr,
1228 const void *data, uint16_t len)
1229{
1230 struct bt_gatt_notify_params params;
1231
1232 memset(&params, 0, sizeof(params));
1233
1234 params.uuid = uuid;
1235 params.attr = attr;
1236 params.data = data;
1237 params.len = len;
1238#if defined(CONFIG_BT_EATT)
1240#endif /* CONFIG_BT_EATT */
1241
1242 return bt_gatt_notify_cb(conn, &params);
1243}
1244
1245/* Forward declaration of the bt_gatt_indicate_params structure */
1247
1255typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
1256 struct bt_gatt_indicate_params *params,
1257 uint8_t err);
1258
1260 struct bt_gatt_indicate_params *params);
1261
1269 const struct bt_uuid *uuid;
1275 const struct bt_gatt_attr *attr;
1281 const void *data;
1285 uint8_t _ref;
1286#if defined(CONFIG_BT_EATT)
1288#endif /* CONFIG_BT_EATT */
1289};
1290
1316int bt_gatt_indicate(struct bt_conn *conn,
1317 struct bt_gatt_indicate_params *params);
1318
1319
1338bool bt_gatt_is_subscribed(struct bt_conn *conn,
1339 const struct bt_gatt_attr *attr, uint16_t ccc_type);
1340
1350uint16_t bt_gatt_get_mtu(struct bt_conn *conn);
1351
1363 void (*func)(struct bt_conn *conn, uint8_t err,
1364 struct bt_gatt_exchange_params *params);
1365};
1366
1394int bt_gatt_exchange_mtu(struct bt_conn *conn,
1395 struct bt_gatt_exchange_params *params);
1396
1398
1443typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
1444 const struct bt_gatt_attr *attr,
1445 struct bt_gatt_discover_params *params);
1446
1448enum {
1489};
1490
1494 const struct bt_uuid *uuid;
1497 union {
1498 struct {
1505 } _included;
1507 uint16_t start_handle;
1508 };
1513#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1516#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1517#if defined(CONFIG_BT_EATT)
1519#endif /* CONFIG_BT_EATT */
1520};
1521
1558int bt_gatt_discover(struct bt_conn *conn,
1559 struct bt_gatt_discover_params *params);
1560
1561struct bt_gatt_read_params;
1562
1578typedef uint8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, uint8_t err,
1579 struct bt_gatt_read_params *params,
1580 const void *data, uint16_t length);
1581
1591 union {
1592 struct {
1598 struct {
1615 struct {
1621 const struct bt_uuid *uuid;
1623 };
1624#if defined(CONFIG_BT_EATT)
1626#endif /* CONFIG_BT_EATT */
1628 uint16_t _att_mtu;
1629};
1630
1673int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
1674
1676
1684typedef void (*bt_gatt_write_func_t)(struct bt_conn *conn, uint8_t err,
1685 struct bt_gatt_write_params *params);
1686
1696 const void *data;
1699#if defined(CONFIG_BT_EATT)
1701#endif /* CONFIG_BT_EATT */
1702};
1703
1726int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
1727
1763int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
1764 const void *data, uint16_t length,
1765 bool sign, bt_gatt_complete_func_t func,
1766 void *user_data);
1767
1789static inline int bt_gatt_write_without_response(struct bt_conn *conn,
1790 uint16_t handle, const void *data,
1791 uint16_t length, bool sign)
1792{
1793 return bt_gatt_write_without_response_cb(conn, handle, data, length,
1794 sign, NULL, NULL);
1795}
1796
1798
1815typedef uint8_t (*bt_gatt_notify_func_t)(struct bt_conn *conn,
1816 struct bt_gatt_subscribe_params *params,
1817 const void *data, uint16_t length);
1818
1826typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
1827 struct bt_gatt_subscribe_params *params);
1828
1830enum {
1841
1855
1864
1876
1879
1888
1895#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
1900#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1903#if defined(CONFIG_BT_SMP)
1909#endif
1912
1914#if defined(CONFIG_BT_EATT)
1916#endif /* CONFIG_BT_EATT */
1917};
1918
1956int bt_gatt_subscribe(struct bt_conn *conn,
1957 struct bt_gatt_subscribe_params *params);
1958
1976 struct bt_gatt_subscribe_params *params);
1977
2002int bt_gatt_unsubscribe(struct bt_conn *conn,
2003 struct bt_gatt_subscribe_params *params);
2004
2022void bt_gatt_cancel(struct bt_conn *conn, void *params);
2023
2026#ifdef __cplusplus
2027}
2028#endif
2029
2034#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:146
@ BT_ATT_CHAN_OPT_NONE
Both Enhanced and Unenhanced channels can be used
Definition: att.h:148
bt_security_t
Security level.
Definition: conn.h:352
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:1443
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:1826
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:1578
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:1789
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:1815
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:1684
@ BT_GATT_DISCOVER_DESCRIPTOR
Discover Descriptors.
Definition: gatt.h:1468
@ BT_GATT_DISCOVER_SECONDARY
Discover Secondary Services.
Definition: gatt.h:1452
@ BT_GATT_DISCOVER_CHARACTERISTIC
Discover Characteristic Values.
Definition: gatt.h:1459
@ BT_GATT_DISCOVER_INCLUDE
Discover Included Services.
Definition: gatt.h:1454
@ BT_GATT_DISCOVER_STD_CHAR_DESC
Discover standard characteristic descriptor values.
Definition: gatt.h:1488
@ BT_GATT_DISCOVER_PRIMARY
Discover Primary Services.
Definition: gatt.h:1450
@ BT_GATT_DISCOVER_ATTRIBUTE
Discover Attributes.
Definition: gatt.h:1477
@ BT_GATT_SUBSCRIBE_FLAG_NO_RESUB
No resubscribe flag.
Definition: gatt.h:1854
@ BT_GATT_SUBSCRIBE_NUM_FLAGS
Definition: gatt.h:1877
@ BT_GATT_SUBSCRIBE_FLAG_SENT
Sent flag.
Definition: gatt.h:1875
@ BT_GATT_SUBSCRIBE_FLAG_VOLATILE
Persistence flag.
Definition: gatt.h:1840
@ BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING
Write pending flag.
Definition: gatt.h:1863
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:1255
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:1225
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:1259
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:1188
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:521
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:782
void(* bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)
Notification complete result callback.
Definition: gatt.h:1062
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:490
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.
@ BT_GATT_ITER_STOP
Definition: gatt.h:476
@ BT_GATT_ITER_CONTINUE
Definition: gatt.h:477
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
Definition: gatt.h:172
uint16_t perm
Attribute permissions.
Definition: gatt.h:183
bt_gatt_attr_write_func_t write
Attribute write callback.
Definition: gatt.h:174
const struct bt_uuid * uuid
Attribute UUID.
Definition: gatt.h:171
void * user_data
Attribute user data.
Definition: gatt.h:176
uint16_t handle
Attribute handle.
Definition: gatt.h:178
GATT authorization callback structure.
Definition: gatt.h:239
bool(* read_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT read operation.
Definition: gatt.h:251
bool(* write_authorize)(struct bt_conn *conn, const struct bt_gatt_attr *attr)
Authorize the GATT write operation.
Definition: gatt.h:265
GATT callback structure.
Definition: gatt.h:223
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:233
sys_snode_t node
Definition: gatt.h:235
GATT CCC configuration entry.
Definition: gatt.h:786
uint16_t value
Configuration value.
Definition: gatt.h:792
bt_addr_le_t peer
Remote peer address.
Definition: gatt.h:790
uint8_t id
Local identity, BT_ID_DEFAULT in most cases.
Definition: gatt.h:788
Client Characteristic Configuration Attribute Value.
Definition: gatt.h:359
uint16_t flags
Client Characteristic Configuration flags.
Definition: gatt.h:361
Characteristic Extended Properties Attribute Value.
Definition: gatt.h:338
uint16_t properties
Characteristic Extended properties.
Definition: gatt.h:340
Characteristic Attribute Value.
Definition: gatt.h:324
uint16_t value_handle
Characteristic Value handle.
Definition: gatt.h:328
uint8_t properties
Characteristic properties.
Definition: gatt.h:330
const struct bt_uuid * uuid
Characteristic UUID.
Definition: gatt.h:326
GATT Characteristic Presentation Format Attribute Value.
Definition: gatt.h:381
uint8_t name_space
Name space of the description.
Definition: gatt.h:391
uint16_t unit
Unit of the characteristic.
Definition: gatt.h:389
int8_t exponent
Exponent field to determine how the value of this characteristic is further formatted.
Definition: gatt.h:387
uint16_t description
Description of the characteristic as defined in a higher layer profile.
Definition: gatt.h:393
uint8_t format
Format of the value of the characteristic.
Definition: gatt.h:383
GATT Discover Attributes parameters.
Definition: gatt.h:1492
uint16_t start_handle
Included service start handle.
Definition: gatt.h:1502
uint16_t end_handle
Included service end handle.
Definition: gatt.h:1504
bt_gatt_discover_func_t func
Discover attribute callback.
Definition: gatt.h:1496
uint16_t attr_handle
Include service attribute declaration handle.
Definition: gatt.h:1500
const struct bt_uuid * uuid
Discover UUID type.
Definition: gatt.h:1494
struct bt_gatt_subscribe_params * sub_params
Only for stack-internal use, used for automatic discovery.
Definition: gatt.h:1515
uint8_t type
Discover type.
Definition: gatt.h:1512
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1518
GATT Exchange MTU parameters.
Definition: gatt.h:1361
void(* func)(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
Response callback.
Definition: gatt.h:1363
Include Attribute Value.
Definition: gatt.h:213
uint16_t end_handle
Service end handle.
Definition: gatt.h:219
uint16_t start_handle
Service start handle.
Definition: gatt.h:217
const struct bt_uuid * uuid
Service UUID.
Definition: gatt.h:215
GATT Indicate Value parameters.
Definition: gatt.h:1263
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1287
uint16_t len
Indicate Value length.
Definition: gatt.h:1283
const struct bt_gatt_attr * attr
Indicate Attribute object.
Definition: gatt.h:1275
const void * data
Indicate Value data.
Definition: gatt.h:1281
bt_gatt_indicate_params_destroy_t destroy
Indicate operation complete callback.
Definition: gatt.h:1279
bt_gatt_indicate_func_t func
Indicate Value callback.
Definition: gatt.h:1277
const struct bt_uuid * uuid
Indicate Attribute UUID type.
Definition: gatt.h:1269
Definition: gatt.h:1064
const struct bt_uuid * uuid
Notification Attribute UUID type.
Definition: gatt.h:1070
uint16_t len
Notification Value length.
Definition: gatt.h:1080
const struct bt_gatt_attr * attr
Notification Attribute object.
Definition: gatt.h:1076
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1086
bt_gatt_complete_func_t func
Notification Value callback.
Definition: gatt.h:1082
void * user_data
Notification Value callback user data.
Definition: gatt.h:1084
const void * data
Notification Value data.
Definition: gatt.h:1078
GATT Read parameters.
Definition: gatt.h:1583
size_t handle_count
If equals to 1 single.handle and single.offset are used.
Definition: gatt.h:1590
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1625
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:1602
uint16_t offset
Attribute data offset.
Definition: gatt.h:1596
bt_gatt_read_func_t func
Read attribute callback.
Definition: gatt.h:1585
struct bt_gatt_read_params::@80::@82 single
bool variable
If true use Read Multiple Variable Length Characteristic Values procedure.
Definition: gatt.h:1613
uint16_t end_handle
Last requested handle number.
Definition: gatt.h:1619
uint16_t start_handle
First requested handle number.
Definition: gatt.h:1617
const struct bt_uuid * uuid
2 or 16 octet UUID.
Definition: gatt.h:1621
uint16_t handle
Attribute handle.
Definition: gatt.h:1594
Server Characteristic Configuration Attribute Value.
Definition: gatt.h:375
uint16_t flags
Server Characteristic Configuration flags.
Definition: gatt.h:377
GATT Service structure.
Definition: gatt.h:187
const struct bt_gatt_attr * attrs
Service Attributes.
Definition: gatt.h:189
size_t attr_count
Service Attribute count.
Definition: gatt.h:191
Service Attribute Value.
Definition: gatt.h:205
const struct bt_uuid * uuid
Service UUID.
Definition: gatt.h:207
uint16_t end_handle
Service end handle.
Definition: gatt.h:209
GATT Service structure.
Definition: gatt.h:195
struct bt_gatt_attr * attrs
Service Attributes.
Definition: gatt.h:197
size_t attr_count
Service Attribute count.
Definition: gatt.h:199
sys_snode_t node
Definition: gatt.h:201
GATT Subscribe parameters.
Definition: gatt.h:1881
bt_gatt_write_func_t write
Definition: gatt.h:1890
uint16_t value
Subscribe value.
Definition: gatt.h:1902
bt_security_t min_security
Minimum required security for received notification.
Definition: gatt.h:1908
uint16_t ccc_handle
Subscribe CCC handle.
Definition: gatt.h:1894
bt_gatt_subscribe_func_t subscribe
Subscribe CCC write request response callback If given, called with the subscription parameters given...
Definition: gatt.h:1887
uint16_t value_handle
Subscribe value handle.
Definition: gatt.h:1892
sys_snode_t node
Definition: gatt.h:1913
bt_gatt_notify_func_t notify
Notification value callback.
Definition: gatt.h:1883
struct bt_gatt_discover_params * disc_params
Discover parameters used when ccc_handle = 0.
Definition: gatt.h:1899
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1915
uint16_t end_handle
Subscribe End handle (for automatic discovery)
Definition: gatt.h:1897
GATT Write parameters.
Definition: gatt.h:1688
bt_gatt_write_func_t func
Response callback.
Definition: gatt.h:1690
uint16_t handle
Attribute handle.
Definition: gatt.h:1692
const void * data
Data to be written.
Definition: gatt.h:1696
enum bt_att_chan_opt chan_opt
Definition: gatt.h:1700
uint16_t offset
Attribute data offset.
Definition: gatt.h:1694
uint16_t length
Length of the data.
Definition: gatt.h:1698
This is a 'tentative' type and should be used as a pointer only.
Definition: uuid.h:49
Misc utilities.
Bluetooth UUID handling.