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(const 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 /** Stores information about GATT Client supported features support */ 235 void btif_storage_set_gatt_cl_supp_feat(const RawAddress& bd_addr, 236 uint8_t feat); 237 238 /** Get client supported features */ 239 uint8_t btif_storage_get_gatt_cl_supp_feat(const RawAddress& bd_addr); 240 241 /** Get the hearing aid device properties. */ 242 bool btif_storage_get_hearing_aid_prop( 243 const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id, 244 uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs); 245 246 /******************************************************************************* 247 * 248 * Function btif_storage_is_retricted_device 249 * 250 * Description BTIF storage API - checks if this device is a restricted 251 * device 252 * 253 * Returns true if the device is labled as restricted 254 * false otherwise 255 * 256 ******************************************************************************/ 257 bool btif_storage_is_restricted_device(const RawAddress* remote_bd_addr); 258 259 int btif_storage_get_num_bonded_devices(void); 260 261 bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr, 262 const uint8_t* key, 263 uint8_t key_type, 264 uint8_t key_length); 265 bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr, 266 uint8_t key_type, 267 uint8_t* key_value, 268 int key_length); 269 270 bt_status_t btif_storage_add_ble_local_key(const Octet16& key, 271 uint8_t key_type); 272 bt_status_t btif_storage_remove_ble_bonding_keys( 273 const RawAddress* remote_bd_addr); 274 bt_status_t btif_storage_remove_ble_local_keys(void); 275 bt_status_t btif_storage_get_ble_local_key(uint8_t key_type, 276 Octet16* key_value); 277 278 bt_status_t btif_storage_get_remote_addr_type(const RawAddress* remote_bd_addr, 279 int* addr_type); 280 281 bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr, 282 uint8_t addr_type); 283 284 /******************************************************************************* 285 * Function btif_storage_load_hidd 286 * 287 * Description Loads hidd bonded device and "plugs" it into hidd 288 * 289 * Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 290 * 291 ******************************************************************************/ 292 bt_status_t btif_storage_load_hidd(void); 293 294 /******************************************************************************* 295 * 296 * Function btif_storage_set_hidd 297 * 298 * Description Stores hidd bonded device info in nvram. 299 * 300 * Returns BT_STATUS_SUCCESS 301 * 302 ******************************************************************************/ 303 304 bt_status_t btif_storage_set_hidd(const RawAddress& remote_bd_addr); 305 306 /******************************************************************************* 307 * 308 * Function btif_storage_remove_hidd 309 * 310 * Description Removes hidd bonded device info from nvram 311 * 312 * Returns BT_STATUS_SUCCESS 313 * 314 ******************************************************************************/ 315 316 bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr); 317 318 // Gets the device name for a given Bluetooth address |bd_addr|. 319 // The device name (if found) is stored in |name|. 320 // Returns true if the device name is found, othervise false. 321 // Note: |name| should point to a buffer that can store string of length 322 // |BTM_MAX_REM_BD_NAME_LEN|. 323 bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name); 324 325 /****************************************************************************** 326 * Exported for unit tests 327 *****************************************************************************/ 328 size_t btif_split_uuids_string(const char* str, bluetooth::Uuid* p_uuid, 329 size_t max_uuids); 330 331 #endif /* BTIF_STORAGE_H */ 332