Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_ble_gen_rpa_by_host' into 'master'
Browse files Browse the repository at this point in the history
Bluedroid: fix ble rpa generate and update by host

See merge request espressif/esp-idf!19617
  • Loading branch information
esp-cjh committed Sep 20, 2022
2 parents 02aad58 + 8598610 commit 6014e92
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
20 changes: 2 additions & 18 deletions components/bt/host/bluedroid/stack/btm/btm_ble_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
p_cb->private_addr[5] = p->param_buf[0];
p_cb->private_addr[4] = p->param_buf[1];
p_cb->private_addr[3] = p->param_buf[2];

/* set it to controller */
btsnd_hcic_ble_set_random_addr(p_cb->private_addr);
btm_ble_set_random_addr(p_cb->private_addr);

p_cb->exist_addr_bit |= BTM_BLE_GAP_ADDR_BIT_RESOLVABLE;
memcpy(p_cb->resolvale_addr, p_cb->private_addr, BD_ADDR_LEN);
Expand All @@ -66,23 +67,6 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
p_cb->set_local_privacy_cback = NULL;
}

if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_ENABLE){
BTM_TRACE_DEBUG("Advertise with new resolvable private address, now.");
/**
* Restart advertising, using new resolvable private address
*/
btm_ble_stop_adv();
btm_ble_start_adv();
}
if (btm_cb.ble_ctr_cb.inq_var.state == BTM_BLE_SCANNING){
BTM_TRACE_DEBUG("Scan with new resolvable private address, now.");
/**
* Restart scaning, using new resolvable private address
*/
btm_ble_stop_scan();
btm_ble_start_scan();
}

/* start a periodical timer to refresh random addr */
btu_stop_timer_oneshot(&p_cb->raddr_timer_ent);
#if (BTM_BLE_CONFORMANCE_TESTING == TRUE)
Expand Down
53 changes: 53 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,59 @@ tBTM_STATUS btm_ble_stop_adv(void)
return rt;
}

tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda)
{
tBTM_STATUS rt = BTM_SUCCESS;

osi_mutex_lock(&adv_enable_lock, OSI_MUTEX_MAX_TIMEOUT);
osi_mutex_lock(&scan_enable_lock, OSI_MUTEX_MAX_TIMEOUT);

if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_ENABLE) {
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) {
osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT);
rt = adv_enable_status;
} else {
rt = BTM_BAD_VALUE_RET;
}
}

if (BTM_BLE_IS_DISCO_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) {
if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_SCAN_DUPLICATE_DISABLE)) {
osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT);
rt = scan_enable_status;
} else {
rt = BTM_BAD_VALUE_RET;
}
}

if (rt == BTM_SUCCESS) {
btsnd_hcic_ble_set_random_addr(random_bda);
}

if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_ENABLE) {
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) {
osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT);
rt = adv_enable_status;
} else {
rt = BTM_BAD_VALUE_RET;
}
}

if (BTM_BLE_IS_DISCO_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) {
if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, btm_cb.ble_ctr_cb.inq_var.scan_duplicate_filter)) {
osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT);
rt = scan_enable_status;
} else {
rt = BTM_BAD_VALUE_RET;
}
}

osi_mutex_unlock(&adv_enable_lock);
osi_mutex_unlock(&scan_enable_lock);

return rt;
}


/*******************************************************************************
**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ tBTM_STATUS btm_ble_stop_adv(void);
tBTM_STATUS btm_ble_start_scan(void);
void btm_ble_create_ll_conn_complete (UINT8 status);
void btm_ble_create_conn_cancel_complete (UINT8 *p);
tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda);

/* LE security function from btm_sec.c */
#if SMP_INCLUDED == TRUE
Expand Down

0 comments on commit 6014e92

Please sign in to comment.