From patchwork Tue Jan 2 18:59:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4629467dyb; Tue, 2 Jan 2024 11:00:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IF425rTorMXLW06s3M5vBt/pzvdWfJ5meh7PSS/U7+QOL7tCa6dJb8rwpWXYUucRKmSePPH X-Received: by 2002:a17:907:1b09:b0:a26:cdae:e295 with SMTP id mp9-20020a1709071b0900b00a26cdaee295mr19017307ejc.74.1704222029039; Tue, 02 Jan 2024 11:00:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222029; cv=none; d=google.com; s=arc-20160816; b=DQUVjGXIPqCXiM2B4y3/RhKiYIuxPJr8HUJB+dwWG5Adp71DkqnZVm1XYay5j/NlIb NRJ7XNpk6CtkFdF0hJY1xMUYbNqQrqyO6gAY3TsUjzs6XUF8Nj4mA6u5nB744VzQ21tS quusL/SKl9pp354+VXyCx3PiQfoeeN8R6iE+ROjufyrv4uizBud1HsmnCpf2KTFdrhyD 23Axq9Dlc9Q4Sp40WVQNRXhemDNtnv1K9DDzy56mI6qKnw1Vxc5nDXK6iat/t66+uwFp ACcuY3mBprzOjQuZiDRvTZ86lmR7XhzmNRVbo/vGpqHcvJfoOGx+Fpl2wh8y+7JQgNNL 0VDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0CFKc1uU2oc55iKdjjsuGNMWD26URjsdIPjyYZJI7Zg=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=sHn70kq8PdvWDoKkLAy6DdM11DWfVFkFHb2cgzc4FTXbgqQpfoJ/A6nc+EcS6YG8+V pIPb2zaCb8HBvUx08+adkMBx4ndtdyIQWpgYBpBXB/3kSqMrgEqhHPPIBiyR5xb7Zaaz Oiwy73gM1rQHawN2+luKDcTrSmj3US1rbriQcfB45n7c/6xC06t81rNL95LnUxSrJREb 3vVlGmhPOs63qS2OMLc96NlCW9nWGDisOW4hnD2zdW0Ov3BGH0J+/lL/+xASo/rrIvn2 auG5+tmsJ0O67QYfV7vHdJdV0T0GQQndJNXSA4hObjNA7R9epLEP50ktK019yuwJ3yg9 88cQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14751-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14751-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id k22-20020a170906681600b00a188852ae17si11429269ejr.681.2024.01.02.11.00.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:00:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14751-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14751-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14751-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A58D91F21B06 for ; Tue, 2 Jan 2024 19:00:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13ABE16424; Tue, 2 Jan 2024 18:59:45 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88FAC15AD3; Tue, 2 Jan 2024 18:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4T4MbY5VtLz9sb4; Tue, 2 Jan 2024 19:59:37 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/5] Bluetooth: Remove superfluous call to hci_conn_check_pending() Date: Tue, 2 Jan 2024 19:59:28 +0100 Message-ID: <20240102185933.64179-2-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4T4MbY5VtLz9sb4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006318139076280 X-GMAIL-MSGID: 1787006318139076280 The "pending connections" feature was originally introduced with commit 4c67bc74f016b0d360b8573e18969c0ff7926974 and 6bd57416127e92d35e6798925502c84e14a3a966 to handle controllers supporting only a single connection request at a time. Later things were extended to also cancel ongoing inquiries on connect() with commit 89e65975fea5c25706e8cc3a89f9f97b20fc45ad. With commit a9de9248064bfc8eb0a183a6a951a4e7b5ca10a4, hci_conn_check_pending() was introduced as a helper to consolidate a few places where we check for pending connections (indicated by the BT_CONNECT2 flag) and then try to connect. This refactoring commit also snuck in two more calls to hci_conn_check_pending(): - One is in the failure callback of hci_cs_inquiry(), this one probably makes sense: If we send an "HCI Inquiry" command and then immediately after a "Create Connection" command, the "Create Connection" command might fail before the "HCI Inquiry" command, and then we want to retry the "Create Connection" on failure of the "HCI Inquiry". - The other added call to hci_conn_check_pending() is in the event handler for the "Remote Name" event, this seems unrelated and is possibly a copy-paste error, so remove that one. Fixes: a9de9248064bfc8eb0a183a6a951a4e7b5ca10a4 Signed-off-by: Jonas Dreßler --- net/bluetooth/hci_event.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 31ca320ce..13396329f 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3538,8 +3538,6 @@ static void hci_remote_name_evt(struct hci_dev *hdev, void *data, bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); - hci_conn_check_pending(hdev); - hci_dev_lock(hdev); conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); From patchwork Tue Jan 2 18:59:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4629961dyb; Tue, 2 Jan 2024 11:01:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd41MZnWUHFWa9OZ9dYedk0fvmy65qKJAIF/HpDspvtA6oZ0xNws2gqEnrELy6eIrl/NX+ X-Received: by 2002:a05:6a20:3a91:b0:196:a56b:4e92 with SMTP id d17-20020a056a203a9100b00196a56b4e92mr2246431pzh.81.1704222067073; Tue, 02 Jan 2024 11:01:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222067; cv=none; d=google.com; s=arc-20160816; b=IGcmYIncBYada1JTqXhOH3zYcFj+ZSM7dels1bZLPWE24SUI7Ab4ueqqTwd8ZjV+Yo DQWvBZqW30U7ctuz8LzE65K0d4IPqnOmrErjM/eUzDThkrH7c3EKZppELwUcaCvi59HR rjyhQeCXxH54y0bLqyXeQYCExyxwEycp7fyRa1s9K6qk0Lmnln+VSaKL1D5Uk/dwGU7k XMjP5wryP47X737iQxjYKf3vOTh19hVZJoMqlhaOPIJp6OvYh92SIK4NZU+MMHCVFFww NgrO5//8FGQz6wL5yYMoj0Xe+8Rj4jGjq95NTYbm2HZYPEiD98vhH8VF0Q/LxnT6YybB wYkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Sz1KVDSy6RfcWKbVdd4pVfTOMN76sxIKW3uTgVzJ+q8=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=y5pBX9cD3txO+K4atqPcdXNHPSfsd6iFPDJfCqrBvrJU9BupRrCVqV1vycnkpDfaMq hcqlr+mSZMuE3R/n0JbTn0A1UnhvyNB6V6VSq+T0LsBclaJdAM3WwLLmh78mP/e4gNNy rM6DtieTD6X+M3Dvwkx00tzp61qDORrBvIa7vT7oc37F3RfhlW9NlVhv3H4HxAn7yI+3 HuBoaPtGFqMnEnT8sXRuDtrElwx+MacCrRuKOYSwXT9Iq5tl4vykt/DVAAnbzv0l//+A KZOK2IGDXPSpEdc3luYeWV8N6fcrbPp8E++wHEpUL7LtBfkZoTGpUh6RcshUAGMKJsMB t6nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14752-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14752-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u8-20020a056a00098800b006d9c8639c70si13150815pfg.354.2024.01.02.11.01.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14752-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14752-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14752-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C33FE280CFD for ; Tue, 2 Jan 2024 19:01:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8F80168DD; Tue, 2 Jan 2024 18:59:46 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41C2D15E97; Tue, 2 Jan 2024 18:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4T4Mbb1SQzz9sq5; Tue, 2 Jan 2024 19:59:39 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/5] Bluetooth: hci_event: Use HCI error defines instead of magic values Date: Tue, 2 Jan 2024 19:59:29 +0100 Message-ID: <20240102185933.64179-3-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006358195185340 X-GMAIL-MSGID: 1787006358195185340 Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 2 ++ net/bluetooth/hci_event.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 111e8f8e5..fef723afd 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -641,6 +641,7 @@ enum { #define HCI_ERROR_PIN_OR_KEY_MISSING 0x06 #define HCI_ERROR_MEMORY_EXCEEDED 0x07 #define HCI_ERROR_CONNECTION_TIMEOUT 0x08 +#define HCI_ERROR_COMMAND_DISALLOWED 0x0c #define HCI_ERROR_REJ_LIMITED_RESOURCES 0x0d #define HCI_ERROR_REJ_BAD_ADDR 0x0f #define HCI_ERROR_INVALID_PARAMETERS 0x12 @@ -649,6 +650,7 @@ enum { #define HCI_ERROR_REMOTE_POWER_OFF 0x15 #define HCI_ERROR_LOCAL_HOST_TERM 0x16 #define HCI_ERROR_PAIRING_NOT_ALLOWED 0x18 +#define HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE 0x1e #define HCI_ERROR_INVALID_LL_PARAMS 0x1e #define HCI_ERROR_UNSPECIFIED 0x1f #define HCI_ERROR_ADVERTISING_TIMEOUT 0x3c diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 13396329f..e8b4a0126 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -92,11 +92,11 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data, /* It is possible that we receive Inquiry Complete event right * before we receive Inquiry Cancel Command Complete event, in * which case the latter event should have status of Command - * Disallowed (0x0c). This should not be treated as error, since + * Disallowed. This should not be treated as error, since * we actually achieve what Inquiry Cancel wants to achieve, * which is to end the last Inquiry session. */ - if (rp->status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { + if (rp->status == HCI_ERROR_COMMAND_DISALLOWED && !test_bit(HCI_INQUIRY, &hdev->flags)) { bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); rp->status = 0x00; } @@ -2323,7 +2323,7 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - if (status != 0x0c || conn->attempt > 2) { + if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { conn->state = BT_CLOSED; hci_connect_cfm(conn, status); hci_conn_del(conn); @@ -6578,7 +6578,7 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data, * transition into connected state and mark it as * successful. */ - if (!conn->out && ev->status == 0x1a && + if (!conn->out && ev->status == HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE && (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) status = 0x00; else From patchwork Tue Jan 2 18:59:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4630323dyb; Tue, 2 Jan 2024 11:01:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgqLAE0mlzU3Gv/nFzEBt6L6CfuG5fiKysKhcjKbp/fPlzTvNQuL6SA4b3ujCDwp3iR4tZ X-Received: by 2002:a17:902:d5cd:b0:1d3:485a:833d with SMTP id g13-20020a170902d5cd00b001d3485a833dmr19442295plh.39.1704222095352; Tue, 02 Jan 2024 11:01:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222095; cv=none; d=google.com; s=arc-20160816; b=RSnpBs88h3KoyXPO3EuDrF6Y31jejr2irRfMDbbCrR9xbcH8XlubqxGvqA4tm9zU1n a1bxs13i5M6VW029FNgg7nweOicBZ4X2J1qiO68+0IdOKD2JiSQDfQlu23o5RovvGCZi mgpuclkzEc3UWItL+HCZGlLc6CDo4RVs/53X/yftAD/2zLOZT1ZNUhkf6sauT7mifVh3 2SRK0gflDpbYFPMMI5kQtop5X+zqP3NJ78x3H22+tx/Vul5AM+aCBtPLAzUzKa5o1SGT 6i3tl/LTU/NcD9BETNT9dY6kyfx7qBUZ+uHvZcz38wVe6UF3RTpIeXMqQKXyPQxkOyo9 ywPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=gooZhh7JPQWGYYCXVr4EkSSJBp4Ez14i+QXmjsCifbA=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=aEBuqaGFxQDJoHM4ro3QO+f1Q1LBuIDSrn0yIyWFY7XrodaT/M5ilsS3v8qG8JXtNO d1XkhHeub8kJp7MCxgiA8LQt+DI8/kixuB44Y6TamAH7EQ+jEqOf/03PbAf+dIkQ8dgE Y9Ah9dhqcrLJ19VM6ff/4jm0EF4vnzxuKLPBR6WzA8FirXGI4hGgXFILcYWm1dQKqNUw Z8El6cZB3w29japrdq+KBz5cTDOLrgfSra/dtNeVPmmUbqzzxQhKrTQBBkHA+h/2eQgR rm23cV6z14Hsce6C4te5LsqhyaTqmhwiQ4KA2FE1pdeelFm/ZA8Fhw0nFUAYIvPDuQzQ UgOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q10-20020a170902daca00b001d3c4df5004si16753413plx.151.2024.01.02.11.01.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AA3B0B22862 for ; Tue, 2 Jan 2024 19:01:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78ABE171B6; Tue, 2 Jan 2024 18:59:47 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3F516415; Tue, 2 Jan 2024 18:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4T4Mbc4QNnz9sQb; Tue, 2 Jan 2024 19:59:40 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/5] Bluetooth: hci_event: Remove limit of 2 reconnection attempts Date: Tue, 2 Jan 2024 19:59:30 +0100 Message-ID: <20240102185933.64179-4-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4T4Mbc4QNnz9sQb X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006387843018230 X-GMAIL-MSGID: 1787006387843018230 Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting later when we get a "Command Disallowed" error returned by "Create Connection". In this commit the intention was to retry only once, and give up if we see "Command Disallowed" again on the second try. This made sense back then when the retry was initiated *only* from the "Connect Complete" event. If we received that event, we knew that now the card now must have a "free slot" for a new connection request again. These days we call hci_conn_check_pending() from a few more places though, and in these places we can't really be sure that there's a "free slot" on the card, so the second try to "Create Connection" might fail again. Deal with this by being less strict about these retries and try again every time we get "Command Disallowed" errors, removing the limitation to only two attempts. Since this can potentially cause us to enter an endless cycle of reconnection attempts, we'll add some guarding against that with the next commit. Signed-off-by: Jonas Dreßler --- net/bluetooth/hci_event.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index e8b4a0126..e1f5b6f90 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { + if (status == HCI_ERROR_COMMAND_DISALLOWED) { + conn->state = BT_CONNECT2; + } else { conn->state = BT_CLOSED; hci_connect_cfm(conn, status); hci_conn_del(conn); - } else - conn->state = BT_CONNECT2; + } } } else { if (!conn) { From patchwork Tue Jan 2 18:59:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4630331dyb; Tue, 2 Jan 2024 11:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdW2RFCWPgeG0ikwfmh7vkX2PKkB/sZmtOZcxpDZw6K+ZeR+gHJeOzNna6JD9iYHoBXa6r X-Received: by 2002:a05:620a:4554:b0:781:284d:3f66 with SMTP id u20-20020a05620a455400b00781284d3f66mr27357672qkp.130.1704222096353; Tue, 02 Jan 2024 11:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222096; cv=none; d=google.com; s=arc-20160816; b=N+Kg937juyvR+wlmPDaVrO7FR7vguMSPwNUoafW037++LBead8K566H0u3vLqjkMon /LluL/wcSYx4dUrSNBKL0vyp9NCxZmO+bYmqiOGUX/+wWeEQ5Q05dLTmSIxjmIYXAnXC SnG9H03nEVYtwBEa0cByQh+B7mGgQc+nH8KlTnQfCBsrr5T6ZM5RS7W/aWpEfhq5bZ2v zIMwBTUu0DC9K0WveGunC85l+GNjwL6YV4Jr5nFcRcwD7/zhbWZmT+gQWnYlRzttE04o wwoz9R0v/ImwqZCdoyzyxpdjjg8dfvNb1RouNwyp3XTYNjLJy9ZZKFv7KwGAptY5zGBr NOeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=c+q/PJHp0tARjnN8Tb7KMBIJSK/Vrj9y4cXLlA6YGAQ=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=jdyaJdEP1zyOE/lJ0HpN2fZQ5puOeLfTmybj2Wtiitif4JefW7661xMAZO/0ey/o8g MHSQSgHJRFrpEkJ5m1qCBbpssGFNqhXMnLDYs81mQlthg7IEYmkdzTzhj0PmQ8PEGKLC X3IiJfXo5SRweXVVbo7eLicBcc8GYGoi3im+S3RBs/usgCRiZ1fj6BWmLzzj7rIk31rd zWXCzshwv13fJ7NaweqcONajCmbnqrfOtLfRkZHkc12jOrTJtJYQk9sy+8wapkrY4J4E VPHAQW3ke0Jt18TnfFRPvz6tdjRiKXnEjbkhBWCn2qyKezHvUJox0lyndJ9tyuvDEMEI v4vQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14754-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14754-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p7-20020a05620a056700b007815c65c9d9si13716490qkp.597.2024.01.02.11.01.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14754-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14754-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14754-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 289AE1C2091D for ; Tue, 2 Jan 2024 19:01:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B301F17723; Tue, 2 Jan 2024 18:59:48 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F0C616433; Tue, 2 Jan 2024 18:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4T4Mbd6BVcz9smm; Tue, 2 Jan 2024 19:59:41 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 4/5] Bluetooth: hci_event: Do sanity checks before retrying to connect Date: Tue, 2 Jan 2024 19:59:31 +0100 Message-ID: <20240102185933.64179-5-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006388930022754 X-GMAIL-MSGID: 1787006388930022754 When we receive "Command Disallowed" response to HCI_CREATE_CONNECTION, we'll try to connect again later, assuming that the command failed either because there's already concurrent "Create Connection" requests on the card and all "slots" for new connections are exhausted, or the card is in the middle of doing an HCI Inquiry. Both of those conditions we should know about, so do some sanity checking to ensure one of them actually applies. If they don't, log an error and delete the connection. Signed-off-by: Jonas Dreßler --- net/bluetooth/hci_event.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index e1f5b6f90..1376092c5 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2323,8 +2323,28 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { + /* If the request failed with "Command Disallowed", the + * card is either using all its available "slots" for + * attempting new connections, or it's currently + * doing an HCI Inquiry. In these cases we'll try to + * do the "Create Connection" request again later. + */ if (status == HCI_ERROR_COMMAND_DISALLOWED) { conn->state = BT_CONNECT2; + + if (!hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && + !test_bit(HCI_INQUIRY, &hdev->flags)) { + bt_dev_err(hdev, + "\"Create Connection\" returned error " + "(0x%2.2x) indicating to try again, but " + "there's no concurrent \"Create " + "Connection\" nor an ongoing inquiry", + status); + + conn->state = BT_CLOSED; + hci_connect_cfm(conn, status); + hci_conn_del(conn); + } } else { conn->state = BT_CLOSED; hci_connect_cfm(conn, status); From patchwork Tue Jan 2 18:59:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 184436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4630645dyb; Tue, 2 Jan 2024 11:01:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwQp3lpYpdKM66E/NLA/W2U12ijQ995MQHe1DFt851TisSVsXoTz93LzzqsVLsYl616WJI X-Received: by 2002:a05:6870:9625:b0:205:21f3:790f with SMTP id d37-20020a056870962500b0020521f3790fmr9350973oaq.42.1704222118966; Tue, 02 Jan 2024 11:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222118; cv=none; d=google.com; s=arc-20160816; b=OvYP/u64Izi2Dfj5yZCwjSw+6nzP+rgjdbSg8/dqBZqJNvXblydC6Hm7JMkOociTkn Nwapo1PIFdKmBoynd1GAStVKlrcBVjlGBE8uifzTe4ViVlXz/lNvS2RGqqyv9zHgEjgl RFHcL8MLXrE5IQjMDSlvfEZYISKOVqoo6wGTkggGSFuHjDfngJ78Gt9P9fMb3BdH1WyV eH+UW/+v0Xr3QBcUvqYQRVKbfZXxKkbjE8jG2/HKGBT9dMW76PWC/pQWz8HzDYsIb8jA 24fsn5Iqd6JW50VK8rdieA3LM9ezTJMFmfAfiXld6U3QYIy9NZ0YbxaG4MzxMHoBEjCO E24Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=mYz1A1U3kOrainhKz7h69+HR2I8R9IIu5H7UkQZUrZI=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=tNhFx5KB1F7imnOfsUNVP4g+r07ctEcfV5ROVehmGH8Q/VrVgoH0gX42GZpXcf9lkd wgBxnyu9YZIJlgQolufYgJaR0ummNiFxAJJohZL617TvP+XmkOy0AaFRuHgXX08IjLwR 1ATDSTOI5dAIXfQC+s6IBgCzVCTDOPAjo0MMC9uqfhUhGQCTqvx6r4H1qnFfROAyGkSs RDOQ6r7pw2lGklRYWH3e7JMSXIqDFVimGKCigXWD01F6VY3+rPStOvYuqtPvUX+AXJ1B +TPZGfuP2bM5OEmzM0BbEiRJPl+GB/e/IWsdNiNxHsWzp6bTzNt5ciiGonK/gTl1xMZL 4j+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cb15-20020a056a02070f00b005cdfd4aa8b3si17857165pgb.193.2024.01.02.11.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14755-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B673D28403C for ; Tue, 2 Jan 2024 19:01:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6425217729; Tue, 2 Jan 2024 18:59:50 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC09D168DF; Tue, 2 Jan 2024 18:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4T4Mbg1nPPz9sp4; Tue, 2 Jan 2024 19:59:43 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 5/5] Bluetooth: hci_event: Try reconnecting on more kinds of errors Date: Tue, 2 Jan 2024 19:59:32 +0100 Message-ID: <20240102185933.64179-6-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4T4Mbg1nPPz9sp4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006413003679876 X-GMAIL-MSGID: 1787006413003679876 While some hardware seems to return "HCI Command Disallowed" errors when trying to connect to too many devices at once, other hardware (eg. the BCM4378 found in M1 macbooks) returns "HCI Hardware Failure" in this case. And the Marvell 88W8897 in various Microsoft Surface devices behaves different again: Here the "HCI Create Connection" succeeds, but later a "HCI Connection Complete" event with status "Rejected Limited Resources" comes in. Handle all these cases as expected by userspace and reuse the existing BT_CONNECT2 logic to try "HCI Create Connection" again after the ongoing connection attempts have been completed. Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index fef723afd..23890f53e 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -637,6 +637,7 @@ enum { /* ---- HCI Error Codes ---- */ #define HCI_ERROR_UNKNOWN_CONN_ID 0x02 +#define HCI_ERROR_HARDWARE_FAILURE 0x03 #define HCI_ERROR_AUTH_FAILURE 0x05 #define HCI_ERROR_PIN_OR_KEY_MISSING 0x06 #define HCI_ERROR_MEMORY_EXCEEDED 0x07 diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1376092c5..46b6d7e27 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2323,13 +2323,14 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - /* If the request failed with "Command Disallowed", the + /* If the request failed with a certain status, the * card is either using all its available "slots" for * attempting new connections, or it's currently * doing an HCI Inquiry. In these cases we'll try to * do the "Create Connection" request again later. */ - if (status == HCI_ERROR_COMMAND_DISALLOWED) { + if (status == HCI_ERROR_COMMAND_DISALLOWED || + status == HCI_ERROR_HARDWARE_FAILURE) { conn->state = BT_CONNECT2; if (!hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && @@ -3254,7 +3255,26 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, done: if (status) { - hci_conn_failed(conn, status); + if (status == HCI_ERROR_REJ_LIMITED_RESOURCES) { + conn->state = BT_CONNECT2; + + if (!hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && + !test_bit(HCI_INQUIRY, &hdev->flags)) { + bt_dev_err(hdev, + "\"Connect Complete\" event with error " + "(0x%2.2x) indicating to try again, but " + "there's no concurrent \"Create " + "Connection\" nor an ongoing inquiry", + status); + + hci_conn_failed(conn, status); + } + + hci_dev_unlock(hdev); + return; + } else { + hci_conn_failed(conn, status); + } } else if (ev->link_type == SCO_LINK) { switch (conn->setting & SCO_AIRMODE_MASK) { case SCO_AIRMODE_CVSD: