Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9516952ybl; Fri, 17 Jan 2020 13:29:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxMINHbbtEinksDDDFE8k3TSF27b2Zew1FGrcC997hjTsBSd4OZ5EC6O9ZAmYRSxwj7fOS/ X-Received: by 2002:a9d:1b26:: with SMTP id l35mr7651044otl.307.1579296565618; Fri, 17 Jan 2020 13:29:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579296565; cv=none; d=google.com; s=arc-20160816; b=YeT+WVGe9nKs1SEZC21AWNbu8Vu4bVamXNlUs/Jo3UIDiKvUc7Y4OXJTyo0GmbDi4u yZJCidKXGBHpOie/4BFlefaoWBEnAzgXXTW9Fh0YEaRi+3Nbqk0mWmcm/mwzL56CjqQG nO4rMokwPvgYe2kZ3YUlmDyo/DIAiIyqQkr+hnATmuYnePnQiVED8/mE2lz22zG5ztI7 pF7OcdPaZ2r6Hl6n6vVD1mN1XNmZ9JPll/qCYVfXz3CheDaOB2PlFQaAS88j0Z9NAAGw yhlz4UEkO0UDXFKYtapfF37Q3602Z+GxfYBVkWPZmtMU6krQwIuhl4Rq2efmBD6UvNo9 K8ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dX/yXK6iGHzCms4pl61rtiy1PGwacxrcd9Tk97W7YsY=; b=u6r9Djk/Ha4fsMZJPm8Y0xlZlRhBKu0PbeHOelIvdubVQpghqVSzT7Mlk6eU/FvqI4 cWWQyL/kJK3a092AyQx71oCQcHCFaFb8Fr49BIklx1Ebm0dtPm7dcCwCfWM4K602Rw5e AZjXX4x73afToMmzzyGOzLNXMZEOVXRPgjddTmxRReGC8xZGZw/qrMDc91/n3g8gacp2 Qy/FnppZcF47lK+T2mK+Bz56fMLi0jrE6qj72zheSUy6y5Arx4AvUgNOiTbP8Lak2yNC d0ui6uMTcCgE4o4OSnvhlb2g4K8qRPgSSWQIioIy4HlcJEEY7JMDeOEBLNIOP8P5w3st a3+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Pvg5bZcN; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h14si13986850oie.98.2020.01.17.13.29.14; Fri, 17 Jan 2020 13:29:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Pvg5bZcN; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729393AbgAQV1k (ORCPT + 99 others); Fri, 17 Jan 2020 16:27:40 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35805 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729288AbgAQV1i (ORCPT ); Fri, 17 Jan 2020 16:27:38 -0500 Received: by mail-pl1-f193.google.com with SMTP id g6so10372917plt.2 for ; Fri, 17 Jan 2020 13:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dX/yXK6iGHzCms4pl61rtiy1PGwacxrcd9Tk97W7YsY=; b=Pvg5bZcNdzM5pAw6eZyeKd+iwD+/Wc8Ds4gXDLa8Ait4HAK+v3N6lyvrZIOKc+cA/j OjWx4Q8wrkjDxMo0vwYwjZzlAUuLfKxrSG7T8z75QJ8vU/EXBTUuPSL1gSxr5mLV49hj HCDANuBi9waZGp7+doBXa6E0NNzP3iRSLfNps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dX/yXK6iGHzCms4pl61rtiy1PGwacxrcd9Tk97W7YsY=; b=jNmoZpyPYkVJWHCDzat4V01CoA1QKB2HXpmvEhqPOnH5Bg6NmD4xtNxYLtMQuAaL0b jyl68scFL9sdGmrt+NxcPMOli4IoTpDzLYMmXZJ3FHRBr0XJoa00EEUrxSfXJxtSunRb Ozpomrl/ZwcicgpI90B2U6HAM426WurOEMggOBdyZFP/qhAL33oOaZFYmQomHZ4Bak8f Q8fKYqsnzCFI6S1oEwXmUEKRav1ILF/vJyt0Z+MzTij79fnGYp3cgUvGqLxzzLudVifp hZL8bVHUorLoSSOC9Qbar9U7JGsAphxKe+g1SxRy80W+wHGKHTF89tITfHkrEKO+0IA7 8itw== X-Gm-Message-State: APjAAAVvcgBqJoiwl3FqMo3TB51isx6g0OIKUkI5RwzAsaEW8I7SrwpB GCkS+hcmVt6/cvd9bKf1/Tb/rg== X-Received: by 2002:a17:90b:258:: with SMTP id fz24mr7917727pjb.6.1579296457428; Fri, 17 Jan 2020 13:27:37 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id k5sm6999655pju.29.2020.01.17.13.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 13:27:37 -0800 (PST) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, luiz.dentz@gmail.com, alainm@chromium.org Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Abhishek Pandit-Subedi , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] Bluetooth: Add mgmt op set_wake_capable Date: Fri, 17 Jan 2020 13:27:04 -0800 Message-Id: <20200117132623.RFC.1.I797e2f4cb824299043e771f3ab9cef86ee09f4db@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200117212705.57436-1-abhishekpandit@chromium.org> References: <20200117212705.57436-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When the system is suspended, only some connected Bluetooth devices cause user input that should wake the system (mostly HID devices). Add a list to keep track of devices that can wake the system and add a management API to let userspace tell the kernel whether a device is wake capable or not. Signed-off-by: Abhishek Pandit-Subedi --- include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 7 ++++++ net/bluetooth/hci_core.c | 1 + net/bluetooth/mgmt.c | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 89ecf0a80aa1..ce4bebcb0265 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -394,6 +394,7 @@ struct hci_dev { struct list_head mgmt_pending; struct list_head blacklist; struct list_head whitelist; + struct list_head wakeable; struct list_head uuids; struct list_head link_keys; struct list_head long_term_keys; diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index a90666af05bd..283ba5320bdb 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -671,6 +671,13 @@ struct mgmt_cp_set_blocked_keys { } __packed; #define MGMT_OP_SET_BLOCKED_KEYS_SIZE 2 +#define MGMT_OP_SET_WAKE_CAPABLE 0x0047 +#define MGMT_SET_WAKE_CAPABLE_SIZE 8 +struct mgmt_cp_set_wake_capable { + struct mgmt_addr_info addr; + u8 wake_capable; +} __packed; + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 1ca7508b6ca7..7057b9b65173 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3299,6 +3299,7 @@ struct hci_dev *hci_alloc_dev(void) INIT_LIST_HEAD(&hdev->mgmt_pending); INIT_LIST_HEAD(&hdev->blacklist); INIT_LIST_HEAD(&hdev->whitelist); + INIT_LIST_HEAD(&hdev->wakeable); INIT_LIST_HEAD(&hdev->uuids); INIT_LIST_HEAD(&hdev->link_keys); INIT_LIST_HEAD(&hdev->long_term_keys); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 0dc610faab70..95092130f16c 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -106,7 +106,10 @@ static const u16 mgmt_commands[] = { MGMT_OP_START_LIMITED_DISCOVERY, MGMT_OP_READ_EXT_INFO, MGMT_OP_SET_APPEARANCE, + MGMT_OP_GET_PHY_CONFIGURATION, + MGMT_OP_SET_PHY_CONFIGURATION, MGMT_OP_SET_BLOCKED_KEYS, + MGMT_OP_SET_WAKE_CAPABLE, }; static const u16 mgmt_events[] = { @@ -4663,6 +4666,37 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, return err; } +static int set_wake_capable(struct sock *sk, struct hci_dev *hdev, void *data, + u16 len) +{ + int err; + u8 status; + struct mgmt_cp_set_wake_capable *cp = data; + u8 addr_type = cp->addr.type == BDADDR_BREDR ? + cp->addr.type : + le_addr_type(cp->addr.type); + + BT_DBG("Set wake capable %pMR (type 0x%x) = 0x%x\n", &cp->addr.bdaddr, + addr_type, cp->wake_capable); + + if (cp->wake_capable) + err = hci_bdaddr_list_add(&hdev->wakeable, &cp->addr.bdaddr, + addr_type); + else + err = hci_bdaddr_list_del(&hdev->wakeable, &cp->addr.bdaddr, + addr_type); + + if (!err || err == -EEXIST || err == -ENOENT) + status = MGMT_STATUS_SUCCESS; + else + status = MGMT_STATUS_FAILED; + + err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_WAKE_CAPABLE, status, + cp, sizeof(*cp)); + + return err; +} + static void set_bredr_complete(struct hci_dev *hdev, u8 status, u16 opcode) { struct mgmt_pending_cmd *cmd; @@ -5791,6 +5825,13 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, err = hci_bdaddr_list_del(&hdev->whitelist, &cp->addr.bdaddr, cp->addr.type); + + /* Don't check result since it either succeeds or device + * wasn't there (not wakeable or invalid params as + * covered by deleting from whitelist). + */ + hci_bdaddr_list_del(&hdev->wakeable, &cp->addr.bdaddr, + cp->addr.type); if (err) { err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, @@ -6990,6 +7031,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { set_phy_configuration, MGMT_SET_PHY_CONFIGURATION_SIZE }, { set_blocked_keys, MGMT_OP_SET_BLOCKED_KEYS_SIZE, HCI_MGMT_VAR_LEN }, + { set_wake_capable, MGMT_SET_WAKE_CAPABLE_SIZE }, }; void mgmt_index_added(struct hci_dev *hdev) -- 2.25.0.341.g760bfbb309-goog