1 /** @file
2  *  @brief Internal API for Generic Attribute Profile handling.
3  */
4 
5 /*
6  * Copyright (c) 2015-2016 Intel Corporation
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 
11 #include <stdbool.h>
12 #include <stdint.h>
13 
14 #include <zephyr/bluetooth/addr.h>
15 #include <zephyr/bluetooth/conn.h>
16 
17 #define BT_GATT_CENTRAL_ADDR_RES_NOT_SUPP	0
18 #define BT_GATT_CENTRAL_ADDR_RES_SUPP		1
19 
20 #define BT_GATT_PERM_READ_MASK			(BT_GATT_PERM_READ | \
21 						BT_GATT_PERM_READ_ENCRYPT | \
22 						BT_GATT_PERM_READ_AUTHEN | \
23 						BT_GATT_PERM_READ_LESC)
24 #define BT_GATT_PERM_WRITE_MASK			(BT_GATT_PERM_WRITE | \
25 						BT_GATT_PERM_WRITE_ENCRYPT | \
26 						BT_GATT_PERM_WRITE_AUTHEN | \
27 						BT_GATT_PERM_WRITE_LESC)
28 #define BT_GATT_PERM_ENCRYPT_MASK		(BT_GATT_PERM_READ_ENCRYPT | \
29 						BT_GATT_PERM_WRITE_ENCRYPT)
30 #define BT_GATT_PERM_AUTHEN_MASK		(BT_GATT_PERM_READ_AUTHEN | \
31 						BT_GATT_PERM_WRITE_AUTHEN)
32 #define BT_GATT_PERM_LESC_MASK			(BT_GATT_PERM_READ_LESC | \
33 						BT_GATT_PERM_WRITE_LESC)
34 #define BT_GATT_PERM_READ_ENCRYPT_MASK		(BT_GATT_PERM_READ_ENCRYPT | \
35 						BT_GATT_PERM_READ_AUTHEN | \
36 						BT_GATT_PERM_READ_LESC)
37 
38 void bt_gatt_init(void);
39 void bt_gatt_connected(struct bt_conn *conn);
40 void bt_gatt_att_max_mtu_changed(struct bt_conn *conn, uint16_t tx, uint16_t rx);
41 void bt_gatt_encrypt_change(struct bt_conn *conn);
42 void bt_gatt_disconnected(struct bt_conn *conn);
43 
44 bool bt_gatt_change_aware(struct bt_conn *conn, bool req);
45 
46 int bt_gatt_store_ccc(uint8_t id, const bt_addr_le_t *addr);
47 
48 int bt_gatt_clear(uint8_t id, const bt_addr_le_t *addr);
49 
50 #if defined(CONFIG_BT_GATT_CLIENT)
51 void bt_gatt_notification(struct bt_conn *conn, uint16_t handle,
52 			  const void *data, uint16_t length);
53 
54 void bt_gatt_mult_notification(struct bt_conn *conn, const void *data,
55 			       uint16_t length);
56 #else
bt_gatt_notification(struct bt_conn * conn,uint16_t handle,const void * data,uint16_t length)57 static inline void bt_gatt_notification(struct bt_conn *conn, uint16_t handle,
58 					const void *data, uint16_t length)
59 {
60 }
61 
bt_gatt_mult_notification(struct bt_conn * conn,const void * data,uint16_t length)62 static inline void bt_gatt_mult_notification(struct bt_conn *conn,
63 					     const void *data, uint16_t length)
64 {
65 }
66 #endif /* CONFIG_BT_GATT_CLIENT */
67 
68 struct bt_gatt_attr;
69 
70 /* Check attribute permission */
71 uint8_t bt_gatt_check_perm(struct bt_conn *conn, const struct bt_gatt_attr *attr,
72 			uint16_t mask);
73