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);