Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1831940ybh; Sun, 8 Mar 2020 14:24:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsgg2eDjTu2XSBbCexHWlUZgWEbBkmwaJoalFUuH+CFHalS/aolN19SZUXo5fZ/62R8OyVB X-Received: by 2002:a9d:7d91:: with SMTP id j17mr11030564otn.218.1583702677902; Sun, 08 Mar 2020 14:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583702677; cv=none; d=google.com; s=arc-20160816; b=iF5jPoUU/i9BxzgGxAYtFaV5TEDaIDX3fe0Yguo4K2AeIB7qLF5bBEcUQf9iEWmyVM 2lp4D5azS8/ZJPqr/5ydrQw4X3E1PyMpmjL9pkuiFs7IvAsgZWIhNhg0XW8k5m+/stsj JcxO08hZgb6q48RtR6BxM1B+EF858LCLmSlqHlm1v3f3jHJhk9+t1ihrT9A4nKiLOB40 FxN9YeHRC3Q6xPLVvOk6gyqnAPmqSGj4eqhrK6zppAtQrm7EiXsoy6A7Sf2Q/eJtV/wy 0s88SQCqkq+MX685PNaBKZ7QmyaXUvjhlR36FjvDV+nO5XmuLDmJUtClDywXWv6Y66PC c8yw== 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=7IXTL5Wmi6zHebO7YXtizBnQaWklYcKumiFOEII320M=; b=xp0EUrAMiDEiJr310c2znfeD1HdZIRmPxUpLD0z4SfZnIfMFKl4tWJXFBUnI89qDX5 kqRf9323ZNXTHePw8v9c90SxybkYmMim0MDVUfTvVstBqq0zJXs7sPzjsEg6h1ToKWca ZRH0Eug9TDyFm31lG4cAPKKNQ0izD/4azpeDCrvzOEsfrceoArMeO9fa3RFT8AVCzZzn 1ojRIEIx38pVT6m/J4Y3fJUL9F6QdypR3bTWVQa0aPjBY280QC7HnWWdLOqy/qqrQun3 MPnJSSfO5DGOVs1D/gG4/ktQLGaS3XHLC/kxTTUidnqhxh9AFDcA31EFv5xOzgIYKwV3 m4QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UjEYkTs2; 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 z14si3223167otq.257.2020.03.08.14.24.19; Sun, 08 Mar 2020 14:24:37 -0700 (PDT) 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=UjEYkTs2; 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 S1726446AbgCHVX7 (ORCPT + 99 others); Sun, 8 Mar 2020 17:23:59 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42016 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbgCHVX6 (ORCPT ); Sun, 8 Mar 2020 17:23:58 -0400 Received: by mail-pg1-f193.google.com with SMTP id h8so3772552pgs.9 for ; Sun, 08 Mar 2020 14:23:56 -0700 (PDT) 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=7IXTL5Wmi6zHebO7YXtizBnQaWklYcKumiFOEII320M=; b=UjEYkTs2VZPBh87df/QUiPqkfDdGEiR8zd3UNoXzVKKcpNfosjh/+mFo+DHY7z9/Xd qPoikHqOyJPT33cpN5LlT6aWcPKzaXOvM7CAF3EQ5qP0HdSRHjPhLgyRNDNTV3vwETSW s8jAOyr+6oAcObpxUnQM7yt+BSyEIPEkwFhss= 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=7IXTL5Wmi6zHebO7YXtizBnQaWklYcKumiFOEII320M=; b=bcFcsgoIhbq4rTWo12jimlUukx+/kchk6KrJVUL3Uy+7enjsgur38vq5SCZIY8yDU/ ttj1gIzlijPNbA9OjzINP5ZjOGUuL1Wde8zkYB76Kzv8a9ERkhlcXp+5/19gGLtCInmx Q6K2PkyPiFbjDTx2/lSKFvujguaifc0X1TRfRnQzqvFXT6mLm/OCA8Q3fdWprpJ+NHT4 sBZxRAIf2WBuHIMEP73PJ7/izhCeq/ZUk48qIpmfxGxfViOx1BTvwsmQR4Tdo2BZnZO+ jLvXXF61z/fgUOAYoLW1W6Lx6u6zOQQLUn9vVuJiCFmxf9UKfuze6TTBZvkBTI4XXiRp aHVQ== X-Gm-Message-State: ANhLgQ2DURsibvsCYX7sXdThTSeR5q1tVW0hw3QGqlQp9Xy067+NFMDc ccDFrPsPcFuWAX2BanNRWQ2UKQ== X-Received: by 2002:a63:7311:: with SMTP id o17mr13071410pgc.377.1583702636376; Sun, 08 Mar 2020 14:23:56 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id k1sm39509228pgt.70.2020.03.08.14.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2020 14:23:55 -0700 (PDT) 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 v5 5/5] Bluetooth: Add mgmt op set_wake_capable Date: Sun, 8 Mar 2020 14:23:34 -0700 Message-Id: <20200308142005.RFC.v5.5.I797e2f4cb824299043e771f3ab9cef86ee09f4db@changeid> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200308212334.213841-1-abhishekpandit@chromium.org> References: <20200308212334.213841-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. 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 v5: * Wakeable entries moved to other commits * Patch moved to end of series Changes in v4: None Changes in v3: * Added wakeable property to le_conn_param * Use wakeable list for BR/EDR and wakeable property for LE Changes in v2: None include/net/bluetooth/mgmt.h | 7 +++++ net/bluetooth/mgmt.c | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index f41cd87550dc..17bbdcbeb67e 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -674,6 +674,13 @@ struct mgmt_cp_set_blocked_keys { #define MGMT_OP_SET_WIDEBAND_SPEECH 0x0047 +#define MGMT_OP_SET_WAKE_CAPABLE 0x0048 +#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/mgmt.c b/net/bluetooth/mgmt.c index 047aea280c84..ab9685e87b84 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -108,6 +108,7 @@ static const u16 mgmt_commands[] = { MGMT_OP_SET_APPEARANCE, MGMT_OP_SET_BLOCKED_KEYS, MGMT_OP_SET_WIDEBAND_SPEECH, + MGMT_OP_SET_WAKE_CAPABLE, }; static const u16 mgmt_events[] = { @@ -4768,6 +4769,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_dev_dbg(hdev, "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; @@ -5896,6 +5939,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, @@ -7096,6 +7146,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { set_blocked_keys, MGMT_OP_SET_BLOCKED_KEYS_SIZE, HCI_MGMT_VAR_LEN }, { set_wideband_speech, MGMT_SETTING_SIZE }, + { set_wake_capable, MGMT_SET_WAKE_CAPABLE_SIZE }, }; void mgmt_index_added(struct hci_dev *hdev) -- 2.25.1.481.gfbce0eb801-goog