Skip to content

Commit 09ae260

Browse files
committed
Bluetooth: Use lower timeout for LE auto-connections
When we establish connections as a consequence of receiving an advertising report it makes no sense to wait the normal 20 second LE connection timeout. This patch modifies the hci_connect_le function to take an extra timeout value and uses a lower 2 second timeout for the auto-connection case. This timeout is intentionally chosen to be just a bit higher than the 1.28 second timeout that High Duty Cycle Advertising uses. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 5ea234d commit 09ae260

6 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ enum {
238238
#define HCI_AUTO_OFF_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
239239
#define HCI_POWER_OFF_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */
240240
#define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(20000) /* 20 seconds */
241+
#define HCI_LE_AUTOCONN_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
241242

242243
/* HCI data types */
243244
#define HCI_COMMAND_PKT 0x01

‎include/net/bluetooth/hci_core.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ struct hci_conn {
385385
__u32 passkey_notify;
386386
__u8 passkey_entered;
387387
__u16 disc_timeout;
388+
__u16 conn_timeout;
388389
__u16 setting;
389390
__u16 le_conn_min_interval;
390391
__u16 le_conn_max_interval;
@@ -703,7 +704,8 @@ void hci_chan_list_flush(struct hci_conn *conn);
703704
struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
704705

705706
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
706-
u8 dst_type, u8 sec_level, u8 auth_type);
707+
u8 dst_type, u8 sec_level, u8 auth_type,
708+
u16 conn_timeout);
707709
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
708710
u8 sec_level, u8 auth_type);
709711
struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,

‎net/bluetooth/hci_conn.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ static void hci_req_directed_advertising(struct hci_request *req,
700700
}
701701

702702
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
703-
u8 dst_type, u8 sec_level, u8 auth_type)
703+
u8 dst_type, u8 sec_level, u8 auth_type,
704+
u16 conn_timeout)
704705
{
705706
struct hci_conn_params *params;
706707
struct hci_conn *conn;
@@ -758,6 +759,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
758759
conn->sec_level = BT_SECURITY_LOW;
759760
conn->pending_sec_level = sec_level;
760761
conn->auth_type = auth_type;
762+
conn->conn_timeout = conn_timeout;
761763

762764
hci_req_init(&req, hdev);
763765

‎net/bluetooth/hci_event.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
10731073
if (conn)
10741074
queue_delayed_work(hdev->workqueue,
10751075
&conn->le_conn_timeout,
1076-
HCI_LE_CONN_TIMEOUT);
1076+
conn->conn_timeout);
10771077
}
10781078

10791079
mgmt_advertising(hdev, *sent);
@@ -1913,7 +1913,7 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
19131913
if (cp->filter_policy == HCI_LE_USE_PEER_ADDR)
19141914
queue_delayed_work(conn->hdev->workqueue,
19151915
&conn->le_conn_timeout,
1916-
HCI_LE_CONN_TIMEOUT);
1916+
conn->conn_timeout);
19171917

19181918
unlock:
19191919
hci_dev_unlock(hdev);
@@ -4238,7 +4238,7 @@ static bool check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
42384238
return false;
42394239

42404240
conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
4241-
HCI_AT_NO_BONDING);
4241+
HCI_AT_NO_BONDING, HCI_LE_AUTOCONN_TIMEOUT);
42424242
if (!IS_ERR(conn))
42434243
return true;
42444244

‎net/bluetooth/l2cap_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7135,7 +7135,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
71357135
dst_type = ADDR_LE_DEV_RANDOM;
71367136

71377137
hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level,
7138-
auth_type);
7138+
auth_type, HCI_LE_CONN_TIMEOUT);
71397139
} else {
71407140
hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type);
71417141
}

‎net/bluetooth/mgmt.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,8 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
31163116
hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
31173117

31183118
conn = hci_connect_le(hdev, &cp->addr.bdaddr, addr_type,
3119-
sec_level, auth_type);
3119+
sec_level, auth_type,
3120+
HCI_LE_CONN_TIMEOUT);
31203121
}
31213122

31223123
if (IS_ERR(conn)) {

0 commit comments

Comments
 (0)