Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1673908rwl; Fri, 24 Mar 2023 13:56:56 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7UmLoLTMJa92U3hcC/Qz2dhJGlbH+l5csGiQkazgcNgKRAmm/8+Z8jfjIQ2NtUPk+mIc/ X-Received: by 2002:a17:906:95c3:b0:93c:daff:4aab with SMTP id n3-20020a17090695c300b0093cdaff4aabmr3903498ejy.26.1679691416197; Fri, 24 Mar 2023 13:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679691416; cv=none; d=google.com; s=arc-20160816; b=ul26rBrdRYJiVnLXyv3hX+hau1kCa229bysggOCQYs/LkmgSRfqRtaj480hgQohHjl vTANf6Q36F2mv2q+96b3XDItTF6XeyD5acRiXoKhtysL0thqmk/hWvz1PhoHLRxc7qfd Y3eIiQxjS7zL7aUsgurJeSvucNpq4J3M2wZ49vRgsdUd2OIvdLqtI8VVZdOJdTMiStuK KYlHrXoOqyq5ga5HOeoeadO6ygRlPmSKpjSI8w5UWCtn5cVv/baqkDV9OtOLF768X1+U D8FY4TyP18isBAqty+xRhdsS/AYdb1aumUGPpT4w44PEJwoHrNxwbgSS68yshzc5Zxz/ 0qew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=JDScRyIfsTebtpYTTraE3O7YzpARmjAA3agUIqqoS5w=; b=jSfexUFB/H0JIe2YLAsgnZ47cjkaFIqiohvVM6xXehrppgymQYJPC3zdSwh6KBT7f9 8EljbxYdc7daQWCgu20JZiiCRc51cajcHruKmyPsYqLoAe70l1LCEhWK2p4Rp7jHpr9R iaswFJUM6lI3gse/R3SpLCrrq7I/8Baog0QAiML/LHdXNetv/VFfx+tWpb2pSHI6eg9i lMZAwZzxIYe1h06dP+wSg6v4WalXno3tB+Aq/rTNculkFV/ZLwvU7RbCCK663BNZ1+4U /Q03UpM5RSX1p6t2qFTXATLGOkAR9gFkwwr02epAQl5x9IJUu+CHFIICJO0go19+ZXvc RuGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dF2aO/Og"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vo9-20020a170907a80900b0093f0fced517si413127ejc.373.2023.03.24.13.56.04; Fri, 24 Mar 2023 13:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dF2aO/Og"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbjCXUpc (ORCPT + 99 others); Fri, 24 Mar 2023 16:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbjCXUpb (ORCPT ); Fri, 24 Mar 2023 16:45:31 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A279B13DC1 for ; Fri, 24 Mar 2023 13:45:30 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id u20so2035898pfk.12 for ; Fri, 24 Mar 2023 13:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679690729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JDScRyIfsTebtpYTTraE3O7YzpARmjAA3agUIqqoS5w=; b=dF2aO/OgVNJE2+IiltfCsV+6GC8NGuQyCskJ5E1rLE693Lu3yHuGoAGd4goz1/C68k 3CvuuyL85I4ENfMi9Dvypt9Hk6PDaFYxT88veM5FWHeMNVOEBVPLUpQ9tN/ZX9bXtI2y sSweh5eY344LP1WEO4Km5ftqbl+ArragRS5OdEqsdGqbtUqNI+zWvObV9DAR6Q5BCKz2 G3gQxHJJUk0lYbJCdOyjebAP4PVMa6fstpL4mOyoyHPhBEQta+OvrzNzbyBWcudwh0AD aJobDeW7tGinYnIdPrUdgxqA89inFopSWU6nlaR4OM4PQHzpcsLBzhZ+TH/mSGURh2gd fezg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679690729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JDScRyIfsTebtpYTTraE3O7YzpARmjAA3agUIqqoS5w=; b=gZlgKLRg3Wcb8aDNdQt47fFrMNUoyM2FtDSAsuqvyqOp2/oA2vchvaNe4q7acdajfD Zas2fu0pIYahbZHumgLPxQJoA7ml/q3qJm1zhPOFcJqf97S3pEs8ofBsTXpOXdxjLI9l urwd1ouP4lxFpnjlk5vhE5Pnn3tlYfTuxTSHfC0yjL9Vio+Vo1LcKJFWL3OUh+rI0ODF o6MLDwpCmKRjZkCQE8+8G4hu3ZxtoZ9YGmTHqK4WdFwOf9z43S1L5KEcPvURgN5bZ/nr dHL8NbyC4azwby2+Uf5907kKlLpU8FnIf0Qr+b2P27DlrzIxqmNUFSsIHodqJBZu3xoH sp7Q== X-Gm-Message-State: AAQBX9fs+tw1eudRkQrHv/64PSyC0sWTMGKTaxG+ofzkXpHHqZNOfPCQ k2gZ7/x+eKxzZbLCqPWpjETK2M5WNKw= X-Received: by 2002:a62:2581:0:b0:628:1b3:d499 with SMTP id l123-20020a622581000000b0062801b3d499mr3798716pfl.21.1679690729479; Fri, 24 Mar 2023 13:45:29 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b0062b485b8e5esm1669916pfm.81.2023.03.24.13.45.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 13:45:28 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/2] Bluetooth: Fix printing errors if LE Connection times out Date: Fri, 24 Mar 2023 13:45:25 -0700 Message-Id: <20230324204525.3630188-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324204525.3630188-1-luiz.dentz@gmail.com> References: <20230324204525.3630188-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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. Link: https://github.com/bluez/bluez/issues/340 Fixes: Fixes: 8e8b92ee60de ("Bluetooth: hci_sync: Add hci_le_create_conn_sync") Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_conn.c | 7 +++++-- net/bluetooth/hci_event.c | 16 ++++++---------- net/bluetooth/hci_sync.c | 13 ++++++++++--- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 6ed9b4d546a7..d5311ceb21c6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -954,6 +954,7 @@ enum { HCI_CONN_STK_ENCRYPT, HCI_CONN_AUTH_INITIATOR, HCI_CONN_DROP, + HCI_CONN_CANCEL, HCI_CONN_PARAM_REMOVAL_PEND, HCI_CONN_NEW_LINK_KEY, HCI_CONN_SCANNING, diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 0cd339ba7858..a51a6cfd5687 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1235,6 +1235,8 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) { struct hci_conn *conn = data; + bt_dev_dbg(hdev, "err %d", err); + hci_dev_lock(hdev); if (!err) { @@ -1242,8 +1244,6 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) goto done; } - bt_dev_err(hdev, "request failed to create LE connection: err %d", err); - /* Check if connection is still pending */ if (conn != hci_lookup_le_connect(hdev)) goto done; @@ -2773,6 +2773,9 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) { int r = 0; + if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) + return 0; + switch (conn->state) { case BT_CONNECTED: case BT_CONFIG: diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index ad92a4be5851..e68f2a7d863a 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2881,16 +2881,6 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, conn->resp_addr_type = peer_addr_type; bacpy(&conn->resp_addr, peer_addr); - - /* We don't want the connection attempt to stick around - * indefinitely since LE doesn't have a page timeout concept - * like BR/EDR. Set a timer for any connection that doesn't use - * the accept list for connecting. - */ - if (filter_policy == HCI_LE_USE_PEER_ADDR) - queue_delayed_work(conn->hdev->workqueue, - &conn->le_conn_timeout, - conn->conn_timeout); } 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, if (status) goto unlock; + /* Drop the connection if it has been aborted */ + if (test_bit(HCI_CONN_CANCEL, &conn->flags)) { + hci_conn_drop(conn); + goto unlock; + } + if (conn->dst_type == ADDR_LE_DEV_PUBLIC) addr_type = BDADDR_LE_PUBLIC; else diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 5a6aa1627791..632be1267288 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -246,8 +246,9 @@ int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); if (IS_ERR(skb)) { - bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, - PTR_ERR(skb)); + if (!event) + bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, + PTR_ERR(skb)); return PTR_ERR(skb); } @@ -5126,8 +5127,11 @@ static int hci_le_connect_cancel_sync(struct hci_dev *hdev, if (test_bit(HCI_CONN_SCANNING, &conn->flags)) return 0; + if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) + return 0; + return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, - 6, &conn->dst, HCI_CMD_TIMEOUT); + 0, NULL, HCI_CMD_TIMEOUT); } 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) conn->conn_timeout, NULL); done: + if (err == -ETIMEDOUT) + hci_le_connect_cancel_sync(hdev, conn); + /* Re-enable advertising after the connection attempt is finished. */ hci_resume_advertising_sync(hdev); return err; -- 2.39.2