xref: /btstack/src/ble/att_db_util.h (revision d68b9e471089a952090597a7df5f856327c96715)
13deb3ec6SMatthias Ringwald /*
23deb3ec6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
33deb3ec6SMatthias Ringwald  *
43deb3ec6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53deb3ec6SMatthias Ringwald  * modification, are permitted provided that the following conditions
63deb3ec6SMatthias Ringwald  * are met:
73deb3ec6SMatthias Ringwald  *
83deb3ec6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103deb3ec6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123deb3ec6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133deb3ec6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143deb3ec6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153deb3ec6SMatthias Ringwald  *    from this software without specific prior written permission.
163deb3ec6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173deb3ec6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183deb3ec6SMatthias Ringwald  *    monetary gain.
193deb3ec6SMatthias Ringwald  *
203deb3ec6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213deb3ec6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223deb3ec6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
233deb3ec6SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
243deb3ec6SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253deb3ec6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263deb3ec6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273deb3ec6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283deb3ec6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293deb3ec6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303deb3ec6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313deb3ec6SMatthias Ringwald  * SUCH DAMAGE.
323deb3ec6SMatthias Ringwald  *
333deb3ec6SMatthias Ringwald  * Please inquire about commercial licensing options at
343deb3ec6SMatthias Ringwald  * [email protected]
353deb3ec6SMatthias Ringwald  *
363deb3ec6SMatthias Ringwald  */
373deb3ec6SMatthias Ringwald 
383deb3ec6SMatthias Ringwald /**
393deb3ec6SMatthias Ringwald  * Helper to construct ATT DB at runtime
403deb3ec6SMatthias Ringwald  * (BTstack GATT Compiler is not used)
413deb3ec6SMatthias Ringwald  */
423deb3ec6SMatthias Ringwald 
433deb3ec6SMatthias Ringwald #ifndef __ATT_DB_UTIL
443deb3ec6SMatthias Ringwald #define __ATT_DB_UTIL
453deb3ec6SMatthias Ringwald 
467907f069SMatthias Ringwald #include "btstack_config.h"
473deb3ec6SMatthias Ringwald #
483deb3ec6SMatthias Ringwald #ifdef HAVE_MALLOC
493deb3ec6SMatthias Ringwald #else
503deb3ec6SMatthias Ringwald #endif
513deb3ec6SMatthias Ringwald 
523deb3ec6SMatthias Ringwald #include <stdint.h>
533deb3ec6SMatthias Ringwald 
543deb3ec6SMatthias Ringwald #if defined __cplusplus
553deb3ec6SMatthias Ringwald extern "C" {
563deb3ec6SMatthias Ringwald #endif
573deb3ec6SMatthias Ringwald 
583deb3ec6SMatthias Ringwald /* API_START */
593deb3ec6SMatthias Ringwald 
603deb3ec6SMatthias Ringwald /**
613deb3ec6SMatthias Ringwald  * @brief Init ATT DB storage
623deb3ec6SMatthias Ringwald  */
633deb3ec6SMatthias Ringwald void att_db_util_init(void);
643deb3ec6SMatthias Ringwald 
653deb3ec6SMatthias Ringwald /**
663deb3ec6SMatthias Ringwald  * @brief Add primary service for 16-bit UUID
67ff04bac7SMatthias Ringwald  * @param uuid16
684e5e1eb0SMatthias Ringwald  * @returns attribute handle for the new service definition
693deb3ec6SMatthias Ringwald  */
70ff04bac7SMatthias Ringwald uint16_t att_db_util_add_service_uuid16(uint16_t uuid16);
713deb3ec6SMatthias Ringwald 
723deb3ec6SMatthias Ringwald /**
733deb3ec6SMatthias Ringwald  * @brief Add primary service for 128-bit UUID
74ff04bac7SMatthias Ringwald  * @param uuid1286
754e5e1eb0SMatthias Ringwald  * @returns attribute handle for the new service definition
763deb3ec6SMatthias Ringwald  */
77ff04bac7SMatthias Ringwald uint16_t att_db_util_add_service_uuid128(const uint8_t * uuid128);
783deb3ec6SMatthias Ringwald 
793deb3ec6SMatthias Ringwald /**
80*d68b9e47SMatthias Ringwald  * @brief Add secondary service for 16-bit UUID
81*d68b9e47SMatthias Ringwald  * @param uuid16
82*d68b9e47SMatthias Ringwald  * @returns attribute handle for the new service definition
83*d68b9e47SMatthias Ringwald  */
84*d68b9e47SMatthias Ringwald uint16_t att_db_util_add_secondary_service_uuid16(uint16_t uuid16);
85*d68b9e47SMatthias Ringwald 
86*d68b9e47SMatthias Ringwald /**
87*d68b9e47SMatthias Ringwald  * @brief Add secondary service for 128-bit UUID
88*d68b9e47SMatthias Ringwald  * @param uuid1286
89*d68b9e47SMatthias Ringwald  * @returns attribute handle for the new service definition
90*d68b9e47SMatthias Ringwald  */
91*d68b9e47SMatthias Ringwald uint16_t att_db_util_add_secondary_service_uuid128(const uint8_t * uuid128);
92*d68b9e47SMatthias Ringwald 
93*d68b9e47SMatthias Ringwald /**
943deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 16-bit UUID, properties, and data
95ff04bac7SMatthias Ringwald  * @param uuid16
96ff04bac7SMatthias Ringwald  * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
97ff04bac7SMatthias Ringwald  * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
98ff04bac7SMatthias Ringwald  * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
99ff04bac7SMatthias Ringwald  * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
100ff04bac7SMatthias Ringwald  * @param data_len
1014e5e1eb0SMatthias Ringwald  * @returns attribute handle of the new characteristic value declaration
1029f28d85dSMatthias Ringwald  * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD)
1039f28d85dSMatthias Ringwald  *       is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1
1043deb3ec6SMatthias Ringwald  */
105ff04bac7SMatthias Ringwald uint16_t att_db_util_add_characteristic_uuid16(uint16_t uuid16, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len);
1063deb3ec6SMatthias Ringwald 
1073deb3ec6SMatthias Ringwald /**
1083deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 128-bit UUID, properties, and data
109ff04bac7SMatthias Ringwald  * @param uuid128
110ff04bac7SMatthias Ringwald  * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
111ff04bac7SMatthias Ringwald  * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
112ff04bac7SMatthias Ringwald  * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
113ff04bac7SMatthias Ringwald  * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
114ff04bac7SMatthias Ringwald  * @param data_len
1154e5e1eb0SMatthias Ringwald  * @returns attribute handle of the new characteristic value declaration
1169f28d85dSMatthias Ringwald  * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD)
1179f28d85dSMatthias Ringwald  *       is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1
1183deb3ec6SMatthias Ringwald  */
119ff04bac7SMatthias Ringwald uint16_t att_db_util_add_characteristic_uuid128(const uint8_t * uuid128, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len);
1209f28d85dSMatthias Ringwald 
1219f28d85dSMatthias Ringwald /**
12293493c27SMatthias Ringwald * @brief Add descriptor with 16-bit UUID, properties, and data
123ff04bac7SMatthias Ringwald * @param uuid16
124ff04bac7SMatthias Ringwald * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
125ff04bac7SMatthias Ringwald * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
126ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
127ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
128ff04bac7SMatthias Ringwald * @param data_len
1294e5e1eb0SMatthias Ringwald * @returns attribute handle of the new characteristic descriptor declaration
1309f28d85dSMatthias Ringwald */
131ff04bac7SMatthias Ringwald uint16_t att_db_util_add_descriptor_uuid16(uint16_t uuid16, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len);
132ff04bac7SMatthias Ringwald 
133ff04bac7SMatthias Ringwald /**
134ff04bac7SMatthias Ringwald * @brief Add descriptor with 128-bit UUID, properties, and data
13593493c27SMatthias Ringwald * @param uuid128
136ff04bac7SMatthias Ringwald * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
137ff04bac7SMatthias Ringwald * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
138ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
139ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
140ff04bac7SMatthias Ringwald * @param data_len
141ff04bac7SMatthias Ringwald * @returns attribute handle of the new characteristic descriptor declaration
142ff04bac7SMatthias Ringwald */
143ff04bac7SMatthias Ringwald uint16_t att_db_util_add_descriptor_uuid128(const uint8_t * uuid128, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len);
1449f28d85dSMatthias Ringwald 
1459f28d85dSMatthias Ringwald /**
1463deb3ec6SMatthias Ringwald  * @brief Get address of constructed ATT DB
1473deb3ec6SMatthias Ringwald  */
1483deb3ec6SMatthias Ringwald uint8_t * att_db_util_get_address(void);
1493deb3ec6SMatthias Ringwald 
1503deb3ec6SMatthias Ringwald /**
1513deb3ec6SMatthias Ringwald  * @brief Get size of constructed ATT DB
1523deb3ec6SMatthias Ringwald  */
1533deb3ec6SMatthias Ringwald uint16_t att_db_util_get_size(void);
1543deb3ec6SMatthias Ringwald 
1553deb3ec6SMatthias Ringwald /* API_END */
1563deb3ec6SMatthias Ringwald 
1573deb3ec6SMatthias Ringwald #if defined __cplusplus
1583deb3ec6SMatthias Ringwald }
1593deb3ec6SMatthias Ringwald #endif
1603deb3ec6SMatthias Ringwald #endif
161