Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp729843pxk; Thu, 24 Sep 2020 17:42:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvg2KTx5Bxk6qo6ZjFm7HO57gsjzOi7OOBNaR/F8jYqRNTnfUoUgwBA1h8XPzyz4ecq48E X-Received: by 2002:a17:906:f150:: with SMTP id gw16mr251641ejb.528.1600994565452; Thu, 24 Sep 2020 17:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600994565; cv=none; d=google.com; s=arc-20160816; b=X75B5aK8+0sZq0JHf2yHKHOCcJpBSoBWHX7P+rovvLEjh5iUGtA9INr+kzi8DgllcP GI37M4OABPhx9u0gt3+Q0yq/m2nW4bGz2yjXDUoNgyJb0HwkjAedmYxh92JI5Y5BGH00 LcyG7lx1g7xi4xAQ8KsA9Ohbbu/1D3Y1NbzHPFCDP7DHaGkMd2PJJuGP/+97PHmdYGTM KebAvn+z+ysTOGxQnN2+gm5+9qOgGNQMpu/lUnNui99XBN2jhn1H0ucXgwIpqnVqg7Su grPh3+p+rUT+AZWnWd553EPTpn+k5Ek58uW565hc8721a7hO1Le6PsOw8urR1gMxfpig l0Hw== 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=tBY3Ix9d0bZ6yJodesZtGMd1wuLGTKSUpwbupAMO6qI=; b=MKk6QAA3UOlYUJx7Iu3Ux71b3hrg5y3q2vLGOADvhk1xMCE3rgLhy7YUpYB5M9Rctm vRz3ISEV1TxXUXnpBrl8qgb3ydAZhPgQvFqPUJ+yCOzX9jSzTrQtw2Pc4HTvoYk7H6DW lEpptYGXhl44yjORqYMSjeDt0Xr5nPxfLgIfB80OXHxFRNug+LZmFnhJ+XK8r7kZejWc ZNfGz2BJ6q8bVcno8BZdxOc5PX1XpVMV+pSsNg2MZKAG8P8RCgzXCvxlUPVBuH1ERVV+ kk0n0B5+6HkgeYQ7Jai5Six3vvu+xeaKNGdpEHJboh+JP6xY1OUIMnuuLX4jjIA2Aom2 F3pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=o9s0lmUG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 z12si832250eju.152.2020.09.24.17.42.22; Thu, 24 Sep 2020 17:42:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=o9s0lmUG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726980AbgIYAkj (ORCPT + 99 others); Thu, 24 Sep 2020 20:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgIYAk2 (ORCPT ); Thu, 24 Sep 2020 20:40:28 -0400 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 E8FF1C0613D7 for ; Thu, 24 Sep 2020 17:40:27 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e2so1021310ybc.17 for ; Thu, 24 Sep 2020 17:40:27 -0700 (PDT) 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=tBY3Ix9d0bZ6yJodesZtGMd1wuLGTKSUpwbupAMO6qI=; b=o9s0lmUGZh7rS8TA9vSIikZI74mDgu9c0zI0gRqtwoQy206ulW955+SxC3PL2ONd14 G+F9aB0ZEZqOJh+lC5Z7ndWcpum0EWZvj4WJZ8BHY7tlTb1tu+HjLIaHCF7hdheDditM QihYcCjMMGFG3Q+Gx8CIZWUNWSqi3/WfzBAWO8y1aJI9L1UGngkqGyzGiEMMi33C3ec/ 4r8LcID4dau3SysUEx7KxFc+BsovWi8Hf9m3MHfUHemab0PMaqugyifG5rBnHdwN2it6 tW2+6mnWD/FaVPq3RAoY7bqn6oI+Z6cQMfY1irCx9PxBnYZjAl1/4obOvY054CcrJo3Z 00Fg== 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=tBY3Ix9d0bZ6yJodesZtGMd1wuLGTKSUpwbupAMO6qI=; b=C4DatlcIOE5gDg78KZUrmVu1fsKrFlODwNqiwvnYGLl74wUoLCamtx3cAh7CTY/qt+ 3WfB3xQUEoW0DwR/MWPsFH0U9ObkRoPwfExG/zjUIuKytNNJ4Qk8hpFjXaRGwnpBxurE NzY6wSoDpt92vu5wg3XxckzkSQKqHjhM6SmN5VUpGgRG78Yx9BQcgwTd9cE7hG4bgxIQ jqImZCgWcfHeeUPXFOs2Ku4wIzCLbaK1vQLEHAF6C+DIMHcuqY11oPMdVwddIPyquje9 Y+z/CjtM5rljlaVx210gcYyhuMVPWiUPr7m03plw3so5kafd+nzLDeTqrZ1efBuQr9X4 0APQ== X-Gm-Message-State: AOAM530hcjwklm6xem/0FoAultJH7RKL1G1G+NKPEgMksMF3emmER9qk nSqZEGw3r9OS4XmFTrpRFq/euN9jHnTo5Kl0JvVQ 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:2a55:: with SMTP id q82mr2184982ybq.160.1600994427100; Thu, 24 Sep 2020 17:40:27 -0700 (PDT) Date: Thu, 24 Sep 2020 17:40:05 -0700 In-Reply-To: <20200925004007.2378410-1-danielwinkler@google.com> Message-Id: <20200924173752.v3.3.I74255537fa99ed3c0025321008b361c6ad90a431@changeid> Mime-Version: 1.0 References: <20200925004007.2378410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v3 3/5] Bluetooth: Use intervals and tx power from mgmt cmds From: Daniel Winkler To: marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.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-kernel@vger.kernel.org This patch takes the min/max intervals and tx power optionally provided in mgmt interface, stores them in the advertisement struct, and uses them when configuring the hci requests. While tx power is not used if extended advertising is unavailable, software rotation will use the min and max advertising intervals specified by the client. This change is validated manually by ensuring the min/max intervals are propagated to the controller on both hatch (extended advertising) and kukui (no extended advertising) chromebooks, and that tx power is propagated correctly on hatch. These tests are performed with multiple advertisements simultaneously. Reviewed-by: Sonny Sasaka Signed-off-by: Daniel Winkler --- Changes in v3: None Changes in v2: None include/net/bluetooth/hci_core.h | 5 ++++- net/bluetooth/hci_core.c | 8 +++++--- net/bluetooth/hci_request.c | 29 +++++++++++++++++++---------- net/bluetooth/mgmt.c | 8 ++++++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 48d144ae8b57d6..ab168f46b6d909 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -230,6 +230,8 @@ struct adv_info { __u16 scan_rsp_len; __u8 scan_rsp_data[HCI_MAX_AD_LENGTH]; __s8 tx_power; + __u32 min_interval; + __u32 max_interval; bdaddr_t random_addr; bool rpa_expired; struct delayed_work rpa_expired_cb; @@ -1292,7 +1294,8 @@ struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance); int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, u16 adv_data_len, u8 *adv_data, u16 scan_rsp_len, u8 *scan_rsp_data, - u16 timeout, u16 duration); + u16 timeout, u16 duration, s8 tx_power, + u32 min_interval, u32 max_interval); int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, u16 adv_data_len, u8 *adv_data, u16 scan_rsp_len, u8 *scan_rsp_data); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 3f73f147826409..3a2332f4a9bba2 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2951,7 +2951,8 @@ static void adv_instance_rpa_expired(struct work_struct *work) int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, u16 adv_data_len, u8 *adv_data, u16 scan_rsp_len, u8 *scan_rsp_data, - u16 timeout, u16 duration) + u16 timeout, u16 duration, s8 tx_power, + u32 min_interval, u32 max_interval) { struct adv_info *adv_instance; @@ -2979,6 +2980,9 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, adv_instance->flags = flags; adv_instance->adv_data_len = adv_data_len; adv_instance->scan_rsp_len = scan_rsp_len; + adv_instance->min_interval = min_interval; + adv_instance->max_interval = max_interval; + adv_instance->tx_power = tx_power; if (adv_data_len) memcpy(adv_instance->adv_data, adv_data, adv_data_len); @@ -2995,8 +2999,6 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, else adv_instance->duration = duration; - adv_instance->tx_power = HCI_TX_POWER_INVALID; - INIT_DELAYED_WORK(&adv_instance->rpa_expired_cb, adv_instance_rpa_expired); diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 413e3a5aabf544..bd984b32e07553 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1425,6 +1425,7 @@ static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) void __hci_req_enable_advertising(struct hci_request *req) { struct hci_dev *hdev = req->hdev; + struct adv_info *adv_instance; struct hci_cp_le_set_adv_param cp; u8 own_addr_type, enable = 0x01; bool connectable; @@ -1432,6 +1433,7 @@ void __hci_req_enable_advertising(struct hci_request *req) u32 flags; flags = get_adv_instance_flags(hdev, hdev->cur_adv_instance); + adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); /* If the "connectable" instance flag was not set, then choose between * ADV_IND and ADV_NONCONN_IND based on the global connectable setting. @@ -1463,11 +1465,16 @@ void __hci_req_enable_advertising(struct hci_request *req) memset(&cp, 0, sizeof(cp)); - if (connectable) { - cp.type = LE_ADV_IND; - + if (adv_instance) { + adv_min_interval = adv_instance->min_interval; + adv_max_interval = adv_instance->max_interval; + } else { adv_min_interval = hdev->le_adv_min_interval; adv_max_interval = hdev->le_adv_max_interval; + } + + if (connectable) { + cp.type = LE_ADV_IND; } else { if (get_cur_adv_instance_scan_rsp_len(hdev)) cp.type = LE_ADV_SCAN_IND; @@ -1478,9 +1485,6 @@ void __hci_req_enable_advertising(struct hci_request *req) hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { adv_min_interval = DISCOV_LE_FAST_ADV_INT_MIN; adv_max_interval = DISCOV_LE_FAST_ADV_INT_MAX; - } else { - adv_min_interval = hdev->le_adv_min_interval; - adv_max_interval = hdev->le_adv_max_interval; } } @@ -1997,9 +2001,15 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) memset(&cp, 0, sizeof(cp)); - /* In ext adv set param interval is 3 octets */ - hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); - hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); + if (adv_instance) { + hci_cpu_to_le24(adv_instance->min_interval, cp.min_interval); + hci_cpu_to_le24(adv_instance->max_interval, cp.max_interval); + cp.tx_power = adv_instance->tx_power; + } else { + hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); + hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); + cp.tx_power = HCI_ADV_TX_POWER_NO_PREFERENCE; + } secondary_adv = (flags & MGMT_ADV_FLAG_SEC_MASK); @@ -2022,7 +2032,6 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) cp.own_addr_type = own_addr_type; cp.channel_map = hdev->le_adv_channel_map; - cp.tx_power = 127; cp.handle = instance; if (flags & MGMT_ADV_FLAG_SEC_2M) { diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index ee425fec43bf1b..c92b809a5e086d 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -7524,7 +7524,10 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, cp->adv_data_len, cp->data, cp->scan_rsp_len, cp->data + cp->adv_data_len, - timeout, duration); + timeout, duration, + HCI_ADV_TX_POWER_NO_PREFERENCE, + hdev->le_adv_min_interval, + hdev->le_adv_max_interval); if (err < 0) { err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, MGMT_STATUS_FAILED); @@ -7725,7 +7728,8 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, /* Create advertising instance with no advertising or response data */ err = hci_add_adv_instance(hdev, cp->instance, flags, - 0, NULL, 0, NULL, timeout, duration); + 0, NULL, 0, NULL, timeout, duration, + tx_power, min_interval, max_interval); if (err < 0) { err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, -- 2.28.0.709.gb0816b6eb0-goog