Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp775022pxu; Thu, 3 Dec 2020 12:16:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJyY47loOj52w6XwalvI0YVyK2l/LuN1dWcULN7F2Tk2PA9MoXSRZAkCoJQ8vy1Q5Fm3l16D X-Received: by 2002:a17:906:3ec8:: with SMTP id d8mr4178795ejj.32.1607026604765; Thu, 03 Dec 2020 12:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607026604; cv=none; d=google.com; s=arc-20160816; b=TwjfNC0x3OLOtu2zBtwjY6Vzzgb8pGeGmTNkj2eMrIPE61AVHnn63hPIuDfuNyIU+S i3lT+xVPJkO/hbOXkGgoGworjmZvrYKT4a84R28CNI/ddS5EqZcRqV1iOu7qiZUIf5Et ERaYl0DBdLoJpTiEjiv99FCdhSPmkYJr3g+cEgRdqD6ApjhHn+yVsD9rtSirSR3+Xan6 pE3zZNVZdrNsOl44erYhOwKp5h5WArzXtWB1Fx9B2P029FIAA91RWhz20sru4dBbjxOR TGXQddCNJj/M8p6PtWPWW+pMfAoHlgHgaazOUrl97NPe2upvn+51bAFjFn4NwtKtH83n a/MA== 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=XGkybabo/zqrt1GnBNphlsW/goZ9FDzuIZiIpirBqGs=; b=0uwss4kwubswhjsOrhfh2Ei1abIOLYor8QpRdCEbwyCJkdJy1s2lgr16wqIVPiv2rv lwtvmPhn6hBL/L2UEzJ5bA64kuuprotv0RY/cAzIa4+cCN9aXEjB770JoRzKOOyTT863 5F6P2jWGenEWkFxq3pCKEFJG6hC+tBhGiXhgpqJscQM49/FyKblgTei2sbI3VDOnNijB /Vv5EsLlS51cQU4HNbUBOk5TgdisH5UclNYMDNMBA5BdQ1/ybFWTq0E79lgYMcLS/cue 1kv77508aiLZBKSSQvqNL0FnO6VlCU5FAsKWV9nqiojsdHgLwj+oijhBuPp0VqQcCKKW wmYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=e5V6zGDP; 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 y15si9008ejp.228.2020.12.03.12.16.20; Thu, 03 Dec 2020 12:16:44 -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=e5V6zGDP; 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 S1731747AbgLCUOd (ORCPT + 99 others); Thu, 3 Dec 2020 15:14:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726915AbgLCUOd (ORCPT ); Thu, 3 Dec 2020 15:14:33 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FF04C08E85E for ; Thu, 3 Dec 2020 12:13:12 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id m45so2616310qvg.16 for ; Thu, 03 Dec 2020 12:13:12 -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=XGkybabo/zqrt1GnBNphlsW/goZ9FDzuIZiIpirBqGs=; b=e5V6zGDPBHm3q7mBzphDgSaL9vKJzwtpRG6YfK/HkYTP56SoHwprNmgLyPW9Khs4c4 CNjp+NCq/QFz7H6Q9XZeAulhVWAi0Yvuz64iwjkvRY+7VemtM3CxEk3tbl/GaImsQDPE 6dLq3yy4TvJD7tfTUjbajkABv+QJ3iJcp0xkzwjdqH6hiRoPRdMW//EZle5XUR+fJM7S JJQWkHP7ZjaI2ZR8dCT1XOZ0MRq9vo1wfhPjDVgsOSIrzJbrx24yPBH1cyKJS0X4Hh0b orwsjga67+pwu4B0iFHpUyDHsDHTTHgqSb4JA8zlEXxtckjTVwo7R6us2lfpNxg17a57 GgJA== 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=XGkybabo/zqrt1GnBNphlsW/goZ9FDzuIZiIpirBqGs=; b=AIhb4LGEh2GNz+5jSc7lLi2M0bhX+Kt8OgLoX28Gcz+isIOJWfjElMRAxDMaDweQYs lWI+nUs8BFqwqg1Hyer5sA6j0EFMskerr2S40XJwUuF4kqrKQ/hfs8JgOqk2hsLEPTOF B+Kxq0bZKs35kzlvs+VoX7fLaUqNbpQ1hpcBVa9OpmU7VjMjo8TLqkovJLg+KyMO6W/B B4mSSXjn8l66l3qYKEP0f4Ufm8O2zA9NAzfc2h24Q9kYQK1Gz2P0dMc+u8XTLIpTAP8f TQPsbkof2GGz7hqTnZ5j4j75NUH4gPdMlm0AmEr2ZZxlIuUpjVDf7ZvKUaVf13iaj29E qoOg== X-Gm-Message-State: AOAM532B8R5/7HVyiVJBvS/E+wP1POhoaFhBCcHxwJ2ETNd5hr4JLQi+ aIEtNf4BgpB7m56psJLRqlmcj5TpvJFKwBZN3dz0 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:a0c:b799:: with SMTP id l25mr743995qve.25.1607026391798; Thu, 03 Dec 2020 12:13:11 -0800 (PST) Date: Thu, 3 Dec 2020 12:12:50 -0800 In-Reply-To: <20201203201252.807616-1-danielwinkler@google.com> Message-Id: <20201203121154.v7.3.I74255537fa99ed3c0025321008b361c6ad90a431@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 3/5] Bluetooth: Use intervals and tx power from mgmt cmds 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 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 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_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 3c2e205f226ac6..88988d4fd34750 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; @@ -1303,7 +1305,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 46ec523d96a76c..8855d07534ed8b 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 d0d0fbbb3fa571..80dc451d6e1242 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1488,6 +1488,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; @@ -1495,6 +1496,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. @@ -1526,11 +1528,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 (adv_cur_instance_is_scannable(hdev)) cp.type = LE_ADV_SCAN_IND; @@ -1541,9 +1548,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; } } @@ -2119,9 +2123,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); @@ -2144,7 +2154,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 ec6b520be368be..668a62c8181eb1 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -7533,7 +7533,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); @@ -7741,7 +7744,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.29.2.576.ga3fc446d84-goog