Skip to content

Commit

Permalink
Allow host to resolve peer RPA without using local RPA.
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero authored and ESPAbhinav committed Feb 14, 2024
1 parent bc4b41a commit bd92630
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
21 changes: 9 additions & 12 deletions nimble/host/src/ble_hs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,22 +448,19 @@ ble_hs_conn_addrs(const struct ble_hs_conn *conn,

#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
/* RPA: Override peer address information. */
struct ble_hs_resolv_entry *rl = NULL;

ble_addr_t bhc_peer_addr;
bhc_peer_addr.type = conn->bhc_peer_addr.type;
memcpy(bhc_peer_addr.val, conn->bhc_peer_addr.val, BLE_DEV_ADDR_LEN);
if (ble_host_rpa_enabled()) {

uint8_t *local_id = NULL;
ble_hs_id_addr(BLE_ADDR_PUBLIC, (const uint8_t **) &local_id, NULL);

rl = ble_hs_resolv_list_find(bhc_peer_addr.val);
if (rl != NULL) {
memcpy(addrs->peer_ota_addr.val, addrs->peer_id_addr.val, BLE_DEV_ADDR_LEN);
memcpy(addrs->peer_id_addr.val, rl->rl_identity_addr, BLE_DEV_ADDR_LEN);

addrs->peer_id_addr.type = rl->rl_addr_type;
struct ble_hs_resolv_entry *rl = NULL;
rl = ble_hs_resolv_list_find(bhc_peer_addr.val);
if (rl != NULL) {
memcpy(addrs->peer_id_addr.val, rl->rl_identity_addr, BLE_DEV_ADDR_LEN);
addrs->peer_id_addr.type = rl->rl_addr_type;

if (ble_host_rpa_enabled()) {
uint8_t *local_id = NULL;
ble_hs_id_addr(BLE_ADDR_PUBLIC, (const uint8_t **) &local_id, NULL);

/* RL is present: populate our id addr with public ID */
memcpy(addrs->our_id_addr.val, local_id, BLE_DEV_ADDR_LEN);
Expand Down
13 changes: 4 additions & 9 deletions nimble/host/src/ble_hs_hci_evt.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,11 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, const void *data,
if (ble_host_rpa_enabled()) {
uint8_t *local_id_rpa = ble_hs_get_rpa_local();
memcpy(evt.local_rpa, local_id_rpa, BLE_DEV_ADDR_LEN);

struct ble_hs_resolv_entry *rl = NULL;
ble_rpa_replace_peer_params_with_rl(evt.peer_addr,
&evt.peer_addr_type, &rl);
if (rl == NULL) {
if (ble_rpa_resolv_add_peer_rec(evt.peer_addr) != 0) {
BLE_HS_LOG(DEBUG, "Memory unavailable for new peer record\n");
}
}
}

struct ble_hs_resolv_entry *rl = NULL;
ble_rpa_replace_peer_params_with_rl(evt.peer_addr,
&evt.peer_addr_type, &rl);
#endif
evt.conn_itvl = le16toh(ev->conn_itvl);
evt.conn_latency = le16toh(ev->conn_latency);
Expand Down
31 changes: 14 additions & 17 deletions nimble/host/src/ble_sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,26 +571,23 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)

identity_ev = 1;
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
if (ble_host_rpa_enabled())
{
struct ble_hs_dev_records *p_dev_rec =
ble_rpa_find_peer_dev_rec(conn->bhc_peer_rpa_addr.val);
if (p_dev_rec == NULL) {
if (!ble_rpa_resolv_add_peer_rec(conn->bhc_peer_rpa_addr.val)) {
p_dev_rec = ble_rpa_find_peer_dev_rec(conn->bhc_peer_rpa_addr.val);
}
struct ble_hs_dev_records *p_dev_rec =
ble_rpa_find_peer_dev_rec(conn->bhc_peer_rpa_addr.val);
if (p_dev_rec == NULL) {
if (!ble_rpa_resolv_add_peer_rec(conn->bhc_peer_rpa_addr.val)) {
p_dev_rec = ble_rpa_find_peer_dev_rec(conn->bhc_peer_rpa_addr.val);
}
}

if (p_dev_rec != NULL) {
/* Once bonded, copy the peer device records */
swap_buf(p_dev_rec->peer_sec.irk, proc->peer_keys.irk, 16);
p_dev_rec->peer_sec.irk_present = proc->peer_keys.irk_valid;
memcpy(p_dev_rec->peer_sec.peer_addr.val,
proc->peer_keys.addr, 6);
p_dev_rec->peer_sec.peer_addr.type = proc->peer_keys.addr_type;
if (p_dev_rec != NULL) {
/* Once bonded, copy the peer device records */
swap_buf(p_dev_rec->peer_sec.irk, proc->peer_keys.irk, 16);
p_dev_rec->peer_sec.irk_present = proc->peer_keys.irk_valid;
memcpy(p_dev_rec->peer_sec.peer_addr.val,
proc->peer_keys.addr, 6);
p_dev_rec->peer_sec.peer_addr.type = proc->peer_keys.addr_type;

ble_store_persist_peer_records();
}
ble_store_persist_peer_records();
}
#endif
}
Expand Down

0 comments on commit bd92630

Please sign in to comment.