xref: /btstack/src/ble/att_db_util.h (revision 9f28d85d18f6ed4b3e8eb18cc057f125f38380be)
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
673deb3ec6SMatthias Ringwald  */
683deb3ec6SMatthias Ringwald void att_db_util_add_service_uuid16(uint16_t udid16);
693deb3ec6SMatthias Ringwald 
703deb3ec6SMatthias Ringwald /**
713deb3ec6SMatthias Ringwald  * @brief Add primary service for 128-bit UUID
723deb3ec6SMatthias Ringwald  */
733deb3ec6SMatthias Ringwald void att_db_util_add_service_uuid128(uint8_t * udid128);
743deb3ec6SMatthias Ringwald 
753deb3ec6SMatthias Ringwald /**
763deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 16-bit UUID, properties, and data
773deb3ec6SMatthias Ringwald  * @returns attribute value handle
78*9f28d85dSMatthias Ringwald  * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD)
79*9f28d85dSMatthias Ringwald  *       is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1
80591423b2SMatthias Ringwald  * @see ATT_PROPERTY_* in ble/att_db.h
813deb3ec6SMatthias Ringwald  */
823deb3ec6SMatthias Ringwald uint16_t att_db_util_add_characteristic_uuid16(uint16_t   udid16,  uint16_t properties, uint8_t * data, uint16_t data_len);
833deb3ec6SMatthias Ringwald 
843deb3ec6SMatthias Ringwald /**
853deb3ec6SMatthias Ringwald  * @brief Add Characteristic with 128-bit UUID, properties, and data
863deb3ec6SMatthias Ringwald  * @returns attribute value handle
87*9f28d85dSMatthias Ringwald  * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD)
88*9f28d85dSMatthias Ringwald  *       is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1
89591423b2SMatthias Ringwald  * @see ATT_PROPERTY_* in ble/att_db.h
903deb3ec6SMatthias Ringwald  */
913deb3ec6SMatthias Ringwald uint16_t att_db_util_add_characteristic_uuid128(uint8_t * udid128, uint16_t properties, uint8_t * data, uint16_t data_len);
923deb3ec6SMatthias Ringwald 
933deb3ec6SMatthias Ringwald /**
94*9f28d85dSMatthias Ringwald * @brief Add descriptor with 16-bit UUID, properties, and data
95*9f28d85dSMatthias Ringwald * @returns attribute value handle
96*9f28d85dSMatthias Ringwald * @see ATT_PROPERTY_* in ble/att_db.h
97*9f28d85dSMatthias Ringwald */
98*9f28d85dSMatthias Ringwald uint16_t att_db_util_add_descriptor_uuid16(uint16_t uuid16, uint16_t properties, uint8_t * data, uint16_t data_len);
99*9f28d85dSMatthias Ringwald 
100*9f28d85dSMatthias Ringwald /**
101*9f28d85dSMatthias Ringwald * @brief Add descriptor with 128-bit UUID, properties, and data
102*9f28d85dSMatthias Ringwald * @returns attribute value handle
103*9f28d85dSMatthias Ringwald * @see ATT_PROPERTY_* in ble/att_db.h
104*9f28d85dSMatthias Ringwald */
105*9f28d85dSMatthias Ringwald uint16_t att_db_util_add_descriptor_uuid128(uint8_t * udid128, uint16_t properties, uint8_t * data, uint16_t data_len);
106*9f28d85dSMatthias Ringwald 
107*9f28d85dSMatthias Ringwald /**
1083deb3ec6SMatthias Ringwald  * @brief Get address of constructed ATT DB
1093deb3ec6SMatthias Ringwald  */
1103deb3ec6SMatthias Ringwald uint8_t * att_db_util_get_address(void);
1113deb3ec6SMatthias Ringwald 
1123deb3ec6SMatthias Ringwald /**
1133deb3ec6SMatthias Ringwald  * @brief Get size of constructed ATT DB
1143deb3ec6SMatthias Ringwald  */
1153deb3ec6SMatthias Ringwald uint16_t att_db_util_get_size(void);
1163deb3ec6SMatthias Ringwald 
1173deb3ec6SMatthias Ringwald /* API_END */
1183deb3ec6SMatthias Ringwald 
1193deb3ec6SMatthias Ringwald #if defined __cplusplus
1203deb3ec6SMatthias Ringwald }
1213deb3ec6SMatthias Ringwald #endif
1223deb3ec6SMatthias Ringwald #endif
123