Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp357703pxu; Thu, 3 Dec 2020 02:00:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxaZFzB09fkSEEvpYYg3130ZeCCMJs/XARXhSSl7wU4VR6E9MU5HIldVsrLT2IwkwN4F9F X-Received: by 2002:a50:e443:: with SMTP id e3mr2049836edm.160.1606989610301; Thu, 03 Dec 2020 02:00:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606989610; cv=none; d=google.com; s=arc-20160816; b=lpwfzWMa9A2jQEBTuyfLEKqSDGx2aHv0B72cRIeh7ExN5m49OQ7VG3o6Qp4EnGzLTI CN6QCtP7oQU6r+vTAczYQZEdS6TZBROHr6pfVn7xdZIUEiltM670NRa6e35XvSUrHb2T +Fcja2HDcKRy3hRvOhqAN3hXnrbzgmdcyzGkRx6w4RyzS0VMMydxka5c6/dFXSXZN7Wn bh5jQ+C0al1pXBA04gU+4tk/dYYK8WpzxFo69JyWmVPRr8S6DBSA0mHswTXETkPQuetn 7GX1TgClqJc9NsknlWPiUC/DgAgrbMY0OH6RMS1wHrJU51hYmkeeohMTOe0OxIveTJvQ IqQg== 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=KEae06VwgJAS8rukqLeFJsuqwHEyuJ41dlqJjIxPQYM=; b=DtuRcdVFkgdeSeBfk6iyj19VtuUNPsrEoQzHcZAN14+sT3idHUSwsTdUL0nO9jwzvH 7ZZIZV/3yUB9L3jPeJcoDqhts4YdjqBwl2VhGrbg/v4GUnbRDn6Z+dKuzZceCAyirXkQ JDFiF922mOoi6ht7sScUE+tj6Aje9wbGfFPXDxv67/e+GTZafU8CVS8NSCbDjFqFBnvm +urSxiq8+VnvAuTpl21sYni5WQQR+uvjBwEOchqdEYfpGc0k6AOiedSbY3T+IOqbRQ/D HsGGf/9mU/avDiKS5seBKtF3EJHw+5w+MaPU10KQ1ys09s53O9Gz4b8nwHoH+uhfEbFp MEeA== 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 r16si760421ejz.602.2020.12.03.01.59.29; Thu, 03 Dec 2020 02:00:10 -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 S1729033AbgLCJ5W convert rfc822-to-8bit (ORCPT + 99 others); Thu, 3 Dec 2020 04:57:22 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:50723 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbgLCJ5W (ORCPT ); Thu, 3 Dec 2020 04:57:22 -0500 Received: from marcel-macbook.holtmann.net (unknown [37.83.193.87]) by mail.holtmann.org (Postfix) with ESMTPSA id 8B706CECF7; Thu, 3 Dec 2020 11:03:54 +0100 (CET) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.21\)) Subject: Re: [PATCH] Bluetooth: Cancel Inquiry before Create Connection From: Marcel Holtmann In-Reply-To: Date: Thu, 3 Dec 2020 10:56:39 +0100 Cc: BlueZ development , Abhishek Pandit-Subedi Content-Transfer-Encoding: 8BIT Message-Id: References: <20201124010906.340433-1-sonnysasaka@chromium.org> <92C0EFAB-EDF1-4EDB-ADE7-FF734928C8AE@holtmann.org> To: Sonny Sasaka X-Mailer: Apple Mail (2.3654.20.0.2.21) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sonny, >>> Many controllers do not allow HCI Create Connection while it is doing >>> Inquiry. This patch adds Inquiry Cancel before Create Connection in this >>> case to allow the controller to do Create Connection. User space will be >>> aware of this Inquiry cancellation and they may issue another discovery >>> request afterwards. >>> >>> Sample Command Disallowed response of HCI Create Connection: >>> < HCI Command: Inquiry (0x01|0x0001) plen 5 >>> Access code: 0x9e8b33 (General Inquiry) >>> Length: 10.24s (0x08) >>> Num responses: 0 >>>> HCI Event: Command Status (0x0f) plen 4 >>> Inquiry (0x01|0x0001) ncmd 2 >>> Status: Success (0x00) >>> < HCI Command: Create Connection (0x01|0x0005) plen 13 >>> Address: XX:XX:XX:XX:XX:XX >>> Packet type: 0xcc18 >>> Page scan repetition mode: R2 (0x02) >>> Page scan mode: Mandatory (0x00) >>> Clock offset: 0x0000 >>> Role switch: Allow slave (0x01) >>>> HCI Event: Command Status (0x0f) plen 4 >>> Create Connection (0x01|0x0005) ncmd 1 >>> Status: Success (0x00) >>>> HCI Event: Connect Complete (0x03) plen 11 >>> Status: Command Disallowed (0x0c) >>> Handle: 65535 >>> Address: XX:XX:XX:XX:XX:XX >>> Link type: ACL (0x01) >>> Encryption: Disabled (0x00) >>> >>> Reviewed-by: Abhishek Pandit-Subedi >>> Signed-off-by: Sonny Sasaka >>> >>> --- >>> net/bluetooth/hci_conn.c | 11 +++++++++++ >>> 1 file changed, 11 insertions(+) >>> >>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c >>> index 4f1cd8063e720..b41ad08f8d411 100644 >>> --- a/net/bluetooth/hci_conn.c >>> +++ b/net/bluetooth/hci_conn.c >>> @@ -233,6 +233,17 @@ static void hci_acl_create_connection(struct hci_conn *conn) >>> else >>> cp.role_switch = 0x00; >>> >>> + /* Many controllers disallow HCI Create Connection while it is doing >>> + * HCI Inquiry. So we cancel the Inquiry first before issuing HCI Create >>> + * Connection. This may cause the MGMT discovering state to become false >>> + * without user space's request but it is okay since the MGMT Discovery >>> + * APIs do not promise that discovery should be done forever. Instead, >>> + * the user space monitors the status of MGMT discovering and it may >>> + * request for discovery again when this flag becomes false. >>> + */ >>> + if (test_bit(HCI_INQUIRY, &hdev->flags)) >>> + hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL); >>> + >> >> while this seems acceptable, what happens when we have interleaved discovery where we toggle between BR/EDR inquiry and LE scanning. Are you sure we not better cancel the mgmt discovery completely. > Only Inquiry is preventing Create Connection, so we don't need to > overcomplicate it by stopping the mgmt discovery completely. In the > case of interleaved discovery, the LE discovery will linger for a > little bit before eventually being disabled and the situation restarts > at a good state. Not perfect but simple, clean, and fixes the issue. can we get a mgmt-tester test case for this that also checks the various combinations of this. And coming to think about it, should we mark controllers as “good” if they allow create connection and inquiry at the same time? So we do this conditionally based on what controller we have. Eventually we have to get to the level to create a proper state machine for BR/EDR and LE so that we serialize all of these commands accordingly. That way we can easily continue where we left off. This should also come in handy for any kind of suspend / resume handling. Since at the end of the day it is all the same problem. We need to pause some radio activity and continue afterwards. In case this wasn’t clear, I am not in favor of just sending a command and hope for the best. That got us in trouble with BlueZ 3.x and to large extend also with BlueZ 4.x since weird corner cases will bring us out of sync. Regards Marcel