Skip to content

Commit bf98fee

Browse files
committed
Bluetooth: hci_conn: Always use sk_timeo as conn_timeout
This aligns the use socket sk_timeo as conn_timeout when initiating a connection and then use it when scheduling the resulting HCI command, that way the command is actually aborted synchronously thus not blocking commands generated by hci_abort_conn_sync to inform the controller the connection is to be aborted. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent f4b0c2b commit bf98fee

File tree

9 files changed

+21
-17
lines changed

9 files changed

+21
-17
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,10 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
14951495
u16 conn_timeout, u8 role);
14961496
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
14971497
u8 sec_level, u8 auth_type,
1498-
enum conn_reasons conn_reason);
1498+
enum conn_reasons conn_reason, u16 timeout);
14991499
struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1500-
__u16 setting, struct bt_codec *codec);
1500+
__u16 setting, struct bt_codec *codec,
1501+
u16 timeout);
15011502
struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
15021503
__u8 dst_type, struct bt_iso_qos *qos);
15031504
struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,

include/net/bluetooth/l2cap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid);
939939
struct l2cap_chan *l2cap_chan_create(void);
940940
void l2cap_chan_close(struct l2cap_chan *chan, int reason);
941941
int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
942-
bdaddr_t *dst, u8 dst_type);
942+
bdaddr_t *dst, u8 dst_type, u16 timeout);
943943
int l2cap_chan_reconfigure(struct l2cap_chan *chan, __u16 mtu);
944944
int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
945945
void l2cap_chan_busy(struct l2cap_chan *chan, int busy);

net/bluetooth/6lowpan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static int bt_6lowpan_connect(bdaddr_t *addr, u8 dst_type)
892892
chan->ops = &bt_6lowpan_chan_ops;
893893

894894
err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
895-
addr, dst_type);
895+
addr, dst_type, L2CAP_CONN_TIMEOUT);
896896

897897
BT_DBG("chan %p err %d", chan, err);
898898
if (err < 0)

net/bluetooth/hci_conn.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
16071607

16081608
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
16091609
u8 sec_level, u8 auth_type,
1610-
enum conn_reasons conn_reason)
1610+
enum conn_reasons conn_reason, u16 timeout)
16111611
{
16121612
struct hci_conn *acl;
16131613

@@ -1643,6 +1643,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
16431643
acl->sec_level = BT_SECURITY_LOW;
16441644
acl->pending_sec_level = sec_level;
16451645
acl->auth_type = auth_type;
1646+
acl->conn_timeout = timeout;
16461647

16471648
err = hci_acl_create_connection_sync(hdev, acl);
16481649
if (err) {
@@ -1683,14 +1684,15 @@ static struct hci_link *hci_conn_link(struct hci_conn *parent,
16831684
}
16841685

16851686
struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1686-
__u16 setting, struct bt_codec *codec)
1687+
__u16 setting, struct bt_codec *codec,
1688+
u16 timeout)
16871689
{
16881690
struct hci_conn *acl;
16891691
struct hci_conn *sco;
16901692
struct hci_link *link;
16911693

16921694
acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING,
1693-
CONN_REASON_SCO_CONNECT);
1695+
CONN_REASON_SCO_CONNECT, timeout);
16941696
if (IS_ERR(acl))
16951697
return acl;
16961698

net/bluetooth/hci_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6548,7 +6548,7 @@ static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data)
65486548
err = __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN,
65496549
sizeof(cp), &cp,
65506550
HCI_EV_CONN_COMPLETE,
6551-
HCI_ACL_CONN_TIMEOUT, NULL);
6551+
conn->conn_timeout, NULL);
65526552

65536553
if (err == -ETIMEDOUT)
65546554
hci_abort_conn_sync(hdev, conn, HCI_ERROR_LOCAL_HOST_TERM);

net/bluetooth/l2cap_core.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6925,7 +6925,7 @@ static void l2cap_chan_by_pid(struct l2cap_chan *chan, void *data)
69256925
}
69266926

69276927
int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
6928-
bdaddr_t *dst, u8 dst_type)
6928+
bdaddr_t *dst, u8 dst_type, u16 timeout)
69296929
{
69306930
struct l2cap_conn *conn;
69316931
struct hci_conn *hcon;
@@ -7018,19 +7018,17 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
70187018

70197019
if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
70207020
hcon = hci_connect_le(hdev, dst, dst_type, false,
7021-
chan->sec_level,
7022-
HCI_LE_CONN_TIMEOUT,
7021+
chan->sec_level, timeout,
70237022
HCI_ROLE_SLAVE);
70247023
else
70257024
hcon = hci_connect_le_scan(hdev, dst, dst_type,
7026-
chan->sec_level,
7027-
HCI_LE_CONN_TIMEOUT,
7025+
chan->sec_level, timeout,
70287026
CONN_REASON_L2CAP_CHAN);
70297027

70307028
} else {
70317029
u8 auth_type = l2cap_get_auth_type(chan);
70327030
hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type,
7033-
CONN_REASON_L2CAP_CHAN);
7031+
CONN_REASON_L2CAP_CHAN, timeout);
70347032
}
70357033

70367034
if (IS_ERR(hcon)) {

net/bluetooth/l2cap_sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
254254
chan->mode = L2CAP_MODE_LE_FLOWCTL;
255255

256256
err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
257-
&la.l2_bdaddr, la.l2_bdaddr_type);
257+
&la.l2_bdaddr, la.l2_bdaddr_type,
258+
sk->sk_sndtimeo);
258259
if (err)
259260
return err;
260261

net/bluetooth/mgmt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,8 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
34443444

34453445
if (cp->addr.type == BDADDR_BREDR) {
34463446
conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level,
3447-
auth_type, CONN_REASON_PAIR_DEVICE);
3447+
auth_type, CONN_REASON_PAIR_DEVICE,
3448+
HCI_ACL_CONN_TIMEOUT);
34483449
} else {
34493450
u8 addr_type = le_addr_type(cp->addr.type);
34503451
struct hci_conn_params *p;

net/bluetooth/sco.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ static int sco_connect(struct sock *sk)
264264
}
265265

266266
hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst,
267-
sco_pi(sk)->setting, &sco_pi(sk)->codec);
267+
sco_pi(sk)->setting, &sco_pi(sk)->codec,
268+
sk->sk_sndtimeo);
268269
if (IS_ERR(hcon)) {
269270
err = PTR_ERR(hcon);
270271
goto unlock;

0 commit comments

Comments
 (0)