xref: /btstack/src/ble/att_db_util.h (revision 93493c270121df174e10742d9975ca59c4df6a26)
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 /**
803deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 16-bit UUID, properties, and data
81ff04bac7SMatthias Ringwald  * @param uuid16
82ff04bac7SMatthias Ringwald  * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
83ff04bac7SMatthias Ringwald  * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
84ff04bac7SMatthias Ringwald  * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
85ff04bac7SMatthias Ringwald  * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
86ff04bac7SMatthias Ringwald  * @param data_len
874e5e1eb0SMatthias Ringwald  * @returns attribute handle of the new characteristic value declaration
889f28d85dSMatthias Ringwald  * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD)
899f28d85dSMatthias Ringwald  *       is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1
903deb3ec6SMatthias Ringwald  */
91ff04bac7SMatthias 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);
923deb3ec6SMatthias Ringwald 
933deb3ec6SMatthias Ringwald /**
943deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 128-bit UUID, properties, and data
95ff04bac7SMatthias Ringwald  * @param uuid128
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_uuid128(const uint8_t * uuid128, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len);
1069f28d85dSMatthias Ringwald 
1079f28d85dSMatthias Ringwald /**
108*93493c27SMatthias Ringwald * @brief Add descriptor with 16-bit UUID, properties, and data
109ff04bac7SMatthias Ringwald * @param uuid16
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 descriptor declaration
1169f28d85dSMatthias Ringwald */
117ff04bac7SMatthias 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);
118ff04bac7SMatthias Ringwald 
119ff04bac7SMatthias Ringwald /**
120ff04bac7SMatthias Ringwald * @brief Add descriptor with 128-bit UUID, properties, and data
121*93493c27SMatthias Ringwald * @param uuid128
122ff04bac7SMatthias Ringwald * @param properties        - see ATT_PROPERTY_* in src/bluetooth.h
123ff04bac7SMatthias Ringwald * @param read_permissions  - see ATT_SECURITY_* in src/bluetooth.h
124ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h
125ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified
126ff04bac7SMatthias Ringwald * @param data_len
127ff04bac7SMatthias Ringwald * @returns attribute handle of the new characteristic descriptor declaration
128ff04bac7SMatthias Ringwald */
129ff04bac7SMatthias 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);
1309f28d85dSMatthias Ringwald 
1319f28d85dSMatthias Ringwald /**
1323deb3ec6SMatthias Ringwald  * @brief Get address of constructed ATT DB
1333deb3ec6SMatthias Ringwald  */
1343deb3ec6SMatthias Ringwald uint8_t * att_db_util_get_address(void);
1353deb3ec6SMatthias Ringwald 
1363deb3ec6SMatthias Ringwald /**
1373deb3ec6SMatthias Ringwald  * @brief Get size of constructed ATT DB
1383deb3ec6SMatthias Ringwald  */
1393deb3ec6SMatthias Ringwald uint16_t att_db_util_get_size(void);
1403deb3ec6SMatthias Ringwald 
1413deb3ec6SMatthias Ringwald /* API_END */
1423deb3ec6SMatthias Ringwald 
1433deb3ec6SMatthias Ringwald #if defined __cplusplus
1443deb3ec6SMatthias Ringwald }
1453deb3ec6SMatthias Ringwald #endif
1463deb3ec6SMatthias Ringwald #endif
147