The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 22 | #include <hardware/bluetooth.h> |
| 23 | |
| 24 | #include "bt_target.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 25 | #include "bt_types.h" |
| 26 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 27 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 28 | * Constants & Macros |
| 29 | *******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \ |
Myles Watson | 40cde56 | 2016-10-21 09:39:13 -0700 | [diff] [blame] | 31 | do { \ |
| 32 | (p_prop)->type = (t); \ |
| 33 | (p_prop)->len = (l); \ |
| 34 | (p_prop)->val = (p_v); \ |
| 35 | } while (0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 36 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 38 | * Functions |
| 39 | *******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | |
| 41 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 55 | |
| 56 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 68 | |
| 69 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | |
| 85 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 98 | |
| 99 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 112 | uint32_t num_properties, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 113 | bt_property_t* properties); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 114 | |
| 115 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | uint8_t pin_length); |
| 129 | |
| 130 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 141 | |
| 142 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | bt_status_t btif_storage_load_bonded_devices(void); |
| 153 | |
| 154 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 155 | * |
| 156 | * Function btif_storage_add_hid_device_info |
| 157 | * |
| 158 | * Description BTIF storage API - Adds the hid information of bonded hid |
Myles Watson | f454816 | 2016-10-19 09:53:56 -0700 | [diff] [blame] | 159 | * devices-to NVRAM |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 160 | * |
| 161 | * Returns BT_STATUS_SUCCESS if the store was successful, |
| 162 | * BT_STATUS_FAIL otherwise |
| 163 | * |
| 164 | ******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 165 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 171 | |
| 172 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 173 | * |
| 174 | * Function btif_storage_load_bonded_hid_info |
| 175 | * |
| 176 | * Description BTIF storage API - Loads hid info for all the bonded devices |
Myles Watson | f454816 | 2016-10-19 09:53:56 -0700 | [diff] [blame] | 177 | * from NVRAM and adds those devices to the BTA_HH. |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 178 | * |
| 179 | * Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise |
| 180 | * |
| 181 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 182 | bt_status_t btif_storage_load_bonded_hid_info(void); |
| 183 | |
| 184 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 185 | * |
| 186 | * Function btif_storage_remove_hid_info |
| 187 | * |
| 188 | * Description BTIF storage API - Deletes the bonded hid device info from |
Myles Watson | f454816 | 2016-10-19 09:53:56 -0700 | [diff] [blame] | 189 | * NVRAM |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 196 | |
Ajay Panicker | 7b266be | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 197 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 198 | * |
| 199 | * Function btif_storage_is_retricted_device |
| 200 | * |
| 201 | * Description BTIF storage API - checks if this device is a restricted |
Myles Watson | f454816 | 2016-10-19 09:53:56 -0700 | [diff] [blame] | 202 | * device |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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); |
Ajay Panicker | 7b266be | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 209 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 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, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 215 | int key_length); |
| 216 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 217 | bt_status_t btif_storage_add_ble_local_key(char* key, uint8_t key_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 218 | uint8_t key_length); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 219 | bt_status_t btif_storage_remove_ble_bonding_keys(bt_bdaddr_t* remote_bd_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 220 | bt_status_t btif_storage_remove_ble_local_keys(void); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 221 | bt_status_t btif_storage_get_ble_local_key(uint8_t key_type, char* key_value, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 222 | int key_len); |
| 223 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 224 | bt_status_t btif_storage_get_remote_addr_type(bt_bdaddr_t* remote_bd_addr, |
| 225 | int* addr_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 226 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 227 | bt_status_t btif_storage_set_remote_addr_type(bt_bdaddr_t* remote_bd_addr, |
Marie Janssen | b7f64bc | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 228 | uint8_t addr_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 229 | |
Andre Eisenbach | 1685664 | 2016-01-29 16:11:13 -0800 | [diff] [blame] | 230 | /****************************************************************************** |
| 231 | * Exported for unit tests |
| 232 | *****************************************************************************/ |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 233 | size_t btif_split_uuids_string(const char* str, bt_uuid_t* p_uuid, |
| 234 | size_t max_uuids); |
Andre Eisenbach | 1685664 | 2016-01-29 16:11:13 -0800 | [diff] [blame] | 235 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | #endif /* BTIF_STORAGE_H */ |