Skip to content

Commit 9489eca

Browse files
jhedbergholtmann
authored andcommitted
Bluetooth: Add timeout for LE connection attempts
LE connection attempts do not have a controller side timeout in the same way as BR/EDR has (in form of the page timeout). Since we always do scanning before initiating connections the attempts are always expected to succeed in some reasonable time. This patch adds a timer which forces a cancellation of the connection attempt within 20 seconds if it has not been successful by then. This way we e.g. ensure that mgmt_pair_device times out eventually and gives an error response. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent a7139ed commit 9489eca

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ enum {
183183
#define HCI_ACL_TX_TIMEOUT msecs_to_jiffies(45000) /* 45 seconds */
184184
#define HCI_AUTO_OFF_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
185185
#define HCI_POWER_OFF_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */
186+
#define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(20000) /* 20 seconds */
186187

187188
/* HCI data types */
188189
#define HCI_COMMAND_PKT 0x01

‎include/net/bluetooth/hci_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ struct hci_conn {
375375
struct delayed_work disc_work;
376376
struct delayed_work auto_accept_work;
377377
struct delayed_work idle_work;
378+
struct delayed_work le_conn_timeout;
378379

379380
struct device dev;
380381

‎net/bluetooth/hci_conn.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ static void hci_conn_auto_accept(struct work_struct *work)
363363
&conn->dst);
364364
}
365365

366+
static void le_conn_timeout(struct work_struct *work)
367+
{
368+
struct hci_conn *conn = container_of(work, struct hci_conn,
369+
le_conn_timeout.work);
370+
371+
BT_DBG("");
372+
373+
hci_le_create_connection_cancel(conn);
374+
}
375+
366376
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
367377
{
368378
struct hci_conn *conn;
@@ -410,6 +420,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
410420
INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout);
411421
INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept);
412422
INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle);
423+
INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout);
413424

414425
atomic_set(&conn->refcnt, 0);
415426

@@ -442,6 +453,8 @@ int hci_conn_del(struct hci_conn *conn)
442453
/* Unacked frames */
443454
hdev->acl_cnt += conn->sent;
444455
} else if (conn->type == LE_LINK) {
456+
cancel_delayed_work_sync(&conn->le_conn_timeout);
457+
445458
if (hdev->le_pkts)
446459
hdev->le_cnt += conn->sent;
447460
else

‎net/bluetooth/hci_event.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,16 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
16781678
conn->resp_addr_type = cp->peer_addr_type;
16791679
bacpy(&conn->resp_addr, &cp->peer_addr);
16801680

1681+
/* We don't want the connection attempt to stick around
1682+
* indefinitely since LE doesn't have a page timeout concept
1683+
* like BR/EDR. Set a timer for any connection that doesn't use
1684+
* the white list for connecting.
1685+
*/
1686+
if (cp->filter_policy == HCI_LE_USE_PEER_ADDR)
1687+
queue_delayed_work(conn->hdev->workqueue,
1688+
&conn->le_conn_timeout,
1689+
HCI_LE_CONN_TIMEOUT);
1690+
16811691
unlock:
16821692
hci_dev_unlock(hdev);
16831693
}
@@ -3794,6 +3804,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
37943804
conn->init_addr_type = ev->bdaddr_type;
37953805
bacpy(&conn->init_addr, &ev->bdaddr);
37963806
}
3807+
} else {
3808+
cancel_delayed_work(&conn->le_conn_timeout);
37973809
}
37983810

37993811
/* Ensure that the hci_conn contains the identity address type

0 commit comments

Comments
 (0)