1 /**
2  * Copyright (c) 2019 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 /**
7  * @brief GATT Macros
8  *
9  *  This code is auto-generated from the Excel Workbook
10  *  'GATT_Qualification_Test_Databases.xlsm' Sheet: 'Large Database 1'
11  *
12  *  Feel free to change it - but be aware that your changes might be
13  *  overwritten at the next generation...
14  */
15 
16 #ifndef GATT_MACS_H
17 #define GATT_MACS_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <zephyr/bluetooth/gatt.h>
24 
25 /**
26  *  @brief Attribute Declaration Macro.
27  *
28  *  Helper macro to declare an attribute.
29  *
30  *  @param _uuid   Attribute uuid.
31  *  @param _perm   Attribute access permissions.
32  *  @param _read   Attribute read callback.
33  *  @param _write  Attribute write callback.
34  *  @param _value  Attribute value.
35  *  @param _handle Attribute handle.
36  */
37 #define BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle) \
38 	{ \
39 	.uuid = _uuid, \
40 	.perm = _perm, \
41 	.read = _read, \
42 	.write = _write, \
43 	.user_data = _value, \
44 	.handle = _handle \
45 	}
46 
47 /**
48  *  @brief Characteristic and Value Declaration Macro.
49  *
50  *  Helper macro to declare a characteristic attribute along with its attribute
51  *  value.
52  *
53  *  @param _uuid   Characteristic attribute uuid.
54  *  @param _props  Characteristic attribute properties.
55  *  @param _perm   Characteristic attribute access permissions.
56  *  @param _read   Characteristic attribute read callback.
57  *  @param _write  Characteristic attribute write callback.
58  *  @param _value  Characteristic attribute value.
59  *  @param _handle Characteristic attribute handle.
60  */
61 #define BT_GATT_H_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _value,\
62 			       _handle) \
63 	BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_CHRC, \
64 			  BT_GATT_PERM_READ, \
65 			  bt_gatt_attr_read_chrc, \
66 			  NULL, \
67 			  (&(struct bt_gatt_chrc) {.uuid = _uuid, \
68 						   .properties = _props \
69 						  }), \
70 			  _handle), \
71 	BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle + 1)
72 
73 /**
74  *  @brief Primary Service Declaration Macro.
75  *
76  *  Helper macro to declare a primary service attribute.
77  *
78  *  @param _service Service attribute value.
79  *  @param _handle  Service attribute handle.
80  */
81 #define BT_GATT_H_PRIMARY_SERVICE(_service, _handle) \
82 		BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_PRIMARY, \
83 				BT_GATT_PERM_READ, \
84 				bt_gatt_attr_read_service, \
85 				NULL, \
86 				(void *)_service, \
87 				_handle)
88 
89 /**
90  *  @brief Secondary Service Declaration Macro.
91  *
92  *  Helper macro to declare a secondary service attribute.
93  *
94  *  @param _service Service attribute value.
95  *  @param _handle  Service attribute handle.
96  */
97 #define BT_GATT_H_SECONDARY_SERVICE(_service, _handle) \
98 		BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_SECONDARY, \
99 				BT_GATT_PERM_READ, \
100 				bt_gatt_attr_read_service, \
101 				NULL, \
102 				(void *)_service, \
103 				_handle)
104 
105 /**
106  *  @brief Include Service Declaration Macro.
107  *
108  *  Helper macro to declare database internal include service attribute.
109  *
110  *  @param _service_incl The first service attribute of service to include.
111  *  @param _handle       Service attribute handle.
112  */
113 #define BT_GATT_H_INCLUDE_SERVICE(_service_incl, _handle) \
114 		BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_INCLUDE, \
115 				BT_GATT_PERM_READ, \
116 				bt_gatt_attr_read_included, \
117 				NULL, \
118 				_service_incl, \
119 				_handle)
120 
121 /**
122  *  @brief Descriptor Declaration Macro.
123  *
124  *  Helper macro to declare a descriptor attribute.
125  *
126  *  @param _uuid   Descriptor attribute uuid.
127  *  @param _perm   Descriptor attribute access permissions.
128  *  @param _read   Descriptor attribute read callback.
129  *  @param _write  Descriptor attribute write callback.
130  *  @param _value  Descriptor attribute value.
131  *  @param _handle Descriptor attribute handle.
132  */
133 #define BT_GATT_H_DESCRIPTOR(_uuid, _perm, _read, _write, _value, _handle) \
134 	       BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle)
135 
136 /**
137  *  @brief Managed Client Characteristic Configuration Declaration Macro.
138  *
139  *  Helper macro to declare a Managed CCC attribute.
140  *
141  *  @param _ccc    CCC attribute user data, shall point to a _bt_gatt_ccc.
142  *  @param _perm   CCC access permissions.
143  *  @param _handle Descriptor attribute handle.
144  */
145 #define BT_GATT_H_MANAGED(_ccc, _perm, _handle) \
146 		BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_CCC, _perm,\
147 		bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, _ccc, _handle)
148 
149 /**
150  *  @brief Client Characteristic Configuration Change Declaration Macro.
151  *
152  *  Helper macro to declare a CCC attribute.
153  *
154  *  @param _cfg         Initial configuration.
155  *  @param _cfg_changed Configuration changed callback.
156  *  @param _handle      Descriptor attribute handle.
157  */
158 /* #undef  BT_GATT_H_CCC
159  *  #define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \
160  *     BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CCC, \
161  *         BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \
162  *         bt_gatt_attr_read_ccc, \
163  *         bt_gatt_attr_write_ccc, \
164  *         (&(struct _bt_gatt_ccc) { \
165  *             .cfg = _cfg, \
166  *             .cfg_len = ARRAY_SIZE(_cfg), \
167  *             .cfg_changed = _cfg_changed \
168  *         } ), \
169  *         _handle)
170  */
171 /**
172  *  @brief Client Characteristic Configuration Change Declaration Macro.
173  *
174  *  Helper macro to declare a CCC attribute.
175  *
176  *  @param _cfg         Initial configuration.
177  *  @param _cfg_changed Configuration changed callback.
178  *  @param _handle      Descriptor attribute handle.
179  */
180 #define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \
181 		BT_GATT_H_MANAGED((&(struct _bt_gatt_ccc) \
182 			BT_GATT_CCC_INITIALIZER(_cfg_changed, NULL, NULL)),\
183 			BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, _handle)
184 
185 /**
186  *  @brief Characteristic Extended Properties Declaration Macro.
187  *
188  *  Helper macro to declare a CEP attribute.
189  *
190  *  @param _value  Descriptor attribute value.
191  *  @param _handle Descriptor attribute handle.
192  */
193 #define BT_GATT_H_CEP(_value, _handle) \
194 		BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CEP, \
195 				BT_GATT_PERM_READ, \
196 				bt_gatt_attr_read_cep, \
197 				NULL, \
198 				(void *)_value, \
199 				_handle)
200 
201 /**
202  *  @brief Characteristic User Format Descriptor Declaration Macro.
203  *
204  *  Helper macro to declare a CUD attribute.
205  *
206  *  @param _value  User description NULL-terminated C string.
207  *  @param _perm   Descriptor attribute access permissions.
208  *  @param _handle Descriptor attribute handle.
209  */
210 #define BT_GATT_H_CUD(_value, _perm, _handle) \
211 		BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CUD, \
212 				_perm, \
213 				bt_gatt_attr_read_cud, \
214 				NULL, \
215 				(void *)_value, \
216 				_handle)
217 
218 /**
219  *  @brief Characteristic Presentation Format Descriptor Declaration Macro.
220  *
221  *  Helper macro to declare a CPF attribute.
222  *
223  *  @param _value  Descriptor attribute value.
224  *  @param _handle Descriptor attribute handle.
225  */
226 #define BT_GATT_H_CPF(_value, _handle) \
227 		BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CPF, \
228 				BT_GATT_PERM_READ, \
229 				bt_gatt_attr_read_cpf, \
230 				NULL, \
231 				(void *)_value, \
232 				_handle)
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif /* GATT_MACS_H */
239