btm_ble_addr.c 21 KB

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