From c6fdf09340bab79ccf8b3c5c7bb5403d2697fb54 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Jun 2016 05:56:30 +0200 Subject: [PATCH] Bluetooth: Fix notifying about cancelled connection attempt If LE Create Connection was cancelled LE Connection Complete event status is set to Unknown Connection Identifier and doesn't contain valid remote address. In such case we need to look for connection object in CONNECT state without using address. There can be only one object in that state anyway so this is OK also for other error codes. Change-Id: Ie61d47b8bb7ade6b2ab4db14ee394a65bb4e642b Signed-off-by: Szymon Janc --- net/bluetooth/hci_core.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 7c1f36ee66d..41b0bf9ade7 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -611,14 +611,15 @@ static void le_conn_complete(struct net_buf *buf) BT_DBG("status %u handle %u role %u %s", evt->status, handle, evt->role, bt_addr_le_str(&evt->peer_addr)); - id_addr = find_id_addr(&evt->peer_addr); - - /* Make lookup to check if there's a connection object in CONNECT state - * associated with passed peer LE address. - */ - conn = bt_conn_lookup_state_le(id_addr, BT_CONN_CONNECT); - if (evt->status) { + /* + * if there was an error we are only interested in pending + * connection so there is no need to check ID address as + * only one connection can be in that state + * + * Depending on error code address might not be valid anyway. + */ + conn = bt_conn_lookup_state_le(NULL, BT_CONN_CONNECT); if (!conn) { return; } @@ -636,6 +637,14 @@ static void le_conn_complete(struct net_buf *buf) return; } + id_addr = find_id_addr(&evt->peer_addr); + + /* + * Make lookup to check if there's a connection object in + * CONNECT state associated with passed peer LE address. + */ + conn = bt_conn_lookup_state_le(id_addr, BT_CONN_CONNECT); + if (evt->role == BT_CONN_ROLE_SLAVE) { /* * clear advertising even if we are not able to add connection