Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp776210pxu; Thu, 3 Dec 2020 12:18:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKWnEpYHyEDbLaMoVnvm49I6BpGSOG8UOjuc0odk16bQWET9f1KJJY/2X9tba+pTGqSYl+ X-Received: by 2002:aa7:d711:: with SMTP id t17mr4367634edq.83.1607026709288; Thu, 03 Dec 2020 12:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607026709; cv=none; d=google.com; s=arc-20160816; b=loA4ikr2gCwz/wixcAN+ZUPB+S4hay1S73oWt/sEdE1G/FftSFFwsQJAHODzROytZ0 BASM0Zp1iHRQUqXFTTgMhfZpNHBAPgKdOPa4m+Ash5zQF4gpgF1zuz67DwNsgREf3/cc 97iV08kV44wzBH+6gBvzO2uItASAIT3OEyUNuWZfYyLeLyQp9iNgGJc4rCPdyb5mZG5U ICNfariov7Ycfi1z4v7IBygIrX6+d/1KbudFn5Gj4LiJ+y3FWDNHQ8J9D7oW1xkhPJ/O bnmqkq7MwmQ/nkE1IZrzs/enjrV8M5xxkdSI0taeRhtAgWLEG44ngw5cJ3g3TWdxzpE7 PVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=LupsF3rdjgovj1oZx0Q4DqgD7ck7/QqBvt1QQWLoyIs=; b=0yksxHJ64ln3DNhYRcb3B6UAIC75bxQ3dRifK+e89wMHAqLgCg5LFlPzjF8OgI2ztN d4MfLwf+25tyCBDhfS0S1Hso20AgD5aiMSnNYUfQYCrxyPGaP+nJ6ym8pzphndK6xeM2 +51I7L0rHAhKREWoV9tyLQO9MDV70d7hdJ9Snh7HxhCsGX3vXS2nFMrQyDeuOpQRWC/5 0CQIOJmncFJ2BZx/x8RO6saPxGxc/Y+L1ChQiWOkD8OzdmOZl8C20odeenYH1B2qA3u6 pY/y6WcmC+3WEjlVclRKOn/FVA63mszGvEf1Ex6Xq2mClJivK3YL4w5iKFs+0VeNp8ZJ SMEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="RALdDC5/"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r27si349701edx.124.2020.12.03.12.18.05; Thu, 03 Dec 2020 12:18:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="RALdDC5/"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731814AbgLCUOl (ORCPT + 99 others); Thu, 3 Dec 2020 15:14:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729078AbgLCUOl (ORCPT ); Thu, 3 Dec 2020 15:14:41 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96426C08E861 for ; Thu, 3 Dec 2020 12:13:14 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w8so4177752ybq.4 for ; Thu, 03 Dec 2020 12:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LupsF3rdjgovj1oZx0Q4DqgD7ck7/QqBvt1QQWLoyIs=; b=RALdDC5/0pCStQeWn5jeiogSSVHJOcB0ccgkb0qEekIEwNi+KX7NFKrGAqF4GcKGGr ZOQgP2W3sbeLSyBLV3j2q5aKj8VH4PoXJvoCsleHfi/KRDpgaL5s630onZzzirix8zUX KPFrD9bJLpM6K7Z5wiQA/9ubUsZQrYDh/SRZYzTva8urUz1uTUGrI7OLejL08tYBwCYi tekYV8K8OrA7vmKVFoR1I0xrZ7RUkFP92lyg9MXXDsTKH5c/rk2LUXVENxmj7Oxt2JGY H4WmfR8DYLeMMrmqiUSod3fCxKRRFCvME9+pifGfq6KQtSUyw3eIGBXJQkSJTCSJIEu3 8Xvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LupsF3rdjgovj1oZx0Q4DqgD7ck7/QqBvt1QQWLoyIs=; b=thHvHyyTxwy6j1YSOFdOOy5nxGERK8RME1v49bBtwwpCPSk+RhwzALrNMm1YZOthAw 7Qo60wcni+ECAZox+xJZV+uoUK20hBMZhE2vvgAStnxH2X860YIpvv7G28jXUNlvV3We ox51ug/LeIOiF5sESZ4eus+UDcqsdW1pFnLFSvtoXJLtOR1zipTq30REfSrEw3WzfRS9 mXFS3Ab1xSYYbpnZuaDuNcjhZuO8dQiDPEM0TiXDjZW8IReKuAZ3fmyP8OUztR/lNbGI HW2e8hVcMz9X6fjmbgMd949jz3lQdJPnYgxM2SHcRkY8becivYEaL4df3OhBk6v4yFvn Lefw== X-Gm-Message-State: AOAM530zMN3gkZy+P7scIub20S+RjtF1C5iT/PWWCvdXN1dVZ2uk8VI/ 1qToZ/81T7+m0YI4TUa5WcgQLXscydP1q8CvLB0Z Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a25:bc91:: with SMTP id e17mr1182376ybk.332.1607026393868; Thu, 03 Dec 2020 12:13:13 -0800 (PST) Date: Thu, 3 Dec 2020 12:12:51 -0800 In-Reply-To: <20201203201252.807616-1-danielwinkler@google.com> Message-Id: <20201203121154.v7.4.Ibedcb7af24f1c01a680de4cc8cc5a98951588393@changeid> Mime-Version: 1.0 References: <20201203201252.807616-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog Subject: [PATCH v7 4/5] Bluetooth: Query LE tx power on startup From: Daniel Winkler To: marcel@holtmann.org Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Queries tx power via HCI_LE_Read_Transmit_Power command when the hci device is initialized, and stores resulting min/max LE power in hdev struct. If command isn't available (< BT5 support), min/max values both default to HCI_TX_POWER_INVALID. This patch is manually verified by ensuring BT5 devices correctly query and receive controller tx power range. Reviewed-by: Sonny Sasaka Signed-off-by: Daniel Winkler --- Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None include/net/bluetooth/hci.h | 7 +++++++ include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 8 ++++++++ net/bluetooth/hci_event.c | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index c8e67042a3b14c..c1504aa3d9cfd5 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1797,6 +1797,13 @@ struct hci_cp_le_set_adv_set_rand_addr { bdaddr_t bdaddr; } __packed; +#define HCI_OP_LE_READ_TRANSMIT_POWER 0x204b +struct hci_rp_le_read_transmit_power { + __u8 status; + __s8 min_le_tx_power; + __s8 max_le_tx_power; +} __packed; + #define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060 struct hci_rp_le_read_buffer_size_v2 { __u8 status; diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 88988d4fd34750..677a8c50b2ad0d 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -384,6 +384,8 @@ struct hci_dev { __u16 def_page_timeout; __u16 def_multi_adv_rotation_duration; __u16 def_le_autoconnect_timeout; + __s8 min_le_tx_power; + __s8 max_le_tx_power; __u16 pkt_type; __u16 esco_type; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 8855d07534ed8b..9d2c9a1c552fd5 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -741,6 +741,12 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) hci_req_add(req, HCI_OP_LE_READ_ADV_TX_POWER, 0, NULL); } + if (hdev->commands[38] & 0x80) { + /* Read LE Min/Max Tx Power*/ + hci_req_add(req, HCI_OP_LE_READ_TRANSMIT_POWER, + 0, NULL); + } + if (hdev->commands[26] & 0x40) { /* Read LE White List Size */ hci_req_add(req, HCI_OP_LE_READ_WHITE_LIST_SIZE, @@ -3660,6 +3666,8 @@ struct hci_dev *hci_alloc_dev(void) hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT; + hdev->min_le_tx_power = HCI_TX_POWER_INVALID; + hdev->max_le_tx_power = HCI_TX_POWER_INVALID; hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index f193e73ef47c14..67668be3461e93 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1202,6 +1202,20 @@ static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, hci_dev_unlock(hdev); } +static void hci_cc_le_read_transmit_power(struct hci_dev *hdev, + struct sk_buff *skb) +{ + struct hci_rp_le_read_transmit_power *rp = (void *)skb->data; + + BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); + + if (rp->status) + return; + + hdev->min_le_tx_power = rp->min_le_tx_power; + hdev->max_le_tx_power = rp->max_le_tx_power; +} + static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb) { __u8 *sent, status = *((__u8 *) skb->data); @@ -3582,6 +3596,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, hci_cc_le_set_adv_set_random_addr(hdev, skb); break; + case HCI_OP_LE_READ_TRANSMIT_POWER: + hci_cc_le_read_transmit_power(hdev, skb); + break; + default: BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); break; -- 2.29.2.576.ga3fc446d84-goog