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