1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __BTC_STORAGE_H__
16 #define __BTC_STORAGE_H__
17 
18 #include <stdint.h>
19 #include "common/bt_defs.h"
20 #include "stack/bt_types.h"
21 #include "esp_gap_bt_api.h"
22 
23 
24 #define BTC_STORAGE_DEV_CLASS_STR       "DevClass"
25 #define BTC_STORAGE_LINK_KEY_STR        "LinkKey"    /* same as the ble */
26 #define BTC_STORAGE_LINK_KEY_TYPE_STR   "LinkKeyType"
27 #define BTC_STORAGE_PIN_LENGTH_STR      "PinLength"
28 #define BTC_STORAGE_SC_SUPPORT          "SCSupport"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*******************************************************************************
35 **
36 ** Function         btc_storage_add_bonded_device
37 **
38 ** Description      BTC storage API - Adds the newly bonded device to NVRAM
39 **                  along with the link-key, Key type and Pin key length
40 **
41 ** Returns          BT_STATUS_SUCCESS if the store was successful,
42 **                  BT_STATUS_FAIL otherwise
43 **
44 *******************************************************************************/
45 bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
46         LINK_KEY link_key,
47         uint8_t key_type,
48         uint8_t pin_length,
49         BOOLEAN sc_support);
50 
51 /*******************************************************************************
52 **
53 ** Function         btc_storage_remove_bonded_device
54 **
55 ** Description      BTC storage API - Deletes the bonded device from NVRAM
56 **
57 ** Returns          BT_STATUS_SUCCESS if the deletion was successful,
58 **                  BT_STATUS_FAIL otherwise
59 **
60 *******************************************************************************/
61 bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr);
62 
63 /*******************************************************************************
64 **
65 ** Function         btc_storage_remove_bonded_device
66 **
67 ** Description      BTC storage API - Deletes the bonded device from NVRAM
68 **
69 ** Returns          BT_STATUS_SUCCESS if the deletion was successful,
70 **                  BT_STATUS_FAIL otherwise
71 **
72 *******************************************************************************/
73 bt_status_t btc_storage_load_bonded_devices(void);
74 
75 /*******************************************************************************
76 **
77 ** Function         btc_storage_get_num_bt_bond_devices
78 **
79 ** Description      BTC storage API - get the num of the bonded device from NVRAM
80 **
81 ** Returns          the num of the bonded device
82 **
83 *******************************************************************************/
84 int btc_storage_get_num_bt_bond_devices(void);
85 
86 /*******************************************************************************
87 **
88 ** Function         btc_storage_get_bonded_bt_devices_list
89 **
90 ** Description      BTC storage API - get the list of the bonded device from NVRAM
91 **
92 ** Returns          BT_STATUS_SUCCESS if get the list successful,
93 **                  BT_STATUS_FAIL otherwise
94 **
95 *******************************************************************************/
96 bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *dev_num);
97 
98 #if (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE)
99 /*******************************************************************************
100  *
101  * Function         btc_storage_add_hid_device_info
102  *
103  * Description      BTC storage API - Adds the hid information of bonded hid
104  *                  devices-to NVRAM
105  *
106  * Returns          BT_STATUS_SUCCESS if the store was successful,
107  *                  BT_STATUS_FAIL otherwise
108  *
109  ******************************************************************************/
110 
111 bt_status_t btc_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, uint16_t attr_mask, uint8_t sub_class,
112                                              uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
113                                              uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
114                                              uint16_t dl_len, uint8_t *dsc_list);
115 
116 /*******************************************************************************
117  *
118  * Function         btc_storage_load_bonded_hid_info
119  *
120  * Description      BTIF storage API - Loads hid info for all the bonded devices
121  *                  from NVRAM and adds those devices  to the BTA_HH.
122  *
123  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
124  *
125  ******************************************************************************/
126 bt_status_t btc_storage_load_bonded_hid_info(void);
127 
128 /*******************************************************************************
129  *
130  * Function         btc_storage_remove_hid_info
131  *
132  * Description      BTC storage API - Deletes the bonded hid device info from
133  *                  NVRAM
134  *
135  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
136  *                  BT_STATUS_FAIL otherwise
137  *
138  ******************************************************************************/
139 bt_status_t btc_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr);
140 #endif // (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE)
141 
142 #if (defined BTC_HD_INCLUDED && BTC_HD_INCLUDED == TRUE)
143 /*******************************************************************************
144  * Function         btc_storage_load_hidd
145  *
146  * Description      Loads hidd bonded device and "plugs" it into hidd
147  *
148  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
149  *
150  ******************************************************************************/
151 bt_status_t btc_storage_load_hidd(void);
152 
153 /*******************************************************************************
154  *
155  * Function         btc_storage_set_hidd
156  *
157  * Description      Stores hidd bonded device info in nvram.
158  *
159  * Returns          BT_STATUS_SUCCESS
160  *
161  ******************************************************************************/
162 bt_status_t btc_storage_set_hidd(bt_bdaddr_t *remote_bd_addr);
163 
164 /*******************************************************************************
165  *
166  * Function         btc_storage_remove_hidd
167  *
168  * Description      Removes hidd bonded device info from nvram
169  *
170  * Returns          BT_STATUS_SUCCESS
171  *
172  ******************************************************************************/
173 bt_status_t btc_storage_remove_hidd(bt_bdaddr_t *remote_bd_addr);
174 #endif //(defined BTC_HD_INCLUDED && BTC_HD_INCLUDED == TRUE)
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* BTC_STORAGE_H */
180