btif_storage.c revision 41d4a266ceca77bb09ab1bf5c04c30d15f3ded3a
1/****************************************************************************** 2 * 3 * Copyright (c) 2014 The Android Open Source Project 4 * Copyright (C) 2009-2012 Broadcom Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20/************************************************************************************ 21 * 22 * Filename: btif_storage.c 23 * 24 * Description: Stores the local BT adapter and remote device properties in 25 * NVRAM storage, typically as xml file in the 26 * mobile's filesystem 27 * 28 * 29 */ 30#include <stdlib.h> 31#include <time.h> 32#include <string.h> 33#include <ctype.h> 34#include <alloca.h> 35 36 37#include <hardware/bluetooth.h> 38#include "btif_config.h" 39#define LOG_TAG "BTIF_STORAGE" 40 41#include "btif_api.h" 42#include "btif_storage.h" 43#include "btif_util.h" 44#include "bd.h" 45#include "config.h" 46#include "gki.h" 47#include "osi.h" 48#include "bta_hh_api.h" 49#include "btif_hh.h" 50 51#include <cutils/log.h> 52 53/************************************************************************************ 54** Constants & Macros 55************************************************************************************/ 56 57#define BTIF_STORAGE_PATH_BLUEDROID "/data/misc/bluedroid" 58 59//#define BTIF_STORAGE_PATH_ADAPTER_INFO "adapter_info" 60//#define BTIF_STORAGE_PATH_REMOTE_DEVICES "remote_devices" 61#define BTIF_STORAGE_PATH_REMOTE_DEVTIME "Timestamp" 62#define BTIF_STORAGE_PATH_REMOTE_DEVCLASS "DevClass" 63#define BTIF_STORAGE_PATH_REMOTE_DEVTYPE "DevType" 64#define BTIF_STORAGE_PATH_REMOTE_NAME "Name" 65#define BTIF_STORAGE_PATH_REMOTE_VER_MFCT "Manufacturer" 66#define BTIF_STORAGE_PATH_REMOTE_VER_VER "LmpVer" 67#define BTIF_STORAGE_PATH_REMOTE_VER_SUBVER "LmpSubVer" 68 69//#define BTIF_STORAGE_PATH_REMOTE_LINKKEYS "remote_linkkeys" 70#define BTIF_STORAGE_PATH_REMOTE_ALIASE "Aliase" 71#define BTIF_STORAGE_PATH_REMOTE_SERVICE "Service" 72#define BTIF_STORAGE_PATH_REMOTE_HIDINFO "HidInfo" 73#define BTIF_STORAGE_KEY_ADAPTER_NAME "Name" 74#define BTIF_STORAGE_KEY_ADAPTER_SCANMODE "ScanMode" 75#define BTIF_STORAGE_KEY_ADAPTER_DISC_TIMEOUT "DiscoveryTimeout" 76 77 78#define BTIF_AUTO_PAIR_CONF_FILE "/etc/bluetooth/auto_pair_devlist.conf" 79#define BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST "AutoPairBlacklist" 80#define BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_ADDR "AddressBlacklist" 81#define BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_EXACTNAME "ExactNameBlacklist" 82#define BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_PARTIALNAME "PartialNameBlacklist" 83#define BTIF_STORAGE_KEY_AUTOPAIR_FIXPIN_KBLIST "FixedPinZerosKeyboardBlacklist" 84#define BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR "DynamicAddressBlacklist" 85 86#define BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR "," 87 88 89/* This is a local property to add a device found */ 90#define BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF 91 92#define BTIF_STORAGE_GET_ADAPTER_PROP(t,v,l,p) \ 93 {p.type=t;p.val=v;p.len=l; btif_storage_get_adapter_property(&p);} 94 95#define BTIF_STORAGE_GET_REMOTE_PROP(b,t,v,l,p) \ 96 {p.type=t;p.val=v;p.len=l;btif_storage_get_remote_device_property(b,&p);} 97 98#define STORAGE_BDADDR_STRING_SZ (18) /* 00:11:22:33:44:55 */ 99#define STORAGE_UUID_STRING_SIZE (36+1) /* 00001200-0000-1000-8000-00805f9b34fb; */ 100#define STORAGE_PINLEN_STRING_MAX_SIZE (2) /* ascii pinlen max chars */ 101#define STORAGE_KEYTYPE_STRING_MAX_SIZE (1) /* ascii keytype max chars */ 102 103#define STORAGE_KEY_TYPE_MAX (10) 104 105#define STORAGE_HID_ATRR_MASK_SIZE (4) 106#define STORAGE_HID_SUB_CLASS_SIZE (2) 107#define STORAGE_HID_APP_ID_SIZE (2) 108#define STORAGE_HID_VENDOR_ID_SIZE (4) 109#define STORAGE_HID_PRODUCT_ID_SIZE (4) 110#define STORAGE_HID_VERSION_SIZE (4) 111#define STORAGE_HID_CTRY_CODE_SIZE (2) 112#define STORAGE_HID_DESC_LEN_SIZE (4) 113#define STORAGE_HID_DESC_MAX_SIZE (2*512) 114 115/* <18 char bd addr> <space> LIST< <36 char uuid> <;> > <keytype (dec)> <pinlen> */ 116#define BTIF_REMOTE_SERVICES_ENTRY_SIZE_MAX (STORAGE_BDADDR_STRING_SZ + 1 +\ 117 STORAGE_UUID_STRING_SIZE*BT_MAX_NUM_UUIDS + \ 118 STORAGE_PINLEN_STRING_MAX_SIZE +\ 119 STORAGE_KEYTYPE_STRING_MAX_SIZE) 120 121#define STORAGE_REMOTE_LINKKEYS_ENTRY_SIZE (LINK_KEY_LEN*2 + 1 + 2 + 1 + 2) 122 123/* <18 char bd addr> <space>LIST <attr_mask> <space> > <sub_class> <space> <app_id> <space> 124 <vendor_id> <space> > <product_id> <space> <version> <space> 125 <ctry_code> <space> > <desc_len> <space> <desc_list> <space> */ 126#define BTIF_HID_INFO_ENTRY_SIZE_MAX (STORAGE_BDADDR_STRING_SZ + 1 +\ 127 STORAGE_HID_ATRR_MASK_SIZE + 1 +\ 128 STORAGE_HID_SUB_CLASS_SIZE + 1 +\ 129 STORAGE_HID_APP_ID_SIZE+ 1 +\ 130 STORAGE_HID_VENDOR_ID_SIZE+ 1 +\ 131 STORAGE_HID_PRODUCT_ID_SIZE+ 1 +\ 132 STORAGE_HID_VERSION_SIZE+ 1 +\ 133 STORAGE_HID_CTRY_CODE_SIZE+ 1 +\ 134 STORAGE_HID_DESC_LEN_SIZE+ 1 +\ 135 STORAGE_HID_DESC_MAX_SIZE+ 1 ) 136 137 138/* currently remote services is the potentially largest entry */ 139#define BTIF_STORAGE_MAX_LINE_SZ BTIF_REMOTE_SERVICES_ENTRY_SIZE_MAX 140 141 142/* check against unv max entry size at compile time */ 143#if (BTIF_STORAGE_ENTRY_MAX_SIZE > UNV_MAXLINE_LENGTH) 144 #error "btif storage entry size exceeds unv max line size" 145#endif 146 147 148#define BTIF_STORAGE_HL_APP "hl_app" 149#define BTIF_STORAGE_HL_APP_CB "hl_app_cb" 150#define BTIF_STORAGE_HL_APP_DATA "hl_app_data_" 151#define BTIF_STORAGE_HL_APP_MDL_DATA "hl_app_mdl_data_" 152 153/************************************************************************************ 154** Local type definitions 155************************************************************************************/ 156typedef struct 157{ 158 uint32_t num_devices; 159 bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS]; 160} btif_bonded_devices_t; 161 162/************************************************************************************ 163** External variables 164************************************************************************************/ 165extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID]; 166extern bt_bdaddr_t btif_local_bd_addr; 167 168/************************************************************************************ 169** External functions 170************************************************************************************/ 171 172extern void btif_gatts_add_bonded_dev_from_nv(BD_ADDR bda); 173 174/************************************************************************************ 175** Internal Functions 176************************************************************************************/ 177 178bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, 179 btif_bonded_devices_t *p_bonded_devices); 180bt_status_t btif_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, 181 int *addr_type); 182 183/************************************************************************************ 184** Static functions 185************************************************************************************/ 186 187/******************************************************************************* 188** 189** Function btif_in_split_uuids_string_to_list 190** 191** Description Internal helper function to split the string of UUIDs 192** read from the NVRAM to an array 193** 194** Returns None 195** 196*******************************************************************************/ 197static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid, 198 uint32_t *p_num_uuid) 199{ 200 char buf[64]; 201 char *p_start = str; 202 char *p_needle; 203 uint32_t num = 0; 204 do 205 { 206 //p_needle = strchr(p_start, ';'); 207 p_needle = strchr(p_start, ' '); 208 if (p_needle < p_start) break; 209 memset(buf, 0, sizeof(buf)); 210 strncpy(buf, p_start, (p_needle-p_start)); 211 string_to_uuid(buf, p_uuid + num); 212 num++; 213 p_start = ++p_needle; 214 215 } while (*p_start != 0); 216 *p_num_uuid = num; 217} 218static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) 219{ 220 bdstr_t bdstr = {0}; 221 if(remote_bd_addr) 222 bd2str(remote_bd_addr, &bdstr); 223 BTIF_TRACE_DEBUG3("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); 224 char value[1024]; 225 if(prop->len <= 0 || prop->len > (int)sizeof(value) - 1) 226 { 227 BTIF_TRACE_ERROR2("property type:%d, len:%d is invalid", prop->type, prop->len); 228 return FALSE; 229 } 230 switch(prop->type) 231 { 232 case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: 233 btif_config_set_int("Remote", bdstr, 234 BTIF_STORAGE_PATH_REMOTE_DEVTIME, (int)time(NULL)); 235 static const char* exclude_filter[] = 236 {"LinkKey", "LE_KEY_PENC", "LE_KEY_PID", "LE_KEY_PCSRK", "LE_KEY_LENC", "LE_KEY_LCSRK"}; 237 btif_config_filter_remove("Remote", exclude_filter, sizeof(exclude_filter)/sizeof(char*), 238 BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE); 239 break; 240 case BT_PROPERTY_BDNAME: 241 strncpy(value, (char*)prop->val, prop->len); 242 value[prop->len]='\0'; 243 if(remote_bd_addr) 244 btif_config_set_str("Remote", bdstr, 245 BTIF_STORAGE_PATH_REMOTE_NAME, value); 246 else btif_config_set_str("Local", "Adapter", 247 BTIF_STORAGE_KEY_ADAPTER_NAME, value); 248 /* save name immediately */ 249 btif_config_save(); 250 break; 251 case BT_PROPERTY_REMOTE_FRIENDLY_NAME: 252 strncpy(value, (char*)prop->val, prop->len); 253 value[prop->len]='\0'; 254 btif_config_set_str("Remote", bdstr, BTIF_STORAGE_PATH_REMOTE_ALIASE, value); 255 break; 256 case BT_PROPERTY_ADAPTER_SCAN_MODE: 257 btif_config_set_int("Local", "Adapter", 258 BTIF_STORAGE_KEY_ADAPTER_SCANMODE, *(int*)prop->val); 259 break; 260 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: 261 btif_config_set_int("Local", "Adapter", 262 BTIF_STORAGE_KEY_ADAPTER_DISC_TIMEOUT, *(int*)prop->val); 263 break; 264 case BT_PROPERTY_CLASS_OF_DEVICE: 265 btif_config_set_int("Remote", bdstr, 266 BTIF_STORAGE_PATH_REMOTE_DEVCLASS, *(int*)prop->val); 267 break; 268 case BT_PROPERTY_TYPE_OF_DEVICE: 269 btif_config_set_int("Remote", bdstr, 270 BTIF_STORAGE_PATH_REMOTE_DEVTYPE, *(int*)prop->val); 271 break; 272 case BT_PROPERTY_UUIDS: 273 { 274 uint32_t i; 275 char buf[64]; 276 value[0] = 0; 277 for (i=0; i < (prop->len)/sizeof(bt_uuid_t); i++) 278 { 279 bt_uuid_t *p_uuid = (bt_uuid_t*)prop->val + i; 280 memset(buf, 0, sizeof(buf)); 281 uuid_to_string(p_uuid, buf); 282 strcat(value, buf); 283 //strcat(value, ";"); 284 strcat(value, " "); 285 } 286 btif_config_set_str("Remote", bdstr, BTIF_STORAGE_PATH_REMOTE_SERVICE, value); 287 btif_config_save(); 288 break; 289 } 290 case BT_PROPERTY_REMOTE_VERSION_INFO: 291 { 292 bt_remote_version_t *info = (bt_remote_version_t *)prop->val; 293 294 if (!info) 295 return FALSE; 296 297 btif_config_set_int("Remote", bdstr, 298 BTIF_STORAGE_PATH_REMOTE_VER_MFCT, info->manufacturer); 299 btif_config_set_int("Remote", bdstr, 300 BTIF_STORAGE_PATH_REMOTE_VER_VER, info->version); 301 btif_config_set_int("Remote", bdstr, 302 BTIF_STORAGE_PATH_REMOTE_VER_SUBVER, info->sub_ver); 303 btif_config_save(); 304 } break; 305 306 default: 307 BTIF_TRACE_ERROR1("Unknow prop type:%d", prop->type); 308 return FALSE; 309 } 310 return TRUE; 311} 312static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) 313{ 314 bdstr_t bdstr = {0}; 315 if(remote_bd_addr) 316 bd2str(remote_bd_addr, &bdstr); 317 BTIF_TRACE_DEBUG3("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); 318 if(prop->len <= 0) 319 { 320 BTIF_TRACE_ERROR2("property type:%d, len:%d is invalid", prop->type, prop->len); 321 return FALSE; 322 } 323 int ret = FALSE; 324 switch(prop->type) 325 { 326 case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: 327 if(prop->len >= (int)sizeof(int)) 328 ret = btif_config_get_int("Remote", bdstr, 329 BTIF_STORAGE_PATH_REMOTE_DEVTIME, (int*)prop->val); 330 break; 331 case BT_PROPERTY_BDNAME: 332 { 333 int len = prop->len; 334 if(remote_bd_addr) 335 ret = btif_config_get_str("Remote", bdstr, 336 BTIF_STORAGE_PATH_REMOTE_NAME, (char*)prop->val, &len); 337 else ret = btif_config_get_str("Local", "Adapter", 338 BTIF_STORAGE_KEY_ADAPTER_NAME, (char*)prop->val, &len); 339 if(ret && len && len <= prop->len) 340 prop->len = len - 1; 341 else 342 { 343 prop->len = 0; 344 ret = FALSE; 345 } 346 break; 347 } 348 case BT_PROPERTY_REMOTE_FRIENDLY_NAME: 349 { 350 int len = prop->len; 351 ret = btif_config_get_str("Remote", bdstr, 352 BTIF_STORAGE_PATH_REMOTE_ALIASE, (char*)prop->val, &len); 353 if(ret && len && len <= prop->len) 354 prop->len = len - 1; 355 else 356 { 357 prop->len = 0; 358 ret = FALSE; 359 } 360 break; 361 } 362 case BT_PROPERTY_ADAPTER_SCAN_MODE: 363 if(prop->len >= (int)sizeof(int)) 364 ret = btif_config_get_int("Local", "Adapter", 365 BTIF_STORAGE_KEY_ADAPTER_SCANMODE, (int*)prop->val); 366 break; 367 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: 368 if(prop->len >= (int)sizeof(int)) 369 ret = btif_config_get_int("Local", "Adapter", 370 BTIF_STORAGE_KEY_ADAPTER_DISC_TIMEOUT, (int*)prop->val); 371 break; 372 case BT_PROPERTY_CLASS_OF_DEVICE: 373 if(prop->len >= (int)sizeof(int)) 374 ret = btif_config_get_int("Remote", bdstr, 375 BTIF_STORAGE_PATH_REMOTE_DEVCLASS, (int*)prop->val); 376 break; 377 case BT_PROPERTY_TYPE_OF_DEVICE: 378 if(prop->len >= (int)sizeof(int)) 379 ret = btif_config_get_int("Remote", 380 bdstr, BTIF_STORAGE_PATH_REMOTE_DEVTYPE, (int*)prop->val); 381 break; 382 case BT_PROPERTY_UUIDS: 383 { 384 char value[1280]; 385 int size = sizeof(value); 386 if(btif_config_get_str("Remote", bdstr, 387 BTIF_STORAGE_PATH_REMOTE_SERVICE, value, &size)) 388 { 389 bt_uuid_t *p_uuid = (bt_uuid_t*)prop->val; 390 uint32_t num_uuids = 0; 391 btif_in_split_uuids_string_to_list(value, p_uuid, &num_uuids); 392 prop->len = num_uuids * sizeof(bt_uuid_t); 393 ret = TRUE; 394 } 395 else 396 { 397 prop->val = NULL; 398 prop->len = 0; 399 } 400 } break; 401 402 case BT_PROPERTY_REMOTE_VERSION_INFO: 403 { 404 bt_remote_version_t *info = (bt_remote_version_t *)prop->val; 405 406 if(prop->len >= (int)sizeof(bt_remote_version_t)) 407 { 408 ret = btif_config_get_int("Remote", bdstr, 409 BTIF_STORAGE_PATH_REMOTE_VER_MFCT, &info->manufacturer); 410 411 if (ret == TRUE) 412 ret = btif_config_get_int("Remote", bdstr, 413 BTIF_STORAGE_PATH_REMOTE_VER_VER, &info->version); 414 415 if (ret == TRUE) 416 ret = btif_config_get_int("Remote", bdstr, 417 BTIF_STORAGE_PATH_REMOTE_VER_SUBVER, &info->sub_ver); 418 } 419 } break; 420 421 default: 422 BTIF_TRACE_ERROR1("Unknow prop type:%d", prop->type); 423 return FALSE; 424 } 425 return ret; 426} 427 428 429/******************************************************************************* 430** 431** Function btif_in_fetch_bonded_devices 432** 433** Description Internal helper function to fetch the bonded devices 434** from NVRAM 435** 436** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 437** 438*******************************************************************************/ 439static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_devices, int add) 440{ 441 BTIF_TRACE_DEBUG1("in add:%d", add); 442 memset(p_bonded_devices, 0, sizeof(btif_bonded_devices_t)); 443 444 char kname[128], vname[128]; 445 short kpos; 446 int kname_size; 447 kname_size = sizeof(kname); 448 kname[0] = 0; 449 kpos = 0; 450 BOOLEAN bt_linkkey_file_found=FALSE; 451 int device_type; 452 453 do 454 { 455 kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size); 456 BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size); 457 int type = BTIF_CFG_TYPE_BIN; 458 LINK_KEY link_key; 459 int size = sizeof(link_key); 460 if(btif_config_get("Remote", kname, "LinkKey", (char*)link_key, &size, &type)) 461 { 462 int linkkey_type; 463 if(btif_config_get_int("Remote", kname, "LinkKeyType", &linkkey_type)) 464 { 465 //int pin_len; 466 //btif_config_get_int("Remote", kname, "PinLength", &pin_len)) 467 bt_bdaddr_t bd_addr; 468 str2bd(kname, &bd_addr); 469 if(add) 470 { 471 DEV_CLASS dev_class = {0, 0, 0}; 472 int cod; 473 if(btif_config_get_int("Remote", kname, "DevClass", &cod)) 474 uint2devclass((UINT32)cod, dev_class); 475 BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0, (UINT8)linkkey_type, 0); 476 477#if BLE_INCLUDED == TRUE 478 if (btif_config_get_int("Remote", kname, "DevType", &device_type) && 479 (device_type == BT_DEVICE_TYPE_DUMO) ) 480 { 481 btif_gatts_add_bonded_dev_from_nv(bd_addr.address); 482 } 483#endif 484 } 485 bt_linkkey_file_found = TRUE; 486 memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); 487 } 488 else 489 { 490#if (BLE_INCLUDED == TRUE) 491 bt_linkkey_file_found = FALSE; 492#else 493 BTIF_TRACE_ERROR1("bounded device:%s, LinkKeyType or PinLength is invalid", kname); 494#endif 495 } 496 } 497#if (BLE_INCLUDED == TRUE) 498 if(!(btif_in_fetch_bonded_ble_device(kname,add, p_bonded_devices)) && (!bt_linkkey_file_found)) 499 { 500 BTIF_TRACE_DEBUG1("Remote device:%s, no link key or ble key found", kname); 501 } 502#else 503 if(!bt_linkkey_file_found) 504 BTIF_TRACE_DEBUG1("Remote device:%s, no link key", kname); 505#endif 506 kname_size = sizeof(kname); 507 kname[0] = 0; 508 } while(kpos != -1); 509 BTIF_TRACE_DEBUG0("out"); 510 return BT_STATUS_SUCCESS; 511} 512 513/************************************************************************************ 514** Externs 515************************************************************************************/ 516 517/************************************************************************************ 518** Functions 519************************************************************************************/ 520 521/** functions are synchronous. 522 * functions can be called by both internal modules such as BTIF_DM and by external entiries from HAL via BTIF_context_switch 523 * For OUT parameters, caller is expected to provide the memory. 524 * Caller is expected to provide a valid pointer to 'property->value' based on the property->type 525 */ 526/******************************************************************************* 527** 528** Function btif_storage_get_adapter_property 529** 530** Description BTIF storage API - Fetches the adapter property->type 531** from NVRAM and fills property->val. 532** Caller should provide memory for property->val and 533** set the property->val 534** 535** Returns BT_STATUS_SUCCESS if the fetch was successful, 536** BT_STATUS_FAIL otherwise 537** 538*******************************************************************************/ 539bt_status_t btif_storage_get_adapter_property(bt_property_t *property) 540{ 541 542 /* Special handling for adapter BD_ADDR and BONDED_DEVICES */ 543 if (property->type == BT_PROPERTY_BDADDR) 544 { 545 BD_ADDR addr; 546 bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)property->val; 547 /* This has been cached in btif. Just fetch it from there */ 548 memcpy(bd_addr, &btif_local_bd_addr, sizeof(bt_bdaddr_t)); 549 property->len = sizeof(bt_bdaddr_t); 550 return BT_STATUS_SUCCESS; 551 } 552 else if (property->type == BT_PROPERTY_ADAPTER_BONDED_DEVICES) 553 { 554 btif_bonded_devices_t bonded_devices; 555 556 btif_in_fetch_bonded_devices(&bonded_devices, 0); 557 558 BTIF_TRACE_DEBUG2("%s: Number of bonded devices: %d Property:BT_PROPERTY_ADAPTER_BONDED_DEVICES", __FUNCTION__, bonded_devices.num_devices); 559 560 if (bonded_devices.num_devices > 0) 561 { 562 property->len = bonded_devices.num_devices * sizeof(bt_bdaddr_t); 563 memcpy(property->val, bonded_devices.devices, property->len); 564 } 565 566 /* if there are no bonded_devices, then length shall be 0 */ 567 return BT_STATUS_SUCCESS; 568 } 569 else if (property->type == BT_PROPERTY_UUIDS) 570 { 571 /* publish list of local supported services */ 572 bt_uuid_t *p_uuid = (bt_uuid_t*)property->val; 573 uint32_t num_uuids = 0; 574 uint32_t i; 575 576 tBTA_SERVICE_MASK service_mask = btif_get_enabled_services_mask(); 577 BTIF_TRACE_ERROR2("%s service_mask:0x%x", __FUNCTION__, service_mask); 578 for (i=0; i < BTA_MAX_SERVICE_ID; i++) 579 { 580 /* This should eventually become a function when more services are enabled */ 581 if (service_mask 582 &(tBTA_SERVICE_MASK)(1 << i)) 583 { 584 switch (i) 585 { 586 case BTA_HFP_SERVICE_ID: 587 { 588 uuid16_to_uuid128(UUID_SERVCLASS_AG_HANDSFREE, 589 p_uuid+num_uuids); 590 num_uuids++; 591 } 592 /* intentional fall through: Send both BFP & HSP UUIDs if HFP is enabled */ 593 case BTA_HSP_SERVICE_ID: 594 { 595 uuid16_to_uuid128(UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, 596 p_uuid+num_uuids); 597 num_uuids++; 598 }break; 599 case BTA_A2DP_SERVICE_ID: 600 { 601 uuid16_to_uuid128(UUID_SERVCLASS_AUDIO_SOURCE, 602 p_uuid+num_uuids); 603 num_uuids++; 604 }break; 605 case BTA_HFP_HS_SERVICE_ID: 606 { 607 uuid16_to_uuid128(UUID_SERVCLASS_HF_HANDSFREE, 608 p_uuid+num_uuids); 609 num_uuids++; 610 }break; 611 } 612 } 613 } 614 property->len = (num_uuids)*sizeof(bt_uuid_t); 615 return BT_STATUS_SUCCESS; 616 } 617 618 /* fall through for other properties */ 619 if(!cfg2prop(NULL, property)) 620 { 621 return btif_dm_get_adapter_property(property); 622 } 623 return BT_STATUS_SUCCESS; 624 } 625 626/******************************************************************************* 627** 628** Function btif_storage_set_adapter_property 629** 630** Description BTIF storage API - Stores the adapter property 631** to NVRAM 632** 633** Returns BT_STATUS_SUCCESS if the store was successful, 634** BT_STATUS_FAIL otherwise 635** 636*******************************************************************************/ 637bt_status_t btif_storage_set_adapter_property(bt_property_t *property) 638{ 639 return prop2cfg(NULL, property) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 640} 641 642/******************************************************************************* 643** 644** Function btif_storage_get_remote_device_property 645** 646** Description BTIF storage API - Fetches the remote device property->type 647** from NVRAM and fills property->val. 648** Caller should provide memory for property->val and 649** set the property->val 650** 651** Returns BT_STATUS_SUCCESS if the fetch was successful, 652** BT_STATUS_FAIL otherwise 653** 654*******************************************************************************/ 655bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, 656 bt_property_t *property) 657{ 658 return cfg2prop(remote_bd_addr, property) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 659} 660/******************************************************************************* 661** 662** Function btif_storage_set_remote_device_property 663** 664** Description BTIF storage API - Stores the remote device property 665** to NVRAM 666** 667** Returns BT_STATUS_SUCCESS if the store was successful, 668** BT_STATUS_FAIL otherwise 669** 670*******************************************************************************/ 671bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, 672 bt_property_t *property) 673{ 674 return prop2cfg(remote_bd_addr, property) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 675} 676 677/******************************************************************************* 678** 679** Function btif_storage_add_remote_device 680** 681** Description BTIF storage API - Adds a newly discovered device to NVRAM 682** along with the timestamp. Also, stores the various 683** properties - RSSI, BDADDR, NAME (if found in EIR) 684** 685** Returns BT_STATUS_SUCCESS if the store was successful, 686** BT_STATUS_FAIL otherwise 687** 688*******************************************************************************/ 689bt_status_t btif_storage_add_remote_device(bt_bdaddr_t *remote_bd_addr, 690 uint32_t num_properties, 691 bt_property_t *properties) 692{ 693 uint32_t i = 0; 694 /* TODO: If writing a property, fails do we go back undo the earlier 695 * written properties? */ 696 for (i=0; i < num_properties; i++) 697 { 698 /* Ignore the RSSI as this is not stored in DB */ 699 if (properties[i].type == BT_PROPERTY_REMOTE_RSSI) 700 continue; 701 702 /* BD_ADDR for remote device needs special handling as we also store timestamp */ 703 if (properties[i].type == BT_PROPERTY_BDADDR) 704 { 705 bt_property_t addr_prop; 706 memcpy(&addr_prop, &properties[i], sizeof(bt_property_t)); 707 addr_prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP; 708 btif_storage_set_remote_device_property(remote_bd_addr, 709 &addr_prop); 710 } 711 else 712 { 713 btif_storage_set_remote_device_property(remote_bd_addr, 714 &properties[i]); 715 } 716 } 717 return BT_STATUS_SUCCESS; 718} 719 720/******************************************************************************* 721** 722** Function btif_storage_add_bonded_device 723** 724** Description BTIF storage API - Adds the newly bonded device to NVRAM 725** along with the link-key, Key type and Pin key length 726** 727** Returns BT_STATUS_SUCCESS if the store was successful, 728** BT_STATUS_FAIL otherwise 729** 730*******************************************************************************/ 731 732bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, 733 LINK_KEY link_key, 734 uint8_t key_type, 735 uint8_t pin_length) 736{ 737 bdstr_t bdstr; 738 bd2str(remote_bd_addr, &bdstr); 739 int ret = btif_config_set_int("Remote", bdstr, "LinkKeyType", (int)key_type); 740 ret &= btif_config_set_int("Remote", bdstr, "PinLength", (int)pin_length); 741 ret &= btif_config_set("Remote", bdstr, "LinkKey", (const char*)link_key, sizeof(LINK_KEY), BTIF_CFG_TYPE_BIN); 742 /* write bonded info immediately */ 743 btif_config_flush(); 744 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 745} 746 747/******************************************************************************* 748** 749** Function btif_storage_remove_bonded_device 750** 751** Description BTIF storage API - Deletes the bonded device from NVRAM 752** 753** Returns BT_STATUS_SUCCESS if the deletion was successful, 754** BT_STATUS_FAIL otherwise 755** 756*******************************************************************************/ 757bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr) 758{ 759 bdstr_t bdstr; 760 bd2str(remote_bd_addr, &bdstr); 761 BTIF_TRACE_DEBUG1("in bd addr:%s", bdstr); 762 int ret = 1; 763 if(btif_config_exist("Remote", bdstr, "LinkKeyType")) 764 ret &= btif_config_remove("Remote", bdstr, "LinkKeyType"); 765 if(btif_config_exist("Remote", bdstr, "PinLength")) 766 ret &= btif_config_remove("Remote", bdstr, "PinLength"); 767 if(btif_config_exist("Remote", bdstr, "LinkKey")) 768 ret &= btif_config_remove("Remote", bdstr, "LinkKey"); 769 /* write bonded info immediately */ 770 btif_config_flush(); 771 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 772 773} 774 775/******************************************************************************* 776** 777** Function btif_storage_load_bonded_devices 778** 779** Description BTIF storage API - Loads all the bonded devices from NVRAM 780** and adds to the BTA. 781** Additionally, this API also invokes the adaper_properties_cb 782** and remote_device_properties_cb for each of the bonded devices. 783** 784** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 785** 786*******************************************************************************/ 787bt_status_t btif_storage_load_bonded_devices(void) 788{ 789 char *fname; 790 btif_bonded_devices_t bonded_devices; 791 uint32_t i = 0; 792 bt_property_t adapter_props[6]; 793 uint32_t num_props = 0; 794 bt_property_t remote_properties[8]; 795 bt_bdaddr_t addr; 796 bt_bdname_t name, alias; 797 bt_scan_mode_t mode; 798 uint32_t disc_timeout; 799 bt_bdaddr_t *devices_list; 800 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS]; 801 bt_uuid_t remote_uuids[BT_MAX_NUM_UUIDS]; 802 uint32_t cod, devtype; 803 804 btif_in_fetch_bonded_devices(&bonded_devices, 1); 805 806 /* Now send the adapter_properties_cb with all adapter_properties */ 807 { 808 memset(adapter_props, 0, sizeof(adapter_props)); 809 810 /* BD_ADDR */ 811 BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDADDR, &addr, sizeof(addr), 812 adapter_props[num_props]); 813 num_props++; 814 815 /* BD_NAME */ 816 BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDNAME, &name, sizeof(name), 817 adapter_props[num_props]); 818 num_props++; 819 820 /* SCAN_MODE */ 821 /* TODO: At the time of BT on, always report the scan mode as 0 irrespective 822 of the scan_mode during the previous enable cycle. 823 This needs to be re-visited as part of the app/stack enable sequence 824 synchronization */ 825 mode = BT_SCAN_MODE_NONE; 826 adapter_props[num_props].type = BT_PROPERTY_ADAPTER_SCAN_MODE; 827 adapter_props[num_props].len = sizeof(mode); 828 adapter_props[num_props].val = &mode; 829 num_props++; 830 831 /* DISC_TIMEOUT */ 832 BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, 833 &disc_timeout, sizeof(disc_timeout), 834 adapter_props[num_props]); 835 num_props++; 836 837 /* BONDED_DEVICES */ 838 devices_list = (bt_bdaddr_t*)malloc(sizeof(bt_bdaddr_t)*bonded_devices.num_devices); 839 adapter_props[num_props].type = BT_PROPERTY_ADAPTER_BONDED_DEVICES; 840 adapter_props[num_props].len = bonded_devices.num_devices * sizeof(bt_bdaddr_t); 841 adapter_props[num_props].val = devices_list; 842 for (i=0; i < bonded_devices.num_devices; i++) 843 { 844 memcpy(devices_list + i, &bonded_devices.devices[i], sizeof(bt_bdaddr_t)); 845 } 846 num_props++; 847 848 /* LOCAL UUIDs */ 849 BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_UUIDS, 850 local_uuids, sizeof(local_uuids), 851 adapter_props[num_props]); 852 num_props++; 853 854 btif_adapter_properties_evt(BT_STATUS_SUCCESS, num_props, adapter_props); 855 856 free(devices_list); 857 } 858 859 BTIF_TRACE_EVENT2("%s: %d bonded devices found", __FUNCTION__, bonded_devices.num_devices); 860 861 { 862 for (i = 0; i < bonded_devices.num_devices; i++) 863 { 864 bt_bdaddr_t *p_remote_addr; 865 866 num_props = 0; 867 p_remote_addr = &bonded_devices.devices[i]; 868 memset(remote_properties, 0, sizeof(remote_properties)); 869 BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_BDNAME, 870 &name, sizeof(name), 871 remote_properties[num_props]); 872 num_props++; 873 874 BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, 875 &alias, sizeof(alias), 876 remote_properties[num_props]); 877 num_props++; 878 879 BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_CLASS_OF_DEVICE, 880 &cod, sizeof(cod), 881 remote_properties[num_props]); 882 num_props++; 883 884 BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_TYPE_OF_DEVICE, 885 &devtype, sizeof(devtype), 886 remote_properties[num_props]); 887 num_props++; 888 889 BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_UUIDS, 890 remote_uuids, sizeof(remote_uuids), 891 remote_properties[num_props]); 892 num_props++; 893 894 btif_remote_properties_evt(BT_STATUS_SUCCESS, p_remote_addr, 895 num_props, remote_properties); 896 } 897 } 898 return BT_STATUS_SUCCESS; 899} 900 901#if (BLE_INCLUDED == TRUE) 902 903/******************************************************************************* 904** 905** Function btif_storage_add_ble_bonding_key 906** 907** Description BTIF storage API - Adds the newly bonded device to NVRAM 908** along with the ble-key, Key type and Pin key length 909** 910** Returns BT_STATUS_SUCCESS if the store was successful, 911** BT_STATUS_FAIL otherwise 912** 913*******************************************************************************/ 914 915bt_status_t btif_storage_add_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, 916 char *key, 917 UINT8 key_type, 918 UINT8 key_length) 919{ 920 bdstr_t bdstr; 921 bd2str(remote_bd_addr, &bdstr); 922 const char* name; 923 switch(key_type) 924 { 925 case BTIF_DM_LE_KEY_PENC: 926 name = "LE_KEY_PENC"; 927 break; 928 case BTIF_DM_LE_KEY_PID: 929 name = "LE_KEY_PID"; 930 break; 931 case BTIF_DM_LE_KEY_PCSRK: 932 name = "LE_KEY_PCSRK"; 933 break; 934 case BTIF_DM_LE_KEY_LENC: 935 name = "LE_KEY_LENC"; 936 break; 937 case BTIF_DM_LE_KEY_LCSRK: 938 name = "LE_KEY_LCSRK"; 939 break; 940 default: 941 return BT_STATUS_FAIL; 942 } 943 int ret = btif_config_set("Remote", bdstr, name, (const char*)key, (int)key_length, BTIF_CFG_TYPE_BIN); 944 btif_config_save(); 945 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 946} 947 948/******************************************************************************* 949** 950** Function btif_storage_get_ble_bonding_key 951** 952** Description 953** 954** Returns BT_STATUS_SUCCESS if the fetch was successful, 955** BT_STATUS_FAIL otherwise 956** 957*******************************************************************************/ 958bt_status_t btif_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, 959 UINT8 key_type, 960 char *key_value, 961 int key_length) 962{ 963 bdstr_t bdstr; 964 bd2str(remote_bd_addr, &bdstr); 965 const char* name; 966 int type = BTIF_CFG_TYPE_BIN; 967 switch(key_type) 968 { 969 case BTIF_DM_LE_KEY_PENC: 970 name = "LE_KEY_PENC"; 971 break; 972 case BTIF_DM_LE_KEY_PID: 973 name = "LE_KEY_PID"; 974 break; 975 case BTIF_DM_LE_KEY_PCSRK: 976 name = "LE_KEY_PCSRK"; 977 break; 978 case BTIF_DM_LE_KEY_LENC: 979 name = "LE_KEY_LENC"; 980 break; 981 case BTIF_DM_LE_KEY_LCSRK: 982 name = "LE_KEY_LCSRK"; 983 break; 984 default: 985 return BT_STATUS_FAIL; 986 } 987 int ret = btif_config_get("Remote", bdstr, name, key_value, &key_length, &type); 988 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 989 990} 991 992/******************************************************************************* 993** 994** Function btif_storage_remove_ble_keys 995** 996** Description BTIF storage API - Deletes the bonded device from NVRAM 997** 998** Returns BT_STATUS_SUCCESS if the deletion was successful, 999** BT_STATUS_FAIL otherwise 1000** 1001*******************************************************************************/ 1002bt_status_t btif_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr) 1003{ 1004 bdstr_t bdstr; 1005 bd2str(remote_bd_addr, &bdstr); 1006 BTIF_TRACE_DEBUG2(" %s in bd addr:%s",__FUNCTION__, bdstr); 1007 int ret = 1; 1008 if(btif_config_exist("Remote", bdstr, "LE_KEY_PENC")) 1009 ret &= btif_config_remove("Remote", bdstr, "LE_KEY_PENC"); 1010 if(btif_config_exist("Remote", bdstr, "LE_KEY_PID")) 1011 ret &= btif_config_remove("Remote", bdstr, "LE_KEY_PID"); 1012 if(btif_config_exist("Remote", bdstr, "LE_KEY_PCSRK")) 1013 ret &= btif_config_remove("Remote", bdstr, "LE_KEY_PCSRK"); 1014 if(btif_config_exist("Remote", bdstr, "LE_KEY_LENC")) 1015 ret &= btif_config_remove("Remote", bdstr, "LE_KEY_LENC"); 1016 if(btif_config_exist("Remote", bdstr, "LE_KEY_LCSRK")) 1017 ret &= btif_config_remove("Remote", bdstr, "LE_KEY_LCSRK"); 1018 btif_config_save(); 1019 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1020} 1021 1022/******************************************************************************* 1023** 1024** Function btif_storage_add_ble_local_key 1025** 1026** Description BTIF storage API - Adds the ble key to NVRAM 1027** 1028** Returns BT_STATUS_SUCCESS if the store was successful, 1029** BT_STATUS_FAIL otherwise 1030** 1031*******************************************************************************/ 1032bt_status_t btif_storage_add_ble_local_key(char *key, 1033 uint8_t key_type, 1034 uint8_t key_length) 1035{ 1036 const char* name; 1037 switch(key_type) 1038 { 1039 case BTIF_DM_LE_LOCAL_KEY_IR: 1040 name = "LE_LOCAL_KEY_IR"; 1041 break; 1042 case BTIF_DM_LE_LOCAL_KEY_IRK: 1043 name = "LE_LOCAL_KEY_IRK"; 1044 break; 1045 case BTIF_DM_LE_LOCAL_KEY_DHK: 1046 name = "LE_LOCAL_KEY_DHK"; 1047 break; 1048 case BTIF_DM_LE_LOCAL_KEY_ER: 1049 name = "LE_LOCAL_KEY_ER"; 1050 break; 1051 default: 1052 return BT_STATUS_FAIL; 1053 } 1054 int ret = btif_config_set("Local", "Adapter", name, (const char*)key, key_length, BTIF_CFG_TYPE_BIN); 1055 btif_config_save(); 1056 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1057} 1058 1059/******************************************************************************* 1060** 1061** Function btif_storage_get_ble_local_key 1062** 1063** Description 1064** 1065** Returns BT_STATUS_SUCCESS if the fetch was successful, 1066** BT_STATUS_FAIL otherwise 1067** 1068*******************************************************************************/ 1069bt_status_t btif_storage_get_ble_local_key(UINT8 key_type, 1070 char *key_value, 1071 int key_length) 1072{ 1073 const char* name; 1074 int type = BTIF_CFG_TYPE_BIN; 1075 switch(key_type) 1076 { 1077 case BTIF_DM_LE_LOCAL_KEY_IR: 1078 name = "LE_LOCAL_KEY_IR"; 1079 break; 1080 case BTIF_DM_LE_LOCAL_KEY_IRK: 1081 name = "LE_LOCAL_KEY_IRK"; 1082 break; 1083 case BTIF_DM_LE_LOCAL_KEY_DHK: 1084 name = "LE_LOCAL_KEY_DHK"; 1085 break; 1086 case BTIF_DM_LE_LOCAL_KEY_ER: 1087 name = "LE_LOCAL_KEY_ER"; 1088 break; 1089 default: 1090 return BT_STATUS_FAIL; 1091 } 1092 int ret = btif_config_get("Local", "Adapter", name, key_value, &key_length, &type); 1093 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1094 1095} 1096 1097/******************************************************************************* 1098** 1099** Function btif_storage_remove_ble_local_keys 1100** 1101** Description BTIF storage API - Deletes the bonded device from NVRAM 1102** 1103** Returns BT_STATUS_SUCCESS if the deletion was successful, 1104** BT_STATUS_FAIL otherwise 1105** 1106*******************************************************************************/ 1107bt_status_t btif_storage_remove_ble_local_keys(void) 1108{ 1109 int ret = 1; 1110 if(btif_config_exist("Local", "Adapter", "LE_LOCAL_KEY_IR")) 1111 ret &= btif_config_remove("Local", "Adapter", "LE_LOCAL_KEY_IR"); 1112 if(btif_config_exist("Local", "Adapter", "LE_LOCAL_KEY_IRK")) 1113 ret &= btif_config_remove("Local", "Adapter", "LE_LOCAL_KEY_IRK"); 1114 if(btif_config_exist("Local", "Adapter", "LE_LOCAL_KEY_DHK")) 1115 ret &= btif_config_remove("Local", "Adapter", "LE_LOCAL_KEY_DHK"); 1116 if(btif_config_exist("Local", "Adapter", "LE_LOCAL_KEY_ER")) 1117 ret &= btif_config_remove("Local", "Adapter", "LE_LOCAL_KEY_ER"); 1118 btif_config_save(); 1119 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1120} 1121 1122bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_bonded_devices_t *p_bonded_devices) 1123{ 1124 int device_type; 1125 int addr_type; 1126 char buf[100]; 1127 UINT32 i; 1128 bt_bdaddr_t bd_addr; 1129 BD_ADDR bta_bd_addr; 1130 BOOLEAN is_device_added =FALSE; 1131 tBTA_LE_KEY_VALUE *p; 1132 1133 if(!btif_config_get_int("Remote", remote_bd_addr,"DevType", &device_type)) 1134 return BT_STATUS_FAIL; 1135 if(device_type == BT_DEVICE_TYPE_BLE) 1136 { 1137 BTIF_TRACE_DEBUG2("%s %s found a BLE device", __FUNCTION__,remote_bd_addr); 1138 str2bd(remote_bd_addr, &bd_addr); 1139 bdcpy(bta_bd_addr, bd_addr.address); 1140 if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) != BT_STATUS_SUCCESS) 1141 { 1142 return BT_STATUS_FAIL; 1143 } 1144 1145 memset(buf, 0, sizeof(buf)); 1146 if (btif_storage_get_ble_bonding_key(&bd_addr, 1147 BTIF_DM_LE_KEY_PENC, 1148 buf, 1149 sizeof(btif_dm_ble_penc_keys_t)) == BT_STATUS_SUCCESS) 1150 { 1151 if(add) 1152 { 1153 if (!is_device_added) 1154 { 1155 BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE); 1156 is_device_added = TRUE; 1157 } 1158 p = (tBTA_LE_KEY_VALUE *)buf; 1159 for (i=0; i<16; i++) 1160 { 1161 BTIF_TRACE_DEBUG2("penc_key.ltk[%d]=0x%02x",i,p->penc_key.ltk[i]); 1162 } 1163 for (i=0; i<8; i++) 1164 { 1165 BTIF_TRACE_DEBUG2("penc_key.rand[%d]=0x%02x",i,p->penc_key.rand[i]); 1166 } 1167 BTIF_TRACE_DEBUG1("p->penc_key.ediv=0x%04x",p->penc_key.ediv); 1168 BTIF_TRACE_DEBUG1("p->penc_key.sec_level=0x%02x",p->penc_key.sec_level); 1169 BTIF_TRACE_DEBUG1("p->penc_key.key_size=0x%02x",p->penc_key.key_size); 1170 BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PENC); 1171 } 1172 } 1173 1174 memset(buf, 0, sizeof(buf)); 1175 if (btif_storage_get_ble_bonding_key(&bd_addr, 1176 BTIF_DM_LE_KEY_PID, 1177 buf, 1178 sizeof(btif_dm_ble_pcsrk_keys_t)) == BT_STATUS_SUCCESS) 1179 { 1180 if(add) 1181 { 1182 if (!is_device_added) 1183 { 1184 BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE); 1185 is_device_added = TRUE; 1186 } 1187 p = (tBTA_LE_KEY_VALUE *)buf; 1188 for (i=0; i<16; i++) 1189 { 1190 BTIF_TRACE_DEBUG2("p->pid_key[%d]=0x%02x",i,p->pid_key.irk[i]); 1191 } 1192 1193 BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PID); 1194 } 1195 } 1196 1197 memset(buf, 0, sizeof(buf)); 1198 if (btif_storage_get_ble_bonding_key(&bd_addr, 1199 BTIF_DM_LE_KEY_PCSRK, 1200 buf, 1201 sizeof(btif_dm_ble_pcsrk_keys_t)) == BT_STATUS_SUCCESS) 1202 { 1203 if(add) 1204 { 1205 if (!is_device_added) 1206 { 1207 BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE); 1208 is_device_added = TRUE; 1209 } 1210 1211 p = (tBTA_LE_KEY_VALUE *)buf; 1212 for (i=0; i<16; i++) 1213 { 1214 BTIF_TRACE_DEBUG2("p->pcsrk_key.csrk[%d]=0x%02x",i, p->psrk_key.csrk[i]); 1215 } 1216 BTIF_TRACE_DEBUG1("p->pcsrk_key.counter=0x%08x",p->psrk_key.counter); 1217 BTIF_TRACE_DEBUG1("p->pcsrk_key.sec_level=0x%02x",p->psrk_key.sec_level); 1218 1219 BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PCSRK); 1220 } 1221 } 1222 1223 memset(buf, 0, sizeof(buf)); 1224 if (btif_storage_get_ble_bonding_key(&bd_addr, 1225 BTIF_DM_LE_KEY_LENC, 1226 buf, 1227 sizeof(btif_dm_ble_lenc_keys_t)) == BT_STATUS_SUCCESS) 1228 { 1229 if(add) 1230 { 1231 if (!is_device_added) 1232 { 1233 BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE); 1234 is_device_added = TRUE; 1235 } 1236 p = (tBTA_LE_KEY_VALUE *)buf; 1237 BTIF_TRACE_DEBUG1("p->lenc_key.div=0x%04x",p->lenc_key.div); 1238 BTIF_TRACE_DEBUG1("p->lenc_key.key_size=0x%02x",p->lenc_key.key_size); 1239 BTIF_TRACE_DEBUG1("p->lenc_key.sec_level=0x%02x",p->lenc_key.sec_level); 1240 1241 BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_LENC); 1242 } 1243 } 1244 1245 memset(buf, 0, sizeof(buf)); 1246 if (btif_storage_get_ble_bonding_key(&bd_addr, 1247 BTIF_DM_LE_KEY_LCSRK, 1248 buf, 1249 sizeof(btif_dm_ble_lcsrk_keys_t)) == BT_STATUS_SUCCESS) 1250 { 1251 if(add) 1252 { 1253 if (!is_device_added) 1254 { 1255 BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE); 1256 is_device_added = TRUE; 1257 } 1258 p = (tBTA_LE_KEY_VALUE *)buf; 1259 BTIF_TRACE_DEBUG1("p->lcsrk_key.div=0x%04x",p->lcsrk_key.div); 1260 BTIF_TRACE_DEBUG1("p->lcsrk_key.counter=0x%08x",p->lcsrk_key.counter); 1261 BTIF_TRACE_DEBUG1("p->lcsrk_key.sec_level=0x%02x",p->lcsrk_key.sec_level); 1262 1263 BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_LCSRK); 1264 } 1265 } 1266 1267 /* Fill in the bonded devices */ 1268 if (is_device_added) 1269 { 1270 memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); 1271 btif_gatts_add_bonded_dev_from_nv(bta_bd_addr); 1272 } 1273 1274 return BT_STATUS_SUCCESS; 1275 } 1276 return BT_STATUS_FAIL; 1277} 1278 1279bt_status_t btif_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, 1280 UINT8 addr_type) 1281{ 1282 bdstr_t bdstr; 1283 bd2str(remote_bd_addr, &bdstr); 1284 int ret = btif_config_set_int("Remote", bdstr, "AddrType", (int)addr_type); 1285 btif_config_save(); 1286 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1287} 1288 1289/******************************************************************************* 1290** 1291** Function btif_storage_get_remote_addr_type 1292** 1293** Description BTIF storage API - Fetches the remote addr type 1294** 1295** Returns BT_STATUS_SUCCESS if the fetch was successful, 1296** BT_STATUS_FAIL otherwise 1297** 1298*******************************************************************************/ 1299bt_status_t btif_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, 1300 int*addr_type) 1301{ 1302 bdstr_t bdstr; 1303 bd2str(remote_bd_addr, &bdstr); 1304 int ret = btif_config_get_int("Remote", bdstr, "AddrType", addr_type); 1305 return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; 1306} 1307#endif 1308/******************************************************************************* 1309** 1310** Function btif_storage_add_hid_device_info 1311** 1312** Description BTIF storage API - Adds the hid information of bonded hid devices-to NVRAM 1313** 1314** Returns BT_STATUS_SUCCESS if the store was successful, 1315** BT_STATUS_FAIL otherwise 1316** 1317*******************************************************************************/ 1318 1319bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, 1320 UINT16 attr_mask, UINT8 sub_class, 1321 UINT8 app_id, UINT16 vendor_id, 1322 UINT16 product_id, UINT16 version, 1323 UINT8 ctry_code, UINT16 ssr_max_latency, 1324 UINT16 ssr_min_tout, UINT16 dl_len, UINT8 *dsc_list) 1325{ 1326 bdstr_t bdstr; 1327 BTIF_TRACE_DEBUG0("btif_storage_add_hid_device_info:"); 1328 bd2str(remote_bd_addr, &bdstr); 1329 btif_config_set_int("Remote", bdstr, "HidAttrMask", attr_mask); 1330 btif_config_set_int("Remote", bdstr, "HidSubClass", sub_class); 1331 btif_config_set_int("Remote", bdstr, "HidAppId", app_id); 1332 btif_config_set_int("Remote", bdstr, "HidVendorId", vendor_id); 1333 btif_config_set_int("Remote", bdstr, "HidProductId", product_id); 1334 btif_config_set_int("Remote", bdstr, "HidVersion", version); 1335 btif_config_set_int("Remote", bdstr, "HidCountryCode", ctry_code); 1336 btif_config_set_int("Remote", bdstr, "HidSSRMaxLatency", ssr_max_latency); 1337 btif_config_set_int("Remote", bdstr, "HidSSRMinTimeout", ssr_min_tout); 1338 if(dl_len > 0) 1339 btif_config_set("Remote", bdstr, "HidDescriptor", (const char*)dsc_list, dl_len, 1340 BTIF_CFG_TYPE_BIN); 1341 btif_config_save(); 1342 return BT_STATUS_SUCCESS; 1343} 1344 1345/******************************************************************************* 1346** 1347** Function btif_storage_load_bonded_hid_info 1348** 1349** Description BTIF storage API - Loads hid info for all the bonded devices from NVRAM 1350** and adds those devices to the BTA_HH. 1351** 1352** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 1353** 1354*******************************************************************************/ 1355bt_status_t btif_storage_load_bonded_hid_info(void) 1356{ 1357 bt_bdaddr_t bd_addr; 1358 tBTA_HH_DEV_DSCP_INFO dscp_info; 1359 uint32_t i; 1360 uint16_t attr_mask; 1361 uint8_t sub_class; 1362 uint8_t app_id; 1363 1364 char kname[128], vname[128]; 1365 short kpos; 1366 int kname_size; 1367 kname_size = sizeof(kname); 1368 kname[0] = 0; 1369 kpos = 0; 1370 memset(&dscp_info, 0, sizeof(dscp_info)); 1371 do 1372 { 1373 kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size); 1374 BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size); 1375 int value; 1376 if(btif_config_get_int("Remote", kname, "HidAttrMask", &value)) 1377 { 1378 attr_mask = (uint16_t)value; 1379 1380 btif_config_get_int("Remote", kname, "HidSubClass", &value); 1381 sub_class = (uint8_t)value; 1382 1383 btif_config_get_int("Remote", kname, "HidAppId", &value); 1384 app_id = (uint8_t)value; 1385 1386 btif_config_get_int("Remote", kname, "HidVendorId", &value); 1387 dscp_info.vendor_id = (uint16_t) value; 1388 1389 btif_config_get_int("Remote", kname, "HidProductId", &value); 1390 dscp_info.product_id = (uint16_t) value; 1391 1392 btif_config_get_int("Remote", kname, "HidVersion", &value); 1393 dscp_info.version = (uint8_t) value; 1394 1395 btif_config_get_int("Remote", kname, "HidCountryCode", &value); 1396 dscp_info.ctry_code = (uint8_t) value; 1397 1398 value = 0; 1399 btif_config_get_int("Remote", kname, "HidSSRMaxLatency", &value); 1400 dscp_info.ssr_max_latency = (uint16_t) value; 1401 1402 value = 0; 1403 btif_config_get_int("Remote", kname, "HidSSRMinTimeout", &value); 1404 dscp_info.ssr_min_tout = (uint16_t) value; 1405 1406 int len = 0; 1407 int type; 1408 btif_config_get("Remote", kname, "HidDescriptor", NULL, &len, &type); 1409 if(len > 0) 1410 { 1411 dscp_info.descriptor.dl_len = (uint16_t)len; 1412 dscp_info.descriptor.dsc_list = (uint8_t*)alloca(len); 1413 btif_config_get("Remote", kname, "HidDescriptor", (char*)dscp_info.descriptor.dsc_list, &len, &type); 1414 } 1415 str2bd(kname, &bd_addr); 1416 // add extracted information to BTA HH 1417 if (btif_hh_add_added_dev(bd_addr,attr_mask)) 1418 { 1419 BTA_HhAddDev(bd_addr.address, attr_mask, sub_class, 1420 app_id, dscp_info); 1421 } 1422 } 1423 } while(kpos != -1); 1424 1425 return BT_STATUS_SUCCESS; 1426} 1427 1428/******************************************************************************* 1429** 1430** Function btif_storage_remove_hid_info 1431** 1432** Description BTIF storage API - Deletes the bonded hid device info from NVRAM 1433** 1434** Returns BT_STATUS_SUCCESS if the deletion was successful, 1435** BT_STATUS_FAIL otherwise 1436** 1437*******************************************************************************/ 1438bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr) 1439{ 1440 char *fname; 1441 int ret; 1442 bdstr_t bdstr; 1443 bd2str(remote_bd_addr, &bdstr); 1444 1445 btif_config_remove("Remote", bdstr, "HidAttrMask"); 1446 btif_config_remove("Remote", bdstr, "HidSubClass"); 1447 btif_config_remove("Remote", bdstr, "HidAppId"); 1448 btif_config_remove("Remote", bdstr, "HidVendorId"); 1449 btif_config_remove("Remote", bdstr, "HidProductId"); 1450 btif_config_remove("Remote", bdstr, "HidVersion"); 1451 btif_config_remove("Remote", bdstr, "HidCountryCode"); 1452 btif_config_remove("Remote", bdstr, "HidSSRMaxLatency"); 1453 btif_config_remove("Remote", bdstr, "HidSSRMinTimeout"); 1454 btif_config_remove("Remote", bdstr, "HidDescriptor"); 1455 btif_config_save(); 1456 return BT_STATUS_SUCCESS; 1457} 1458 1459/******************************************************************************* 1460** 1461** Function btif_storage_read_hl_apps_cb 1462** 1463** Description BTIF storage API - Read HL application control block from NVRAM 1464** 1465** Returns BT_STATUS_SUCCESS if the operation was successful, 1466** BT_STATUS_FAIL otherwise 1467** 1468*******************************************************************************/ 1469bt_status_t btif_storage_read_hl_apps_cb(char *value, int value_size) 1470{ 1471 bt_status_t bt_status = BT_STATUS_SUCCESS; 1472 int read_size=value_size, read_type=BTIF_CFG_TYPE_BIN; 1473 1474 if (!btif_config_exist("Local", BTIF_STORAGE_HL_APP, BTIF_STORAGE_HL_APP_CB)) 1475 { 1476 memset(value, 0, value_size); 1477 if (!btif_config_set("Local", BTIF_STORAGE_HL_APP,BTIF_STORAGE_HL_APP_CB, 1478 value, value_size, BTIF_CFG_TYPE_BIN)) 1479 { 1480 bt_status = BT_STATUS_FAIL; 1481 } 1482 else 1483 { 1484 btif_config_save(); 1485 } 1486 } 1487 else 1488 { 1489 if (!btif_config_get("Local", BTIF_STORAGE_HL_APP, BTIF_STORAGE_HL_APP_CB, 1490 value, &read_size, &read_type)) 1491 { 1492 bt_status = BT_STATUS_FAIL; 1493 } 1494 else 1495 { 1496 if ((read_size != value_size) || (read_type != BTIF_CFG_TYPE_BIN) ) 1497 { 1498 BTIF_TRACE_ERROR4("%s value_size=%d read_size=%d read_type=%d", 1499 __FUNCTION__, value_size, read_size, read_type); 1500 bt_status = BT_STATUS_FAIL; 1501 } 1502 } 1503 1504 } 1505 1506 BTIF_TRACE_DEBUG3("%s status=%d value_size=%d", __FUNCTION__, bt_status, value_size); 1507 return bt_status; 1508} 1509 1510 1511/******************************************************************************* 1512** 1513** Function btif_storage_load_autopair_device_list 1514** 1515** Description BTIF storage API - Populates auto pair device list 1516** 1517** Returns BT_STATUS_SUCCESS if the auto pair blacklist is successfully populated 1518** BT_STATUS_FAIL otherwise 1519** 1520*******************************************************************************/ 1521bt_status_t btif_storage_load_autopair_device_list() { 1522 // Configuration has already been loaded. No need to reload. 1523 if (btif_config_exist("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, NULL)) { 1524 return BT_STATUS_SUCCESS; 1525 } 1526 1527 static const char *key_names[] = { 1528 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_ADDR, 1529 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_EXACTNAME, 1530 BTIF_STORAGE_KEY_AUTOPAIR_FIXPIN_KBLIST, 1531 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_PARTIALNAME, 1532 BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR, 1533 }; 1534 1535 config_t *config = config_new(BTIF_AUTO_PAIR_CONF_FILE); 1536 if (!config) { 1537 ALOGE("%s failed to open auto pair blacklist conf file '%s'.", __func__, BTIF_AUTO_PAIR_CONF_FILE); 1538 return BT_STATUS_FAIL; 1539 } 1540 1541 for (size_t i = 0; i < ARRAY_SIZE(key_names); ++i) { 1542 const char *value = config_get_string(config, CONFIG_DEFAULT_SECTION, key_names[i], NULL); 1543 if (value) { 1544 btif_config_set_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, key_names[i], value); 1545 } 1546 } 1547 1548 config_free(config); 1549 return BT_STATUS_SUCCESS; 1550} 1551 1552/******************************************************************************* 1553** 1554** Function btif_storage_is_device_autopair_blacklisted 1555** 1556** Description BTIF storage API Checks if the given device is blacklisted for auto pairing 1557** 1558** Returns TRUE if the device is found in the auto pair blacklist 1559** FALSE otherwise 1560** 1561*******************************************************************************/ 1562BOOLEAN btif_storage_is_device_autopair_blacklisted(bt_bdaddr_t *remote_bd_addr) 1563{ 1564 char *token; 1565 int ret; 1566 bdstr_t bdstr; 1567 char *dev_name_str; 1568 uint8_t i = 0; 1569 char value[BTIF_STORAGE_MAX_LINE_SZ]; 1570 int value_size = sizeof(value); 1571 1572 bd2str(remote_bd_addr, &bdstr); 1573 1574 /* Consider only Lower Address Part from BD Address */ 1575 bdstr[8] = '\0'; 1576 1577 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1578 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_ADDR, value, &value_size)) 1579 { 1580 if (strcasestr(value,bdstr) != NULL) 1581 return TRUE; 1582 } 1583 1584 dev_name_str = BTM_SecReadDevName((remote_bd_addr->address)); 1585 1586 if (dev_name_str != NULL) 1587 { 1588 value_size = sizeof(value); 1589 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1590 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_EXACTNAME, value, &value_size)) 1591 { 1592 if (strstr(value,dev_name_str) != NULL) 1593 return TRUE; 1594 } 1595 value_size = sizeof(value); 1596 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1597 BTIF_STORAGE_KEY_AUTOPAIR_BLACKLIST_PARTIALNAME, value, &value_size)) 1598 { 1599 token = strtok(value, BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR); 1600 while (token != NULL) 1601 { 1602 if (strstr(dev_name_str, token) != NULL) 1603 return TRUE; 1604 1605 token = strtok(NULL, BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR); 1606 } 1607 } 1608 } 1609 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1610 BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR, value, &value_size)) 1611 { 1612 if (strstr(value,bdstr) != NULL) 1613 return TRUE; 1614 } 1615 return FALSE; 1616} 1617 1618/******************************************************************************* 1619** 1620** Function btif_storage_add_device_to_autopair_blacklist 1621** 1622** Description BTIF storage API - Add a remote device to the auto pairing blacklist 1623** 1624** Returns BT_STATUS_SUCCESS if the device is successfully added to the auto pair blacklist 1625** BT_STATUS_FAIL otherwise 1626** 1627*******************************************************************************/ 1628bt_status_t btif_storage_add_device_to_autopair_blacklist(bt_bdaddr_t *remote_bd_addr) 1629{ 1630 int ret; 1631 bdstr_t bdstr; 1632 char linebuf[BTIF_STORAGE_MAX_LINE_SZ+20]; 1633 char input_value [20]; 1634 1635 bd2str(remote_bd_addr, &bdstr); 1636 strlcpy(input_value, (char*)bdstr, sizeof(input_value)); 1637 strlcat(input_value,BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR, sizeof(input_value)); 1638 1639 int line_size = sizeof(linebuf); 1640 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1641 BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR, linebuf, &line_size)) 1642 { 1643 /* Append this address to the dynamic List of BD address */ 1644 strncat (linebuf, input_value, BTIF_STORAGE_MAX_LINE_SZ); 1645 } 1646 else 1647 { 1648 strncpy( linebuf,input_value, BTIF_STORAGE_MAX_LINE_SZ); 1649 } 1650 1651 /* Write back the key value */ 1652 ret = btif_config_set_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1653 BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR, linebuf); 1654 1655 return ret ? BT_STATUS_SUCCESS:BT_STATUS_FAIL; 1656} 1657 1658/******************************************************************************* 1659** 1660** Function btif_storage_is_fixed_pin_zeros_keyboard 1661** 1662** Description BTIF storage API - checks if this device has fixed PIN key device list 1663** 1664** Returns TRUE if the device is found in the fixed pin keyboard device list 1665** FALSE otherwise 1666** 1667*******************************************************************************/ 1668BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr) 1669{ 1670 int ret; 1671 bdstr_t bdstr; 1672 char *dev_name_str; 1673 uint8_t i = 0; 1674 char linebuf[BTIF_STORAGE_MAX_LINE_SZ]; 1675 1676 bd2str(remote_bd_addr, &bdstr); 1677 1678 /*consider on LAP part of BDA string*/ 1679 bdstr[8] = '\0'; 1680 1681 int line_size = sizeof(linebuf); 1682 if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST, 1683 BTIF_STORAGE_KEY_AUTOPAIR_FIXPIN_KBLIST, linebuf, &line_size)) 1684 { 1685 if (strcasestr(linebuf,bdstr) != NULL) 1686 return TRUE; 1687 } 1688 return FALSE; 1689 1690} 1691 1692/******************************************************************************* 1693** 1694** Function btif_storage_set_dmt_support_type 1695** 1696** Description Sets DMT support status for a remote device 1697** 1698** Returns BT_STATUS_SUCCESS if config update is successful 1699** BT_STATUS_FAIL otherwise 1700** 1701*******************************************************************************/ 1702 1703bt_status_t btif_storage_set_dmt_support_type(const bt_bdaddr_t *remote_bd_addr, 1704 BOOLEAN dmt_supported) 1705{ 1706 int ret; 1707 bdstr_t bdstr = {0}; 1708 if(remote_bd_addr) 1709 { 1710 bd2str(remote_bd_addr, &bdstr); 1711 } 1712 else 1713 { 1714 BTIF_TRACE_ERROR1("%s NULL BD Address", __FUNCTION__); 1715 return BT_STATUS_FAIL; 1716 } 1717 1718 ret = btif_config_set_int("Remote", bdstr,"DMTSupported", (int)dmt_supported); 1719 return ret ? BT_STATUS_SUCCESS:BT_STATUS_FAIL; 1720 1721} 1722 1723/******************************************************************************* 1724** 1725** Function btif_storage_is_dmt_supported_device 1726** 1727** Description checks if a device supports Dual mode topology 1728** 1729** Returns TRUE if remote address is valid and supports DMT else FALSE 1730** 1731*******************************************************************************/ 1732 1733BOOLEAN btif_storage_is_dmt_supported_device(const bt_bdaddr_t *remote_bd_addr) 1734{ 1735 int dmt_supported = 0; 1736 bdstr_t bdstr = {0}; 1737 if(remote_bd_addr) 1738 bd2str(remote_bd_addr, &bdstr); 1739 1740 if(remote_bd_addr) 1741 { 1742 bd2str(remote_bd_addr, &bdstr); 1743 } 1744 else 1745 { 1746 BTIF_TRACE_ERROR1("%s NULL BD Address", __FUNCTION__); 1747 return FALSE; 1748 } 1749 1750 btif_config_get_int("Remote", bdstr,"DMTSupported", &dmt_supported); 1751 1752 return dmt_supported == 1 ? TRUE:FALSE; 1753} 1754 1755 1756