From: Dylan MacKenzie <ecstaticmorse@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Dylan MacKenzie <ecstaticmorse@gmail.com>
Subject: [PATCH BlueZ 2/2] input/device: Only auto-reconnect on link loss
Date: Sat, 21 Nov 2026 12:58:35 -0800 [thread overview]
Message-ID: <20261121205835.381239-3-ecstaticmorse@gmail.com> (raw)
In-Reply-To: <20261121205835.381239-1-ecstaticmorse@gmail.com>
Commit 5cbdfbd83d66 ("input: Automatically attempt a reconnect when
required.") added a timer that pages a HID device every 30 seconds
for up to 3 minutes after its connection is closed, in order to
restore the connection of a device that "goes out of range and comes
back". The timer is armed whenever the interrupt channel is closed
though, including when the link was terminated on purpose.
This breaks devices which can be bonded to several hosts and expose
HID next to other profiles, such as earbuds with a head tracking
sensor (ReconnectMode "any"). When they move to another host they
disconnect with Remote User Terminated Connection:
> HCI Event: Disconnect Complete (0x05) plen 4
Status: Success (0x00)
Handle: 51
Reason: Remote User Terminated Connection (0x13)
and 30 seconds later bluetoothd connects HID again, which brings the
audio profiles back with it and takes the device away from the host
the user just switched to.
Check why the BR/EDR link ended and do not start the timer if it was
terminated by the remote device or by the local host. Other reasons,
including an unknown one, keep reconnecting as before.
Assisted-by: Claude:claude-fable-5-2
---
profiles/input/device.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 5b1be2b16..93d51be49 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -24,6 +24,7 @@
#include "bluetooth/bluetooth.h"
#include "bluetooth/hidp.h"
+#include "bluetooth/mgmt.h"
#include "bluetooth/sdp.h"
#include "bluetooth/sdp_lib.h"
#include "bluetooth/uuid.h"
@@ -1422,6 +1423,8 @@ static const char *reconnect_mode_to_string(const enum reconnect_mode_t mode)
static void input_device_enter_reconnect_mode(struct input_device *idev)
{
+ uint8_t reason;
+
DBG("path=%s reconnect_mode=%s", idev->path,
reconnect_mode_to_string(idev->reconnect_mode));
@@ -1443,6 +1446,21 @@ static void input_device_enter_reconnect_mode(struct input_device *idev)
btd_device_is_connected(idev->device))
return;
+ /* The host is only expected to restore a connection that was lost,
+ * e.g. because the device went out of range. Do not page a device
+ * that terminated the link on purpose, or that the host itself
+ * disconnected: devices which can be bonded to several hosts (e.g.
+ * earbuds exposing a HID sensor) would otherwise be pulled back from
+ * the host they just switched to.
+ */
+ reason = btd_device_get_disconnect_reason(idev->device, BDADDR_BREDR);
+ if (reason == MGMT_DEV_DISCONN_REMOTE ||
+ reason == MGMT_DEV_DISCONN_LOCAL_HOST) {
+ DBG("link terminated on purpose (reason %u), not reconnecting",
+ reason);
+ return;
+ }
+
if (idev->reconnect_timer > 0)
timeout_remove(idev->reconnect_timer);
--
2.56.0
prev parent reply other threads:[~2026-11-21 20:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 20:58 [PATCH BlueZ 0/2] input: Do not re-page HID devices that disconnected on purpose Dylan MacKenzie
2026-11-21 20:58 ` [PATCH BlueZ 1/2] device: Add btd_device_get_disconnect_reason Dylan MacKenzie
2026-11-21 23:18 ` input: Do not re-page HID devices that disconnected on purpose bluez.test.bot
2026-11-21 20:58 ` Dylan MacKenzie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121205835.381239-3-ecstaticmorse@gmail.com \
--to=ecstaticmorse@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox