BluetootH: Host: add helper functions for resolved addresses
There is special handling done for resolved addresses to convert them to "regular" addresses for the upper layers. This commits adds two helper functions to check if they are resolved, and if so, then properly copied. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
4af1c99f9d
commit
baad0c300f
6 changed files with 49 additions and 30 deletions
|
@ -14,6 +14,8 @@
|
|||
#include <zephyr/bluetooth/addr.h>
|
||||
#include <zephyr/bluetooth/crypto.h>
|
||||
|
||||
#define ADDR_RESOLVED_BITMASK (0x02)
|
||||
|
||||
static inline int create_random_addr(bt_addr_le_t *addr)
|
||||
{
|
||||
addr->type = BT_ADDR_LE_RANDOM;
|
||||
|
@ -101,3 +103,15 @@ int bt_addr_le_from_str(const char *str, const char *type, bt_addr_le_t *addr)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_addr_le_copy_resolved(bt_addr_le_t *dst, const bt_addr_le_t *src)
|
||||
{
|
||||
bt_addr_le_copy(dst, src);
|
||||
/* translate to "regular" address type */
|
||||
dst->type &= ~ADDR_RESOLVED_BITMASK;
|
||||
}
|
||||
|
||||
bool bt_addr_le_is_resolved(const bt_addr_le_t *addr)
|
||||
{
|
||||
return (addr->type & ADDR_RESOLVED_BITMASK) != 0;
|
||||
}
|
||||
|
|
14
subsys/bluetooth/host/addr_internal.h
Normal file
14
subsys/bluetooth/host/addr_internal.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
/** @file
|
||||
* @brief Internal header for Bluetooth address functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <zephyr/bluetooth/addr.h>
|
||||
|
||||
void bt_addr_le_copy_resolved(bt_addr_le_t *dst, const bt_addr_le_t *src);
|
||||
|
||||
bool bt_addr_le_is_resolved(const bt_addr_le_t *addr);
|
|
@ -12,6 +12,7 @@
|
|||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/bluetooth/buf.h>
|
||||
|
||||
#include "addr_internal.h"
|
||||
#include "hci_core.h"
|
||||
#include "conn_internal.h"
|
||||
#include "id.h"
|
||||
|
@ -2092,10 +2093,8 @@ void bt_hci_le_scan_req_received(struct net_buf *buf)
|
|||
struct bt_le_ext_adv_scanned_info info;
|
||||
bt_addr_le_t id_addr;
|
||||
|
||||
if (evt->addr.type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
evt->addr.type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&id_addr, &evt->addr);
|
||||
id_addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(&evt->addr)) {
|
||||
bt_addr_le_copy_resolved(&id_addr, &evt->addr);
|
||||
} else {
|
||||
bt_addr_le_copy(&id_addr,
|
||||
bt_lookup_id_addr(adv->id, &evt->addr));
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "common/assert.h"
|
||||
|
||||
#include "addr_internal.h"
|
||||
#include "hci_core.h"
|
||||
#include "id.h"
|
||||
#include "adv.h"
|
||||
|
@ -2817,10 +2818,8 @@ int bt_conn_le_create(const bt_addr_le_t *peer,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (peer->type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
peer->type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&dst, peer);
|
||||
dst.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(peer)) {
|
||||
bt_addr_le_copy_resolved(&dst, peer);
|
||||
} else {
|
||||
bt_addr_le_copy(&dst, bt_lookup_id_addr(BT_ID_DEFAULT, peer));
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "adv.h"
|
||||
#include "scan.h"
|
||||
|
||||
#include "addr_internal.h"
|
||||
#include "conn_internal.h"
|
||||
#include "iso_internal.h"
|
||||
#include "l2cap_internal.h"
|
||||
|
@ -1205,11 +1206,8 @@ void bt_hci_le_enh_conn_complete(struct bt_hci_evt_le_enh_conn_complete *evt)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Translate "enhanced" identity address type to normal one */
|
||||
if (evt->peer_addr.type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
evt->peer_addr.type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&id_addr, &evt->peer_addr);
|
||||
id_addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(&evt->peer_addr)) {
|
||||
bt_addr_le_copy_resolved(&id_addr, &evt->peer_addr);
|
||||
|
||||
bt_addr_copy(&peer_addr.a, &evt->peer_rpa);
|
||||
peer_addr.type = BT_ADDR_LE_RANDOM;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/bluetooth/hci_vs.h>
|
||||
|
||||
#include "addr_internal.h"
|
||||
#include "hci_core.h"
|
||||
#include "conn_internal.h"
|
||||
#include "direction_internal.h"
|
||||
|
@ -453,10 +454,8 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
|
|||
return;
|
||||
}
|
||||
|
||||
if (addr->type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
addr->type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&id_addr, addr);
|
||||
id_addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(addr)) {
|
||||
bt_addr_le_copy_resolved(&id_addr, addr);
|
||||
} else if (addr->type == BT_HCI_PEER_ADDR_ANONYMOUS) {
|
||||
bt_addr_le_copy(&id_addr, BT_ADDR_LE_ANY);
|
||||
} else {
|
||||
|
@ -912,10 +911,8 @@ void bt_hci_le_per_adv_sync_established(struct net_buf *buf)
|
|||
return;
|
||||
}
|
||||
|
||||
if (evt->adv_addr.type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
evt->adv_addr.type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&id_addr, &evt->adv_addr);
|
||||
id_addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(&evt->adv_addr)) {
|
||||
bt_addr_le_copy_resolved(&id_addr, &evt->adv_addr);
|
||||
} else {
|
||||
bt_addr_le_copy(&id_addr,
|
||||
bt_lookup_id_addr(BT_ID_DEFAULT,
|
||||
|
@ -979,13 +976,13 @@ void bt_hci_le_per_adv_sync_established(struct net_buf *buf)
|
|||
if (atomic_test_bit(pending_per_adv_sync->flags,
|
||||
BT_PER_ADV_SYNC_SYNCING_USE_LIST)) {
|
||||
/* Now we know which address and SID we synchronized to. */
|
||||
bt_addr_le_copy(&pending_per_adv_sync->addr, &id_addr);
|
||||
pending_per_adv_sync->sid = evt->sid;
|
||||
|
||||
/* Translate "enhanced" identity address type to normal one */
|
||||
if (pending_per_adv_sync->addr.type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
pending_per_adv_sync->addr.type == BT_ADDR_LE_RANDOM_ID) {
|
||||
pending_per_adv_sync->addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(&pending_per_adv_sync->addr)) {
|
||||
bt_addr_le_copy_resolved(&pending_per_adv_sync->addr,
|
||||
&id_addr);
|
||||
} else {
|
||||
bt_addr_le_copy(&pending_per_adv_sync->addr, &id_addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1055,10 +1052,8 @@ void bt_hci_le_past_received(struct net_buf *buf)
|
|||
|
||||
atomic_set_bit(per_adv_sync->flags, BT_PER_ADV_SYNC_SYNCED);
|
||||
|
||||
if (evt->addr.type == BT_ADDR_LE_PUBLIC_ID ||
|
||||
evt->addr.type == BT_ADDR_LE_RANDOM_ID) {
|
||||
bt_addr_le_copy(&id_addr, &evt->addr);
|
||||
id_addr.type -= BT_ADDR_LE_PUBLIC_ID;
|
||||
if (bt_addr_le_is_resolved(&evt->addr)) {
|
||||
bt_addr_le_copy_resolved(&id_addr, &evt->addr);
|
||||
} else {
|
||||
bt_addr_le_copy(&id_addr,
|
||||
bt_lookup_id_addr(BT_ID_DEFAULT, &evt->addr));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue