From patchwork Tue Feb 25 00:00:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 11402195 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F2F4138D for ; Tue, 25 Feb 2020 00:01:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5549F22464 for ; Tue, 25 Feb 2020 00:01:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="F4gi54FJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728606AbgBYAAw (ORCPT ); Mon, 24 Feb 2020 19:00:52 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46465 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728541AbgBYAAu (ORCPT ); Mon, 24 Feb 2020 19:00:50 -0500 Received: by mail-pg1-f195.google.com with SMTP id y30so5931194pga.13 for ; Mon, 24 Feb 2020 16:00:48 -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=kaVCPPxHc40mrNYqH9lQEfFX5d6zeck8hgx/mYih64U=; b=F4gi54FJx9W9NsOhzfC3tDJp8NovGcNme3kdY86iOVd0jmRr5bUz6q8q2KFLCYAUXa fYMjwjUUjLGhSRlWgC8U2MuGfaVRzgmTuMIiI+q7hPNYs/ZsVMSbOWcZ1vzX7a4pFHCr TztLLVUtF96YYdh393AmwGBlUmY53EPTBC/kE= 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=kaVCPPxHc40mrNYqH9lQEfFX5d6zeck8hgx/mYih64U=; b=aDY94Y68X9IdZpvTrVFn0n6EwER8AXlpBlsp4msanIJChtqIxou8s7loU9Nl7h8m00 xYf8lb6pkzdhGglTWye40ZY/ijcADaNm++LFqA3VLrBmDgIYqtb/8NYc8I01Wuar0hHO 8VuFjQo5a98QcLr3H0saBn6j6KwgH1CUBceMYsCoa1hHm+zRlYCt+JU/D0hzUu5a8VL1 e/TeWVaZ8RS4B6a/lr88qeSiR6pPKWpAvJSqlAn/CiZGNUbUT23HScDjQpLwDTbyYNWs 9hgfFBW68qosI6I2H7rFkwxO9XKoJCRvTgTapC4HAHnCVOmH+CZWa4ny1Di/GHqw+a/9 hWwg== X-Gm-Message-State: APjAAAXIG/GIriNdvrcuqv/v5wWHn/NJ8pYZnClhyLoOQ9nK0WmeQJ0X SmWj8HovyOrlzGt+6//Lg+KrMg== X-Google-Smtp-Source: APXvYqzxgWUbf63leJRRwe95Viu2F5jUfEK3x9nWPu9XeJJ7mD+wcYOoFw+Mysx/CdLf8Mf8lWVBog== X-Received: by 2002:a63:d94d:: with SMTP id e13mr54065336pgj.240.1582588848141; Mon, 24 Feb 2020 16:00:48 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id c188sm14477657pfb.151.2020.02.24.16.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 16:00:47 -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, Jakub Kicinski Subject: [RFC PATCH v3 1/5] Bluetooth: Add mgmt op set_wake_capable Date: Mon, 24 Feb 2020 16:00:32 -0800 Message-Id: <20200224160019.RFC.v3.1.I797e2f4cb824299043e771f3ab9cef86ee09f4db@changeid> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200225000036.156250-1-abhishekpandit@chromium.org> References: <20200225000036.156250-1-abhishekpandit@chromium.org> MIME-Version: 1.0 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. For LE devices, the wakeable property is added to the connection parameter and can only be modified after calling add_device. Signed-off-by: Abhishek Pandit-Subedi --- Changes in v3: None Changes in v2: None include/net/bluetooth/hci_core.h | 2 ++ include/net/bluetooth/mgmt.h | 7 +++++ net/bluetooth/hci_core.c | 1 + net/bluetooth/mgmt.c | 51 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index dcc0dc6e2624..9d9ada5bc9d4 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; @@ -575,6 +576,7 @@ struct hci_conn_params { struct hci_conn *conn; bool explicit_connect; + bool wakeable; }; extern struct list_head hci_dev_list; 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 cbbc34a006d1..2fceaf76644a 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 3074363c68df..9a873097000b 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -107,6 +107,7 @@ static const u16 mgmt_commands[] = { MGMT_OP_READ_EXT_INFO, MGMT_OP_SET_APPEARANCE, MGMT_OP_SET_BLOCKED_KEYS, + MGMT_OP_SET_WAKE_CAPABLE, }; static const u16 mgmt_events[] = { @@ -4663,6 +4664,48 @@ 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) +{ + struct mgmt_cp_set_wake_capable *cp = data; + struct hci_conn_params *params; + int err; + u8 status = MGMT_STATUS_FAILED; + 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->addr.type == BDADDR_BREDR) { + 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; + + goto done; + } + + /* Add wakeable param to le connection parameters */ + params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); + if (params) { + params->wakeable = cp->wake_capable; + status = MGMT_STATUS_SUCCESS; + } + +done: + 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 +5834,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 +7040,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)