* [PATCH v7 2/4] Bluetooth: btintel: support link statistics telemetry events
2021-08-12 9:15 [PATCH v7 1/4] Bluetooth: btusb: disable Intel link statistics telemetry events Joseph Hwang
@ 2021-08-12 9:15 ` Joseph Hwang
2021-08-12 9:16 ` [PATCH v7 3/4] Bluetooth: set quality report callback for Intel Joseph Hwang
2021-08-12 9:16 ` [PATCH v7 4/4] Bluetooth: Support the quality report events Joseph Hwang
2 siblings, 0 replies; 6+ messages in thread
From: Joseph Hwang @ 2021-08-12 9:15 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz, pali
Cc: josephsih, chromeos-bluetooth-upstreaming, Chethan T N,
Miao-chen Chou, Kiran K, Joseph Hwang, Johan Hedberg,
linux-kernel
From: Chethan T N <chethan.tumkur.narayan@intel.com>
This patch supports the link statistics telemetry events for
intel controllers
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Chethan T N <chethan.tumkur.narayan@intel.com>
Signed-off-by: Kiran K <kiran.k@intel.com>
Signed-off-by: Joseph Hwang <josephsih@chromium.org>
---
Changes in v7:
- Rebase on Tedd's patches that moved functionality from btusb to
btintel.
drivers/bluetooth/btintel.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index 0fe093fa5158..643e2194ca01 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -1285,8 +1285,10 @@ static int btintel_read_debug_features(struct hci_dev *hdev,
static int btintel_set_debug_features(struct hci_dev *hdev,
const struct intel_debug_features *features)
{
- u8 mask[11] = { 0x0a, 0x92, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00,
+ u8 mask[11] = { 0x0a, 0x92, 0x02, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
+ u8 period[5] = { 0x04, 0x91, 0x02, 0x05, 0x00 };
+ u8 trace_enable = 0x02;
struct sk_buff *skb;
if (!features)
@@ -1303,8 +1305,24 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
PTR_ERR(skb));
return PTR_ERR(skb);
}
+ kfree_skb(skb);
+
+ skb = __hci_cmd_sync(hdev, 0xfc8b, 5, period, HCI_INIT_TIMEOUT);
+ if (IS_ERR(skb)) {
+ bt_dev_err(hdev, "Setting periodicity for link statistics traces failed (%ld)",
+ PTR_ERR(skb));
+ return PTR_ERR(skb);
+ }
+ kfree_skb(skb);
+ skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
+ if (IS_ERR(skb)) {
+ bt_dev_err(hdev, "Enable tracing of link statistics events failed (%ld)",
+ PTR_ERR(skb));
+ return PTR_ERR(skb);
+ }
kfree_skb(skb);
+
return 0;
}
--
2.32.0.605.g8dce9f2422-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v7 3/4] Bluetooth: set quality report callback for Intel
2021-08-12 9:15 [PATCH v7 1/4] Bluetooth: btusb: disable Intel link statistics telemetry events Joseph Hwang
2021-08-12 9:15 ` [PATCH v7 2/4] Bluetooth: btintel: support " Joseph Hwang
@ 2021-08-12 9:16 ` Joseph Hwang
2021-08-12 17:59 ` Luiz Augusto von Dentz
2021-08-12 9:16 ` [PATCH v7 4/4] Bluetooth: Support the quality report events Joseph Hwang
2 siblings, 1 reply; 6+ messages in thread
From: Joseph Hwang @ 2021-08-12 9:16 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz, pali
Cc: josephsih, chromeos-bluetooth-upstreaming, Joseph Hwang,
Miao-chen Chou, Johan Hedberg, linux-kernel
This patch sets up set_quality_report callback for Intel to
set and reset the debug features.
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Joseph Hwang <josephsih@chromium.org>
---
Changes in v7:
- Rebase on Tedd's patches that moved functionality from btusb to
btintel.
Changes in v5:
- Removed CONFIG_BT_FEATURE_QUALITY_REPORT since there was no
large size impact.
drivers/bluetooth/btintel.c | 81 ++++++++++++++++++++++++++++++++++++-
drivers/bluetooth/btintel.h | 6 +++
2 files changed, 86 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index 643e2194ca01..611c3ea5425f 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -1291,8 +1291,10 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
u8 trace_enable = 0x02;
struct sk_buff *skb;
- if (!features)
+ if (!features) {
+ bt_dev_warn(hdev, "Debug features not read");
return -EINVAL;
+ }
if (!(features->page1[0] & 0x3f)) {
bt_dev_info(hdev, "Telemetry exception format not supported");
@@ -1323,9 +1325,77 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
}
kfree_skb(skb);
+ bt_dev_info(hdev, "set debug features: trace_enable 0x%02x mask 0x%02x",
+ trace_enable, mask[3]);
+
return 0;
}
+static int btintel_reset_debug_features(struct hci_dev *hdev,
+ const struct intel_debug_features *features)
+{
+ u8 mask[11] = { 0x0a, 0x92, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00 };
+ u8 trace_enable = 0x00;
+ struct sk_buff *skb;
+
+ if (!features) {
+ bt_dev_warn(hdev, "Debug features not read");
+ return -EINVAL;
+ }
+
+ if (!(features->page1[0] & 0x3f)) {
+ bt_dev_info(hdev, "Telemetry exception format not supported");
+ return 0;
+ }
+
+ /* Should stop the trace before writing ddc event mask. */
+ skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
+ if (IS_ERR(skb)) {
+ bt_dev_err(hdev, "Stop tracing of link statistics events failed (%ld)",
+ PTR_ERR(skb));
+ return PTR_ERR(skb);
+ }
+ kfree_skb(skb);
+
+ skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
+ if (IS_ERR(skb)) {
+ bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
+ PTR_ERR(skb));
+ return PTR_ERR(skb);
+ }
+ kfree_skb(skb);
+
+ bt_dev_info(hdev, "reset debug features: trace_enable 0x%02x mask 0x%02x",
+ trace_enable, mask[3]);
+
+ return 0;
+}
+
+int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
+{
+ struct intel_debug_features features;
+ int err;
+
+ bt_dev_dbg(hdev, "enable %d", enable);
+
+ /* Read the Intel supported features and if new exception formats
+ * supported, need to load the additional DDC config to enable.
+ */
+ err = btintel_read_debug_features(hdev, &features);
+ if (err)
+ return err;
+
+ /* Set or reset the debug features. */
+ if (enable)
+ err = btintel_set_debug_features(hdev, &features);
+ else
+ err = btintel_reset_debug_features(hdev, &features);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(btintel_set_quality_report);
+
static const struct firmware *btintel_legacy_rom_get_fw(struct hci_dev *hdev,
struct intel_version *ver)
{
@@ -1951,6 +2021,9 @@ static int btintel_bootloader_setup(struct hci_dev *hdev,
btintel_load_ddc_config(hdev, ddcname);
}
+ hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
+ bt_dev_dbg(hdev, "HCI_QUALITY_REPORT cleared");
+
/* Read the Intel version information after loading the FW */
err = btintel_read_version(hdev, &new_ver);
if (err)
@@ -2132,6 +2205,9 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
*/
btintel_load_ddc_config(hdev, ddcname);
+ hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
+ bt_dev_dbg(hdev, "HCI_QUALITY_REPORT cleared");
+
/* Read the Intel version information after loading the FW */
err = btintel_read_version_tlv(hdev, &new_ver);
if (err)
@@ -2230,6 +2306,9 @@ static int btintel_setup_combined(struct hci_dev *hdev)
set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
+ /* Set up the quality report callback for Intel devices */
+ hdev->set_quality_report = btintel_set_quality_report;
+
/* For Legacy device, check the HW platform value and size */
if (skb->len == sizeof(ver) && skb->data[1] == 0x37) {
bt_dev_dbg(hdev, "Read the legacy Intel version information");
diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
index aa64072bbe68..fe02cb9ac96c 100644
--- a/drivers/bluetooth/btintel.h
+++ b/drivers/bluetooth/btintel.h
@@ -204,6 +204,7 @@ int btintel_configure_setup(struct hci_dev *hdev);
void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len);
void btintel_secure_send_result(struct hci_dev *hdev,
const void *ptr, unsigned int len);
+int btintel_set_quality_report(struct hci_dev *hdev, bool enable);
#else
static inline int btintel_check_bdaddr(struct hci_dev *hdev)
@@ -294,4 +295,9 @@ static inline void btintel_secure_send_result(struct hci_dev *hdev,
const void *ptr, unsigned int len)
{
}
+
+static inline int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
+{
+ return -ENODEV;
+}
#endif
--
2.32.0.605.g8dce9f2422-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v7 3/4] Bluetooth: set quality report callback for Intel
2021-08-12 9:16 ` [PATCH v7 3/4] Bluetooth: set quality report callback for Intel Joseph Hwang
@ 2021-08-12 17:59 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2021-08-12 17:59 UTC (permalink / raw)
To: Joseph Hwang
Cc: linux-bluetooth, Marcel Holtmann, Pali Rohár, Joseph Hwang,
ChromeOS Bluetooth Upstreaming, Miao-chen Chou, Johan Hedberg,
Linux Kernel Mailing List
Hi Joseph,
On Thu, Aug 12, 2021 at 2:16 AM Joseph Hwang <josephsih@chromium.org> wrote:
>
> This patch sets up set_quality_report callback for Intel to
> set and reset the debug features.
>
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> Signed-off-by: Joseph Hwang <josephsih@chromium.org>
> ---
>
> Changes in v7:
> - Rebase on Tedd's patches that moved functionality from btusb to
> btintel.
>
> Changes in v5:
> - Removed CONFIG_BT_FEATURE_QUALITY_REPORT since there was no
> large size impact.
>
> drivers/bluetooth/btintel.c | 81 ++++++++++++++++++++++++++++++++++++-
> drivers/bluetooth/btintel.h | 6 +++
> 2 files changed, 86 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
> index 643e2194ca01..611c3ea5425f 100644
> --- a/drivers/bluetooth/btintel.c
> +++ b/drivers/bluetooth/btintel.c
> @@ -1291,8 +1291,10 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
> u8 trace_enable = 0x02;
> struct sk_buff *skb;
>
> - if (!features)
> + if (!features) {
> + bt_dev_warn(hdev, "Debug features not read");
> return -EINVAL;
> + }
>
> if (!(features->page1[0] & 0x3f)) {
> bt_dev_info(hdev, "Telemetry exception format not supported");
> @@ -1323,9 +1325,77 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
> }
> kfree_skb(skb);
>
> + bt_dev_info(hdev, "set debug features: trace_enable 0x%02x mask 0x%02x",
> + trace_enable, mask[3]);
> +
> return 0;
> }
>
> +static int btintel_reset_debug_features(struct hci_dev *hdev,
> + const struct intel_debug_features *features)
> +{
> + u8 mask[11] = { 0x0a, 0x92, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00 };
> + u8 trace_enable = 0x00;
> + struct sk_buff *skb;
> +
> + if (!features) {
> + bt_dev_warn(hdev, "Debug features not read");
> + return -EINVAL;
> + }
> +
> + if (!(features->page1[0] & 0x3f)) {
> + bt_dev_info(hdev, "Telemetry exception format not supported");
> + return 0;
> + }
> +
> + /* Should stop the trace before writing ddc event mask. */
> + skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
> + if (IS_ERR(skb)) {
> + bt_dev_err(hdev, "Stop tracing of link statistics events failed (%ld)",
> + PTR_ERR(skb));
> + return PTR_ERR(skb);
> + }
> + kfree_skb(skb);
> +
> + skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
> + if (IS_ERR(skb)) {
> + bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
> + PTR_ERR(skb));
> + return PTR_ERR(skb);
> + }
> + kfree_skb(skb);
> +
> + bt_dev_info(hdev, "reset debug features: trace_enable 0x%02x mask 0x%02x",
> + trace_enable, mask[3]);
> +
> + return 0;
> +}
> +
> +int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
> +{
> + struct intel_debug_features features;
> + int err;
> +
> + bt_dev_dbg(hdev, "enable %d", enable);
> +
> + /* Read the Intel supported features and if new exception formats
> + * supported, need to load the additional DDC config to enable.
> + */
> + err = btintel_read_debug_features(hdev, &features);
> + if (err)
> + return err;
> +
> + /* Set or reset the debug features. */
> + if (enable)
> + err = btintel_set_debug_features(hdev, &features);
> + else
> + err = btintel_reset_debug_features(hdev, &features);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(btintel_set_quality_report);
> +
> static const struct firmware *btintel_legacy_rom_get_fw(struct hci_dev *hdev,
> struct intel_version *ver)
> {
> @@ -1951,6 +2021,9 @@ static int btintel_bootloader_setup(struct hci_dev *hdev,
> btintel_load_ddc_config(hdev, ddcname);
> }
>
> + hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
> + bt_dev_dbg(hdev, "HCI_QUALITY_REPORT cleared");
I would remove such debugs since I don't think they have any value
here, besides it doesn't seem HCI_QUALITY_REPORT is ever set anyway
which perhaps should be done by the core itself after calling the
callback.
> /* Read the Intel version information after loading the FW */
> err = btintel_read_version(hdev, &new_ver);
> if (err)
> @@ -2132,6 +2205,9 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
> */
> btintel_load_ddc_config(hdev, ddcname);
>
> + hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
> + bt_dev_dbg(hdev, "HCI_QUALITY_REPORT cleared");
Ditto.
> /* Read the Intel version information after loading the FW */
> err = btintel_read_version_tlv(hdev, &new_ver);
> if (err)
> @@ -2230,6 +2306,9 @@ static int btintel_setup_combined(struct hci_dev *hdev)
> set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
> set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
>
> + /* Set up the quality report callback for Intel devices */
> + hdev->set_quality_report = btintel_set_quality_report;
> +
> /* For Legacy device, check the HW platform value and size */
> if (skb->len == sizeof(ver) && skb->data[1] == 0x37) {
> bt_dev_dbg(hdev, "Read the legacy Intel version information");
> diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
> index aa64072bbe68..fe02cb9ac96c 100644
> --- a/drivers/bluetooth/btintel.h
> +++ b/drivers/bluetooth/btintel.h
> @@ -204,6 +204,7 @@ int btintel_configure_setup(struct hci_dev *hdev);
> void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len);
> void btintel_secure_send_result(struct hci_dev *hdev,
> const void *ptr, unsigned int len);
> +int btintel_set_quality_report(struct hci_dev *hdev, bool enable);
> #else
>
> static inline int btintel_check_bdaddr(struct hci_dev *hdev)
> @@ -294,4 +295,9 @@ static inline void btintel_secure_send_result(struct hci_dev *hdev,
> const void *ptr, unsigned int len)
> {
> }
> +
> +static inline int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
> +{
> + return -ENODEV;
> +}
> #endif
> --
> 2.32.0.605.g8dce9f2422-goog
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v7 4/4] Bluetooth: Support the quality report events
2021-08-12 9:15 [PATCH v7 1/4] Bluetooth: btusb: disable Intel link statistics telemetry events Joseph Hwang
2021-08-12 9:15 ` [PATCH v7 2/4] Bluetooth: btintel: support " Joseph Hwang
2021-08-12 9:16 ` [PATCH v7 3/4] Bluetooth: set quality report callback for Intel Joseph Hwang
@ 2021-08-12 9:16 ` Joseph Hwang
2021-08-12 18:06 ` Luiz Augusto von Dentz
2 siblings, 1 reply; 6+ messages in thread
From: Joseph Hwang @ 2021-08-12 9:16 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz, pali
Cc: josephsih, chromeos-bluetooth-upstreaming, Joseph Hwang,
Miao-chen Chou, David S. Miller, Jakub Kicinski, Johan Hedberg,
linux-kernel, netdev
This patch allows a user space process to enable/disable the quality
report events dynamically through the set experimental feature mgmt
interface if CONFIG_BT_FEATURE_QUALITY_REPORT is enabled.
Since the quality report feature needs to invoke the callback function
provided by the driver, i.e., hdev->set_quality_report, a valid
controller index is required.
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Joseph Hwang <josephsih@chromium.org>
---
Changes in v7:
- Rebase on Tedd's patches that moved functionality from btusb to
btintel.
Changes in v5:
- Removed CONFIG_BT_FEATURE_QUALITY_REPORT since there was no
large size impact.
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 2 +
net/bluetooth/mgmt.c | 110 ++++++++++++++++++++++++++++++-
3 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index b80415011dcd..bb6b7398f490 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -330,6 +330,7 @@ enum {
HCI_ENABLE_LL_PRIVACY,
HCI_CMD_PENDING,
HCI_FORCE_NO_MITM,
+ HCI_QUALITY_REPORT,
__HCI_NUM_FLAGS,
};
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index a7d06d7da602..7e9ae36b2582 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -606,6 +606,7 @@ struct hci_dev {
int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
void (*cmd_timeout)(struct hci_dev *hdev);
bool (*prevent_wake)(struct hci_dev *hdev);
+ int (*set_quality_report)(struct hci_dev *hdev, bool enable);
};
#define HCI_PHY_HANDLE(handle) (handle & 0xff)
@@ -759,6 +760,7 @@ extern struct mutex hci_cb_list_lock;
hci_dev_clear_flag(hdev, HCI_LE_ADV); \
hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \
+ hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); \
} while (0)
/* ----- HCI interface to upper protocols ----- */
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1e21e014efd2..358250862720 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3791,6 +3791,12 @@ static const u8 debug_uuid[16] = {
};
#endif
+/* 330859bc-7506-492d-9370-9a6f0614037f */
+static const u8 quality_report_uuid[16] = {
+ 0x7f, 0x03, 0x14, 0x06, 0x6f, 0x9a, 0x70, 0x93,
+ 0x2d, 0x49, 0x06, 0x75, 0xbc, 0x59, 0x08, 0x33,
+};
+
/* 671b10b5-42c0-4696-9227-eb28d1b049d6 */
static const u8 simult_central_periph_uuid[16] = {
0xd6, 0x49, 0xb0, 0xd1, 0x28, 0xeb, 0x27, 0x92,
@@ -3806,7 +3812,7 @@ static const u8 rpa_resolution_uuid[16] = {
static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
void *data, u16 data_len)
{
- char buf[62]; /* Enough space for 3 features */
+ char buf[82]; /* Enough space for 4 features: 2 + 20 * 4 */
struct mgmt_rp_read_exp_features_info *rp = (void *)buf;
u16 idx = 0;
u32 flags;
@@ -3850,6 +3856,24 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
idx++;
}
+ if (hdev) {
+ if (hdev->set_quality_report) {
+ /* BIT(0): indicating if set_quality_report is
+ * supported by controller.
+ */
+ flags = BIT(0);
+
+ /* BIT(1): indicating if the feature is enabled. */
+ if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT))
+ flags |= BIT(1);
+ } else {
+ flags = 0;
+ }
+ memcpy(rp->features[idx].uuid, quality_report_uuid, 16);
+ rp->features[idx].flags = cpu_to_le32(flags);
+ idx++;
+ }
+
rp->feature_count = cpu_to_le16(idx);
/* After reading the experimental features information, enable
@@ -3892,6 +3916,21 @@ static int exp_debug_feature_changed(bool enabled, struct sock *skip)
}
#endif
+static int exp_quality_report_feature_changed(bool enabled, struct sock *skip)
+{
+ struct mgmt_ev_exp_feature_changed ev;
+
+ BT_INFO("enabled %d", enabled);
+
+ memset(&ev, 0, sizeof(ev));
+ memcpy(ev.uuid, quality_report_uuid, 16);
+ ev.flags = cpu_to_le32(enabled ? BIT(0) : 0);
+
+ return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, NULL,
+ &ev, sizeof(ev),
+ HCI_MGMT_EXP_FEATURE_EVENTS, skip);
+}
+
static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
void *data, u16 data_len)
{
@@ -4038,6 +4077,75 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
return err;
}
+ if (!memcmp(cp->uuid, quality_report_uuid, 16)) {
+ bool val, changed;
+ int err;
+
+ /* Command requires to use a valid controller index */
+ if (!hdev)
+ return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+ MGMT_OP_SET_EXP_FEATURE,
+ MGMT_STATUS_INVALID_INDEX);
+
+ /* Parameters are limited to a single octet */
+ if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
+ return mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_SET_EXP_FEATURE,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ /* Only boolean on/off is supported */
+ if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
+ return mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_SET_EXP_FEATURE,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ hci_req_sync_lock(hdev);
+
+ val = !!cp->param[0];
+ changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT));
+
+ if (!hdev->set_quality_report) {
+ BT_INFO("quality report not supported");
+ err = mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_SET_EXP_FEATURE,
+ MGMT_STATUS_NOT_SUPPORTED);
+ goto unlock_quality_report;
+ }
+
+ if (changed) {
+ err = hdev->set_quality_report(hdev, val);
+ if (err) {
+ BT_ERR("set_quality_report value %d err %d",
+ val, err);
+ err = mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_SET_EXP_FEATURE,
+ MGMT_STATUS_FAILED);
+ goto unlock_quality_report;
+ }
+ if (val)
+ hci_dev_set_flag(hdev, HCI_QUALITY_REPORT);
+ else
+ hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
+ }
+
+ BT_INFO("quality report enable %d changed %d",
+ val, changed);
+
+ memcpy(rp.uuid, quality_report_uuid, 16);
+ rp.flags = cpu_to_le32(val ? BIT(0) : 0);
+ hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
+ err = mgmt_cmd_complete(sk, hdev->id,
+ MGMT_OP_SET_EXP_FEATURE, 0,
+ &rp, sizeof(rp));
+
+ if (changed)
+ exp_quality_report_feature_changed(val, sk);
+
+unlock_quality_report:
+ hci_req_sync_unlock(hdev);
+ return err;
+ }
+
return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
MGMT_OP_SET_EXP_FEATURE,
MGMT_STATUS_NOT_SUPPORTED);
--
2.32.0.605.g8dce9f2422-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v7 4/4] Bluetooth: Support the quality report events
2021-08-12 9:16 ` [PATCH v7 4/4] Bluetooth: Support the quality report events Joseph Hwang
@ 2021-08-12 18:06 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2021-08-12 18:06 UTC (permalink / raw)
To: Joseph Hwang
Cc: linux-bluetooth, Marcel Holtmann, Pali Rohár, Joseph Hwang,
ChromeOS Bluetooth Upstreaming, Miao-chen Chou, David S. Miller,
Jakub Kicinski, Johan Hedberg, Linux Kernel Mailing List,
open list:NETWORKING [GENERAL]
Hi Joseph,
On Thu, Aug 12, 2021 at 2:16 AM Joseph Hwang <josephsih@chromium.org> wrote:
>
> This patch allows a user space process to enable/disable the quality
> report events dynamically through the set experimental feature mgmt
> interface if CONFIG_BT_FEATURE_QUALITY_REPORT is enabled.
>
> Since the quality report feature needs to invoke the callback function
> provided by the driver, i.e., hdev->set_quality_report, a valid
> controller index is required.
>
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> Signed-off-by: Joseph Hwang <josephsih@chromium.org>
> ---
>
> Changes in v7:
> - Rebase on Tedd's patches that moved functionality from btusb to
> btintel.
>
> Changes in v5:
> - Removed CONFIG_BT_FEATURE_QUALITY_REPORT since there was no
> large size impact.
>
> include/net/bluetooth/hci.h | 1 +
> include/net/bluetooth/hci_core.h | 2 +
> net/bluetooth/mgmt.c | 110 ++++++++++++++++++++++++++++++-
> 3 files changed, 112 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index b80415011dcd..bb6b7398f490 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -330,6 +330,7 @@ enum {
> HCI_ENABLE_LL_PRIVACY,
> HCI_CMD_PENDING,
> HCI_FORCE_NO_MITM,
> + HCI_QUALITY_REPORT,
Hmm, 3/4 actually makes use of HCI_QUALITY_REPORT so this should
actually appear before it (3/4 4/4 should be swapped) otherwise we
break the likes of bisect, I usually recommend using git rebase -i
origin/master --exec make to check if each and every change build
properly.
>
> __HCI_NUM_FLAGS,
> };
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index a7d06d7da602..7e9ae36b2582 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -606,6 +606,7 @@ struct hci_dev {
> int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
> void (*cmd_timeout)(struct hci_dev *hdev);
> bool (*prevent_wake)(struct hci_dev *hdev);
> + int (*set_quality_report)(struct hci_dev *hdev, bool enable);
> };
>
> #define HCI_PHY_HANDLE(handle) (handle & 0xff)
> @@ -759,6 +760,7 @@ extern struct mutex hci_cb_list_lock;
> hci_dev_clear_flag(hdev, HCI_LE_ADV); \
> hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \
> + hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); \
> } while (0)
>
> /* ----- HCI interface to upper protocols ----- */
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 1e21e014efd2..358250862720 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -3791,6 +3791,12 @@ static const u8 debug_uuid[16] = {
> };
> #endif
>
> +/* 330859bc-7506-492d-9370-9a6f0614037f */
> +static const u8 quality_report_uuid[16] = {
> + 0x7f, 0x03, 0x14, 0x06, 0x6f, 0x9a, 0x70, 0x93,
> + 0x2d, 0x49, 0x06, 0x75, 0xbc, 0x59, 0x08, 0x33,
> +};
> +
> /* 671b10b5-42c0-4696-9227-eb28d1b049d6 */
> static const u8 simult_central_periph_uuid[16] = {
> 0xd6, 0x49, 0xb0, 0xd1, 0x28, 0xeb, 0x27, 0x92,
> @@ -3806,7 +3812,7 @@ static const u8 rpa_resolution_uuid[16] = {
> static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
> void *data, u16 data_len)
> {
> - char buf[62]; /* Enough space for 3 features */
> + char buf[82]; /* Enough space for 4 features: 2 + 20 * 4 */
> struct mgmt_rp_read_exp_features_info *rp = (void *)buf;
> u16 idx = 0;
> u32 flags;
> @@ -3850,6 +3856,24 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
> idx++;
> }
>
> + if (hdev) {
> + if (hdev->set_quality_report) {
> + /* BIT(0): indicating if set_quality_report is
> + * supported by controller.
> + */
> + flags = BIT(0);
> +
> + /* BIT(1): indicating if the feature is enabled. */
> + if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT))
> + flags |= BIT(1);
> + } else {
> + flags = 0;
> + }
> + memcpy(rp->features[idx].uuid, quality_report_uuid, 16);
> + rp->features[idx].flags = cpu_to_le32(flags);
> + idx++;
> + }
> +
> rp->feature_count = cpu_to_le16(idx);
>
> /* After reading the experimental features information, enable
> @@ -3892,6 +3916,21 @@ static int exp_debug_feature_changed(bool enabled, struct sock *skip)
> }
> #endif
>
> +static int exp_quality_report_feature_changed(bool enabled, struct sock *skip)
> +{
> + struct mgmt_ev_exp_feature_changed ev;
> +
> + BT_INFO("enabled %d", enabled);
> +
> + memset(&ev, 0, sizeof(ev));
> + memcpy(ev.uuid, quality_report_uuid, 16);
> + ev.flags = cpu_to_le32(enabled ? BIT(0) : 0);
> +
> + return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, NULL,
> + &ev, sizeof(ev),
> + HCI_MGMT_EXP_FEATURE_EVENTS, skip);
> +}
> +
> static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
> void *data, u16 data_len)
> {
> @@ -4038,6 +4077,75 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
> return err;
> }
Perhaps it would be a good idea to have a function table e.g:
struct mgmt_exp_feature {
const char *uuid;
int (func*)(...)
} exp_features[] = {
...
};
That way we don't have to add such changes directly into
set_exp_feature just in the table and implement its callback.
> + if (!memcmp(cp->uuid, quality_report_uuid, 16)) {
> + bool val, changed;
> + int err;
> +
> + /* Command requires to use a valid controller index */
> + if (!hdev)
> + return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
> + MGMT_OP_SET_EXP_FEATURE,
> + MGMT_STATUS_INVALID_INDEX);
> +
> + /* Parameters are limited to a single octet */
> + if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
> + return mgmt_cmd_status(sk, hdev->id,
> + MGMT_OP_SET_EXP_FEATURE,
> + MGMT_STATUS_INVALID_PARAMS);
> +
> + /* Only boolean on/off is supported */
> + if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
> + return mgmt_cmd_status(sk, hdev->id,
> + MGMT_OP_SET_EXP_FEATURE,
> + MGMT_STATUS_INVALID_PARAMS);
> +
> + hci_req_sync_lock(hdev);
> +
> + val = !!cp->param[0];
> + changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT));
> +
> + if (!hdev->set_quality_report) {
> + BT_INFO("quality report not supported");
> + err = mgmt_cmd_status(sk, hdev->id,
> + MGMT_OP_SET_EXP_FEATURE,
> + MGMT_STATUS_NOT_SUPPORTED);
> + goto unlock_quality_report;
> + }
> +
> + if (changed) {
> + err = hdev->set_quality_report(hdev, val);
> + if (err) {
> + BT_ERR("set_quality_report value %d err %d",
> + val, err);
> + err = mgmt_cmd_status(sk, hdev->id,
> + MGMT_OP_SET_EXP_FEATURE,
> + MGMT_STATUS_FAILED);
> + goto unlock_quality_report;
> + }
> + if (val)
> + hci_dev_set_flag(hdev, HCI_QUALITY_REPORT);
> + else
> + hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
> + }
> +
> + BT_INFO("quality report enable %d changed %d",
> + val, changed);
> +
> + memcpy(rp.uuid, quality_report_uuid, 16);
> + rp.flags = cpu_to_le32(val ? BIT(0) : 0);
> + hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
> + err = mgmt_cmd_complete(sk, hdev->id,
> + MGMT_OP_SET_EXP_FEATURE, 0,
> + &rp, sizeof(rp));
> +
> + if (changed)
> + exp_quality_report_feature_changed(val, sk);
> +
> +unlock_quality_report:
> + hci_req_sync_unlock(hdev);
> + return err;
> + }
> +
> return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
> MGMT_OP_SET_EXP_FEATURE,
> MGMT_STATUS_NOT_SUPPORTED);
> --
> 2.32.0.605.g8dce9f2422-goog
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 6+ messages in thread