From patchwork Tue Jan 2 13:33:09 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: 184353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4450747dyb; Tue, 2 Jan 2024 05:43:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYkoy3oIPa7X1UGBpYa8qhID6fufy9wPDGaYVIl23ggQVNfybcFM8DNJ40IqdIhIqxJC6E X-Received: by 2002:a05:622a:386:b0:425:a69f:9780 with SMTP id j6-20020a05622a038600b00425a69f9780mr25105992qtx.30.1704203020300; Tue, 02 Jan 2024 05:43:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704203020; cv=none; d=google.com; s=arc-20160816; b=EdWQYTI/q4bckjc6LkpCIhH0lgzMrhsok3pTNCTIBZ7nFoaBO0O/ngOljKev/5ND5j 38y9hS02Dtc5HSSkzSs8B8D+A8f3Rhjhan5IDI6uYmwBC+m05ufpIluhw6bNoLYU7IH5 2Nse4yZU5owd7UQymnV6HfA11GTeqm3I8oJDzLLdA0Psiv0KYC+KjRDw/kELkL7Nm2yF piqVoUb4g0wxMXqJ+DvqKk+AWVaooNvJ4ZMo8SGGFnp5ELhcPjSIbenMVNlsWGzDjV2H bu4QmIO++D7K6ATm9bV7kq8ZykZAjUYRm/gtkMmd/VFLuzKOgKTsSKXX9dk2GU/LAUdv OKrg== 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=den5Eoi9tjG885w25HxzuCi7niU+nGAVYurFh4dct9I=; fh=S5rf2bc7VLlSXYQ0EqFAIodb1qEiUfsxulvZhQKZRws=; b=fIi4+XoEGdi8dsVlv5x0/PizIyew5QJaUXYXRCnUTVXswwItUmdOyDuxHnpod0KI83 Ceh2sdoae5B8xenS4rq71OPYHcZxwYT08NuhrTQPpwZYDpT4mQ9VfHgjUePK/Px56Axi kG3UjI1nMF+ArVPWQZViAuoJ94yL/pNtT5gPAuCZGsNYXFJ3bVQJBGy8qn65WEliYOVz ebgqIrxb64qNS9J9VYgk2WlDwa3qphDWVmwdT27UVe9E9O/VHoNR/ZnDXmHQ3Cw1cvQk e0IJaZ9dAs5DkWUyeuAL2BBKYQA4YMoSxQojJf+SzfGnB0nntehrrqOFX/tCk7Bq7BxO UVCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14432-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 fc21-20020a05622a489500b004283020694asi1110587qtb.579.2024.01.02.05.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:43:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14432-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-14432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14432-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 F2A881C22188 for ; Tue, 2 Jan 2024 13:43:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD53B12E5B; Tue, 2 Jan 2024 13:42:51 +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 D95CC125B5; Tue, 2 Jan 2024 13:42:48 +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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4T4DM83spzz9tJ3; Tue, 2 Jan 2024 14:33:24 +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?= , asahi@lists.linux.dev, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/4] Bluetooth: HCI: Add new state HCI_POWERING_DOWN Date: Tue, 2 Jan 2024 14:33:09 +0100 Message-ID: <20240102133311.6712-4-verdre@v0yd.nl> In-Reply-To: <20240102133311.6712-1-verdre@v0yd.nl> References: <20240102133311.6712-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: 4T4DM83spzz9tJ3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786986386654627730 X-GMAIL-MSGID: 1786986386654627730 Add a new state HCI_POWERING_DOWN that indicates that the device is currently powering down, this will be useful for the next commit. Signed-off-by: Jonas Dreßler --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_sync.c | 16 +++++++++++----- net/bluetooth/mgmt.c | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index cf5d6230c..e08afd870 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -361,6 +361,7 @@ enum { HCI_SETUP, HCI_CONFIG, HCI_DEBUGFS_CREATED, + HCI_POWERING_DOWN, HCI_AUTO_OFF, HCI_RFKILLED, HCI_MGMT, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index e6eee1808..c920de0a2 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5389,27 +5389,33 @@ static int hci_power_off_sync(struct hci_dev *hdev) if (!test_bit(HCI_UP, &hdev->flags)) return 0; + hci_dev_set_flag(hdev, HCI_POWERING_DOWN); + if (test_bit(HCI_ISCAN, &hdev->flags) || test_bit(HCI_PSCAN, &hdev->flags)) { err = hci_write_scan_enable_sync(hdev, 0x00); if (err) - return err; + goto out; } err = hci_clear_adv_sync(hdev, NULL, false); if (err) - return err; + goto out; err = hci_stop_discovery_sync(hdev); if (err) - return err; + goto out; /* Terminated due to Power Off */ err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); if (err) - return err; + goto out; + + err = hci_dev_close_sync(hdev); - return hci_dev_close_sync(hdev); +out: + hci_dev_clear_flag(hdev, HCI_POWERING_DOWN); + return err; } int hci_set_powered_sync(struct hci_dev *hdev, u8 val) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index c5291e139..8f42ee059 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1382,6 +1382,14 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, hci_dev_lock(hdev); + if (!cp->val) { + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, + MGMT_STATUS_BUSY); + goto failed; + } + } + if (pending_find(MGMT_OP_SET_POWERED, hdev)) { err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, MGMT_STATUS_BUSY); @@ -9742,6 +9750,9 @@ bool mgmt_powering_down(struct hci_dev *hdev) struct mgmt_pending_cmd *cmd; struct mgmt_mode *cp; + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) + return true; + cmd = pending_find(MGMT_OP_SET_POWERED, hdev); if (!cmd) return false; @@ -10049,6 +10060,9 @@ void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) /* If this is a HCI command related to powering on the * HCI dev don't send any mgmt signals. */ + if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) + return; + if (pending_find(MGMT_OP_SET_POWERED, hdev)) return; }