btm_dev.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /******************************************************************************
  2. *
  3. * Copyright 1999-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. * This file contains functions for the Bluetooth Device Manager
  21. *
  22. ******************************************************************************/
  23. #include <stddef.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "bt_common.h"
  28. #include "bt_types.h"
  29. #include "btm_api.h"
  30. #include "btm_int.h"
  31. #include "btu.h"
  32. #include "device/include/controller.h"
  33. #include "hcidefs.h"
  34. #include "hcimsgs.h"
  35. #include "l2c_api.h"
  36. /*******************************************************************************
  37. *
  38. * Function BTM_SecAddDevice
  39. *
  40. * Description Add/modify device. This function will be normally called
  41. * during host startup to restore all required information
  42. * stored in the NVRAM.
  43. *
  44. * Parameters: bd_addr - BD address of the peer
  45. * dev_class - Device Class
  46. * bd_name - Name of the peer device. NULL if unknown.
  47. * features - Remote device's features (up to 3 pages).
  48. * NULL if not known
  49. * trusted_mask - Bitwise OR of services that do not
  50. * require authorization.
  51. * (array of uint32_t)
  52. * link_key - Connection link key. NULL if unknown.
  53. *
  54. * Returns true if added OK, else false
  55. *
  56. ******************************************************************************/
  57. bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
  58. BD_NAME bd_name, uint8_t* features,
  59. uint32_t trusted_mask[], LinkKey* p_link_key,
  60. uint8_t key_type, tBTM_IO_CAP io_cap,
  61. uint8_t pin_length) {
  62. BTM_TRACE_API("%s: link key type:%x", __func__, key_type);
  63. tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  64. if (!p_dev_rec) {
  65. p_dev_rec = btm_sec_allocate_dev_rec();
  66. BTM_TRACE_API("%s: allocated p_dev_rec=%p, bd_addr=%s", __func__, p_dev_rec,
  67. bd_addr.ToString().c_str());
  68. p_dev_rec->bd_addr = bd_addr;
  69. p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR);
  70. /* use default value for background connection params */
  71. /* update conn params, use default value for background connection params */
  72. memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS));
  73. } else {
  74. /* "Bump" timestamp for existing record */
  75. p_dev_rec->timestamp = btm_cb.dev_rec_count++;
  76. /* TODO(eisenbach):
  77. * Small refactor, but leaving original logic for now.
  78. * On the surface, this does not make any sense at all. Why change the
  79. * bond state for an existing device here? This logic should be verified
  80. * as part of a larger refactor.
  81. */
  82. p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
  83. }
  84. if (dev_class) memcpy(p_dev_rec->dev_class, dev_class, DEV_CLASS_LEN);
  85. memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME));
  86. if (bd_name && bd_name[0]) {
  87. p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN;
  88. strlcpy((char*)p_dev_rec->sec_bd_name, (char*)bd_name,
  89. BTM_MAX_REM_BD_NAME_LEN);
  90. }
  91. p_dev_rec->num_read_pages = 0;
  92. if (features) {
  93. bool found = false;
  94. memcpy(p_dev_rec->feature_pages, features,
  95. sizeof(p_dev_rec->feature_pages));
  96. for (int i = HCI_EXT_FEATURES_PAGE_MAX; !found && i >= 0; i--) {
  97. for (int j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++) {
  98. if (p_dev_rec->feature_pages[i][j] != 0) {
  99. found = true;
  100. p_dev_rec->num_read_pages = i + 1;
  101. break;
  102. }
  103. }
  104. }
  105. } else {
  106. memset(p_dev_rec->feature_pages, 0, sizeof(p_dev_rec->feature_pages));
  107. }
  108. BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask);
  109. if (p_link_key) {
  110. VLOG(2) << __func__ << ": BDA: " << bd_addr;
  111. p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN;
  112. p_dev_rec->link_key = *p_link_key;
  113. p_dev_rec->link_key_type = key_type;
  114. p_dev_rec->pin_code_length = pin_length;
  115. if (pin_length >= 16 || key_type == BTM_LKEY_TYPE_AUTH_COMB ||
  116. key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) {
  117. // Set the flag if the link key was made by using either a 16 digit
  118. // pin or MITM.
  119. p_dev_rec->sec_flags |=
  120. BTM_SEC_16_DIGIT_PIN_AUTHED | BTM_SEC_LINK_KEY_AUTHED;
  121. }
  122. }
  123. #if (BTIF_MIXED_MODE_INCLUDED == TRUE)
  124. if (key_type < BTM_MAX_PRE_SM4_LKEY_TYPE)
  125. p_dev_rec->sm4 = BTM_SM4_KNOWN;
  126. else
  127. p_dev_rec->sm4 = BTM_SM4_TRUE;
  128. #endif
  129. p_dev_rec->rmt_io_caps = io_cap;
  130. p_dev_rec->device_type |= BT_DEVICE_TYPE_BREDR;
  131. return true;
  132. }
  133. void wipe_secrets_and_remove(tBTM_SEC_DEV_REC* p_dev_rec) {
  134. p_dev_rec->link_key.fill(0);
  135. memset(&p_dev_rec->ble.keys, 0, sizeof(tBTM_SEC_BLE_KEYS));
  136. list_remove(btm_cb.sec_dev_rec, p_dev_rec);
  137. }
  138. /** Free resources associated with the device associated with |bd_addr| address.
  139. *
  140. * *** WARNING ***
  141. * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function
  142. * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is
  143. * no longer valid!
  144. * *** WARNING ***
  145. *
  146. * Returns true if removed OK, false if not found or ACL link is active.
  147. */
  148. bool BTM_SecDeleteDevice(const RawAddress& bd_addr) {
  149. if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
  150. BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) {
  151. BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active",
  152. __func__);
  153. return false;
  154. }
  155. tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  156. if (p_dev_rec != NULL) {
  157. RawAddress bda = p_dev_rec->bd_addr;
  158. /* Clear out any saved BLE keys */
  159. btm_sec_clear_ble_keys(p_dev_rec);
  160. wipe_secrets_and_remove(p_dev_rec);
  161. /* Tell controller to get rid of the link key, if it has one stored */
  162. BTM_DeleteStoredLinkKey(&bda, NULL);
  163. }
  164. return true;
  165. }
  166. /*******************************************************************************
  167. *
  168. * Function BTM_SecClearSecurityFlags
  169. *
  170. * Description Reset the security flags (mark as not-paired) for a given
  171. * remove device.
  172. *
  173. ******************************************************************************/
  174. extern void BTM_SecClearSecurityFlags(const RawAddress& bd_addr) {
  175. tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  176. if (p_dev_rec == NULL) return;
  177. p_dev_rec->sec_flags = 0;
  178. p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
  179. p_dev_rec->sm4 = BTM_SM4_UNKNOWN;
  180. }
  181. /*******************************************************************************
  182. *
  183. * Function BTM_SecReadDevName
  184. *
  185. * Description Looks for the device name in the security database for the
  186. * specified BD address.
  187. *
  188. * Returns Pointer to the name or NULL
  189. *
  190. ******************************************************************************/
  191. char* BTM_SecReadDevName(const RawAddress& bd_addr) {
  192. char* p_name = NULL;
  193. tBTM_SEC_DEV_REC* p_srec;
  194. p_srec = btm_find_dev(bd_addr);
  195. if (p_srec != NULL) p_name = (char*)p_srec->sec_bd_name;
  196. return (p_name);
  197. }
  198. /*******************************************************************************
  199. *
  200. * Function btm_sec_alloc_dev
  201. *
  202. * Description Look for the record in the device database for the record
  203. * with specified address
  204. *
  205. * Returns Pointer to the record or NULL
  206. *
  207. ******************************************************************************/
  208. tBTM_SEC_DEV_REC* btm_sec_alloc_dev(const RawAddress& bd_addr) {
  209. tBTM_INQ_INFO* p_inq_info;
  210. tBTM_SEC_DEV_REC* p_dev_rec = btm_sec_allocate_dev_rec();
  211. BTM_TRACE_EVENT("%s: allocated p_dev_rec=%p, bd_addr=%s", __func__, p_dev_rec,
  212. bd_addr.ToString().c_str());
  213. /* Check with the BT manager if details about remote device are known */
  214. /* outgoing connection */
  215. p_inq_info = BTM_InqDbRead(bd_addr);
  216. if (p_inq_info != NULL) {
  217. memcpy(p_dev_rec->dev_class, p_inq_info->results.dev_class, DEV_CLASS_LEN);
  218. p_dev_rec->device_type = p_inq_info->results.device_type;
  219. p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type;
  220. } else if (bd_addr == btm_cb.connecting_bda)
  221. memcpy(p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN);
  222. /* update conn params, use default value for background connection params */
  223. memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS));
  224. p_dev_rec->bd_addr = bd_addr;
  225. p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);
  226. p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR);
  227. return (p_dev_rec);
  228. }
  229. /*******************************************************************************
  230. *
  231. * Function btm_dev_support_switch
  232. *
  233. * Description This function is called by the L2CAP to check if remote
  234. * device supports role switch
  235. *
  236. * Parameters: bd_addr - Address of the peer device
  237. *
  238. * Returns true if device is known and role switch is supported
  239. *
  240. ******************************************************************************/
  241. bool btm_dev_support_switch(const RawAddress& bd_addr) {
  242. tBTM_SEC_DEV_REC* p_dev_rec;
  243. uint8_t xx;
  244. bool feature_empty = true;
  245. /* Role switch is not allowed if a SCO is up */
  246. if (btm_is_sco_active_by_bdaddr(bd_addr)) return (false);
  247. p_dev_rec = btm_find_dev(bd_addr);
  248. if (p_dev_rec &&
  249. controller_get_interface()->supports_master_slave_role_switch()) {
  250. if (HCI_SWITCH_SUPPORTED(p_dev_rec->feature_pages[0])) {
  251. BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature found)");
  252. return (true);
  253. }
  254. /* If the feature field is all zero, we never received them */
  255. for (xx = 0; xx < BD_FEATURES_LEN; xx++) {
  256. if (p_dev_rec->feature_pages[0][xx] != 0x00) {
  257. feature_empty = false; /* at least one is != 0 */
  258. break;
  259. }
  260. }
  261. /* If we don't know peer's capabilities, assume it supports Role-switch */
  262. if (feature_empty) {
  263. BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature empty)");
  264. return (true);
  265. }
  266. }
  267. BTM_TRACE_DEBUG("btm_dev_support_switch return false");
  268. return (false);
  269. }
  270. bool is_handle_equal(void* data, void* context) {
  271. tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data);
  272. uint16_t* handle = static_cast<uint16_t*>(context);
  273. if (p_dev_rec->hci_handle == *handle || p_dev_rec->ble_hci_handle == *handle)
  274. return false;
  275. return true;
  276. }
  277. /*******************************************************************************
  278. *
  279. * Function btm_find_dev_by_handle
  280. *
  281. * Description Look for the record in the device database for the record
  282. * with specified handle
  283. *
  284. * Returns Pointer to the record or NULL
  285. *
  286. ******************************************************************************/
  287. tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) {
  288. list_node_t* n = list_foreach(btm_cb.sec_dev_rec, is_handle_equal, &handle);
  289. if (n) return static_cast<tBTM_SEC_DEV_REC*>(list_node(n));
  290. return NULL;
  291. }
  292. bool is_address_equal(void* data, void* context) {
  293. tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data);
  294. const RawAddress* bd_addr = ((RawAddress*)context);
  295. if (p_dev_rec->bd_addr == *bd_addr) return false;
  296. // If a LE random address is looking for device record
  297. if (p_dev_rec->ble.pseudo_addr == *bd_addr) return false;
  298. if (btm_ble_addr_resolvable(*bd_addr, p_dev_rec)) return false;
  299. return true;
  300. }
  301. /*******************************************************************************
  302. *
  303. * Function btm_find_dev
  304. *
  305. * Description Look for the record in the device database for the record
  306. * with specified BD address
  307. *
  308. * Returns Pointer to the record or NULL
  309. *
  310. ******************************************************************************/
  311. tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr) {
  312. list_node_t* n =
  313. list_foreach(btm_cb.sec_dev_rec, is_address_equal, (void*)&bd_addr);
  314. if (n) return static_cast<tBTM_SEC_DEV_REC*>(list_node(n));
  315. return NULL;
  316. }
  317. /*******************************************************************************
  318. *
  319. * Function btm_consolidate_dev
  320. 5**
  321. * Description combine security records if identified as same peer
  322. *
  323. * Returns none
  324. *
  325. ******************************************************************************/
  326. void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec) {
  327. tBTM_SEC_DEV_REC temp_rec = *p_target_rec;
  328. BTM_TRACE_DEBUG("%s", __func__);
  329. list_node_t* end = list_end(btm_cb.sec_dev_rec);
  330. list_node_t* node = list_begin(btm_cb.sec_dev_rec);
  331. while (node != end) {
  332. tBTM_SEC_DEV_REC* p_dev_rec =
  333. static_cast<tBTM_SEC_DEV_REC*>(list_node(node));
  334. // we do list_remove in some cases, must grab next before removing
  335. node = list_next(node);
  336. if (p_target_rec == p_dev_rec) continue;
  337. if (p_dev_rec->bd_addr == p_target_rec->bd_addr) {
  338. memcpy(p_target_rec, p_dev_rec, sizeof(tBTM_SEC_DEV_REC));
  339. p_target_rec->ble = temp_rec.ble;
  340. p_target_rec->ble_hci_handle = temp_rec.ble_hci_handle;
  341. p_target_rec->enc_key_size = temp_rec.enc_key_size;
  342. p_target_rec->conn_params = temp_rec.conn_params;
  343. p_target_rec->device_type |= temp_rec.device_type;
  344. p_target_rec->sec_flags |= temp_rec.sec_flags;
  345. p_target_rec->new_encryption_key_is_p256 =
  346. temp_rec.new_encryption_key_is_p256;
  347. p_target_rec->no_smp_on_br = temp_rec.no_smp_on_br;
  348. p_target_rec->bond_type = temp_rec.bond_type;
  349. /* remove the combined record */
  350. wipe_secrets_and_remove(p_dev_rec);
  351. // p_dev_rec gets freed in list_remove, we should not access it further
  352. continue;
  353. }
  354. /* an RPA device entry is a duplicate of the target record */
  355. if (btm_ble_addr_resolvable(p_dev_rec->bd_addr, p_target_rec)) {
  356. if (p_target_rec->ble.pseudo_addr == p_dev_rec->bd_addr) {
  357. p_target_rec->ble.ble_addr_type = p_dev_rec->ble.ble_addr_type;
  358. p_target_rec->device_type |= p_dev_rec->device_type;
  359. /* remove the combined record */
  360. wipe_secrets_and_remove(p_dev_rec);
  361. }
  362. }
  363. }
  364. }
  365. /*******************************************************************************
  366. *
  367. * Function btm_find_or_alloc_dev
  368. *
  369. * Description Look for the record in the device database for the record
  370. * with specified BD address
  371. *
  372. * Returns Pointer to the record or NULL
  373. *
  374. ******************************************************************************/
  375. tBTM_SEC_DEV_REC* btm_find_or_alloc_dev(const RawAddress& bd_addr) {
  376. tBTM_SEC_DEV_REC* p_dev_rec;
  377. BTM_TRACE_EVENT("btm_find_or_alloc_dev");
  378. p_dev_rec = btm_find_dev(bd_addr);
  379. if (p_dev_rec == NULL) {
  380. /* Allocate a new device record or reuse the oldest one */
  381. p_dev_rec = btm_sec_alloc_dev(bd_addr);
  382. }
  383. return (p_dev_rec);
  384. }
  385. /*******************************************************************************
  386. *
  387. * Function btm_find_oldest_dev_rec
  388. *
  389. * Description Locates the oldest device in use. It first looks for
  390. * the oldest non-paired device. If all devices are paired it
  391. * returns the oldest paired device.
  392. *
  393. * Returns Pointer to the record or NULL
  394. *
  395. ******************************************************************************/
  396. static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec(void) {
  397. tBTM_SEC_DEV_REC* p_oldest = NULL;
  398. uint32_t ts_oldest = 0xFFFFFFFF;
  399. tBTM_SEC_DEV_REC* p_oldest_paired = NULL;
  400. uint32_t ts_oldest_paired = 0xFFFFFFFF;
  401. list_node_t* end = list_end(btm_cb.sec_dev_rec);
  402. for (list_node_t* node = list_begin(btm_cb.sec_dev_rec); node != end;
  403. node = list_next(node)) {
  404. tBTM_SEC_DEV_REC* p_dev_rec =
  405. static_cast<tBTM_SEC_DEV_REC*>(list_node(node));
  406. if ((p_dev_rec->sec_flags &
  407. (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_KNOWN)) == 0) {
  408. // Device is not paired
  409. if (p_dev_rec->timestamp < ts_oldest) {
  410. p_oldest = p_dev_rec;
  411. ts_oldest = p_dev_rec->timestamp;
  412. }
  413. } else {
  414. // Paired device
  415. if (p_dev_rec->timestamp < ts_oldest_paired) {
  416. p_oldest_paired = p_dev_rec;
  417. ts_oldest_paired = p_dev_rec->timestamp;
  418. }
  419. }
  420. }
  421. // If we did not find any non-paired devices, use the oldest paired one...
  422. if (ts_oldest == 0xFFFFFFFF) p_oldest = p_oldest_paired;
  423. return p_oldest;
  424. }
  425. /*******************************************************************************
  426. *
  427. * Function btm_sec_allocate_dev_rec
  428. *
  429. * Description Attempts to allocate a new device record. If we have
  430. * exceeded the maximum number of allowable records to
  431. * allocate, the oldest record will be deleted to make room
  432. * for the new record.
  433. *
  434. * Returns Pointer to the newly allocated record
  435. *
  436. ******************************************************************************/
  437. tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) {
  438. tBTM_SEC_DEV_REC* p_dev_rec = NULL;
  439. if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) {
  440. p_dev_rec = btm_find_oldest_dev_rec();
  441. wipe_secrets_and_remove(p_dev_rec);
  442. }
  443. p_dev_rec =
  444. static_cast<tBTM_SEC_DEV_REC*>(osi_calloc(sizeof(tBTM_SEC_DEV_REC)));
  445. list_append(btm_cb.sec_dev_rec, p_dev_rec);
  446. // Initialize defaults
  447. p_dev_rec->sec_flags = BTM_SEC_IN_USE;
  448. p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
  449. p_dev_rec->timestamp = btm_cb.dev_rec_count++;
  450. p_dev_rec->rmt_io_caps = BTM_IO_CAP_UNKNOWN;
  451. return p_dev_rec;
  452. }
  453. /*******************************************************************************
  454. *
  455. * Function btm_get_bond_type_dev
  456. *
  457. * Description Get the bond type for a device in the device database
  458. * with specified BD address
  459. *
  460. * Returns The device bond type if known, otherwise BOND_TYPE_UNKNOWN
  461. *
  462. ******************************************************************************/
  463. tBTM_BOND_TYPE btm_get_bond_type_dev(const RawAddress& bd_addr) {
  464. tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  465. if (p_dev_rec == NULL) return BOND_TYPE_UNKNOWN;
  466. return p_dev_rec->bond_type;
  467. }
  468. /*******************************************************************************
  469. *
  470. * Function btm_set_bond_type_dev
  471. *
  472. * Description Set the bond type for a device in the device database
  473. * with specified BD address
  474. *
  475. * Returns true on success, otherwise false
  476. *
  477. ******************************************************************************/
  478. bool btm_set_bond_type_dev(const RawAddress& bd_addr,
  479. tBTM_BOND_TYPE bond_type) {
  480. tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  481. if (p_dev_rec == NULL) return false;
  482. p_dev_rec->bond_type = bond_type;
  483. return true;
  484. }