• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef BTIF_STORAGE_H
20 #define BTIF_STORAGE_H
21 
22 #include <hardware/bluetooth.h>
23 
24 #include "bt_target.h"
25 #include "bt_types.h"
26 
27 /*******************************************************************************
28  *  Constants & Macros
29  ******************************************************************************/
30 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
31   do {                                                \
32     (p_prop)->type = (t);                             \
33     (p_prop)->len = (l);                              \
34     (p_prop)->val = (p_v);                            \
35   } while (0)
36 
37 /*******************************************************************************
38  *  Functions
39  ******************************************************************************/
40 
41 /*******************************************************************************
42  *
43  * Function         btif_storage_get_adapter_property
44  *
45  * Description      BTIF storage API - Fetches the adapter property->type
46  *                  from NVRAM and fills property->val.
47  *                  Caller should provide memory for property->val and
48  *                  set the property->val
49  *
50  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
51  *                  BT_STATUS_FAIL otherwise
52  *
53  ******************************************************************************/
54 bt_status_t btif_storage_get_adapter_property(bt_property_t* property);
55 
56 /*******************************************************************************
57  *
58  * Function         btif_storage_set_adapter_property
59  *
60  * Description      BTIF storage API - Stores the adapter property
61  *                  to NVRAM
62  *
63  * Returns          BT_STATUS_SUCCESS if the store was successful,
64  *                  BT_STATUS_FAIL otherwise
65  *
66  ******************************************************************************/
67 bt_status_t btif_storage_set_adapter_property(bt_property_t* property);
68 
69 /*******************************************************************************
70  *
71  * Function         btif_storage_get_remote_device_property
72  *
73  * Description      BTIF storage API - Fetches the remote device property->type
74  *                  from NVRAM and fills property->val.
75  *                  Caller should provide memory for property->val and
76  *                  set the property->val
77  *
78  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
79  *                  BT_STATUS_FAIL otherwise
80  *
81  ******************************************************************************/
82 bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t* remote_bd_addr,
83                                                     bt_property_t* property);
84 
85 /*******************************************************************************
86  *
87  * Function         btif_storage_set_remote_device_property
88  *
89  * Description      BTIF storage API - Stores the remote device property
90  *                  to NVRAM
91  *
92  * Returns          BT_STATUS_SUCCESS if the store was successful,
93  *                  BT_STATUS_FAIL otherwise
94  *
95  ******************************************************************************/
96 bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t* remote_bd_addr,
97                                                     bt_property_t* property);
98 
99 /*******************************************************************************
100  *
101  * Function         btif_storage_add_remote_device
102  *
103  * Description      BTIF storage API - Adds a newly discovered device to
104  *                  track along with the timestamp. Also, stores the various
105  *                  properties - RSSI, BDADDR, NAME (if found in EIR)
106  *
107  * Returns          BT_STATUS_SUCCESS if successful,
108  *                  BT_STATUS_FAIL otherwise
109  *
110  ******************************************************************************/
111 bt_status_t btif_storage_add_remote_device(bt_bdaddr_t* remote_bd_addr,
112                                            uint32_t num_properties,
113                                            bt_property_t* properties);
114 
115 /*******************************************************************************
116  *
117  * Function         btif_storage_add_bonded_device
118  *
119  * Description      BTIF storage API - Adds the newly bonded device to NVRAM
120  *                  along with the link-key, Key type and Pin key length
121  *
122  * Returns          BT_STATUS_SUCCESS if the store was successful,
123  *                  BT_STATUS_FAIL otherwise
124  *
125  ******************************************************************************/
126 bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t* remote_bd_addr,
127                                            LINK_KEY link_key, uint8_t key_type,
128                                            uint8_t pin_length);
129 
130 /*******************************************************************************
131  *
132  * Function         btif_storage_remove_bonded_device
133  *
134  * Description      BTIF storage API - Deletes the bonded device from NVRAM
135  *
136  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
137  *                  BT_STATUS_FAIL otherwise
138  *
139  ******************************************************************************/
140 bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t* remote_bd_addr);
141 
142 /*******************************************************************************
143  *
144  * Function         btif_storage_remove_bonded_device
145  *
146  * Description      BTIF storage API - Deletes the bonded device from NVRAM
147  *
148  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
149  *                  BT_STATUS_FAIL otherwise
150  *
151  ******************************************************************************/
152 bt_status_t btif_storage_load_bonded_devices(void);
153 
154 /*******************************************************************************
155  *
156  * Function         btif_storage_add_hid_device_info
157  *
158  * Description      BTIF storage API - Adds the hid information of bonded hid
159  *                  devices-to NVRAM
160  *
161  * Returns          BT_STATUS_SUCCESS if the store was successful,
162  *                  BT_STATUS_FAIL otherwise
163  *
164  ******************************************************************************/
165 
166 bt_status_t btif_storage_add_hid_device_info(
167     bt_bdaddr_t* remote_bd_addr, uint16_t attr_mask, uint8_t sub_class,
168     uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
169     uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
170     uint16_t dl_len, uint8_t* dsc_list);
171 
172 /*******************************************************************************
173  *
174  * Function         btif_storage_load_bonded_hid_info
175  *
176  * Description      BTIF storage API - Loads hid info for all the bonded devices
177  *                  from NVRAM and adds those devices  to the BTA_HH.
178  *
179  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
180  *
181  ******************************************************************************/
182 bt_status_t btif_storage_load_bonded_hid_info(void);
183 
184 /*******************************************************************************
185  *
186  * Function         btif_storage_remove_hid_info
187  *
188  * Description      BTIF storage API - Deletes the bonded hid device info from
189  *                  NVRAM
190  *
191  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
192  *                  BT_STATUS_FAIL otherwise
193  *
194  ******************************************************************************/
195 bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t* remote_bd_addr);
196 
197 /*******************************************************************************
198  *
199  * Function         btif_storage_is_retricted_device
200  *
201  * Description      BTIF storage API - checks if this device is a restricted
202  *                  device
203  *
204  * Returns          true  if the device is labled as restricted
205  *                  false otherwise
206  *
207  ******************************************************************************/
208 bool btif_storage_is_restricted_device(const bt_bdaddr_t* remote_bd_addr);
209 
210 bt_status_t btif_storage_add_ble_bonding_key(bt_bdaddr_t* remote_bd_addr,
211                                              char* key, uint8_t key_type,
212                                              uint8_t key_length);
213 bt_status_t btif_storage_get_ble_bonding_key(bt_bdaddr_t* remote_bd_addr,
214                                              uint8_t key_type, char* key_value,
215                                              int key_length);
216 
217 bt_status_t btif_storage_add_ble_local_key(char* key, uint8_t key_type,
218                                            uint8_t key_length);
219 bt_status_t btif_storage_remove_ble_bonding_keys(bt_bdaddr_t* remote_bd_addr);
220 bt_status_t btif_storage_remove_ble_local_keys(void);
221 bt_status_t btif_storage_get_ble_local_key(uint8_t key_type, char* key_value,
222                                            int key_len);
223 
224 bt_status_t btif_storage_get_remote_addr_type(bt_bdaddr_t* remote_bd_addr,
225                                               int* addr_type);
226 
227 bt_status_t btif_storage_set_remote_addr_type(bt_bdaddr_t* remote_bd_addr,
228                                               uint8_t addr_type);
229 
230 /*******************************************************************************
231  * Function         btif_storage_load_hidd
232  *
233  * Description      Loads hidd bonded device and "plugs" it into hidd
234  *
235  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
236  *
237  ******************************************************************************/
238 bt_status_t btif_storage_load_hidd(void);
239 
240 /*******************************************************************************
241  *
242  * Function         btif_storage_set_hidd
243  *
244  * Description      Stores hidd bonded device info in nvram.
245  *
246  * Returns          BT_STATUS_SUCCESS
247  *
248  ******************************************************************************/
249 
250 bt_status_t btif_storage_set_hidd(bt_bdaddr_t* remote_bd_addr);
251 
252 /*******************************************************************************
253  *
254  * Function         btif_storage_remove_hidd
255  *
256  * Description      Removes hidd bonded device info from nvram
257  *
258  * Returns          BT_STATUS_SUCCESS
259  *
260  ******************************************************************************/
261 
262 bt_status_t btif_storage_remove_hidd(bt_bdaddr_t* remote_bd_addr);
263 
264 // Gets the device name for a given Bluetooth address |bd_addr|.
265 // The device name (if found) is stored in |name|.
266 // Returns true if the device name is found, othervise false.
267 // Note: |name| should point to a buffer that can store string of length
268 // |BTM_MAX_REM_BD_NAME_LEN|.
269 bool btif_storage_get_stored_remote_name(const bt_bdaddr_t& bd_addr,
270                                          char* name);
271 
272 /******************************************************************************
273  * Exported for unit tests
274  *****************************************************************************/
275 size_t btif_split_uuids_string(const char* str, bt_uuid_t* p_uuid,
276                                size_t max_uuids);
277 
278 #endif /* BTIF_STORAGE_H */
279