• 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 "stack/include/bt_device_type.h"
27 #include "stack/include/bt_octets.h"
28 #include "types/ble_address_with_type.h"
29 #include "types/raw_address.h"
30 
31 /*******************************************************************************
32  *  Constants & Macros
33  ******************************************************************************/
34 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
35   do {                                                \
36     (p_prop)->type = (t);                             \
37     (p_prop)->len = (l);                              \
38     (p_prop)->val = (p_v);                            \
39   } while (0)
40 
41 /*******************************************************************************
42  *  Functions
43  ******************************************************************************/
44 
45 /*******************************************************************************
46  *
47  * Function         btif_storage_get_adapter_property
48  *
49  * Description      BTIF storage API - Fetches the adapter property->type
50  *                  from NVRAM and fills property->val.
51  *                  Caller should provide memory for property->val and
52  *                  set the property->val
53  *
54  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
55  *                  BT_STATUS_FAIL otherwise
56  *
57  ******************************************************************************/
58 bt_status_t btif_storage_get_adapter_property(bt_property_t* property);
59 
60 /*******************************************************************************
61  *
62  * Function         btif_storage_set_adapter_property
63  *
64  * Description      BTIF storage API - Stores the adapter property
65  *                  to NVRAM
66  *
67  * Returns          BT_STATUS_SUCCESS if the store was successful,
68  *                  BT_STATUS_FAIL otherwise
69  *
70  ******************************************************************************/
71 bt_status_t btif_storage_set_adapter_property(bt_property_t* property);
72 
73 /*******************************************************************************
74  *
75  * Function         btif_storage_get_remote_device_property
76  *
77  * Description      BTIF storage API - Fetches the remote device property->type
78  *                  from NVRAM and fills property->val.
79  *                  Caller should provide memory for property->val and
80  *                  set the property->val
81  *
82  * Returns          BT_STATUS_SUCCESS if the fetch was successful,
83  *                  BT_STATUS_FAIL otherwise
84  *
85  ******************************************************************************/
86 bt_status_t btif_storage_get_remote_device_property(
87     const RawAddress* remote_bd_addr, bt_property_t* property);
88 
89 /*******************************************************************************
90  *
91  * Function         btif_storage_set_remote_device_property
92  *
93  * Description      BTIF storage API - Stores the remote device property
94  *                  to NVRAM
95  *
96  * Returns          BT_STATUS_SUCCESS if the store was successful,
97  *                  BT_STATUS_FAIL otherwise
98  *
99  ******************************************************************************/
100 bt_status_t btif_storage_set_remote_device_property(
101     const RawAddress* remote_bd_addr, bt_property_t* property);
102 
103 /*******************************************************************************
104  *
105  * Function         btif_storage_get_io_caps
106  *
107  * Description      BTIF storage API - Fetches the local Input/Output
108  *                  capabilities of the device.
109  *
110  * Returns          Returns local IO Capability of device. If not stored,
111  *                  returns BTM_LOCAL_IO_CAPS.
112  *
113  ******************************************************************************/
114 uint8_t btif_storage_get_local_io_caps();
115 
116 /*******************************************************************************
117  *
118  * Function         btif_storage_get_io_caps_ble
119  *
120  * Description      BTIF storage API - Fetches the local Input/Output
121  *                  capabilities of the BLE device.
122  *
123  * Returns          Returns local IO Capability of BLE device. If not stored,
124  *                  returns BTM_LOCAL_IO_CAPS_BLE.
125  *
126  ******************************************************************************/
127 uint8_t btif_storage_get_local_io_caps_ble();
128 
129 /*******************************************************************************
130  *
131  * Function         btif_storage_add_remote_device
132  *
133  * Description      BTIF storage API - Adds a newly discovered device to
134  *                  track along with the timestamp. Also, stores the various
135  *                  properties - RSSI, BDADDR, NAME (if found in EIR)
136  *
137  * Returns          BT_STATUS_SUCCESS if successful,
138  *                  BT_STATUS_FAIL otherwise
139  *
140  ******************************************************************************/
141 bt_status_t btif_storage_add_remote_device(const RawAddress* remote_bd_addr,
142                                            uint32_t num_properties,
143                                            bt_property_t* properties);
144 
145 /*******************************************************************************
146  *
147  * Function         btif_storage_add_bonded_device
148  *
149  * Description      BTIF storage API - Adds the newly bonded device to NVRAM
150  *                  along with the link-key, Key type and Pin key length
151  *
152  * Returns          BT_STATUS_SUCCESS if the store was successful,
153  *                  BT_STATUS_FAIL otherwise
154  *
155  ******************************************************************************/
156 bt_status_t btif_storage_add_bonded_device(RawAddress* remote_bd_addr,
157                                            LinkKey link_key, uint8_t key_type,
158                                            uint8_t pin_length);
159 
160 /*******************************************************************************
161  *
162  * Function         btif_storage_remove_bonded_device
163  *
164  * Description      BTIF storage API - Deletes the bonded device from NVRAM
165  *
166  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
167  *                  BT_STATUS_FAIL otherwise
168  *
169  ******************************************************************************/
170 bt_status_t btif_storage_remove_bonded_device(const RawAddress* remote_bd_addr);
171 
172 /*******************************************************************************
173  *
174  * Function         btif_storage_load_le_devices
175  *
176  * Description      BTIF storage API - Loads all LE-only and Dual Mode devices
177  *                  from NVRAM. This API invokes the adaper_properties_cb.
178  *                  It also invokes invoke_address_consolidate_cb
179  *                  to consolidate each Dual Mode device and
180  *                  invoke_le_address_associate_cb to associate each LE-only
181  *                  device between its RPA and identity address.
182  *
183  ******************************************************************************/
184 void btif_storage_load_le_devices(void);
185 
186 /*******************************************************************************
187  *
188  * Function         btif_storage_load_bonded_devices
189  *
190  * Description      BTIF storage API - Loads all the bonded devices from NVRAM
191  *                  and adds to the BTA.
192  *                  Additionally, this API also invokes the adaper_properties_cb
193  *                  and remote_device_properties_cb for each of the bonded
194  *                  devices.
195  *
196  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
197  *
198  ******************************************************************************/
199 bt_status_t btif_storage_load_bonded_devices(void);
200 
201 /*******************************************************************************
202  *
203  * Function         btif_storage_add_hid_device_info
204  *
205  * Description      BTIF storage API - Adds the hid information of bonded hid
206  *                  devices-to NVRAM
207  *
208  * Returns          BT_STATUS_SUCCESS if the store was successful,
209  *                  BT_STATUS_FAIL otherwise
210  *
211  ******************************************************************************/
212 
213 bt_status_t btif_storage_add_hid_device_info(
214     RawAddress* remote_bd_addr, uint16_t attr_mask, uint8_t sub_class,
215     uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
216     uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
217     uint16_t dl_len, uint8_t* dsc_list);
218 
219 /*******************************************************************************
220  *
221  * Function         btif_storage_load_bonded_hid_info
222  *
223  * Description      BTIF storage API - Loads hid info for all the bonded devices
224  *                  from NVRAM and adds those devices  to the BTA_HH.
225  *
226  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
227  *
228  ******************************************************************************/
229 bt_status_t btif_storage_load_bonded_hid_info(void);
230 
231 /*******************************************************************************
232  *
233  * Function         btif_storage_remove_hid_info
234  *
235  * Description      BTIF storage API - Deletes the bonded hid device info from
236  *                  NVRAM
237  *
238  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
239  *                  BT_STATUS_FAIL otherwise
240  *
241  ******************************************************************************/
242 bt_status_t btif_storage_remove_hid_info(const RawAddress& remote_bd_addr);
243 
244 /** Loads information about bonded hearing aid devices */
245 void btif_storage_load_bonded_hearing_aids();
246 
247 /** Deletes the bonded hearing aid device info from NVRAM */
248 void btif_storage_remove_hearing_aid(const RawAddress& address);
249 
250 /** Set/Unset the hearing aid device HEARING_AID_IS_ACCEPTLISTED flag. */
251 void btif_storage_set_hearing_aid_acceptlist(const RawAddress& address,
252                                              bool add_to_acceptlist);
253 
254 /** Stores information about GATT Client supported features support */
255 void btif_storage_set_gatt_cl_supp_feat(const RawAddress& bd_addr,
256                                         uint8_t feat);
257 
258 /** Get client supported features */
259 uint8_t btif_storage_get_gatt_cl_supp_feat(const RawAddress& bd_addr);
260 
261 /** Remove client supported features */
262 void btif_storage_remove_gatt_cl_supp_feat(const RawAddress& bd_addr);
263 
264 /** Stores information about GATT server supported features */
265 void btif_storage_set_gatt_sr_supp_feat(const RawAddress& addr, uint8_t feat);
266 
267 /** Gets information about GATT server supported features */
268 uint8_t btif_storage_get_sr_supp_feat(const RawAddress& bd_addr);
269 
270 /** Store last server database hash for remote client */
271 void btif_storage_set_gatt_cl_db_hash(const RawAddress& bd_addr, Octet16 hash);
272 
273 /** Get last server database hash for remote client */
274 Octet16 btif_storage_get_gatt_cl_db_hash(const RawAddress& bd_addr);
275 
276 /** Remove last server database hash for remote client */
277 void btif_storage_remove_gatt_cl_db_hash(const RawAddress& bd_addr);
278 
279 /** Get the hearing aid device properties. */
280 bool btif_storage_get_hearing_aid_prop(
281     const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
282     uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs);
283 
284 /** Store Le Audio device autoconnect flag */
285 void btif_storage_set_leaudio_autoconnect(const RawAddress& addr,
286                                           bool autoconnect);
287 
288 /** Store PACs information */
289 void btif_storage_leaudio_update_pacs_bin(const RawAddress& addr);
290 
291 /** Store ASEs information */
292 void btif_storage_leaudio_update_ase_bin(const RawAddress& addr);
293 
294 /** Store Handles information */
295 void btif_storage_leaudio_update_handles_bin(const RawAddress& addr);
296 
297 /** Store Le Audio device audio locations */
298 void btif_storage_set_leaudio_audio_location(const RawAddress& addr,
299                                              uint32_t sink_location,
300                                              uint32_t source_location);
301 
302 /** Store Le Audio device context types */
303 void btif_storage_set_leaudio_supported_context_types(
304     const RawAddress& addr, uint16_t sink_supported_context_type,
305     uint16_t source_supported_context_type);
306 
307 /** Remove Le Audio device from the storage */
308 void btif_storage_remove_leaudio(const RawAddress& address);
309 
310 /** Load bonded Le Audio devices */
311 void btif_storage_load_bonded_leaudio(void);
312 
313 /** Loads information about bonded HAS devices */
314 void btif_storage_load_bonded_leaudio_has_devices(void);
315 
316 /** Deletes the bonded HAS device info from NVRAM */
317 void btif_storage_remove_leaudio_has(const RawAddress& address);
318 
319 /** Set/Unset the HAS device acceptlist flag. */
320 void btif_storage_set_leaudio_has_acceptlist(const RawAddress& address,
321                                              bool add_to_acceptlist);
322 
323 /*******************************************************************************
324  *
325  * Function         btif_storage_is_retricted_device
326  *
327  * Description      BTIF storage API - checks if this device is a restricted
328  *                  device
329  *
330  * Returns          true  if the device is labled as restricted
331  *                  false otherwise
332  *
333  ******************************************************************************/
334 bool btif_storage_is_restricted_device(const RawAddress* remote_bd_addr);
335 
336 int btif_storage_get_num_bonded_devices(void);
337 
338 bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr,
339                                              const uint8_t* key,
340                                              uint8_t key_type,
341                                              uint8_t key_length);
342 bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr,
343                                              uint8_t key_type,
344                                              uint8_t* key_value,
345                                              int key_length);
346 
347 bt_status_t btif_storage_add_ble_local_key(const Octet16& key,
348                                            uint8_t key_type);
349 bt_status_t btif_storage_remove_ble_bonding_keys(
350     const RawAddress* remote_bd_addr);
351 bt_status_t btif_storage_remove_ble_local_keys(void);
352 bt_status_t btif_storage_get_ble_local_key(uint8_t key_type,
353                                            Octet16* key_value);
354 
355 bt_status_t btif_storage_get_remote_addr_type(const RawAddress* remote_bd_addr,
356                                               tBLE_ADDR_TYPE* addr_type);
357 
358 bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr,
359                                               tBLE_ADDR_TYPE addr_type);
360 
361 bool btif_storage_get_remote_addr_type(const RawAddress& remote_bd_addr,
362                                        tBLE_ADDR_TYPE& addr_type);
363 void btif_storage_set_remote_addr_type(const RawAddress& remote_bd_addr,
364                                        const tBLE_ADDR_TYPE& addr_type);
365 bool btif_storage_get_remote_device_type(const RawAddress& remote_bd_addr,
366                                          tBT_DEVICE_TYPE& device_type);
367 void btif_storage_set_remote_device_type(const RawAddress& remote_bd_addr,
368                                          const tBT_DEVICE_TYPE& device_type);
369 
370 void btif_storage_add_groups(const RawAddress& addr);
371 void btif_storage_load_bonded_groups(void);
372 void btif_storage_remove_groups(const RawAddress& address);
373 
374 void btif_storage_set_csis_autoconnect(const RawAddress& addr,
375                                        bool autoconnect);
376 void btif_storage_update_csis_info(const RawAddress& addr);
377 void btif_storage_load_bonded_csis_devices();
378 void btif_storage_remove_csis_device(const RawAddress& address);
379 
380 /*******************************************************************************
381  * Function         btif_storage_load_hidd
382  *
383  * Description      Loads hidd bonded device and "plugs" it into hidd
384  *
385  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
386  *
387  ******************************************************************************/
388 bt_status_t btif_storage_load_hidd(void);
389 
390 /*******************************************************************************
391  *
392  * Function         btif_storage_set_hidd
393  *
394  * Description      Stores hidd bonded device info in nvram.
395  *
396  * Returns          BT_STATUS_SUCCESS
397  *
398  ******************************************************************************/
399 
400 bt_status_t btif_storage_set_hidd(const RawAddress& remote_bd_addr);
401 
402 /*******************************************************************************
403  *
404  * Function         btif_storage_remove_hidd
405  *
406  * Description      Removes hidd bonded device info from nvram
407  *
408  * Returns          BT_STATUS_SUCCESS
409  *
410  ******************************************************************************/
411 
412 bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr);
413 
414 // Gets the device name for a given Bluetooth address |bd_addr|.
415 // The device name (if found) is stored in |name|.
416 // Returns true if the device name is found, othervise false.
417 // Note: |name| should point to a buffer that can store string of length
418 // |BTM_MAX_REM_BD_NAME_LEN|.
419 bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name);
420 
421 /******************************************************************************
422  * Exported for unit tests
423  *****************************************************************************/
424 size_t btif_split_uuids_string(const char* str, bluetooth::Uuid* p_uuid,
425                                size_t max_uuids);
426 
427 #endif /* BTIF_STORAGE_H */
428