Bluetooth: Don't treat connection timeout as a failure
authorJohan Hedberg <johan.hedberg@intel.com>
Thu, 3 Dec 2015 10:45:20 +0000 (12:45 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 9 Dec 2015 23:51:51 +0000 (00:51 +0100)
When we're doing background scanning and connection attempts it's
possible we timeout trying to connect and go back to scanning again.
The timeout triggers a HCI_LE_Create_Connection_Cancel which will
trigger a Connection Complete with "Unknown Connection Identifier"
error status. Since we go back to scanning this isn't really a failure
and shouldn't be presented as such to user space through mgmt.

The exception to this is if the connection attempt was due to an
explicit request on an L2CAP socket (indicated by
params->explicit_connect being true). Since the socket will get an
error it's consistent to also notify the failure on mgmt in this case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/hci_conn.c

index 48a7eac6ef71490c5608c8df1f876bfcdc3df615..32575b49f4a0c2218ef8a084888bc8469ba92306 100644 (file)
@@ -668,8 +668,16 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status)
 
        conn->state = BT_CLOSED;
 
-       mgmt_connect_failed(hdev, &conn->dst, conn->type, conn->dst_type,
-                           status);
+       /* If the status indicates successful cancellation of
+        * the attempt (i.e. Unkown Connection Id) there's no point of
+        * notifying failure since we'll go back to keep trying to
+        * connect. The only exception is explicit connect requests
+        * where a timeout + cancel does indicate an actual failure.
+        */
+       if (status != HCI_ERROR_UNKNOWN_CONN_ID ||
+           (params && params->explicit_connect))
+               mgmt_connect_failed(hdev, &conn->dst, conn->type,
+                                   conn->dst_type, status);
 
        hci_connect_cfm(conn, status);