• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 <bluetooth/uuid.h>
23 #include <hardware/bluetooth.h>
24 
25 #include "bt_target.h"
26 #include "bt_types.h"
27 
28 /*******************************************************************************
29  *  Constants & Macros
30  ******************************************************************************/
31 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
32   do {                                                \
33     (p_prop)->type = (t);                             \
34     (p_prop)->len = (l);                              \
35     (p_prop)->val = (p_v);                            \
36   } while (0)
37 
38 /*******************************************************************************
39  *  Functions
40  ******************************************************************************/
41 
42 /*******************************************************************************
43  *
44  * Function         btif_storage_get_adapter_property
45  *
46  * Description      BTIF storage API - Fetches the adapter property->type
47  *                  from NVRAM and fills property->val.
48  *                  Caller should provide memory for property->val and
49  *                  set the property->val
50  *
51  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
52  *                  BT_STATUS_FAIL otherwise
53  *
54  ******************************************************************************/
55 bt_status_t btif_storage_get_adapter_property(bt_property_t* property);
56 
57 /*******************************************************************************
58  *
59  * Function         btif_storage_set_adapter_property
60  *
61  * Description      BTIF storage API - Stores the adapter property
62  *                  to NVRAM
63  *
64  * Returns          BT_STATUS_SUCCESS if the store was successful,
65  *                  BT_STATUS_FAIL otherwise
66  *
67  ******************************************************************************/
68 bt_status_t btif_storage_set_adapter_property(bt_property_t* property);
69 
70 /*******************************************************************************
71  *
72  * Function         btif_storage_get_remote_device_property
73  *
74  * Description      BTIF storage API - Fetches the remote device property->type
75  *                  from NVRAM and fills property->val.
76  *                  Caller should provide memory for property->val and
77  *                  set the property->val
78  *
79  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
80  *                  BT_STATUS_FAIL otherwise
81  *
82  ******************************************************************************/
83 bt_status_t btif_storage_get_remote_device_property(
84     const RawAddress* remote_bd_addr, bt_property_t* property);
85 
86 /*******************************************************************************
87  *
88  * Function         btif_storage_set_remote_device_property
89  *
90  * Description      BTIF storage API - Stores the remote device property
91  *                  to NVRAM
92  *
93  * Returns          BT_STATUS_SUCCESS if the store was successful,
94  *                  BT_STATUS_FAIL otherwise
95  *
96  ******************************************************************************/
97 bt_status_t btif_storage_set_remote_device_property(
98     const RawAddress* remote_bd_addr, bt_property_t* property);
99 
100 /*******************************************************************************
101  *
102  * Function         btif_storage_get_io_caps
103  *
104  * Description      BTIF storage API - Fetches the local Input/Output
105  *                  capabilities of the device.
106  *
107  * Returns          Returns local IO Capability of device. If not stored,
108  *                  returns BTM_LOCAL_IO_CAPS.
109  *
110  ******************************************************************************/
111 uint8_t btif_storage_get_local_io_caps();
112 
113 /*******************************************************************************
114  *
115  * Function         btif_storage_get_io_caps_ble
116  *
117  * Description      BTIF storage API - Fetches the local Input/Output
118  *                  capabilities of the BLE device.
119  *
120  * Returns          Returns local IO Capability of BLE device. If not stored,
121  *                  returns BTM_LOCAL_IO_CAPS_BLE.
122  *
123  ******************************************************************************/
124 uint8_t btif_storage_get_local_io_caps_ble();
125 
126 /*******************************************************************************
127  *
128  * Function         btif_storage_add_remote_device
129  *
130  * Description      BTIF storage API - Adds a newly discovered device to
131  *                  track along with the timestamp. Also, stores the various
132  *                  properties - RSSI, BDADDR, NAME (if found in EIR)
133  *
134  * Returns          BT_STATUS_SUCCESS if successful,
135  *                  BT_STATUS_FAIL otherwise
136  *
137  ******************************************************************************/
138 bt_status_t btif_storage_add_remote_device(const RawAddress* remote_bd_addr,
139                                            uint32_t num_properties,
140                                            bt_property_t* properties);
141 
142 /*******************************************************************************
143  *
144  * Function         btif_storage_add_bonded_device
145  *
146  * Description      BTIF storage API - Adds the newly bonded device to NVRAM
147  *                  along with the link-key, Key type and Pin key length
148  *
149  * Returns          BT_STATUS_SUCCESS if the store was successful,
150  *                  BT_STATUS_FAIL otherwise
151  *
152  ******************************************************************************/
153 bt_status_t btif_storage_add_bonded_device(RawAddress* remote_bd_addr,
154                                            LinkKey link_key, uint8_t key_type,
155                                            uint8_t pin_length);
156 
157 /*******************************************************************************
158  *
159  * Function         btif_storage_remove_bonded_device
160  *
161  * Description      BTIF storage API - Deletes the bonded device from NVRAM
162  *
163  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
164  *                  BT_STATUS_FAIL otherwise
165  *
166  ******************************************************************************/
167 bt_status_t btif_storage_remove_bonded_device(const RawAddress* remote_bd_addr);
168 
169 /*******************************************************************************
170  *
171  * Function         btif_storage_remove_bonded_device
172  *
173  * Description      BTIF storage API - Deletes the bonded device from NVRAM
174  *
175  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
176  *                  BT_STATUS_FAIL otherwise
177  *
178  ******************************************************************************/
179 bt_status_t btif_storage_load_bonded_devices(void);
180 
181 /*******************************************************************************
182  *
183  * Function         btif_storage_add_hid_device_info
184  *
185  * Description      BTIF storage API - Adds the hid information of bonded hid
186  *                  devices-to NVRAM
187  *
188  * Returns          BT_STATUS_SUCCESS if the store was successful,
189  *                  BT_STATUS_FAIL otherwise
190  *
191  ******************************************************************************/
192 
193 bt_status_t btif_storage_add_hid_device_info(
194     RawAddress* remote_bd_addr, uint16_t attr_mask, uint8_t sub_class,
195     uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
196     uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
197     uint16_t dl_len, uint8_t* dsc_list);
198 
199 /*******************************************************************************
200  *
201  * Function         btif_storage_load_bonded_hid_info
202  *
203  * Description      BTIF storage API - Loads hid info for all the bonded devices
204  *                  from NVRAM and adds those devices  to the BTA_HH.
205  *
206  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
207  *
208  ******************************************************************************/
209 bt_status_t btif_storage_load_bonded_hid_info(void);
210 
211 /*******************************************************************************
212  *
213  * Function         btif_storage_remove_hid_info
214  *
215  * Description      BTIF storage API - Deletes the bonded hid device info from
216  *                  NVRAM
217  *
218  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
219  *                  BT_STATUS_FAIL otherwise
220  *
221  ******************************************************************************/
222 bt_status_t btif_storage_remove_hid_info(RawAddress* remote_bd_addr);
223 
224 /** Loads information about bonded hearing aid devices */
225 void btif_storage_load_bonded_hearing_aids();
226 
227 /** Deletes the bonded hearing aid device info from NVRAM */
228 void btif_storage_remove_hearing_aid(const RawAddress& address);
229 
230 /** Set/Unset the hearing aid device HEARING_AID_IS_WHITE_LISTED flag. */
231 void btif_storage_set_hearing_aid_white_list(const RawAddress& address,
232                                              bool add_to_whitelist);
233 
234 /** Get the hearing aid device properties. */
235 bool btif_storage_get_hearing_aid_prop(
236     const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
237     uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs);
238 
239 /*******************************************************************************
240  *
241  * Function         btif_storage_is_retricted_device
242  *
243  * Description      BTIF storage API - checks if this device is a restricted
244  *                  device
245  *
246  * Returns          true  if the device is labled as restricted
247  *                  false otherwise
248  *
249  ******************************************************************************/
250 bool btif_storage_is_restricted_device(const RawAddress* remote_bd_addr);
251 
252 int btif_storage_get_num_bonded_devices(void);
253 
254 bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr,
255                                              const uint8_t* key,
256                                              uint8_t key_type,
257                                              uint8_t key_length);
258 bt_status_t btif_storage_get_ble_bonding_key(RawAddress* remote_bd_addr,
259                                              uint8_t key_type,
260                                              uint8_t* key_value,
261                                              int key_length);
262 
263 bt_status_t btif_storage_add_ble_local_key(const Octet16& key,
264                                            uint8_t key_type);
265 bt_status_t btif_storage_remove_ble_bonding_keys(
266     const RawAddress* remote_bd_addr);
267 bt_status_t btif_storage_remove_ble_local_keys(void);
268 bt_status_t btif_storage_get_ble_local_key(uint8_t key_type,
269                                            Octet16* key_value);
270 
271 bt_status_t btif_storage_get_remote_addr_type(const RawAddress* remote_bd_addr,
272                                               int* addr_type);
273 
274 bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr,
275                                               uint8_t addr_type);
276 
277 /*******************************************************************************
278  * Function         btif_storage_load_hidd
279  *
280  * Description      Loads hidd bonded device and "plugs" it into hidd
281  *
282  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
283  *
284  ******************************************************************************/
285 bt_status_t btif_storage_load_hidd(void);
286 
287 /*******************************************************************************
288  *
289  * Function         btif_storage_set_hidd
290  *
291  * Description      Stores hidd bonded device info in nvram.
292  *
293  * Returns          BT_STATUS_SUCCESS
294  *
295  ******************************************************************************/
296 
297 bt_status_t btif_storage_set_hidd(RawAddress* remote_bd_addr);
298 
299 /*******************************************************************************
300  *
301  * Function         btif_storage_remove_hidd
302  *
303  * Description      Removes hidd bonded device info from nvram
304  *
305  * Returns          BT_STATUS_SUCCESS
306  *
307  ******************************************************************************/
308 
309 bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr);
310 
311 // Gets the device name for a given Bluetooth address |bd_addr|.
312 // The device name (if found) is stored in |name|.
313 // Returns true if the device name is found, othervise false.
314 // Note: |name| should point to a buffer that can store string of length
315 // |BTM_MAX_REM_BD_NAME_LEN|.
316 bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name);
317 
318 /******************************************************************************
319  * Exported for unit tests
320  *****************************************************************************/
321 size_t btif_split_uuids_string(const char* str, bluetooth::Uuid* p_uuid,
322                                size_t max_uuids);
323 
324 #endif /* BTIF_STORAGE_H */
325