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