2020-12-09 21:38:33

by Sonny Sasaka

[permalink] [raw]
Subject: [PATCH v2] Bluetooth: Cancel Inquiry before Create Connection

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 <[email protected]>
Reviewed-by: Alain Michaud <[email protected]>
Signed-off-by: Sonny Sasaka <[email protected]>

---
net/bluetooth/hci_conn.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 4f1cd8063e720..23c0d77ea7370 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -203,6 +203,23 @@ static void hci_acl_create_connection(struct hci_conn *conn)

BT_DBG("hcon %p", conn);

+ /* 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)) {
+ /* Put this connection to "pending" state so that it will be
+ * executed after the inquiry cancel command complete event.
+ */
+ conn->state = BT_CONNECT2;
+ hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
+ return;
+ }
+
conn->state = BT_CONNECT;
conn->out = true;
conn->role = HCI_ROLE_MASTER;
--
2.26.2


2020-12-09 22:04:14

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v2] Bluetooth: Cancel Inquiry before Create Connection

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=399287

---Test result---

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

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

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



---
Regards,
Linux Bluetooth

2020-12-18 21:49:34

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: Cancel Inquiry before Create Connection

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 <[email protected]>
> Reviewed-by: Alain Michaud <[email protected]>
> Signed-off-by: Sonny Sasaka <[email protected]>
>
> ---
> net/bluetooth/hci_conn.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel