Skip to content

Commit b7fafbc

Browse files
RyuzakiKKVudentz
authored andcommitted
Bluetooth: hci_event: Mark connection as closed during suspend disconnect
When suspending, the disconnect command for an active Bluetooth connection could be issued, but the corresponding `HCI_EV_DISCONN_COMPLETE` event might not be received before the system completes the suspend process. This can lead to an inconsistent state. On resume, the controller may auto-accept reconnections from the same device (due to suspend event filters), but these new connections are rejected by the kernel which still has connection objects from before suspend. Resulting in errors like: ``` kernel: Bluetooth: hci0: ACL packet for unknown connection handle 1 kernel: Bluetooth: hci0: Ignoring HCI_Connection_Complete for existing connection ``` This is a btmon snippet that shows the issue: ``` < HCI Command: Disconnect (0x01|0x0006) plen 3 Handle: 1 Address: 78:20:A5:4A:DF:28 (Nintendo Co.,Ltd) Reason: Remote User Terminated Connection (0x13) > HCI Event: Command Status (0x0f) plen 4 Disconnect (0x01|0x0006) ncmd 2 Status: Success (0x00) [...] // Host suspends with the event filter set for the device // On resume, the device tries to reconnect with a new handle > HCI Event: Connect Complete (0x03) plen 11 Status: Success (0x00) Handle: 2 Address: 78:20:A5:4A:DF:28 (Nintendo Co.,Ltd) // Kernel ignores this event because there is an existing connection with // handle 1 ``` By explicitly setting the connection state to BT_CLOSED we can ensure a consistent state, even if we don't receive the disconnect complete event in time. Link: bluez/bluez#1226 Fixes: 182ee45 ("Bluetooth: hci_sync: Rework hci_suspend_notifier") Signed-off-by: Ludovico de Nittis <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 2f050a5 commit b7fafbc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/bluetooth/hci_event.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,12 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
27182718
goto done;
27192719
}
27202720

2721+
/* During suspend, mark connection as closed immediately
2722+
* since we might not receive HCI_EV_DISCONN_COMPLETE
2723+
*/
2724+
if (hdev->suspended)
2725+
conn->state = BT_CLOSED;
2726+
27212727
mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags);
27222728

27232729
if (conn->type == ACL_LINK) {

0 commit comments

Comments
 (0)