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