xref: /btstack/src/ble/att_db.h (revision c436b760549c6da73e320c4d93ff3b76282abccb)
1591423b2SMatthias Ringwald /*
2591423b2SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3591423b2SMatthias Ringwald  *
4591423b2SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5591423b2SMatthias Ringwald  * modification, are permitted provided that the following conditions
6591423b2SMatthias Ringwald  * are met:
7591423b2SMatthias Ringwald  *
8591423b2SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9591423b2SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10591423b2SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11591423b2SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12591423b2SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13591423b2SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14591423b2SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15591423b2SMatthias Ringwald  *    from this software without specific prior written permission.
16591423b2SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17591423b2SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18591423b2SMatthias Ringwald  *    monetary gain.
19591423b2SMatthias Ringwald  *
20591423b2SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21591423b2SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22591423b2SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23591423b2SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24591423b2SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25591423b2SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26591423b2SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27591423b2SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28591423b2SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29591423b2SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30591423b2SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31591423b2SMatthias Ringwald  * SUCH DAMAGE.
32591423b2SMatthias Ringwald  *
33591423b2SMatthias Ringwald  * Please inquire about commercial licensing options at
34591423b2SMatthias Ringwald  * [email protected]
35591423b2SMatthias Ringwald  *
36591423b2SMatthias Ringwald  */
37591423b2SMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title ATT Database Engine
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
42591423b2SMatthias Ringwald 
4347a0820cSMatthias Ringwald #ifndef ATT_DB_H
4447a0820cSMatthias Ringwald #define ATT_DB_H
45591423b2SMatthias Ringwald 
46591423b2SMatthias Ringwald #include <stdint.h>
47711e6c80SMatthias Ringwald #include "bluetooth.h"
488ac574d6SMatthias Ringwald #include "btstack_linked_list.h"
495d07396bSMatthias Ringwald #include "btstack_defines.h"
504d5915b3SMatthias Ringwald #include "btstack_bool.h"
51591423b2SMatthias Ringwald 
52591423b2SMatthias Ringwald #if defined __cplusplus
53591423b2SMatthias Ringwald extern "C" {
54591423b2SMatthias Ringwald #endif
55591423b2SMatthias Ringwald 
5609f91c9fSMatthias Ringwald // MARK: Attribute PDU Opcodes
5709f91c9fSMatthias Ringwald #define ATT_ERROR_RESPONSE              0x01
5809f91c9fSMatthias Ringwald 
5909f91c9fSMatthias Ringwald #define ATT_EXCHANGE_MTU_REQUEST        0x02
6009f91c9fSMatthias Ringwald #define ATT_EXCHANGE_MTU_RESPONSE       0x03
6109f91c9fSMatthias Ringwald 
6209f91c9fSMatthias Ringwald #define ATT_FIND_INFORMATION_REQUEST    0x04
6309f91c9fSMatthias Ringwald #define ATT_FIND_INFORMATION_REPLY      0x05
6409f91c9fSMatthias Ringwald #define ATT_FIND_BY_TYPE_VALUE_REQUEST  0x06
6509f91c9fSMatthias Ringwald #define ATT_FIND_BY_TYPE_VALUE_RESPONSE 0x07
6609f91c9fSMatthias Ringwald 
6709f91c9fSMatthias Ringwald #define ATT_READ_BY_TYPE_REQUEST        0x08
6809f91c9fSMatthias Ringwald #define ATT_READ_BY_TYPE_RESPONSE       0x09
6909f91c9fSMatthias Ringwald #define ATT_READ_REQUEST                0x0a
7009f91c9fSMatthias Ringwald #define ATT_READ_RESPONSE               0x0b
7109f91c9fSMatthias Ringwald #define ATT_READ_BLOB_REQUEST           0x0c
7209f91c9fSMatthias Ringwald #define ATT_READ_BLOB_RESPONSE          0x0d
7309f91c9fSMatthias Ringwald #define ATT_READ_MULTIPLE_REQUEST       0x0e
7409f91c9fSMatthias Ringwald #define ATT_READ_MULTIPLE_RESPONSE      0x0f
7509f91c9fSMatthias Ringwald #define ATT_READ_BY_GROUP_TYPE_REQUEST  0x10
7609f91c9fSMatthias Ringwald #define ATT_READ_BY_GROUP_TYPE_RESPONSE 0x11
7709f91c9fSMatthias Ringwald 
7809f91c9fSMatthias Ringwald #define ATT_WRITE_REQUEST               0x12
7909f91c9fSMatthias Ringwald #define ATT_WRITE_RESPONSE              0x13
8009f91c9fSMatthias Ringwald 
8109f91c9fSMatthias Ringwald #define ATT_PREPARE_WRITE_REQUEST       0x16
8209f91c9fSMatthias Ringwald #define ATT_PREPARE_WRITE_RESPONSE      0x17
8309f91c9fSMatthias Ringwald #define ATT_EXECUTE_WRITE_REQUEST       0x18
8409f91c9fSMatthias Ringwald #define ATT_EXECUTE_WRITE_RESPONSE      0x19
8509f91c9fSMatthias Ringwald 
8609f91c9fSMatthias Ringwald #define ATT_HANDLE_VALUE_NOTIFICATION   0x1b
8709f91c9fSMatthias Ringwald #define ATT_HANDLE_VALUE_INDICATION     0x1d
8809f91c9fSMatthias Ringwald #define ATT_HANDLE_VALUE_CONFIRMATION   0x1e
8909f91c9fSMatthias Ringwald 
906d6595cfSMatthias Ringwald #define ATT_READ_MULTIPLE_VARIABLE_REQ  0x20
916d6595cfSMatthias Ringwald #define ATT_READ_MULTIPLE_VARIABLE_RSP  0x21
926d6595cfSMatthias Ringwald #define ATT_MULTIPLE_HANDLE_VALUE_NTF   0x23
9309f91c9fSMatthias Ringwald 
9409f91c9fSMatthias Ringwald #define ATT_WRITE_COMMAND                0x52
9509f91c9fSMatthias Ringwald #define ATT_SIGNED_WRITE_COMMAND         0xD2
9609f91c9fSMatthias Ringwald 
9756c3a347SMatthias Ringwald 
9809f91c9fSMatthias Ringwald // internal additions
9909f91c9fSMatthias Ringwald // 128 bit UUID used
10009f91c9fSMatthias Ringwald #define ATT_PROPERTY_UUID128             0x200
10109f91c9fSMatthias Ringwald // Read/Write Permission bits
10209f91c9fSMatthias Ringwald #define ATT_PROPERTY_READ_PERMISSION_BIT_0  0x0400
10309f91c9fSMatthias Ringwald #define ATT_PROPERTY_READ_PERMISSION_BIT_1  0x0800
10409f91c9fSMatthias Ringwald #define ATT_PROPERTY_WRITE_PERMISSION_BIT_0 0x0001
10509f91c9fSMatthias Ringwald #define ATT_PROPERTY_WRITE_PERMISSION_BIT_1 0x0010
10609f91c9fSMatthias Ringwald #define ATT_PROPERTY_READ_PERMISSION_SC     0x0020
10709f91c9fSMatthias Ringwald #define ATT_PROPERTY_WRITE_PERMISSION_SC    0x0080
10809f91c9fSMatthias Ringwald 
10909f91c9fSMatthias Ringwald 
110591423b2SMatthias Ringwald typedef struct att_connection {
111711e6c80SMatthias Ringwald     hci_con_handle_t con_handle;
112591423b2SMatthias Ringwald     uint16_t mtu;       // initialized to ATT_DEFAULT_MTU (23), negotiated during MTU exchange
113591423b2SMatthias Ringwald     uint16_t max_mtu;   // local maximal L2CAP_MTU, set to l2cap_max_le_mtu()
114dde9ff1eSMatthias Ringwald     bool     mtu_exchanged;
115591423b2SMatthias Ringwald     uint8_t  encryption_key_size;
116591423b2SMatthias Ringwald     uint8_t  authenticated;
117591423b2SMatthias Ringwald     uint8_t  authorized;
11813eb7322SMatthias Ringwald     uint8_t  secure_connection;
119591423b2SMatthias Ringwald } att_connection_t;
120591423b2SMatthias Ringwald 
121*c436b760SMilanka Ringwald /* API_START */
122*c436b760SMilanka Ringwald 
123*c436b760SMilanka Ringwald // map ATT ERROR CODES on to att_read_callback length
124*c436b760SMilanka Ringwald #define ATT_READ_ERROR_CODE_OFFSET       0xfe00
125*c436b760SMilanka Ringwald 
126*c436b760SMilanka Ringwald // custom BTstack ATT Response Pending for att_read_callback
127*c436b760SMilanka Ringwald #define ATT_READ_RESPONSE_PENDING                 0xffff
128*c436b760SMilanka Ringwald 
129*c436b760SMilanka Ringwald // internally used to signal write response pending
130*c436b760SMilanka Ringwald #define ATT_INTERNAL_WRITE_RESPONSE_PENDING       0xfffe
131*c436b760SMilanka Ringwald 
132*c436b760SMilanka Ringwald /**
133*c436b760SMilanka Ringwald  * @brief ATT Client Read Callback for Dynamic Data
134*c436b760SMilanka Ringwald  * - if buffer == NULL, don't copy data, just return size of value
135*c436b760SMilanka Ringwald  * - if buffer != NULL, copy data and return number bytes copied
136*c436b760SMilanka Ringwald  * If ENABLE_ATT_DELAYED_READ_RESPONSE is defined, you may return ATT_READ_RESPONSE_PENDING if data isn't available yet
137*c436b760SMilanka Ringwald  * @param con_handle of hci le connection
138*c436b760SMilanka Ringwald  * @param attribute_handle to be read
139*c436b760SMilanka Ringwald  * @param offset defines start of attribute value
140*c436b760SMilanka Ringwald  * @param buffer
141*c436b760SMilanka Ringwald  * @param buffer_size
142*c436b760SMilanka Ringwald  * @return size of value if buffer is NULL, otherwise number of bytes copied
143*c436b760SMilanka Ringwald  */
144711e6c80SMatthias Ringwald typedef uint16_t (*att_read_callback_t)(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
145591423b2SMatthias Ringwald 
146*c436b760SMilanka Ringwald /**
147*c436b760SMilanka Ringwald  * @brief ATT Client Write Callback for Dynamic Data
148*c436b760SMilanka Ringwald  * Each Prepared Write Request triggers a callback with transaction mode ATT_TRANSACTION_MODE_ACTIVE.
149*c436b760SMilanka Ringwald  * On Execute Write, the callback will be called with ATT_TRANSACTION_MODE_VALIDATE and allows to validate all queued writes and return an application error.
150*c436b760SMilanka Ringwald  * If none of the registered callbacks return an error for ATT_TRANSACTION_MODE_VALIDATE and the callback will be called with ATT_TRANSACTION_MODE_EXECUTE.
151*c436b760SMilanka Ringwald  * Otherwise, all callbacks will be called with ATT_TRANSACTION_MODE_CANCEL.
152*c436b760SMilanka Ringwald  *
153*c436b760SMilanka Ringwald  * If the additional validation step is not needed, just return 0 for all callbacks with transaction mode ATT_TRANSACTION_MODE_VALIDATE.
154*c436b760SMilanka Ringwald  *
155*c436b760SMilanka Ringwald  * @param con_handle of hci le connection
156*c436b760SMilanka Ringwald  * @param attribute_handle to be written
157*c436b760SMilanka Ringwald  * @param transaction - ATT_TRANSACTION_MODE_NONE for regular writes. For prepared writes: ATT_TRANSACTION_MODE_ACTIVE, ATT_TRANSACTION_MODE_VALIDATE, ATT_TRANSACTION_MODE_EXECUTE, ATT_TRANSACTION_MODE_CANCEL
158*c436b760SMilanka Ringwald  * @param offset into the value - used for queued writes and long attributes
159*c436b760SMilanka Ringwald  * @param buffer
160*c436b760SMilanka Ringwald  * @param buffer_size
161*c436b760SMilanka Ringwald  * @param signature used for signed write commmands
162*c436b760SMilanka Ringwald  * @return 0 if write was ok, ATT_ERROR_PREPARE_QUEUE_FULL if no space in queue, ATT_ERROR_INVALID_OFFSET if offset is larger than max buffer
163*c436b760SMilanka Ringwald  */
164711e6c80SMatthias Ringwald typedef int (*att_write_callback_t)(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
165591423b2SMatthias Ringwald 
1668ac574d6SMatthias Ringwald // Read & Write Callbacks for handle range
1678ac574d6SMatthias Ringwald typedef struct att_service_handler {
1688ac574d6SMatthias Ringwald     btstack_linked_item_t * item;
1698ac574d6SMatthias Ringwald     uint16_t start_handle;
1708ac574d6SMatthias Ringwald     uint16_t end_handle;
1718ac574d6SMatthias Ringwald     att_read_callback_t read_callback;
1728ac574d6SMatthias Ringwald     att_write_callback_t write_callback;
1735d07396bSMatthias Ringwald     btstack_packet_handler_t packet_handler;
1748ac574d6SMatthias Ringwald } att_service_handler_t;
1758ac574d6SMatthias Ringwald 
176591423b2SMatthias Ringwald // MARK: ATT Operations
177591423b2SMatthias Ringwald 
178*c436b760SMilanka Ringwald /**
179591423b2SMatthias Ringwald  * @brief setup ATT database
180*c436b760SMilanka Ringwald  * @param db
181591423b2SMatthias Ringwald  */
182591423b2SMatthias Ringwald void att_set_db(uint8_t const * db);
183591423b2SMatthias Ringwald 
184591423b2SMatthias Ringwald /*
185591423b2SMatthias Ringwald  * @brief set callback for read of dynamic attributes
186591423b2SMatthias Ringwald  * @param callback
187591423b2SMatthias Ringwald  */
188591423b2SMatthias Ringwald void att_set_read_callback(att_read_callback_t callback);
189591423b2SMatthias Ringwald 
190*c436b760SMilanka Ringwald /**
191591423b2SMatthias Ringwald  * @brief set callback for write of dynamic attributes
192591423b2SMatthias Ringwald  * @param callback
193591423b2SMatthias Ringwald  */
194591423b2SMatthias Ringwald void att_set_write_callback(att_write_callback_t callback);
195591423b2SMatthias Ringwald 
196*c436b760SMilanka Ringwald /**
197591423b2SMatthias Ringwald  * @brief debug helper, dump ATT database to stdout using log_info
198591423b2SMatthias Ringwald  */
199591423b2SMatthias Ringwald void att_dump_attributes(void);
200591423b2SMatthias Ringwald 
201*c436b760SMilanka Ringwald /**
202591423b2SMatthias Ringwald  * @brief process ATT request against database and put response into response buffer
203591423b2SMatthias Ringwald  * @param att_connection used for mtu and security properties
204591423b2SMatthias Ringwald  * @param request_buffer, request_len: ATT request from clinet
205591423b2SMatthias Ringwald  * @param response_buffer for result
206*c436b760SMilanka Ringwald  * @return len of data in response buffer. 0 = no response,
207e404a688SMatthias Ringwald  *          ATT_READ_RESPONSE_PENDING if it was returned at least once for dynamic data (requires ENABLE_ATT_DELAYED_READ_RESPONSE)
208591423b2SMatthias Ringwald  */
209591423b2SMatthias Ringwald uint16_t att_handle_request(att_connection_t * att_connection,
210591423b2SMatthias Ringwald                             uint8_t * request_buffer,
211591423b2SMatthias Ringwald                             uint16_t request_len,
212591423b2SMatthias Ringwald                             uint8_t * response_buffer);
213591423b2SMatthias Ringwald 
214*c436b760SMilanka Ringwald /**
215591423b2SMatthias Ringwald  * @brief setup value notification in response buffer for a given handle and value
216591423b2SMatthias Ringwald  * @param att_connection
217fc64f94aSMatthias Ringwald  * @param attribute_handle
218fc64f94aSMatthias Ringwald  * @param value
219fc64f94aSMatthias Ringwald  * @param value_len
220591423b2SMatthias Ringwald  * @param response_buffer for notification
221591423b2SMatthias Ringwald  */
222591423b2SMatthias Ringwald uint16_t att_prepare_handle_value_notification(att_connection_t * att_connection,
223fc64f94aSMatthias Ringwald                                                uint16_t attribute_handle,
2243bb3035fSMilanka Ringwald                                                const uint8_t *value,
225591423b2SMatthias Ringwald                                                uint16_t value_len,
226591423b2SMatthias Ringwald                                                uint8_t * response_buffer);
227591423b2SMatthias Ringwald 
228*c436b760SMilanka Ringwald /**
229591423b2SMatthias Ringwald  * @brief setup value indication in response buffer for a given handle and value
230591423b2SMatthias Ringwald  * @param att_connection
231fc64f94aSMatthias Ringwald  * @param attribute_handle
232fc64f94aSMatthias Ringwald  * @param value
233fc64f94aSMatthias Ringwald  * @param value_len
234591423b2SMatthias Ringwald  * @param response_buffer for indication
235591423b2SMatthias Ringwald  */
236591423b2SMatthias Ringwald uint16_t att_prepare_handle_value_indication(att_connection_t * att_connection,
237fc64f94aSMatthias Ringwald                                              uint16_t attribute_handle,
2383bb3035fSMilanka Ringwald                                              const uint8_t *value,
239591423b2SMatthias Ringwald                                              uint16_t value_len,
240591423b2SMatthias Ringwald                                              uint8_t * response_buffer);
241591423b2SMatthias Ringwald 
242*c436b760SMilanka Ringwald /**
243591423b2SMatthias Ringwald  * @brief transcation queue of prepared writes, e.g., after disconnect
244*c436b760SMilanka Ringwald  * @return att_connection
245591423b2SMatthias Ringwald  */
246591423b2SMatthias Ringwald void att_clear_transaction_queue(att_connection_t * att_connection);
247591423b2SMatthias Ringwald 
248bfd413f0SMatthias Ringwald // att_read_callback helpers for a various data types
249bfd413f0SMatthias Ringwald 
250*c436b760SMilanka Ringwald /**
251bfd413f0SMatthias Ringwald  * @brief Handle read of blob like data for att_read_callback
252bfd413f0SMatthias Ringwald  * @param blob of data
253bfd413f0SMatthias Ringwald  * @param blob_size of blob
254bfd413f0SMatthias Ringwald  * @param offset from att_read_callback
255bfd413f0SMatthias Ringwald  * @param buffer from att_read_callback
256bfd413f0SMatthias Ringwald  * @param buffer_size from att_read_callback
257*c436b760SMilanka Ringwald  * @return value size for buffer == 0 and num bytes copied otherwise
258bfd413f0SMatthias Ringwald  */
259bfd413f0SMatthias Ringwald uint16_t att_read_callback_handle_blob(const uint8_t * blob, uint16_t blob_size, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
260bfd413f0SMatthias Ringwald 
261*c436b760SMilanka Ringwald /**
262bfd413f0SMatthias Ringwald  * @brief Handle read of little endian unsigned 32 bit value for att_read_callback
263bfd413f0SMatthias Ringwald  * @param value
264bfd413f0SMatthias Ringwald  * @param offset from att_read_callback
265bfd413f0SMatthias Ringwald  * @param buffer from att_read_callback
266bfd413f0SMatthias Ringwald  * @param buffer_size from att_read_callback
267*c436b760SMilanka Ringwald  * @return value size for buffer == 0 and num bytes copied otherwise
268bfd413f0SMatthias Ringwald  */
269bfd413f0SMatthias Ringwald uint16_t att_read_callback_handle_little_endian_32(uint32_t value, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
270bfd413f0SMatthias Ringwald 
271*c436b760SMilanka Ringwald /**
272bfd413f0SMatthias Ringwald  * @brief Handle read of little endian unsigned 16 bit value for att_read_callback
273bfd413f0SMatthias Ringwald  * @param value
274bfd413f0SMatthias Ringwald  * @param offset from att_read_callback
275bfd413f0SMatthias Ringwald  * @param buffer from att_read_callback
276bfd413f0SMatthias Ringwald  * @param buffer_size from att_read_callback
277*c436b760SMilanka Ringwald  * @return value size for buffer == 0 and num bytes copied otherwise
278bfd413f0SMatthias Ringwald  */
279bfd413f0SMatthias Ringwald uint16_t att_read_callback_handle_little_endian_16(uint16_t value, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
280bfd413f0SMatthias Ringwald 
281*c436b760SMilanka Ringwald /**
282bfd413f0SMatthias Ringwald  * @brief Handle read of single byte for att_read_callback
283bfd413f0SMatthias Ringwald  * @param blob of data
284bfd413f0SMatthias Ringwald  * @param blob_size of blob
285bfd413f0SMatthias Ringwald  * @param offset from att_read_callback
286bfd413f0SMatthias Ringwald  * @param buffer from att_read_callback
287bfd413f0SMatthias Ringwald  * @param buffer_size from att_read_callback
288*c436b760SMilanka Ringwald  * @return value size for buffer == 0 and num bytes copied otherwise
289bfd413f0SMatthias Ringwald  */
290bfd413f0SMatthias Ringwald uint16_t att_read_callback_handle_byte(uint8_t value, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
291bfd413f0SMatthias Ringwald 
292bfd413f0SMatthias Ringwald 
293591423b2SMatthias Ringwald // experimental client API
294*c436b760SMilanka Ringwald /**
295*c436b760SMilanka Ringwald  * @brief Get UUID for handle
296*c436b760SMilanka Ringwald  * @param attribute_handle
297*c436b760SMilanka Ringwald  * @return 0 if not found
298*c436b760SMilanka Ringwald  */
299fc64f94aSMatthias Ringwald uint16_t att_uuid_for_handle(uint16_t attribute_handle);
300591423b2SMatthias Ringwald 
301660ce368SMatthias Ringwald // experimental GATT Server API
302660ce368SMatthias Ringwald 
303*c436b760SMilanka Ringwald /**
304*c436b760SMilanka Ringwald  * @brief Get handle range for primary service.
305*c436b760SMilanka Ringwald  * @param uuid16
306*c436b760SMilanka Ringwald  * @param start_handle
307*c436b760SMilanka Ringwald  * @param end_handle
308*c436b760SMilanka Ringwald  * @return false if not found
309*c436b760SMilanka Ringwald  */
310*c436b760SMilanka Ringwald bool gatt_server_get_handle_range_for_service_with_uuid16(uint16_t uuid16, uint16_t * start_handle, uint16_t * end_handle);
311660ce368SMatthias Ringwald 
312*c436b760SMilanka Ringwald /**
313*c436b760SMilanka Ringwald  * @brief Get value handle for characteristic.
314*c436b760SMilanka Ringwald  * @param start_handle
315*c436b760SMilanka Ringwald  * @param end_handle
316*c436b760SMilanka Ringwald  * @param uuid16
317*c436b760SMilanka Ringwald  * @return 0 if not found
318*c436b760SMilanka Ringwald  */
319660ce368SMatthias Ringwald uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
320660ce368SMatthias Ringwald 
321*c436b760SMilanka Ringwald /**
322*c436b760SMilanka Ringwald  * @brief Get descriptor handle for characteristic.
323*c436b760SMilanka Ringwald  * @param start_handle
324*c436b760SMilanka Ringwald  * @param end_handle
325*c436b760SMilanka Ringwald  * @param characteristic_uuid16
326*c436b760SMilanka Ringwald  * @param descriptor_uuid16
327*c436b760SMilanka Ringwald  * @return 0 if not found
328*c436b760SMilanka Ringwald  */
329c7774db7SMilanka Ringwald uint16_t gatt_server_get_descriptor_handle_for_characteristic_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t characteristic_uuid16, uint16_t descriptor_uuid16);
330*c436b760SMilanka Ringwald 
331*c436b760SMilanka Ringwald /**
332*c436b760SMilanka Ringwald  * @brief Get client configuration handle for characteristic.
333*c436b760SMilanka Ringwald  * @param start_handle
334*c436b760SMilanka Ringwald  * @param end_handle
335*c436b760SMilanka Ringwald  * @param characteristic_uuid16
336*c436b760SMilanka Ringwald  * @return 0 if not found
337*c436b760SMilanka Ringwald  */
338c7774db7SMilanka Ringwald uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t characteristic_uuid16);
339*c436b760SMilanka Ringwald 
340*c436b760SMilanka Ringwald /**
341*c436b760SMilanka Ringwald  * @brief Get server configuration handle for characteristic.
342*c436b760SMilanka Ringwald  * @param start_handle
343*c436b760SMilanka Ringwald  * @param end_handle
344*c436b760SMilanka Ringwald  * @param characteristic_uuid16
345*c436b760SMilanka Ringwald  * @param descriptor_uuid16
346*c436b760SMilanka Ringwald  * @return 0 if not found
347*c436b760SMilanka Ringwald  */
348c7774db7SMilanka Ringwald uint16_t gatt_server_get_server_configuration_handle_for_characteristic_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t characteristic_uuid16);
349660ce368SMatthias Ringwald 
350*c436b760SMilanka Ringwald /**
351*c436b760SMilanka Ringwald  * @brief Get handle range for primary service.
352*c436b760SMilanka Ringwald  * @param uuid128
353*c436b760SMilanka Ringwald  * @param start_handle
354*c436b760SMilanka Ringwald  * @param end_handle
355*c436b760SMilanka Ringwald  * @return 0 if not found
356*c436b760SMilanka Ringwald  */
357*c436b760SMilanka Ringwald int gatt_server_get_handle_range_for_service_with_uuid128(const uint8_t * uuid128, uint16_t * start_handle, uint16_t * end_handle);
35815f22304SMatthias Ringwald 
359*c436b760SMilanka Ringwald /**
360*c436b760SMilanka Ringwald  * @brief Get value handle.
361*c436b760SMilanka Ringwald  * @param start_handle
362*c436b760SMilanka Ringwald  * @param end_handle
363*c436b760SMilanka Ringwald  * @param uuid128
364*c436b760SMilanka Ringwald  * @return 0 if not found
365*c436b760SMilanka Ringwald  */
36615f22304SMatthias Ringwald uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid128(uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128);
36715f22304SMatthias Ringwald 
368*c436b760SMilanka Ringwald /**
369*c436b760SMilanka Ringwald  * @brief Get client configuration handle.
370*c436b760SMilanka Ringwald  * @param start_handle
371*c436b760SMilanka Ringwald  * @param end_handle
372*c436b760SMilanka Ringwald  * @param uuid128
373*c436b760SMilanka Ringwald  * @return 0 if not found
374*c436b760SMilanka Ringwald  */
37515f22304SMatthias Ringwald uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uuid128(uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128);
37615f22304SMatthias Ringwald 
377*c436b760SMilanka Ringwald /* API_END */
378*c436b760SMilanka Ringwald 
3798b1d64c6SMatthias Ringwald // non-user functionality for att_server
3808b1d64c6SMatthias Ringwald 
381*c436b760SMilanka Ringwald /**
3828b1d64c6SMatthias Ringwald  * @brief Check if writes to handle should be persistent
3838b1d64c6SMatthias Ringwald  * @param handle
384*c436b760SMilanka Ringwald  * @return 1 if persistent
3858b1d64c6SMatthias Ringwald  */
3864d5915b3SMatthias Ringwald bool att_is_persistent_ccc(uint16_t handle);
3878b1d64c6SMatthias Ringwald 
388*c436b760SMilanka Ringwald 
389*c436b760SMilanka Ringwald 
39044127f43SMatthias Ringwald // auto-pts testing, returns response size
39144127f43SMatthias Ringwald #ifdef ENABLE_BTP
39244127f43SMatthias Ringwald uint16_t btp_att_get_attributes_by_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t uuid16, uint8_t * response_buffer, uint16_t response_buffer_size);
39344127f43SMatthias Ringwald uint16_t btp_att_get_attributes_by_uuid128(uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128, uint8_t * response_buffer, uint16_t response_buffer_size);
3946de29f25SMatthias Ringwald uint16_t btp_att_get_attribute_value(att_connection_t * att_connection, uint16_t attribute_handle, uint8_t * response_buffer, uint16_t response_buffer_size);
39544127f43SMatthias Ringwald #endif
3968b1d64c6SMatthias Ringwald 
397591423b2SMatthias Ringwald #if defined __cplusplus
398591423b2SMatthias Ringwald }
399591423b2SMatthias Ringwald #endif
400591423b2SMatthias Ringwald 
40180e33422SMatthias Ringwald #endif // ATT_H
402