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 23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24*2fca4dadSMilanka Ringwald * GMBH 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 /** 39fe5a6c4eSMilanka Ringwald * @title Runtine ATT Database Setup 40fe5a6c4eSMilanka Ringwald * 41fe5a6c4eSMilanka Ringwald * Helper to construct ATT DB at runtime (BTstack GATT Compiler is not used). 42fe5a6c4eSMilanka Ringwald * 433deb3ec6SMatthias Ringwald */ 443deb3ec6SMatthias Ringwald 454495c8c0SMilanka Ringwald #ifndef ATT_DB_UTIL_H 464495c8c0SMilanka Ringwald #define ATT_DB_UTIL_H 473deb3ec6SMatthias Ringwald 487907f069SMatthias Ringwald #include "btstack_config.h" 49a4419cc8SMatthias Ringwald #include "btstack_crypto.h" 503deb3ec6SMatthias Ringwald 513deb3ec6SMatthias Ringwald #include <stdint.h> 523deb3ec6SMatthias Ringwald 533deb3ec6SMatthias Ringwald #if defined __cplusplus 543deb3ec6SMatthias Ringwald extern "C" { 553deb3ec6SMatthias Ringwald #endif 563deb3ec6SMatthias Ringwald 573deb3ec6SMatthias Ringwald /* API_START */ 583deb3ec6SMatthias Ringwald 593deb3ec6SMatthias Ringwald /** 603deb3ec6SMatthias Ringwald * @brief Init ATT DB storage 613deb3ec6SMatthias Ringwald */ 623deb3ec6SMatthias Ringwald void att_db_util_init(void); 633deb3ec6SMatthias Ringwald 643deb3ec6SMatthias Ringwald /** 653deb3ec6SMatthias Ringwald * @brief Add primary service for 16-bit UUID 66ff04bac7SMatthias Ringwald * @param uuid16 676b65794dSMilanka Ringwald * @return attribute handle for the new service definition 683deb3ec6SMatthias Ringwald */ 69ff04bac7SMatthias Ringwald uint16_t att_db_util_add_service_uuid16(uint16_t uuid16); 703deb3ec6SMatthias Ringwald 713deb3ec6SMatthias Ringwald /** 723deb3ec6SMatthias Ringwald * @brief Add primary service for 128-bit UUID 7391974b5bSMatthias Ringwald * @param uuid128 746b65794dSMilanka Ringwald * @return attribute handle for the new service definition 753deb3ec6SMatthias Ringwald */ 76ff04bac7SMatthias Ringwald uint16_t att_db_util_add_service_uuid128(const uint8_t * uuid128); 773deb3ec6SMatthias Ringwald 783deb3ec6SMatthias Ringwald /** 79d68b9e47SMatthias Ringwald * @brief Add secondary service for 16-bit UUID 80d68b9e47SMatthias Ringwald * @param uuid16 816b65794dSMilanka Ringwald * @return attribute handle for the new service definition 82d68b9e47SMatthias Ringwald */ 83d68b9e47SMatthias Ringwald uint16_t att_db_util_add_secondary_service_uuid16(uint16_t uuid16); 84d68b9e47SMatthias Ringwald 85d68b9e47SMatthias Ringwald /** 86d68b9e47SMatthias Ringwald * @brief Add secondary service for 128-bit UUID 8791974b5bSMatthias Ringwald * @param uuid128 886b65794dSMilanka Ringwald * @return attribute handle for the new service definition 89d68b9e47SMatthias Ringwald */ 90d68b9e47SMatthias Ringwald uint16_t att_db_util_add_secondary_service_uuid128(const uint8_t * uuid128); 91d68b9e47SMatthias Ringwald 92d68b9e47SMatthias Ringwald /** 9391974b5bSMatthias Ringwald * @brief Add included service with 16-bit UUID 9491974b5bSMatthias Ringwald * @param start_group_handle 9591974b5bSMatthias Ringwald * @param end_group_handle 9691974b5bSMatthias Ringwald * @param uuid16 976b65794dSMilanka Ringwald * @return attribute handle for the new service definition 9891974b5bSMatthias Ringwald */ 9991974b5bSMatthias Ringwald uint16_t att_db_util_add_included_service_uuid16(uint16_t start_group_handle, uint16_t end_group_handle, uint16_t uuid16); 10091974b5bSMatthias Ringwald 10191974b5bSMatthias Ringwald /** 1023deb3ec6SMatthias Ringwald * @brief Add Characteristic with 16-bit UUID, properties, and data 103ff04bac7SMatthias Ringwald * @param uuid16 104ff04bac7SMatthias Ringwald * @param properties - see ATT_PROPERTY_* in src/bluetooth.h 105ff04bac7SMatthias Ringwald * @param read_permissions - see ATT_SECURITY_* in src/bluetooth.h 106ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h 107ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified 108ff04bac7SMatthias Ringwald * @param data_len 1096b65794dSMilanka Ringwald * @return attribute handle of the new characteristic value declaration 1109f28d85dSMatthias Ringwald * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD) 1119f28d85dSMatthias Ringwald * is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1 1123deb3ec6SMatthias Ringwald */ 113ff04bac7SMatthias 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); 1143deb3ec6SMatthias Ringwald 1153deb3ec6SMatthias Ringwald /** 1163deb3ec6SMatthias Ringwald * @brief Add Characteristic with 128-bit UUID, properties, and data 117ff04bac7SMatthias Ringwald * @param uuid128 118ff04bac7SMatthias Ringwald * @param properties - see ATT_PROPERTY_* in src/bluetooth.h 119ff04bac7SMatthias Ringwald * @param read_permissions - see ATT_SECURITY_* in src/bluetooth.h 120ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h 121ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified 122ff04bac7SMatthias Ringwald * @param data_len 1236b65794dSMilanka Ringwald * @return attribute handle of the new characteristic value declaration 1249f28d85dSMatthias Ringwald * @note If properties contains ATT_PROPERTY_NOTIFY or ATT_PROPERTY_INDICATE flags, a Client Configuration Characteristic Descriptor (CCCD) 1259f28d85dSMatthias Ringwald * is created as well. The attribute value handle of the CCCD is the attribute value handle plus 1 1263deb3ec6SMatthias Ringwald */ 127ff04bac7SMatthias 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); 1289f28d85dSMatthias Ringwald 1299f28d85dSMatthias Ringwald /** 13093493c27SMatthias Ringwald * @brief Add descriptor with 16-bit UUID, properties, and data 131ff04bac7SMatthias Ringwald * @param uuid16 132ff04bac7SMatthias Ringwald * @param properties - see ATT_PROPERTY_* in src/bluetooth.h 133ff04bac7SMatthias Ringwald * @param read_permissions - see ATT_SECURITY_* in src/bluetooth.h 134ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h 135ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified 136ff04bac7SMatthias Ringwald * @param data_len 1376b65794dSMilanka Ringwald * @return attribute handle of the new characteristic descriptor declaration 1389f28d85dSMatthias Ringwald */ 139ff04bac7SMatthias 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); 140ff04bac7SMatthias Ringwald 141ff04bac7SMatthias Ringwald /** 142ff04bac7SMatthias Ringwald * @brief Add descriptor with 128-bit UUID, properties, and data 14393493c27SMatthias Ringwald * @param uuid128 144ff04bac7SMatthias Ringwald * @param properties - see ATT_PROPERTY_* in src/bluetooth.h 145ff04bac7SMatthias Ringwald * @param read_permissions - see ATT_SECURITY_* in src/bluetooth.h 146ff04bac7SMatthias Ringwald * @param write_permissions - see ATT_SECURITY_* in src/bluetooth.h 147ff04bac7SMatthias Ringwald * @param data returned in read operations if ATT_PROPERTY_DYNAMIC is not specified 148ff04bac7SMatthias Ringwald * @param data_len 1496b65794dSMilanka Ringwald * @return attribute handle of the new characteristic descriptor declaration 150ff04bac7SMatthias Ringwald */ 151ff04bac7SMatthias 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); 1529f28d85dSMatthias Ringwald 1539f28d85dSMatthias Ringwald /** 1543deb3ec6SMatthias Ringwald * @brief Get address of constructed ATT DB 1553deb3ec6SMatthias Ringwald */ 1563deb3ec6SMatthias Ringwald uint8_t * att_db_util_get_address(void); 1573deb3ec6SMatthias Ringwald 1583deb3ec6SMatthias Ringwald /** 1593deb3ec6SMatthias Ringwald * @brief Get size of constructed ATT DB 1603deb3ec6SMatthias Ringwald */ 1613deb3ec6SMatthias Ringwald uint16_t att_db_util_get_size(void); 1623deb3ec6SMatthias Ringwald 163bc6b65c7SMatthias Ringwald /** 164bc6b65c7SMatthias Ringwald * @brief Get number of bytes that are included in GATT Database Hash 165bc6b65c7SMatthias Ringwald */ 166bc6b65c7SMatthias Ringwald uint16_t att_db_util_hash_len(void); 167bc6b65c7SMatthias Ringwald 16873843592SMatthias Ringwald /** 16973843592SMatthias Ringwald * @brief init generator for GATT Database Hash 17073843592SMatthias Ringwald */ 17173843592SMatthias Ringwald void att_db_util_hash_init(void); 17273843592SMatthias Ringwald 17373843592SMatthias Ringwald /** 17473843592SMatthias Ringwald * @brief get next byte from generator for GATT Database Hash 17573843592SMatthias Ringwald */ 17673843592SMatthias Ringwald uint8_t att_db_util_hash_get_next(void); 17773843592SMatthias Ringwald 178a4419cc8SMatthias Ringwald /** 179a4419cc8SMatthias Ringwald * @brief Calculate GATT Database Hash using crypto engine 180a4419cc8SMatthias Ringwald * @param request 181a4419cc8SMatthias Ringwald * @param db_hash 182a4419cc8SMatthias Ringwald * @param callback 183a4419cc8SMatthias Ringwald * @param callback_arg 184a4419cc8SMatthias Ringwald */ 185a4419cc8SMatthias Ringwald void att_db_util_hash_calc(btstack_crypto_aes128_cmac_t * request, uint8_t * db_hash, void (* callback)(void * arg), void * callback_arg); 186a4419cc8SMatthias Ringwald 1873deb3ec6SMatthias Ringwald /* API_END */ 1883deb3ec6SMatthias Ringwald 1893deb3ec6SMatthias Ringwald #if defined __cplusplus 1903deb3ec6SMatthias Ringwald } 1913deb3ec6SMatthias Ringwald #endif 1923deb3ec6SMatthias Ringwald #endif 193