Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3428670ybb; Mon, 23 Mar 2020 00:29:43 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuZAGhKNqlviSqt03bfeKbWd+QfYpVcEMRE4wxetLrXJ1xX43+udybvs0G88hJ+eRun65qu X-Received: by 2002:aca:4243:: with SMTP id p64mr16200921oia.21.1584948583664; Mon, 23 Mar 2020 00:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584948583; cv=none; d=google.com; s=arc-20160816; b=WBwN564TsM9V2J/4y7N5vlLTTVfugicOR+Q1m8ZZlsQ8mOQ+3jzSFf6rJxGaCykpDO 1FaL3nMICUqxL+eJ5gsuUlevfFM8wZb0tT/3IB7Y219FUJwWbc3qcgy2vHMXp6TtHCrZ RvO2b9XS1Zgn5JlkT1/MFt3OlP0XH+BNVCv1XSeXcYqMzJwTct/BMcXk+vLYxKaROb8g mXUokpxho78sPoIWuRuiwASaAIejqsj/RWLrv7u7qNthXpvhU22ppVw3dhEnQuA9gem1 NZxugNuwT6Mj4TlQwXAbIv6Ei+YahlqKcI8W64OtHngkE4baH7jp9MkKFtJiM3Eq4dPB Mlog== 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=peUcUJiWwH+jNWHv1XJjZ5RdsEPMfqXUmHLM2UZ+oGY=; b=QFVB8eMXOnf39uxcjyTSHj/p+XSkeuDQp64ahESF4Q3nclaEeXVXYlAx0ZljtBD78I 3/0GVxgbZwjB2dRbjiKLdUuV54SxYK70cUkpVisi3zL7l0r+kb6W0470M9dEklpeSNli rDz9MB1V/7xpn97p1ISs22hIG25Z8W05TE4SuUyGqOcrN/iabB0MrXyNYK38BJG94vF6 g/qF4ipV/4nghNB6JXMfQ1NttnKJa96oJQ+LYqligJBt+zRDZmZzFHkCnWFgD9I3hPPG dxWjqZd4c8TOoHU88QL0irUl3nhk11WstYsPZLPvFxcFh0mVub33LSSFozYZ8s6mr0Ie Vxpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gLnDgnE5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 w11si6968215oib.235.2020.03.23.00.29.31; Mon, 23 Mar 2020 00:29:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=gLnDgnE5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727480AbgCWH2l (ORCPT + 99 others); Mon, 23 Mar 2020 03:28:41 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:54572 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727468AbgCWH2j (ORCPT ); Mon, 23 Mar 2020 03:28:39 -0400 Received: by mail-pj1-f66.google.com with SMTP id np9so5763778pjb.4 for ; Mon, 23 Mar 2020 00:28:38 -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=peUcUJiWwH+jNWHv1XJjZ5RdsEPMfqXUmHLM2UZ+oGY=; b=gLnDgnE5axXZulHjrMwIKcMzI2z0jYs+ovG+RkBPPaHMnfDz8hyi3Ug3TYUXvOf2sk Jjxp3JN+gfykwgJp2859+PEUvlNywm/0Enznrra+RS20S2Ds08PykqxaT+Dv7sHcKIbU EHNelb/RxLV9ouR3oKbMbll6l1lkRM4G6M9SY= 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=peUcUJiWwH+jNWHv1XJjZ5RdsEPMfqXUmHLM2UZ+oGY=; b=e9jNc770lL70Xr/HC8ZsH2EQGSn5jjIvkhZoKaZpREqzjheNqqsJ0OSzJrLgIWsA9s RRDGXGZojGEV/UpaF2x7QhcqNMJ4ll3bxjgNDIozVnaYUZnsxFkNhr0MA/I49R2xS03l c/m9lu5Tin/o4kIrdJJ640om0QLcrT35/7WbahzGg7F9ByhrC1J6gzhupOffyjAKr+wo /XvYpqjNiYSWTMu26sZStYEJa6whba07WDIXtt4bAn86W6X9JnC2tBuU5Ek6bkPVWcwW Zqd6ZHwgZpTLUE9gfTFr4yWD2qyn2gOopxg94xOe82ozGXkKC/8PQZcSN9A7qcr+hIxC Gm5w== X-Gm-Message-State: ANhLgQ006aVvH3j5yR9qZRdDB8uALL5Fqrs+B0JLWSEyjaZ6+6KCA65P Ks6Bty6ed9b7PVMstIMgPmlsQw== X-Received: by 2002:a17:902:a588:: with SMTP id az8mr20125265plb.163.1584948518415; Mon, 23 Mar 2020 00:28:38 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:b46:ac84:1014:9555]) by smtp.gmail.com with ESMTPSA id z16sm12645399pfr.138.2020.03.23.00.28.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2020 00:28:37 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Luiz Augusto von Dentz , Marcel Holtmann , Alain Michaud , Miao-chen Chou , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 2/2] Bluetooth: btusb: Read the supported features of Microsoft vendor extension Date: Mon, 23 Mar 2020 00:28:24 -0700 Message-Id: <20200323002820.v1.2.I4e01733fa5b818028dc9188ca91438fc54aa5028@changeid> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323072824.254495-1-mcchou@chromium.org> References: <20200323072824.254495-1-mcchou@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a new header to facilitate the opcode and packet structures of vendor extension(s). For now, we add only the HCI_VS_MSFT_Read_Supported_Features command from Microsoft vendor extension. See https://docs.microsoft.com/en-us/windows-hardware/drivers/ bluetooth/microsoft-defined-bluetooth-hci-commands-and-events# microsoft-defined-bluetooth-hci-events for more details. Upon initialization of a hci_dev, we issue a HCI_VS_MSFT_Read_Supported_Features command to read the supported features of Microsoft vendor extension if the opcode of Microsoft vendor extension is valid. See https://docs.microsoft.com/en-us/windows-hardware/drivers/ bluetooth/microsoft-defined-bluetooth-hci-commands-and-events# hci_vs_msft_read_supported_features for more details. This was verified on a device with Intel ThhunderPeak BT controller where the Microsoft vendor extension features are 0x000000000000003f. Signed-off-by: Miao-chen Chou --- Changes in v1: - Add vendor_hci.h to facilitate opcodes and packet structures of vendor extension(s). - Add opcode for the HCI_VS_MSFT_Read_Supported_Features command from Microsoft vendor extension. - Issue a HCI_VS_MSFT_Read_Supported_Features command upon hci_dev_do_open and save the return values. include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/vendor_hci.h | 51 ++++++++++++++++++++++++++++++ net/bluetooth/hci_core.c | 30 ++++++++++++++++++ net/bluetooth/hci_event.c | 49 +++++++++++++++++++++++++++- 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 include/net/bluetooth/vendor_hci.h diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 15daf3b2d4f0..941e71bdad42 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -30,6 +30,7 @@ #include #include +#include /* HCI priority */ #define HCI_PRIO_MAX 7 diff --git a/include/net/bluetooth/vendor_hci.h b/include/net/bluetooth/vendor_hci.h new file mode 100644 index 000000000000..bd374a7bf976 --- /dev/null +++ b/include/net/bluetooth/vendor_hci.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * BlueZ - Bluetooth protocol stack for Linux + * Copyright (C) 2020 Google Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. + */ + +#ifndef __VENDOR_HCI_H +#define __VENDOR_HCI_H + +#define MSFT_EVT_PREFIX_MAX_LEN 255 + +struct msft_cmd_cmp_info { + __u8 status; + __u8 sub_opcode; +} __packed; + +/* Microsoft Vendor HCI subcommands */ +#define MSFT_OP_READ_SUPPORTED_FEATURES 0x00 +#define MSFT_FEATURE_MASK_RSSI_MONITOR_BREDR_CONN 0x0000000000000001 +#define MSFT_FEATURE_MASK_RSSI_MONITOR_LE_CONN 0x0000000000000002 +#define MSFT_FEATURE_MASK_RSSI_MONITOR_LE_ADV 0x0000000000000004 +#define MSFT_FEATURE_MASK_ADV_MONITOR_LE_ADV 0x0000000000000008 +#define MSFT_FEATURE_MASK_VERIFY_CURVE_ 0x0000000000000010 +#define MSFT_FEATURE_MASK_CONCURRENT_ADV_MONITOR 0x0000000000000020 +struct msft_cp_read_supported_features { + __u8 sub_opcode; +} __packed; +struct msft_rp_read_supported_features { + __u64 features; + __u8 msft_evt_prefix_len; + __u8 msft_evt_prefix[0]; +} __packed; + +#endif /* __VENDOR_HCI_H */ diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbd2ad3a26ed..3cec58ca0047 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1407,6 +1407,32 @@ static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) bacpy(&hdev->public_addr, &ba); } +static int hci_msft_read_supported_features_req(struct hci_request *req, + unsigned long opt) +{ + struct hci_dev *hdev = req->hdev; + struct msft_cp_read_supported_features cp; + + if (hdev->msft_vnd_ext_opcode == HCI_OP_NOP) + return -EOPNOTSUPP; + + cp.sub_opcode = MSFT_OP_READ_SUPPORTED_FEATURES; + hci_req_add(req, hdev->msft_vnd_ext_opcode, sizeof(cp), &cp); + return 0; +} + +static void read_vendor_extension_features(struct hci_dev *hdev) +{ + int err; + + if (hdev->msft_vnd_ext_opcode != HCI_OP_NOP) { + err = __hci_req_sync(hdev, hci_msft_read_supported_features_req, + 0, HCI_CMD_TIMEOUT, NULL); + if (err) + BT_ERR("HCI_VS_MSFT_Read_Supported_Feature failed"); + } +} + static int hci_dev_do_open(struct hci_dev *hdev) { int ret = 0; @@ -1572,6 +1598,10 @@ static int hci_dev_do_open(struct hci_dev *hdev) set_bit(HCI_UP, &hdev->flags); hci_sock_dev_event(hdev, HCI_DEV_UP); hci_leds_update_powered(hdev, true); + + /* Check features supported by HCI extensions. */ + read_vendor_extension_features(hdev); + if (!hci_dev_test_flag(hdev, HCI_SETUP) && !hci_dev_test_flag(hdev, HCI_CONFIG) && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 20408d386268..6a156167dfc9 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -23,7 +23,6 @@ */ /* Bluetooth HCI event handling. */ - #include #include @@ -1787,6 +1786,47 @@ static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *sk hdev->ssp_debug_mode = *mode; } +static void hci_cc_msft_vnd_ext(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct msft_cmd_cmp_info *info = (void *)skb->data; + const u8 status = info->status; + const u16 sub_opcode = __le16_to_cpu(info->sub_opcode); + + skb_pull(skb, sizeof(*info)); + + if (status) { + BT_ERR("Microsoft vendor extension sub command 0x%2.2x failed", + sub_opcode); + return; + } + + BT_DBG("%s status 0x%2.2x sub opcode 0x%2.2x", hdev->name, status, + sub_opcode); + + switch (sub_opcode) { + case MSFT_OP_READ_SUPPORTED_FEATURES: { + struct msft_rp_read_supported_features *rp = (void *)skb->data; + + hdev->msft_vnd_ext_features = __le64_to_cpu(rp->features); + hdev->msft_vnd_ext_evt_prefix_len = rp->msft_evt_prefix_len; + hdev->msft_vnd_ext_evt_prefix = + kmalloc(hdev->msft_vnd_ext_evt_prefix_len, GFP_ATOMIC); + if (!hdev->msft_vnd_ext_evt_prefix) + return; + + memcpy(hdev->msft_vnd_ext_evt_prefix, rp->msft_evt_prefix, + hdev->msft_vnd_ext_evt_prefix_len); + BT_DBG("%s Microsoft vendor extension features 0x%016llx", + hdev->name, hdev->msft_vnd_ext_features); + break; + } + default: + BT_ERR("%s unknown sub opcode 0x%2.2x", hdev->name, + sub_opcode); + break; + } +} + static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) { BT_DBG("%s status 0x%2.2x", hdev->name, status); @@ -3198,6 +3238,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, hci_req_complete_skb_t *req_complete_skb) { struct hci_ev_cmd_complete *ev = (void *) skb->data; + const u16 msft_vnd_ext_opcode = hdev->msft_vnd_ext_opcode; *opcode = __le16_to_cpu(ev->opcode); *status = skb->data[sizeof(*ev)]; @@ -3538,6 +3579,12 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, break; default: + /* Check if it's a Microsoft vendor extension opcode. */ + if (msft_vnd_ext_opcode != HCI_OP_NOP && + *opcode == msft_vnd_ext_opcode) { + hci_cc_msft_vnd_ext(hdev, skb); + break; + } BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); break; } -- 2.24.1