Linux-Bluetooth Archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event
@ 2023-08-23 12:52 Xin-Yu Liu
  2023-08-23 13:14 ` bluez.test.bot
  2023-08-23 21:26 ` [PATCH] " Luiz Augusto von Dentz
  0 siblings, 2 replies; 4+ messages in thread
From: Xin-Yu Liu @ 2023-08-23 12:52 UTC (permalink / raw
  To: marcel, johan.hedberg, luiz.dentz
  Cc: baijiaju, sy2239101, linux-bluetooth, linux-kernel, Xin-Yu Liu

During a connection attempt, if the HCI_Connection_Complete event
is lost and not received by the Host, it will result in
a connection failure.

In that process, the hci_conn, the handle of which is still
HCI_CONN_HANDLE_UNSET, will not be removed from the conn_hash
as it would during a regular disconnection opration.
Consequently, when an ACL connection is initiated for the same device,
the hci_conn is found in hash_conn based on "ba", with its state remaining
BT_CONNECT. Then the Host will send an HCI_Create_Connection_Cancel 
command, which will result in subsequent Bluetooth connections 
for the same device consistently failing.

In order to solve the potential bug, if the hci_conn's state is
BT_CONNECT and handle is HCI_CONN_HANDLE_UNSET, remove this hci_conn
from conn_hash. This adjustment could potentially help ensure that the
specific conn is cleaned up at the appropriate times, then the subsequent
connection for the same device will no longer experience failures.

Signed-off-by: Xin-Yu Liu <by2239112@buaa.edu.cn>
---
 net/bluetooth/hci_conn.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 76222565e..219c62579 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -2886,6 +2886,10 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
 		} else if (conn->type == ACL_LINK) {
 			if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2)
 				break;
+			if (conn->state == HCI_CONN_HANDLE_UNSET) {
+				hci_conn_cleanup(conn);
+				break;
+			}
 			r = hci_send_cmd(conn->hdev,
 					 HCI_OP_CREATE_CONN_CANCEL,
 					 6, &conn->dst);
-- 
2.25.1


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

* RE: net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event
  2023-08-23 12:52 [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event Xin-Yu Liu
@ 2023-08-23 13:14 ` bluez.test.bot
  2023-08-23 21:26 ` [PATCH] " Luiz Augusto von Dentz
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2023-08-23 13:14 UTC (permalink / raw
  To: linux-bluetooth, by2239112

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

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: patch failed: net/bluetooth/hci_conn.c:2886
error: net/bluetooth/hci_conn.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.


---
Regards,
Linux Bluetooth


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

* Re: [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event
  2023-08-23 12:52 [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event Xin-Yu Liu
  2023-08-23 13:14 ` bluez.test.bot
@ 2023-08-23 21:26 ` Luiz Augusto von Dentz
  2023-08-25 14:13   ` Xin-Yu Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2023-08-23 21:26 UTC (permalink / raw
  To: Xin-Yu Liu
  Cc: marcel, johan.hedberg, baijiaju, sy2239101, linux-bluetooth,
	linux-kernel

Hi,

On Wed, Aug 23, 2023 at 5:52 AM Xin-Yu Liu <by2239112@buaa.edu.cn> wrote:
>
> During a connection attempt, if the HCI_Connection_Complete event
> is lost and not received by the Host, it will result in
> a connection failure.
>
> In that process, the hci_conn, the handle of which is still
> HCI_CONN_HANDLE_UNSET, will not be removed from the conn_hash
> as it would during a regular disconnection opration.
> Consequently, when an ACL connection is initiated for the same device,
> the hci_conn is found in hash_conn based on "ba", with its state remaining
> BT_CONNECT. Then the Host will send an HCI_Create_Connection_Cancel
> command, which will result in subsequent Bluetooth connections
> for the same device consistently failing.
>
> In order to solve the potential bug, if the hci_conn's state is
> BT_CONNECT and handle is HCI_CONN_HANDLE_UNSET, remove this hci_conn
> from conn_hash. This adjustment could potentially help ensure that the
> specific conn is cleaned up at the appropriate times, then the subsequent
> connection for the same device will no longer experience failures.
>
> Signed-off-by: Xin-Yu Liu <by2239112@buaa.edu.cn>
> ---
>  net/bluetooth/hci_conn.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 76222565e..219c62579 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -2886,6 +2886,10 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
>                 } else if (conn->type == ACL_LINK) {
>                         if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2)
>                                 break;
> +                       if (conn->state == HCI_CONN_HANDLE_UNSET) {
> +                               hci_conn_cleanup(conn);
> +                               break;
> +                       }

This won't apply upstream if you are wondering why CI hasn't managed
to pick it up, this should be fixed by the following line if
connection cannot be aborted:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_sync.c?id=c452805643ff9762626f2c87c2640ab7c7099eb8#n5432

>                         r = hci_send_cmd(conn->hdev,
>                                          HCI_OP_CREATE_CONN_CANCEL,
>                                          6, &conn->dst);
> --
> 2.25.1
>


-- 
Luiz Augusto von Dentz

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

* Re: [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event
  2023-08-23 21:26 ` [PATCH] " Luiz Augusto von Dentz
@ 2023-08-25 14:13   ` Xin-Yu Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Xin-Yu Liu @ 2023-08-25 14:13 UTC (permalink / raw
  To: Luiz Augusto von Dentz, Xin-Yu Liu
  Cc: marcel, johan.hedberg, baijiaju, sy2239101, linux-bluetooth,
	linux-kernel

Hi,

Thanks for your reply!

After receiving your guidance, we implement the code changes you
provided to us and find that the bug has indeed been resolved.

Thank you for your time, support, and for sharing your knowledge.
We look forward to continuing our involvement in the Linux community
and hope to contribute positively, just as you have done.

Best regards,
Xin-Yu Liu

2023/8/24 5:26, Luiz Augusto von Dentz wrote:
> Hi,
>
> On Wed, Aug 23, 2023 at 5:52 AM Xin-Yu Liu <by2239112@buaa.edu.cn> wrote:
>> During a connection attempt, if the HCI_Connection_Complete event
>> is lost and not received by the Host, it will result in
>> a connection failure.
>> In that process, the hci_conn, the handle of which is still
>> HCI_CONN_HANDLE_UNSET, will not be removed from the conn_hash
>> as it would during a regular disconnection opration.
>> Consequently, when an ACL connection is initiated for the same device,
>> the hci_conn is found in hash_conn based on "ba", with its state remaining
>> BT_CONNECT. Then the Host will send an HCI_Create_Connection_Cancel
>> command, which will result in subsequent Bluetooth connections
>> for the same device consistently failing.
>>
>> In order to solve the potential bug, if the hci_conn's state is
>> BT_CONNECT and handle is HCI_CONN_HANDLE_UNSET, remove this hci_conn
>> from conn_hash. This adjustment could potentially help ensure that the
>> specific conn is cleaned up at the appropriate times, then the subsequent
>> connection for the same device will no longer experience failures.
>>
>> Signed-off-by: Xin-Yu Liu <by2239112@buaa.edu.cn>
>> ---
>>   net/bluetooth/hci_conn.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
>> index 76222565e..219c62579 100644
>> --- a/net/bluetooth/hci_conn.c
>> +++ b/net/bluetooth/hci_conn.c
>> @@ -2886,6 +2886,10 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
>>                  } else if (conn->type == ACL_LINK) {
>>                          if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2)
>>                                  break;
>> +                       if (conn->state == HCI_CONN_HANDLE_UNSET) {
>> +                               hci_conn_cleanup(conn);
>> +                               break;
>> +                       }
> This won't apply upstream if you are wondering why CI hasn't managed
> to pick it up, this should be fixed by the following line if
> connection cannot be aborted:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_sync.c?id=c452805643ff9762626f2c87c2640ab7c7099eb8#n5432
>
>>                          r = hci_send_cmd(conn->hdev,
>>                                           HCI_OP_CREATE_CONN_CANCEL,
>>                                           6, &conn->dst);
>> --
>> 2.25.1
>>
>


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

end of thread, other threads:[~2023-08-25 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23 12:52 [PATCH] net: bluetooth: fix consistent connection failure caused by the loss of HCI_Connection_Complete event Xin-Yu Liu
2023-08-23 13:14 ` bluez.test.bot
2023-08-23 21:26 ` [PATCH] " Luiz Augusto von Dentz
2023-08-25 14:13   ` Xin-Yu Liu

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 read-only IMAP folder(s) and NNTP newsgroup(s).