1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /** 39 * interface to provide link key storage 40 */ 41 42 #ifndef BTSTACK_LINK_KEY_DB_H 43 #define BTSTACK_LINK_KEY_DB_H 44 45 #include "bluetooth.h" 46 47 #if defined __cplusplus 48 extern "C" { 49 #endif 50 51 typedef struct { 52 void * context; 53 } btstack_link_key_iterator_t; 54 55 /* API_START */ 56 typedef struct { 57 58 // management 59 60 /** 61 * @brief Open the Link Key DB 62 */ 63 void (*open)(void); 64 65 /** 66 * @brief Sets BD Addr of local Bluetooth Controller. 67 * @note Only needed if Bluetooth Controller can be swapped, e.g. USB Dongles on desktop systems 68 */ 69 void (*set_local_bd_addr)(bd_addr_t bd_addr); 70 71 /** 72 * @brief Close the Link Key DB 73 */ 74 void (*close)(void); 75 76 // get/set/delete link key 77 78 /** 79 * @brief Get Link Key for given address 80 * @param addr to lookup 81 * @param link_key (out) 82 * @param type (out) 83 * @returns 1 on success 84 */ 85 int (*get_link_key)(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * type); 86 87 /** 88 * @brief Update/Store Link key 89 * @brief addr 90 * @brief link_key 91 * @brief type of link key 92 */ 93 void (*put_link_key)(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t type); 94 95 /** 96 * @brief Delete Link Keys 97 * @brief addr 98 */ 99 void (*delete_link_key)(bd_addr_t bd_addr); 100 101 // iterator: it's allowed to delete 102 103 /** 104 * @brief Setup iterator 105 * @param it 106 * @returns 1 on success 107 */ 108 int (*iterator_init)(btstack_link_key_iterator_t * it); 109 110 /** 111 * @brief Get next Link Key 112 * @param it 113 * @brief addr 114 * @brief link_key 115 * @brief type of link key 116 * @returns 1, if valid link key found 117 */ 118 int (*iterator_get_next)(btstack_link_key_iterator_t * it, bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * type); 119 120 /** 121 * @brief Frees resources allocated by iterator_init 122 * @note Must be called after iteration to free resources 123 * @param it 124 */ 125 void (*iterator_done)(btstack_link_key_iterator_t * it); 126 127 } btstack_link_key_db_t; 128 129 /* API_END */ 130 131 #if defined __cplusplus 132 } 133 #endif 134 135 #endif // BTSTACK_LINK_KEY_DB_H 136