From patchwork Sun Jan 7 18:02:49 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: 185754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp646602dyq; Sun, 7 Jan 2024 10:04:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHY9aglpDjOsHuMzfJTpMX4rdPgXdjtIltZF5LinNQqPvlGFnDak2Bh2GD8Jcdu4f9VT+bH X-Received: by 2002:a05:6e02:2162:b0:35f:b606:fe9a with SMTP id s2-20020a056e02216200b0035fb606fe9amr4424204ilv.3.1704650686971; Sun, 07 Jan 2024 10:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704650686; cv=none; d=google.com; s=arc-20160816; b=CvmTxnD0qQn8FEdpSyCiaCEeeqNNTXJwsb/lhQGVMcGQu+RfAqvoDNSl1IPwgyVU6e wrRWSqG+CgccENeEeWCh+UctUohCsJMY+n9xKkGewveXs3MKi2U+QfRPrO9b9cdvmZW6 yP+XC/js56+lmI/Q235hwSGd/2IYT25pEMqDeA07DO12fRxALk80H4oM5r+z1xm65gHt /nvrgteUbIN2sbRm49xvSSqaDc/KYPVkgAkTEZ3grLODcwW2MwmxUSqZ+uWhgFq4zaVL BJrj+GkF49p9vFcD8OVD7m0zDc2X6Rm2zzq6OgtRa6P0+u5V+xbzGsb+QZORb6Ggpm7E 8PlA== 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=FLKUJr4JfDvj70hO6K2Yc9eB4XQzdhOc+lLuGQczYqsvpwmp47K5lAxdqqBLm/4RW7 aBmG21RK5h2Qa3EVD38eumeLdRX1lwkyGWimaqIVJZLjJnftSImvlKRvpBfvXlU17xet ktmXHHmCVbERfHono0ZdIo5+grzzOqR9a9zxzOP8HFhQRpWjpWwPFwMFn/vYZn3dkrqs E+mdXFu4Q8i06zFFUqCnW64Wwg3G5oQ+FingzRamueD+8jIT/9bx9J+tc7a9vNqAnmUH gBrsaGSWouQLRUK+O2W7F900/JpBMzR6PF16u9m/wBKvad6FrtVAj9TdPni1iqBUygHb F4vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m4-20020a170902768400b001d4dd43fc06si4640919pll.284.2024.01.07.10.04.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 10:04:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18943-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18943-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 B779928214A for ; Sun, 7 Jan 2024 18:04:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B75622BCF7; Sun, 7 Jan 2024 18:03:19 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (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 851C513FEC; Sun, 7 Jan 2024 18:03:15 +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-102.mailbox.org (Postfix) with ESMTPS id 4T7Q624zzNz9tCY; Sun, 7 Jan 2024 19:03:06 +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 v3 3/4] Bluetooth: Add new state HCI_POWERING_DOWN Date: Sun, 7 Jan 2024 19:02:49 +0100 Message-ID: <20240107180252.73436-4-verdre@v0yd.nl> In-Reply-To: <20240107180252.73436-1-verdre@v0yd.nl> References: <20240107180252.73436-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: 1787455798286157621 X-GMAIL-MSGID: 1787455798286157621 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; }