Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1502083pxb; Fri, 26 Feb 2021 12:25:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq3PqpASesQb+XaFu9Aw6l8ydJ3+5xobQC0XSgJ28ljhvC7ZVn7c0YqbkU7yQe3F/5kc7l X-Received: by 2002:a17:906:3b84:: with SMTP id u4mr5177465ejf.431.1614371123954; Fri, 26 Feb 2021 12:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614371123; cv=none; d=google.com; s=arc-20160816; b=NYXMgyscA05dqhu2dhs5gNS/rZ/N/ATdWvH4kZ8CRAKkQd8rzVP8DvxxFvBaarbreK EctViPwxAg8vrMuxEZD0UVde1LA/0wtMGuinckJa5D9T55BNZe5smufyJqb2sbqEkVPf WctcKRBjyMjE5AqDumRHnm12lPDdGmIyeH4zuf4d0DLtKvDz0nIMwW90ConQYkqO87bT 8JuHe5rMIftrxFP/lAgMxSF2+CnBj8BUCp7stlnEdvLPVyXu9/U36tceo94uk7PEMhpD xMvbSgpELy7Ro5zhPpoRFJLYdkwQjaA3WyccfCWcZZ8GeEaaUR4mwzY9SKX8ks8OKUTK puBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=BoXnhbrgnNYZZtqhS4ZY2nzFOEfZy94HTENnLdbuRjY=; b=qNBhd37yehUpBS4Or//cj6nkc842Bd6wcxsg0go8js9LKNsdCsbXFPPrPvnSJYf7kw CoJuayYyRyY5XXR7TODTLdw0k3CXYC8v6G/Ct4NHFRNQE8ne5sPAEbYFCnevpkYaittQ Cdz1jqERSFogdohV7dBcsXUNu6rDWqcFukwK0PJQnCu3igm730rsoRiLAED+YWuB+WiU U1LCicJs6V8UmCpzZZuKh8Pgramzi0XsDyMeHRo/hbE/uilGmBQCzecq2ieiKQPTwWWR O6qAuIp6yvl2Y9GkKIOGKr7xaBkDiXwDFPlJ+FOOj0VJt9vUNue/lf4aD2dWpJnIn1Fa r97g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si7548061eda.350.2021.02.26.12.25.01; Fri, 26 Feb 2021 12:25:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbhBZUXQ convert rfc822-to-8bit (ORCPT + 99 others); Fri, 26 Feb 2021 15:23:16 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:38689 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbhBZUUf (ORCPT ); Fri, 26 Feb 2021 15:20:35 -0500 Received: from marcel-macbook.holtmann.net (p4ff9fb90.dip0.t-ipconnect.de [79.249.251.144]) by mail.holtmann.org (Postfix) with ESMTPSA id 48DB9CEC82; Fri, 26 Feb 2021 21:27:25 +0100 (CET) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [PATCH v1] Bluetooth: Tolerate valid pre 4.2 conn params From: Marcel Holtmann In-Reply-To: <20210217142511.3221605-1-alainm@chromium.org> Date: Fri, 26 Feb 2021 21:19:52 +0100 Cc: Bluetooth Kernel Mailing List , Miao-chen Chou , Harry Cutts Content-Transfer-Encoding: 8BIT Message-Id: <16346FE7-7DD1-4575-8EAC-6B7AE6AAAA99@holtmann.org> References: <20210217142511.3221605-1-alainm@chromium.org> To: Alain Michaud X-Mailer: Apple Mail (2.3654.60.0.2.21) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 > Reviewed-by: Miao-chen Chou > Tested-by: Harry Cutts > > --- > > 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