linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params
@ 2021-02-17 14:25 Alain Michaud
  2021-02-17 15:11 ` [v1] " bluez.test.bot
  2021-02-26 20:19 ` [PATCH v1] " Marcel Holtmann
  0 siblings, 2 replies; 5+ messages in thread
From: Alain Michaud @ 2021-02-17 14:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Alain Michaud, Miao-chen Chou, Harry Cutts

This patch tolerates connection parameters that were valid before
ESR08_v1.0.0 which was also incoporated into the 4.2 core specification.

In particular, this addresses compatibility issues with the Lenovo Yoga
Mouse that sees its connection parameters rejected by the max_latency
computation in hci_conn_check_params, but was perfectly valid at the
time this mouse was qualified.

Before the patch, the mouse was extremely laggy, after the patch, the
mouse worked as expected.

Signed-off-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Tested-by: Harry Cutts <hcutts@chromium.org>

---

 include/net/bluetooth/hci_core.h | 30 ++++++++++++++++++++++++++++++
 net/bluetooth/l2cap_core.c       | 12 ++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ebdd4afe30d2..67b75077c82e 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1646,6 +1646,36 @@ static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
 	return hci_find_irk_by_rpa(hdev, bdaddr);
 }
 
+/* Erratum 5412 which has been fixed in 4.2 changed the validation of
+ * connection parameters.  For backwards compatibility reasons, the old
+ * calculation must be tolerated.
+ * For further details :
+ * https://www.bluetooth.org/errata/errata_view.cfm?errata_id=5419
+ */
+static inline int hci_check_conn_params_legacy(u16 min, u16 max, u16 latency,
+					u16 to_multiplier)
+{
+	u16 max_latency;
+
+	if (min > max || min < 6 || max > 3200)
+		return -EINVAL;
+
+	if (to_multiplier < 10 || to_multiplier > 3200)
+		return -EINVAL;
+
+	if (max >= to_multiplier * 8)
+		return -EINVAL;
+
+	max_latency = (to_multiplier * 8 / max) - 1;
+	if (latency > 499 || latency > max_latency)
+		return -EINVAL;
+
+	return 0;
+}
+
+/* Connection Parameter Validation Helper.
+ * See Vol 6, Part B, section 4.5.1.
+ */
 static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
 					u16 to_multiplier)
 {
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 72c2f5226d67..726e78bd85ff 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5553,6 +5553,18 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 	memset(&rsp, 0, sizeof(rsp));
 
 	err = hci_check_conn_params(min, max, latency, to_multiplier);
+	if (err) {
+		BT_WARN("Invalid conn params min 0x%4.4x max 0x%4.4x latency: 0x%4.4x TO: 0x%4.4x",
+			min, max, latency, to_multiplier);
+
+		err = hci_check_conn_params_legacy(min, max, latency,
+						   to_multiplier);
+		if (!err) {
+			/* latency is invalid, cap it to the max allowed */
+			latency = min(499, (to_multiplier * 4 / max) - 1);
+		}
+	}
+
 	if (err)
 		rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
 	else
-- 
2.30.0.478.g8a0d178c01-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [v1] Bluetooth: Tolerate valid pre 4.2 conn params
  2021-02-17 14:25 [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params Alain Michaud
@ 2021-02-17 15:11 ` bluez.test.bot
  2021-02-18 20:06   ` Alain Michaud
  2021-02-26 20:19 ` [PATCH v1] " Marcel Holtmann
  1 sibling, 1 reply; 5+ messages in thread
From: bluez.test.bot @ 2021-02-17 15:11 UTC (permalink / raw)
  To: linux-bluetooth, alainm

[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=434523

---Test result---

##############################
    Test: CheckPatch - PASS
    

    ##############################
    Test: CheckGitLint - PASS
    

    ##############################
    Test: CheckBuildK - PASS
    

    ##############################
    Test: CheckTestRunner: Setup - PASS
    

    ##############################
    Test: CheckTestRunner: l2cap-tester - PASS
    Total: 40, Passed: 34 (85.0%), Failed: 0, Not Run: 6

    ##############################
    Test: CheckTestRunner: bnep-tester - PASS
    Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

    ##############################
    Test: CheckTestRunner: mgmt-tester - PASS
    Total: 416, Passed: 402 (96.6%), Failed: 0, Not Run: 14

    ##############################
    Test: CheckTestRunner: rfcomm-tester - PASS
    Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

    ##############################
    Test: CheckTestRunner: sco-tester - PASS
    Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

    ##############################
    Test: CheckTestRunner: smp-tester - PASS
    Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

    ##############################
    Test: CheckTestRunner: userchan-tester - PASS
    Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0

    

---
Regards,
Linux Bluetooth


[-- Attachment #2: l2cap-tester.log --]
[-- Type: application/octet-stream, Size: 43342 bytes --]

[-- Attachment #3: bnep-tester.log --]
[-- Type: application/octet-stream, Size: 3533 bytes --]

[-- Attachment #4: mgmt-tester.log --]
[-- Type: application/octet-stream, Size: 546680 bytes --]

[-- Attachment #5: rfcomm-tester.log --]
[-- Type: application/octet-stream, Size: 11653 bytes --]

[-- Attachment #6: sco-tester.log --]
[-- Type: application/octet-stream, Size: 9888 bytes --]

[-- Attachment #7: smp-tester.log --]
[-- Type: application/octet-stream, Size: 11798 bytes --]

[-- Attachment #8: userchan-tester.log --]
[-- Type: application/octet-stream, Size: 5430 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v1] Bluetooth: Tolerate valid pre 4.2 conn params
  2021-02-17 15:11 ` [v1] " bluez.test.bot
@ 2021-02-18 20:06   ` Alain Michaud
  2021-02-24 18:57     ` Alain Michaud
  0 siblings, 1 reply; 5+ messages in thread
From: Alain Michaud @ 2021-02-18 20:06 UTC (permalink / raw)
  To: BlueZ, Marcel Holtmann; +Cc: Alain Michaud

+Marcel for viz


On Wed, Feb 17, 2021 at 10:11 AM <bluez.test.bot@gmail.com> wrote:
>
> This is automated email and please do not reply to this email!
>
> Dear submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=434523
>
> ---Test result---
>
> ##############################
>     Test: CheckPatch - PASS
>
>
>     ##############################
>     Test: CheckGitLint - PASS
>
>
>     ##############################
>     Test: CheckBuildK - PASS
>
>
>     ##############################
>     Test: CheckTestRunner: Setup - PASS
>
>
>     ##############################
>     Test: CheckTestRunner: l2cap-tester - PASS
>     Total: 40, Passed: 34 (85.0%), Failed: 0, Not Run: 6
>
>     ##############################
>     Test: CheckTestRunner: bnep-tester - PASS
>     Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
>
>     ##############################
>     Test: CheckTestRunner: mgmt-tester - PASS
>     Total: 416, Passed: 402 (96.6%), Failed: 0, Not Run: 14
>
>     ##############################
>     Test: CheckTestRunner: rfcomm-tester - PASS
>     Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0
>
>     ##############################
>     Test: CheckTestRunner: sco-tester - PASS
>     Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
>
>     ##############################
>     Test: CheckTestRunner: smp-tester - PASS
>     Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
>
>     ##############################
>     Test: CheckTestRunner: userchan-tester - PASS
>     Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0
>
>
>
> ---
> Regards,
> Linux Bluetooth
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v1] Bluetooth: Tolerate valid pre 4.2 conn params
  2021-02-18 20:06   ` Alain Michaud
@ 2021-02-24 18:57     ` Alain Michaud
  0 siblings, 0 replies; 5+ messages in thread
From: Alain Michaud @ 2021-02-24 18:57 UTC (permalink / raw)
  To: BlueZ, Marcel Holtmann; +Cc: Alain Michaud

Friendly ping.


On Thu, Feb 18, 2021 at 3:06 PM Alain Michaud <alainmichaud@google.com> wrote:
>
> +Marcel for viz
>
>
> On Wed, Feb 17, 2021 at 10:11 AM <bluez.test.bot@gmail.com> wrote:
> >
> > This is automated email and please do not reply to this email!
> >
> > Dear submitter,
> >
> > Thank you for submitting the patches to the linux bluetooth mailing list.
> > This is a CI test results with your patch series:
> > PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=434523
> >
> > ---Test result---
> >
> > ##############################
> >     Test: CheckPatch - PASS
> >
> >
> >     ##############################
> >     Test: CheckGitLint - PASS
> >
> >
> >     ##############################
> >     Test: CheckBuildK - PASS
> >
> >
> >     ##############################
> >     Test: CheckTestRunner: Setup - PASS
> >
> >
> >     ##############################
> >     Test: CheckTestRunner: l2cap-tester - PASS
> >     Total: 40, Passed: 34 (85.0%), Failed: 0, Not Run: 6
> >
> >     ##############################
> >     Test: CheckTestRunner: bnep-tester - PASS
> >     Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
> >
> >     ##############################
> >     Test: CheckTestRunner: mgmt-tester - PASS
> >     Total: 416, Passed: 402 (96.6%), Failed: 0, Not Run: 14
> >
> >     ##############################
> >     Test: CheckTestRunner: rfcomm-tester - PASS
> >     Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0
> >
> >     ##############################
> >     Test: CheckTestRunner: sco-tester - PASS
> >     Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
> >
> >     ##############################
> >     Test: CheckTestRunner: smp-tester - PASS
> >     Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
> >
> >     ##############################
> >     Test: CheckTestRunner: userchan-tester - PASS
> >     Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0
> >
> >
> >
> > ---
> > Regards,
> > Linux Bluetooth
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params
  2021-02-17 14:25 [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params Alain Michaud
  2021-02-17 15:11 ` [v1] " bluez.test.bot
@ 2021-02-26 20:19 ` Marcel Holtmann
  1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2021-02-26 20:19 UTC (permalink / raw)
  To: Alain Michaud; +Cc: Bluetooth Kernel Mailing List, Miao-chen Chou, Harry Cutts

Hi Alain,

> This patch tolerates connection parameters that were valid before
> ESR08_v1.0.0 which was also incoporated into the 4.2 core specification.
> 
> In particular, this addresses compatibility issues with the Lenovo Yoga
> Mouse that sees its connection parameters rejected by the max_latency
> computation in hci_conn_check_params, but was perfectly valid at the
> time this mouse was qualified.
> 
> Before the patch, the mouse was extremely laggy, after the patch, the
> mouse worked as expected.
> 
> Signed-off-by: Alain Michaud <alainm@chromium.org>
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> Tested-by: Harry Cutts <hcutts@chromium.org>
> 
> ---
> 
> include/net/bluetooth/hci_core.h | 30 ++++++++++++++++++++++++++++++
> net/bluetooth/l2cap_core.c       | 12 ++++++++++++
> 2 files changed, 42 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index ebdd4afe30d2..67b75077c82e 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1646,6 +1646,36 @@ static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
> 	return hci_find_irk_by_rpa(hdev, bdaddr);
> }
> 
> +/* Erratum 5412 which has been fixed in 4.2 changed the validation of
> + * connection parameters.  For backwards compatibility reasons, the old
> + * calculation must be tolerated.
> + * For further details :
> + * https://www.bluetooth.org/errata/errata_view.cfm?errata_id=5419
> + */
> +static inline int hci_check_conn_params_legacy(u16 min, u16 max, u16 latency,
> +					u16 to_multiplier)

I would not bother with “inline” here. Let the compiler decide.

> +{
> +	u16 max_latency;
> +
> +	if (min > max || min < 6 || max > 3200)
> +		return -EINVAL;
> +
> +	if (to_multiplier < 10 || to_multiplier > 3200)
> +		return -EINVAL;
> +
> +	if (max >= to_multiplier * 8)
> +		return -EINVAL;
> +
> +	max_latency = (to_multiplier * 8 / max) - 1;
> +	if (latency > 499 || latency > max_latency)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +/* Connection Parameter Validation Helper.
> + * See Vol 6, Part B, section 4.5.1.
> + */
> static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
> 					u16 to_multiplier)
> {
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 72c2f5226d67..726e78bd85ff 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -5553,6 +5553,18 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
> 	memset(&rsp, 0, sizeof(rsp));
> 
> 	err = hci_check_conn_params(min, max, latency, to_multiplier);
> +	if (err) {
> +		BT_WARN("Invalid conn params min 0x%4.4x max 0x%4.4x latency: 0x%4.4x TO: 0x%4.4x",
> +			min, max, latency, to_multiplier);

Can we use bt_dev_warn() here?

> +
> +		err = hci_check_conn_params_legacy(min, max, latency,
> +						   to_multiplier);
> +		if (!err) {
> +			/* latency is invalid, cap it to the max allowed */
> +			latency = min(499, (to_multiplier * 4 / max) - 1);
> +		}
> +	}
> +
> 	if (err)
> 		rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
> 	else

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-26 20:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17 14:25 [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params Alain Michaud
2021-02-17 15:11 ` [v1] " bluez.test.bot
2021-02-18 20:06   ` Alain Michaud
2021-02-24 18:57     ` Alain Michaud
2021-02-26 20:19 ` [PATCH v1] " Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).