From c19dac1a668176d19bc88b0a7a2c7230ef10fa06 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 16 Aug 2019 10:45:40 +0200 Subject: [PATCH] Bluetooth: Host: Fix unable to connect using host resolution Fix issue unable to connect to bonded peer when host resolution is used either because the controller does not support privacy, or the controller resolving list was exceeded. In this case we need to use the RPA from the advertising report directly, there is a small chance of the peer cycling the RPA here, in which case the connection might be unsuccessful. Bug introduced here: 45da629b24f720019355fca8e1ddddb798ac409f Fixes: #18306 Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/hci_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 55e96f3fd60..cabd154faeb 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -763,6 +763,7 @@ static int hci_le_create_conn(const struct bt_conn *conn) struct net_buf *buf; struct bt_hci_cp_le_create_conn *cp; u8_t own_addr_type; + const bt_addr_le_t *peer_addr; int err; if (IS_ENABLED(CONFIG_BT_PRIVACY)) { @@ -802,7 +803,14 @@ static int hci_le_create_conn(const struct bt_conn *conn) cp->scan_interval = sys_cpu_to_le16(BT_GAP_SCAN_FAST_INTERVAL); cp->scan_window = cp->scan_interval; - bt_addr_le_copy(&cp->peer_addr, &conn->le.dst); + peer_addr = &conn->le.dst; +#if defined(CONFIG_BT_SMP) + if (!bt_dev.le.rl_size || bt_dev.le.rl_entries > bt_dev.le.rl_size) { + /* Host resolving is used, use the RPA directly. */ + peer_addr = &conn->le.resp_addr; + } +#endif + bt_addr_le_copy(&cp->peer_addr, peer_addr); cp->own_addr_type = own_addr_type; cp->conn_interval_min = sys_cpu_to_le16(conn->le.interval_min); cp->conn_interval_max = sys_cpu_to_le16(conn->le.interval_max); @@ -1545,6 +1553,7 @@ static void check_pending_conn(const bt_addr_le_t *id_addr, goto failed; } + bt_addr_le_copy(&conn->le.resp_addr, addr); if (hci_le_create_conn(conn)) { goto failed; }