Commit d850bf08 authored by Luiz Augusto von Dentz's avatar Luiz Augusto von Dentz Committed by Marcel Holtmann

Bluetooth: Fix using RPA when address has been resolved

When connecting to a device using an RPA if the address has been
resolved by the controller (types 0x02 and 0x03) the identity address
shall be used as the actual RPA in the advertisement won't be visible
to the host.
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 4ec4d63b
...@@ -1101,8 +1101,9 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -1101,8 +1101,9 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
u16 conn_timeout, u16 conn_timeout,
enum conn_reasons conn_reason); enum conn_reasons conn_reason);
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
u8 dst_type, u8 sec_level, u16 conn_timeout, u8 dst_type, bool dst_resolved, u8 sec_level,
u8 role, bdaddr_t *direct_rpa); u16 conn_timeout, u8 role,
bdaddr_t *direct_rpa);
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
u8 sec_level, u8 auth_type, u8 sec_level, u8 auth_type,
enum conn_reasons conn_reason); enum conn_reasons conn_reason);
......
...@@ -1040,8 +1040,8 @@ static void hci_req_directed_advertising(struct hci_request *req, ...@@ -1040,8 +1040,8 @@ static void hci_req_directed_advertising(struct hci_request *req,
} }
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
u8 dst_type, u8 sec_level, u16 conn_timeout, u8 dst_type, bool dst_resolved, u8 sec_level,
u8 role, bdaddr_t *direct_rpa) u16 conn_timeout, u8 role, bdaddr_t *direct_rpa)
{ {
struct hci_conn_params *params; struct hci_conn_params *params;
struct hci_conn *conn; struct hci_conn *conn;
...@@ -1078,19 +1078,24 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, ...@@ -1078,19 +1078,24 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
} }
/* When given an identity address with existing identity /* Check if the destination address has been resolved by the controller
* resolving key, the connection needs to be established * since if it did then the identity address shall be used.
* to a resolvable random address.
*
* Storing the resolvable random address is required here
* to handle connection failures. The address will later
* be resolved back into the original identity address
* from the connect request.
*/ */
irk = hci_find_irk_by_addr(hdev, dst, dst_type); if (!dst_resolved) {
if (irk && bacmp(&irk->rpa, BDADDR_ANY)) { /* When given an identity address with existing identity
dst = &irk->rpa; * resolving key, the connection needs to be established
dst_type = ADDR_LE_DEV_RANDOM; * to a resolvable random address.
*
* Storing the resolvable random address is required here
* to handle connection failures. The address will later
* be resolved back into the original identity address
* from the connect request.
*/
irk = hci_find_irk_by_addr(hdev, dst, dst_type);
if (irk && bacmp(&irk->rpa, BDADDR_ANY)) {
dst = &irk->rpa;
dst_type = ADDR_LE_DEV_RANDOM;
}
} }
if (conn) { if (conn) {
......
...@@ -2367,7 +2367,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) ...@@ -2367,7 +2367,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type) static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved)
{ {
/* When using controller based address resolution, then the new /* When using controller based address resolution, then the new
* address types 0x02 and 0x03 are used. These types need to be * address types 0x02 and 0x03 are used. These types need to be
...@@ -2375,11 +2375,17 @@ static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type) ...@@ -2375,11 +2375,17 @@ static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type)
*/ */
switch (type) { switch (type) {
case ADDR_LE_DEV_PUBLIC_RESOLVED: case ADDR_LE_DEV_PUBLIC_RESOLVED:
if (resolved)
*resolved = true;
return ADDR_LE_DEV_PUBLIC; return ADDR_LE_DEV_PUBLIC;
case ADDR_LE_DEV_RANDOM_RESOLVED: case ADDR_LE_DEV_RANDOM_RESOLVED:
if (resolved)
*resolved = true;
return ADDR_LE_DEV_RANDOM; return ADDR_LE_DEV_RANDOM;
} }
if (resolved)
*resolved = false;
return type; return type;
} }
...@@ -2394,7 +2400,7 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, ...@@ -2394,7 +2400,7 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
if (!conn) if (!conn)
return; return;
own_address_type = ev_bdaddr_type(hdev, own_address_type); own_address_type = ev_bdaddr_type(hdev, own_address_type, NULL);
/* Store the initiator and responder address information which /* Store the initiator and responder address information which
* is needed for SMP. These values will not change during the * is needed for SMP. These values will not change during the
...@@ -5284,7 +5290,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, ...@@ -5284,7 +5290,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
conn->dst_type = irk->addr_type; conn->dst_type = irk->addr_type;
} }
conn->dst_type = ev_bdaddr_type(hdev, conn->dst_type); conn->dst_type = ev_bdaddr_type(hdev, conn->dst_type, NULL);
if (status) { if (status) {
hci_le_conn_failed(conn, status); hci_le_conn_failed(conn, status);
...@@ -5466,8 +5472,8 @@ static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, ...@@ -5466,8 +5472,8 @@ static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
/* This function requires the caller holds hdev->lock */ /* This function requires the caller holds hdev->lock */
static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
bdaddr_t *addr, bdaddr_t *addr,
u8 addr_type, u8 adv_type, u8 addr_type, bool addr_resolved,
bdaddr_t *direct_rpa) u8 adv_type, bdaddr_t *direct_rpa)
{ {
struct hci_conn *conn; struct hci_conn *conn;
struct hci_conn_params *params; struct hci_conn_params *params;
...@@ -5519,9 +5525,9 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, ...@@ -5519,9 +5525,9 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
} }
} }
conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, conn = hci_connect_le(hdev, addr, addr_type, addr_resolved,
hdev->def_le_autoconnect_timeout, HCI_ROLE_MASTER, BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout,
direct_rpa); HCI_ROLE_MASTER, direct_rpa);
if (!IS_ERR(conn)) { if (!IS_ERR(conn)) {
/* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
* by higher layer that tried to connect, if no then * by higher layer that tried to connect, if no then
...@@ -5562,7 +5568,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, ...@@ -5562,7 +5568,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
struct discovery_state *d = &hdev->discovery; struct discovery_state *d = &hdev->discovery;
struct smp_irk *irk; struct smp_irk *irk;
struct hci_conn *conn; struct hci_conn *conn;
bool match; bool match, bdaddr_resolved;
u32 flags; u32 flags;
u8 *ptr; u8 *ptr;
...@@ -5606,7 +5612,8 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, ...@@ -5606,7 +5612,8 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
* controller address. * controller address.
*/ */
if (direct_addr) { if (direct_addr) {
direct_addr_type = ev_bdaddr_type(hdev, direct_addr_type); direct_addr_type = ev_bdaddr_type(hdev, direct_addr_type,
&bdaddr_resolved);
/* Only resolvable random addresses are valid for these /* Only resolvable random addresses are valid for these
* kind of reports and others can be ignored. * kind of reports and others can be ignored.
...@@ -5635,15 +5642,15 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, ...@@ -5635,15 +5642,15 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
bdaddr_type = irk->addr_type; bdaddr_type = irk->addr_type;
} }
bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type); bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved);
/* Check if we have been requested to connect to this device. /* Check if we have been requested to connect to this device.
* *
* direct_addr is set only for directed advertising reports (it is NULL * direct_addr is set only for directed advertising reports (it is NULL
* for advertising reports) and is already verified to be RPA above. * for advertising reports) and is already verified to be RPA above.
*/ */
conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type, conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved,
direct_addr); type, direct_addr);
if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) { if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) {
/* Store report for later inclusion by /* Store report for later inclusion by
* mgmt_device_connected * mgmt_device_connected
......
...@@ -7902,7 +7902,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, ...@@ -7902,7 +7902,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
dst_type = ADDR_LE_DEV_RANDOM; dst_type = ADDR_LE_DEV_RANDOM;
if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
hcon = hci_connect_le(hdev, dst, dst_type, hcon = hci_connect_le(hdev, dst, dst_type, false,
chan->sec_level, chan->sec_level,
HCI_LE_CONN_TIMEOUT, HCI_LE_CONN_TIMEOUT,
HCI_ROLE_SLAVE, NULL); HCI_ROLE_SLAVE, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment