History

Bluetooth: Fix printing errors if LE Connection times out

This fixes errors like bellow when LE Connection times out since that is actually not a controller error: Bluetooth: hci0: Opcode 0x200d failed: -110 Bluetooth: hci0: request failed to create LE connection: err -110 Instead the code shall properly detect if -ETIMEDOUT is returned and send HCI_OP_LE_CREATE_CONN_CANCEL to give up on the connection.

Luiz Augusto von Dentz committed 3 years ago

Commit b62e7221 parent 19cf60b4 files · +22 −15Browse files

Unified · Split

4 files
  1. include/net/bluetooth/hci_core.h +1 −0
  2. net/bluetooth/hci_conn.c +5 −2
  3. net/bluetooth/hci_event.c +6 −10
  4. net/bluetooth/hci_sync.c +10 −3
include/net/bluetooth/hci_core.h+1−0
@@ -954,6 +954,7 @@ enum { · 953 unmodified lines
954954 HCI_CONN_STK_ENCRYPT,
955955 HCI_CONN_AUTH_INITIATOR,
956956 HCI_CONN_DROP,
957+ HCI_CONN_CANCEL,
957958 HCI_CONN_PARAM_REMOVAL_PEND,
958959 HCI_CONN_NEW_LINK_KEY,
959960 HCI_CONN_SCANNING,
net/bluetooth/hci_conn.c+5−2
@@ -1233,6 +1233,8 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) · 1232 unmodified lines
12331233 {
12341234 struct hci_conn *conn = data;
12351235
1236+ bt_dev_dbg(hdev, "err %d", err);
1237+
12361238 hci_dev_lock(hdev);
12371239
12381240 if (!err) {
@@ -1240,8 +1242,6 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) · 1 unmodified line
12401242 goto done;
12411243 }
12421244
1243− bt_dev_err(hdev, "request failed to create LE connection: err %d", err);
1244−
12451245 /* Check if connection is still pending */
12461246 if (conn != hci_lookup_le_connect(hdev))
12471247 goto done;
@@ -2771,6 +2771,9 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) · 1523 unmodified lines
27712771 {
27722772 int r = 0;
27732773
2774+ if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags))
2775+ return 0;
2776+
27742777 switch (conn->state) {
27752778 case BT_CONNECTED:
27762779 case BT_CONFIG:
net/bluetooth/hci_event.c+6−10
@@ -2881,16 +2881,6 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, · 2880 unmodified lines
28812881
28822882 conn->resp_addr_type = peer_addr_type;
28832883 bacpy(&conn->resp_addr, peer_addr);
2884−
2885− /* We don't want the connection attempt to stick around
2886− * indefinitely since LE doesn't have a page timeout concept
2887− * like BR/EDR. Set a timer for any connection that doesn't use
2888− * the accept list for connecting.
2889− */
2890− if (filter_policy == HCI_LE_USE_PEER_ADDR)
2891− queue_delayed_work(conn->hdev->workqueue,
2892− &conn->le_conn_timeout,
2893− conn->conn_timeout);
28942884 }
28952885
28962886 static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
@@ -5902,6 +5892,12 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, · 3005 unmodified lines
59025892 if (status)
59035893 goto unlock;
59045894
5895+ /* Drop the connection if it has been aborted */
5896+ if (test_bit(HCI_CONN_CANCEL, &conn->flags)) {
5897+ hci_conn_drop(conn);
5898+ goto unlock;
5899+ }
5900+
59055901 if (conn->dst_type == ADDR_LE_DEV_PUBLIC)
59065902 addr_type = BDADDR_LE_PUBLIC;
59075903 else
net/bluetooth/hci_sync.c+10−3
@@ -246,8 +246,9 @@ int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, · 245 unmodified lines
246246
247247 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk);
248248 if (IS_ERR(skb)) {
249− bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode,
250− PTR_ERR(skb));
249+ if (!event)
250+ bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode,
251+ PTR_ERR(skb));
251252 return PTR_ERR(skb);
252253 }
253254
@@ -5126,8 +5127,11 @@ static int hci_le_connect_cancel_sync(struct hci_dev *hdev, · 4872 unmodified lines
51265127 if (test_bit(HCI_CONN_SCANNING, &conn->flags))
51275128 return 0;
51285129
5130+ if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags))
5131+ return 0;
5132+
51295133 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL,
5130− 6, &conn->dst, HCI_CMD_TIMEOUT);
5134+ 0, NULL, HCI_CMD_TIMEOUT);
51315135 }
51325136
51335137 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn)
@@ -6102,6 +6106,9 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) · 968 unmodified lines
61026106 conn->conn_timeout, NULL);
61036107
61046108 done:
6109+ if (err == -ETIMEDOUT)
6110+ hci_le_connect_cancel_sync(hdev, conn);
6111+
61056112 /* Re-enable advertising after the connection attempt is finished. */
61066113 hci_resume_advertising_sync(hdev);
61076114 return err;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t