btm_ble_addr.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 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 BLE address management.
  21. *
  22. ******************************************************************************/
  23. #include <string.h>
  24. #include "bt_types.h"
  25. #include "hcimsgs.h"
  26. #include "btu.h"
  27. #include "btm_int.h"
  28. #include "gap_api.h"
  29. #include "controller.h"
  30. #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
  31. #include "btm_ble_int.h"
  32. #include "smp_api.h"
  33. /*******************************************************************************
  34. **
  35. ** Function btm_gen_resolve_paddr_cmpl
  36. **
  37. ** Description This is callback functioin when resolvable private address
  38. ** generation is complete.
  39. **
  40. ** Returns void
  41. **
  42. *******************************************************************************/
  43. static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
  44. {
  45. tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  46. BTM_TRACE_EVENT ("btm_gen_resolve_paddr_cmpl");
  47. if (p) {
  48. /* set hash to be LSB of rpAddress */
  49. p_cb->private_addr[5] = p->param_buf[0];
  50. p_cb->private_addr[4] = p->param_buf[1];
  51. p_cb->private_addr[3] = p->param_buf[2];
  52. /* set it to controller */
  53. btsnd_hcic_ble_set_random_addr(p_cb->private_addr);
  54. p_cb->own_addr_type = BLE_ADDR_RANDOM;
  55. /* start a periodical timer to refresh random addr */
  56. btu_stop_timer_oneshot(&p_cb->raddr_timer_ent);
  57. #if (BTM_BLE_CONFORMANCE_TESTING == TRUE)
  58. btu_start_timer_oneshot(&p_cb->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
  59. btm_cb.ble_ctr_cb.rpa_tout);
  60. #else
  61. btu_start_timer_oneshot(&p_cb->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
  62. BTM_BLE_PRIVATE_ADDR_INT);
  63. #endif
  64. } else {
  65. /* random address set failure */
  66. BTM_TRACE_DEBUG("set random address failed");
  67. }
  68. }
  69. /*******************************************************************************
  70. **
  71. ** Function btm_gen_resolve_paddr_low
  72. **
  73. ** Description This function is called when random address has generate the
  74. ** random number base for low 3 byte bd address.
  75. **
  76. ** Returns void
  77. **
  78. *******************************************************************************/
  79. void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p)
  80. {
  81. #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
  82. tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  83. tSMP_ENC output;
  84. BTM_TRACE_EVENT ("btm_gen_resolve_paddr_low");
  85. if (p) {
  86. p->param_buf[2] &= (~BLE_RESOLVE_ADDR_MASK);
  87. p->param_buf[2] |= BLE_RESOLVE_ADDR_MSB;
  88. p_cb->private_addr[2] = p->param_buf[0];
  89. p_cb->private_addr[1] = p->param_buf[1];
  90. p_cb->private_addr[0] = p->param_buf[2];
  91. /* encrypt with ur IRK */
  92. if (!SMP_Encrypt(btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN, p->param_buf, 3, &output)) {
  93. btm_gen_resolve_paddr_cmpl(NULL);
  94. } else {
  95. btm_gen_resolve_paddr_cmpl(&output);
  96. }
  97. }
  98. #endif
  99. }
  100. /*******************************************************************************
  101. **
  102. ** Function btm_gen_resolvable_private_addr
  103. **
  104. ** Description This function generate a resolvable private address.
  105. **
  106. ** Returns void
  107. **
  108. *******************************************************************************/
  109. void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback)
  110. {
  111. BTM_TRACE_EVENT ("btm_gen_resolvable_private_addr");
  112. /* generate 3B rand as BD LSB, SRK with it, get BD MSB */
  113. if (!btsnd_hcic_ble_rand((void *)p_cmd_cplt_cback)) {
  114. btm_gen_resolve_paddr_cmpl(NULL);
  115. }
  116. }
  117. /*******************************************************************************
  118. **
  119. ** Function btm_gen_non_resolve_paddr_cmpl
  120. **
  121. ** Description This is the callback function when non-resolvable private
  122. ** function is generated and write to controller.
  123. **
  124. ** Returns void
  125. **
  126. *******************************************************************************/
  127. static void btm_gen_non_resolve_paddr_cmpl(tBTM_RAND_ENC *p)
  128. {
  129. tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  130. tBTM_BLE_ADDR_CBACK *p_cback = p_cb->p_generate_cback;
  131. void *p_data = p_cb->p;
  132. UINT8 *pp;
  133. BD_ADDR static_random;
  134. BTM_TRACE_EVENT ("btm_gen_non_resolve_paddr_cmpl");
  135. p_cb->p_generate_cback = NULL;
  136. if (p) {
  137. pp = p->param_buf;
  138. STREAM_TO_BDADDR(static_random, pp);
  139. /* mask off the 2 MSB */
  140. static_random[0] &= BLE_STATIC_PRIVATE_MSB_MASK;
  141. /* report complete */
  142. if (p_cback) {
  143. (* p_cback)(static_random, p_data);
  144. }
  145. } else {
  146. BTM_TRACE_DEBUG("btm_gen_non_resolvable_private_addr failed");
  147. if (p_cback) {
  148. (* p_cback)(NULL, p_data);
  149. }
  150. }
  151. }
  152. /*******************************************************************************
  153. **
  154. ** Function btm_gen_non_resolvable_private_addr
  155. **
  156. ** Description This function generate a non-resolvable private address.
  157. **
  158. **
  159. ** Returns void
  160. **
  161. *******************************************************************************/
  162. void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p)
  163. {
  164. tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  165. BTM_TRACE_EVENT ("btm_gen_non_resolvable_private_addr");
  166. if (p_mgnt_cb->p_generate_cback != NULL) {
  167. return;
  168. }
  169. p_mgnt_cb->p_generate_cback = p_cback;
  170. p_mgnt_cb->p = p;
  171. if (!btsnd_hcic_ble_rand((void *)btm_gen_non_resolve_paddr_cmpl)) {
  172. btm_gen_non_resolve_paddr_cmpl(NULL);
  173. }
  174. }
  175. #if SMP_INCLUDED == TRUE
  176. /*******************************************************************************
  177. ** Utility functions for Random address resolving
  178. *******************************************************************************/
  179. /*******************************************************************************
  180. **
  181. ** Function btm_ble_resolve_address_cmpl
  182. **
  183. ** Description This function sends the random address resolving complete
  184. ** callback.
  185. **
  186. ** Returns None.
  187. **
  188. *******************************************************************************/
  189. static void btm_ble_resolve_address_cmpl(void)
  190. {
  191. tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  192. tBTM_SEC_DEV_REC *p_dev_rec = NULL;
  193. BTM_TRACE_EVENT ("btm_ble_resolve_address_cmpl p_mgnt_cb->index = %d", p_mgnt_cb->index);
  194. if (p_mgnt_cb->index < BTM_SEC_MAX_DEVICE_RECORDS) {
  195. p_dev_rec = &btm_cb.sec_dev_rec[p_mgnt_cb->index];
  196. }
  197. p_mgnt_cb->busy = FALSE;
  198. (* p_mgnt_cb->p_resolve_cback)(p_dev_rec, p_mgnt_cb->p);
  199. }
  200. /*******************************************************************************
  201. **
  202. ** Function btm_ble_proc_resolve_x
  203. **
  204. ** Description This function compares the X with random address 3 MSO bytes
  205. ** to find a match, if not match, continue for next record.
  206. **
  207. ** Returns None.
  208. **
  209. *******************************************************************************/
  210. static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p)
  211. {
  212. tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  213. UINT8 comp[3];
  214. BTM_TRACE_EVENT ("btm_ble_proc_resolve_x");
  215. /* compare the hash with 3 LSB of bd address */
  216. comp[0] = p_mgnt_cb->random_bda[5];
  217. comp[1] = p_mgnt_cb->random_bda[4];
  218. comp[2] = p_mgnt_cb->random_bda[3];
  219. if (p) {
  220. if (!memcmp(p->param_buf, &comp[0], 3)) {
  221. /* match is found */
  222. BTM_TRACE_EVENT ("match is found");
  223. btm_ble_resolve_address_cmpl();
  224. return TRUE;
  225. }
  226. }
  227. return FALSE;
  228. }
  229. /*******************************************************************************
  230. **
  231. ** Function btm_ble_init_pseudo_addr
  232. **
  233. ** Description This function is used to initialize pseudo address.
  234. ** If pseudo address is not available, use dummy address
  235. **
  236. ** Returns TRUE is updated; FALSE otherwise.
  237. **
  238. *******************************************************************************/
  239. BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr)
  240. {
  241. BD_ADDR dummy_bda = {0};
  242. if (memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN) == 0) {
  243. memcpy(p_dev_rec->ble.pseudo_addr, new_pseudo_addr, BD_ADDR_LEN);
  244. return TRUE;
  245. }
  246. return FALSE;
  247. }
  248. /*******************************************************************************
  249. **
  250. ** Function btm_ble_addr_resolvable
  251. **
  252. ** Description This function checks if a RPA is resolvable by the device key.
  253. **
  254. ** Returns TRUE is resolvable; FALSE otherwise.
  255. **
  256. *******************************************************************************/
  257. BOOLEAN btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec)
  258. {
  259. BOOLEAN rt = FALSE;
  260. if (!BTM_BLE_IS_RESOLVE_BDA(rpa)) {
  261. return rt;
  262. }
  263. UINT8 rand[3];
  264. tSMP_ENC output;
  265. if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) &&
  266. (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) {
  267. BTM_TRACE_DEBUG("%s try to resolve", __func__);
  268. /* use the 3 MSB of bd address as prand */
  269. rand[0] = rpa[2];
  270. rand[1] = rpa[1];
  271. rand[2] = rpa[0];
  272. /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */
  273. SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN,
  274. &rand[0], 3, &output);
  275. rand[0] = rpa[5];
  276. rand[1] = rpa[4];
  277. rand[2] = rpa[3];
  278. if (!memcmp(output.param_buf, &rand[0], 3)) {
  279. btm_ble_init_pseudo_addr (p_dev_rec, rpa);
  280. rt = TRUE;
  281. }
  282. }
  283. return rt;
  284. }
  285. /*******************************************************************************
  286. **
  287. ** Function btm_ble_match_random_bda
  288. **
  289. ** Description This function match the random address to the appointed device
  290. ** record, starting from calculating IRK. If record index exceed
  291. ** the maximum record number, matching failed and send callback.
  292. **
  293. ** Returns None.
  294. **
  295. *******************************************************************************/
  296. static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index)
  297. {
  298. #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
  299. /* use the 3 MSB of bd address as prand */
  300. tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  301. UINT8 rand[3];
  302. rand[0] = p_mgnt_cb->random_bda[2];
  303. rand[1] = p_mgnt_cb->random_bda[1];
  304. rand[2] = p_mgnt_cb->random_bda[0];
  305. BTM_TRACE_EVENT("%s rec_index = %d", __func__, rec_index);
  306. if (rec_index < BTM_SEC_MAX_DEVICE_RECORDS) {
  307. tSMP_ENC output;
  308. tBTM_SEC_DEV_REC *p_dev_rec;
  309. p_dev_rec = &btm_cb.sec_dev_rec[rec_index];
  310. BTM_TRACE_DEBUG("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags,
  311. p_dev_rec->device_type);
  312. if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) &&
  313. (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) {
  314. /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */
  315. SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN,
  316. &rand[0], 3, &output);
  317. return btm_ble_proc_resolve_x(&output);
  318. } else {
  319. // not completed
  320. return FALSE;
  321. }
  322. } else { /* no match found */
  323. btm_ble_resolve_address_cmpl();
  324. return TRUE;
  325. }
  326. #endif
  327. }
  328. /*******************************************************************************
  329. **
  330. ** Function btm_ble_resolve_random_addr
  331. **
  332. ** Description This function is called to resolve a random address.
  333. **
  334. ** Returns pointer to the security record of the device whom a random
  335. ** address is matched to.
  336. **
  337. *******************************************************************************/
  338. void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK *p_cback, void *p)
  339. {
  340. tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
  341. BTM_TRACE_EVENT ("btm_ble_resolve_random_addr");
  342. if ( !p_mgnt_cb->busy) {
  343. p_mgnt_cb->p = p;
  344. p_mgnt_cb->busy = TRUE;
  345. p_mgnt_cb->index = 0;
  346. p_mgnt_cb->p_resolve_cback = p_cback;
  347. memcpy(p_mgnt_cb->random_bda, random_bda, BD_ADDR_LEN);
  348. /* start to resolve random address */
  349. /* check for next security record */
  350. while (TRUE) {
  351. if (btm_ble_match_random_bda(p_mgnt_cb->index)) {
  352. /* atch found or went through the list */
  353. break;
  354. }
  355. p_mgnt_cb->index ++;
  356. }
  357. } else {
  358. (*p_cback)(NULL, p);
  359. }
  360. }
  361. #endif
  362. /*******************************************************************************
  363. ** address mapping between pseudo address and real connection address
  364. *******************************************************************************/
  365. /*******************************************************************************
  366. **
  367. ** Function btm_find_dev_by_identity_addr
  368. **
  369. ** Description find the security record whose LE static address is matching
  370. **
  371. *******************************************************************************/
  372. tBTM_SEC_DEV_REC *btm_find_dev_by_identity_addr(BD_ADDR bd_addr, UINT8 addr_type)
  373. {
  374. #if BLE_PRIVACY_SPT == TRUE
  375. UINT8 i;
  376. tBTM_SEC_DEV_REC *p_dev_rec = &btm_cb.sec_dev_rec[0];
  377. for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev_rec ++) {
  378. if ((p_dev_rec->sec_flags & BTM_SEC_IN_USE) &&
  379. memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) {
  380. if ((p_dev_rec->ble.static_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) !=
  381. (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) {
  382. BTM_TRACE_WARNING("%s find pseudo->random match with diff addr type: %d vs %d",
  383. __func__, p_dev_rec->ble.static_addr_type, addr_type);
  384. }
  385. /* found the match */
  386. return p_dev_rec;
  387. }
  388. }
  389. #endif
  390. return NULL;
  391. }
  392. /*******************************************************************************
  393. **
  394. ** Function btm_identity_addr_to_random_pseudo
  395. **
  396. ** Description This function map a static BD address to a pseudo random address
  397. ** in security database.
  398. **
  399. *******************************************************************************/
  400. BOOLEAN btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, UINT8 *p_addr_type, BOOLEAN refresh)
  401. {
  402. #if BLE_PRIVACY_SPT == TRUE
  403. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_identity_addr(bd_addr, *p_addr_type);
  404. BTM_TRACE_EVENT ("%s", __func__);
  405. /* evt reported on static address, map static address to random pseudo */
  406. if (p_dev_rec != NULL) {
  407. /* if RPA offloading is supported, or 4.2 controller, do RPA refresh */
  408. if (refresh && controller_get_interface()->get_ble_resolving_list_max_size() != 0) {
  409. btm_ble_read_resolving_list_entry(p_dev_rec);
  410. }
  411. /* assign the original address to be the current report address */
  412. if (!btm_ble_init_pseudo_addr (p_dev_rec, bd_addr)) {
  413. memcpy(bd_addr, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN);
  414. }
  415. *p_addr_type = p_dev_rec->ble.ble_addr_type;
  416. return TRUE;
  417. }
  418. #endif
  419. return FALSE;
  420. }
  421. /*******************************************************************************
  422. **
  423. ** Function btm_random_pseudo_to_identity_addr
  424. **
  425. ** Description This function map a random pseudo address to a public address
  426. ** random_pseudo is input and output parameter
  427. **
  428. *******************************************************************************/
  429. BOOLEAN btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, UINT8 *p_static_addr_type)
  430. {
  431. #if BLE_PRIVACY_SPT == TRUE
  432. tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (random_pseudo);
  433. if (p_dev_rec != NULL) {
  434. if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) {
  435. * p_static_addr_type = p_dev_rec->ble.static_addr_type;
  436. memcpy(random_pseudo, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
  437. if (controller_get_interface()->supports_ble_privacy()) {
  438. *p_static_addr_type |= BLE_ADDR_TYPE_ID_BIT;
  439. }
  440. return TRUE;
  441. }
  442. }
  443. #endif
  444. return FALSE;
  445. }
  446. /*******************************************************************************
  447. **
  448. ** Function btm_ble_refresh_peer_resolvable_private_addr
  449. **
  450. ** Description This function refresh the currently used resolvable remote private address into security
  451. ** database and set active connection address.
  452. **
  453. *******************************************************************************/
  454. void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rpa,
  455. UINT8 rra_type)
  456. {
  457. #if BLE_PRIVACY_SPT == TRUE
  458. UINT8 rra_dummy = FALSE;
  459. BD_ADDR dummy_bda = {0};
  460. if (memcmp(dummy_bda, rpa, BD_ADDR_LEN) == 0) {
  461. rra_dummy = TRUE;
  462. }
  463. /* update security record here, in adv event or connection complete process */
  464. tBTM_SEC_DEV_REC *p_sec_rec = btm_find_dev(pseudo_bda);
  465. if (p_sec_rec != NULL) {
  466. memcpy(p_sec_rec->ble.cur_rand_addr, rpa, BD_ADDR_LEN);
  467. /* unknown, if dummy address, set to static */
  468. if (rra_type == BTM_BLE_ADDR_PSEUDO) {
  469. p_sec_rec->ble.active_addr_type = rra_dummy ? BTM_BLE_ADDR_STATIC : BTM_BLE_ADDR_RRA;
  470. } else {
  471. p_sec_rec->ble.active_addr_type = rra_type;
  472. }
  473. } else {
  474. BTM_TRACE_ERROR("No matching known device in record");
  475. return;
  476. }
  477. BTM_TRACE_DEBUG("%s: active_addr_type: %d ",
  478. __func__, p_sec_rec->ble.active_addr_type);
  479. /* connection refresh remote address */
  480. tACL_CONN *p_acl = btm_bda_to_acl(p_sec_rec->bd_addr, BT_TRANSPORT_LE);
  481. if (p_acl == NULL) {
  482. p_acl = btm_bda_to_acl(p_sec_rec->ble.pseudo_addr, BT_TRANSPORT_LE);
  483. }
  484. if (p_acl != NULL) {
  485. if (rra_type == BTM_BLE_ADDR_PSEUDO) {
  486. /* use static address, resolvable_private_addr is empty */
  487. if (rra_dummy) {
  488. p_acl->active_remote_addr_type = p_sec_rec->ble.static_addr_type;
  489. memcpy(p_acl->active_remote_addr, p_sec_rec->ble.static_addr, BD_ADDR_LEN);
  490. } else {
  491. p_acl->active_remote_addr_type = BLE_ADDR_RANDOM;
  492. memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN);
  493. }
  494. } else {
  495. p_acl->active_remote_addr_type = rra_type;
  496. memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN);
  497. }
  498. BTM_TRACE_DEBUG("p_acl->active_remote_addr_type: %d ", p_acl->active_remote_addr_type);
  499. BTM_TRACE_DEBUG("%s conn_addr: %02x:%02x:%02x:%02x:%02x:%02x",
  500. __func__, p_acl->active_remote_addr[0], p_acl->active_remote_addr[1],
  501. p_acl->active_remote_addr[2], p_acl->active_remote_addr[3],
  502. p_acl->active_remote_addr[4], p_acl->active_remote_addr[5]);
  503. }
  504. #endif
  505. }
  506. /*******************************************************************************
  507. **
  508. ** Function btm_ble_refresh_local_resolvable_private_addr
  509. **
  510. ** Description This function refresh the currently used resolvable private address for the
  511. ** active link to the remote device
  512. **
  513. *******************************************************************************/
  514. void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr,
  515. BD_ADDR local_rpa)
  516. {
  517. #if BLE_PRIVACY_SPT == TRUE
  518. tACL_CONN *p = btm_bda_to_acl(pseudo_addr, BT_TRANSPORT_LE);
  519. BD_ADDR dummy_bda = {0};
  520. if (p != NULL) {
  521. if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) {
  522. p->conn_addr_type = BLE_ADDR_RANDOM;
  523. if (memcmp(local_rpa, dummy_bda, BD_ADDR_LEN)) {
  524. memcpy(p->conn_addr, local_rpa, BD_ADDR_LEN);
  525. } else {
  526. memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN);
  527. }
  528. } else {
  529. p->conn_addr_type = BLE_ADDR_PUBLIC;
  530. memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN);
  531. }
  532. }
  533. #endif
  534. }
  535. #endif