xref: /btstack/src/classic/btstack_link_key_db.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
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
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,
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 /**
39fe5a6c4eSMilanka Ringwald  * @title Link Key DB
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  * Interface to provide link key storage.
42fe5a6c4eSMilanka Ringwald  *
43a98592bcSMatthias Ringwald  */
44a98592bcSMatthias Ringwald 
4580e33422SMatthias Ringwald #ifndef BTSTACK_LINK_KEY_DB_H
4680e33422SMatthias Ringwald #define BTSTACK_LINK_KEY_DB_H
47a98592bcSMatthias Ringwald 
488974fcd6SMatthias Ringwald #include "bluetooth.h"
49a98592bcSMatthias Ringwald 
50a98592bcSMatthias Ringwald #if defined __cplusplus
51a98592bcSMatthias Ringwald extern "C" {
52a98592bcSMatthias Ringwald #endif
53a98592bcSMatthias Ringwald 
5492369ee0SMatthias Ringwald typedef struct {
5592369ee0SMatthias Ringwald 	void * context;
5692369ee0SMatthias Ringwald } btstack_link_key_iterator_t;
57a98592bcSMatthias Ringwald 
5892369ee0SMatthias Ringwald /* API_START */
59a98592bcSMatthias Ringwald typedef struct {
60a98592bcSMatthias Ringwald 
61a98592bcSMatthias Ringwald     // management
6292369ee0SMatthias Ringwald 
6392369ee0SMatthias Ringwald     /**
6492369ee0SMatthias Ringwald      * @brief Open the Link Key DB
6592369ee0SMatthias Ringwald      */
66a98592bcSMatthias Ringwald     void (*open)(void);
6792369ee0SMatthias Ringwald 
6892369ee0SMatthias Ringwald     /**
6992369ee0SMatthias Ringwald      * @brief Sets BD Addr of local Bluetooth Controller.
7092369ee0SMatthias Ringwald      * @note Only needed if Bluetooth Controller can be swapped, e.g. USB Dongles on desktop systems
7192369ee0SMatthias Ringwald      */
721624665aSMatthias Ringwald     void (*set_local_bd_addr)(bd_addr_t bd_addr);
7392369ee0SMatthias Ringwald 
7492369ee0SMatthias Ringwald     /**
7592369ee0SMatthias Ringwald      * @brief Close the Link Key DB
7692369ee0SMatthias Ringwald      */
77a98592bcSMatthias Ringwald     void (*close)(void);
78a98592bcSMatthias Ringwald 
7992369ee0SMatthias Ringwald     // get/set/delete link key
8092369ee0SMatthias Ringwald 
8192369ee0SMatthias Ringwald     /**
8292369ee0SMatthias Ringwald      * @brief Get Link Key for given address
8392369ee0SMatthias Ringwald      * @param addr to lookup
8492369ee0SMatthias Ringwald      * @param link_key (out)
8592369ee0SMatthias Ringwald      * @param type (out)
866b65794dSMilanka Ringwald      * @return 1 on success
8792369ee0SMatthias Ringwald      */
88a98592bcSMatthias Ringwald     int  (*get_link_key)(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * type);
8992369ee0SMatthias Ringwald 
9092369ee0SMatthias Ringwald     /**
9192369ee0SMatthias Ringwald      * @brief Update/Store Link key
9292369ee0SMatthias Ringwald      * @brief addr
9392369ee0SMatthias Ringwald      * @brief link_key
9492369ee0SMatthias Ringwald      * @brief type of link key
9592369ee0SMatthias Ringwald      */
96a98592bcSMatthias Ringwald     void (*put_link_key)(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t type);
9792369ee0SMatthias Ringwald 
9892369ee0SMatthias Ringwald     /**
9992369ee0SMatthias Ringwald      * @brief Delete Link Keys
10092369ee0SMatthias Ringwald      * @brief addr
10192369ee0SMatthias Ringwald      */
102a98592bcSMatthias Ringwald     void (*delete_link_key)(bd_addr_t bd_addr);
103a98592bcSMatthias Ringwald 
10492369ee0SMatthias Ringwald     // iterator: it's allowed to delete
10592369ee0SMatthias Ringwald 
10692369ee0SMatthias Ringwald     /**
10792369ee0SMatthias Ringwald      * @brief Setup iterator
10892369ee0SMatthias Ringwald      * @param it
1096b65794dSMilanka Ringwald      * @return 1 on success
11092369ee0SMatthias Ringwald      */
11192369ee0SMatthias Ringwald     int (*iterator_init)(btstack_link_key_iterator_t * it);
11292369ee0SMatthias Ringwald 
11392369ee0SMatthias Ringwald     /**
11492369ee0SMatthias Ringwald      * @brief Get next Link Key
11592369ee0SMatthias Ringwald      * @param it
11692369ee0SMatthias Ringwald      * @brief addr
11792369ee0SMatthias Ringwald      * @brief link_key
11892369ee0SMatthias Ringwald      * @brief type of link key
1196b65794dSMilanka Ringwald      * @return 1, if valid link key found
12092369ee0SMatthias Ringwald      */
12192369ee0SMatthias 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);
12292369ee0SMatthias Ringwald 
12392369ee0SMatthias Ringwald     /**
12492369ee0SMatthias Ringwald      * @brief Frees resources allocated by iterator_init
12592369ee0SMatthias Ringwald      * @note Must be called after iteration to free resources
12692369ee0SMatthias Ringwald      * @param it
12792369ee0SMatthias Ringwald      */
12892369ee0SMatthias Ringwald     void (*iterator_done)(btstack_link_key_iterator_t * it);
12992369ee0SMatthias Ringwald 
130a98592bcSMatthias Ringwald } btstack_link_key_db_t;
131a98592bcSMatthias Ringwald 
132a98592bcSMatthias Ringwald /* API_END */
133a98592bcSMatthias Ringwald 
134a98592bcSMatthias Ringwald #if defined __cplusplus
135a98592bcSMatthias Ringwald }
136a98592bcSMatthias Ringwald #endif
137a98592bcSMatthias Ringwald 
13880e33422SMatthias Ringwald #endif // BTSTACK_LINK_KEY_DB_H
139