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