btm_ble_addr.c 22 KB

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