public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] Bluetooth: Increase LE connection timeout for industrial sensors
@ 2026-03-02 23:37 Dajid MOREL
  2026-03-03  0:11 ` [v4] " bluez.test.bot
  2026-03-03 17:24 ` [PATCH v4] " Luiz Augusto von Dentz
  0 siblings, 2 replies; 22+ messages in thread
From: Dajid MOREL @ 2026-03-02 23:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Dajid MOREL

In an industrial IoT context at Volvo Group, we use TE Connectivity
BLE pressure sensors. These sensors exhibit high latency during
the initial LE connection handshake in noisy RF environments. The
connection systematically fails on Ubuntu Core 22 (BlueZ) because the
connection attempt is aborted too early.

In the v2 thread, it was suggested that userspace (via setsockopt
SO_SNDTIMEO) dictates the connection timeout (defaulting to 40s),
suspecting that userspace was cutting the connection at 2 seconds,
not the kernel.

To verify this, an empirical test was conducted using the following
Python/Bleak script to force the application timeout to 45.0 seconds:

  import asyncio
  from bleak import BleakClient, BleakScanner
  import time

  ADDRESS = "E8:C0:B1:D4:A3:3C"

  async def test_connection():
      device = await BleakScanner.find_device_by_address(ADDRESS, timeout=15.0)
      start_time = time.time()
      try:
          # Forcing 45s timeout in userspace
          async with BleakClient(device, timeout=45.0) as client:
              print(f"Connected in {time.time() - start_time:.2f}s")
      except Exception as e:
          print(f"Failed after {time.time() - start_time:.2f}s: {e}")

  asyncio.run(test_connection())

1. Result on UNMODIFIED Kernel: The userspace script patiently waited
   for the full 45 seconds before raising a TimeoutError. If the kernel
   had actually kept the radio connection attempt alive for those
   45 seconds, the connection would have succeeded around the
   12.5-second mark (as proven by the patched kernel test below).
   The fact that it did not proves that the underlying HCI connection
   attempt was aborted early by the kernel. Userspace was blind to this
   abort and kept waiting in a vacuum.

2. Result on MODIFIED Kernel (with this patch): Using the exact same
   userspace script (45.0s timeout), the connection successfully
   established at the 12.51-second mark.

Conclusion:
This proves that the underlying HCI LE Connection creation is bound by
a strict 2-second timeout derived from `conn_timeout` in `hci_conn.c`,
and that userspace socket options do not override this hardcoded HCI
abort in our stack. The sensor physically takes 12.5 seconds to
handshake, making the 2-second kernel limit a hard blocker.

This patch increases the hardcoded LE connection timeout to 20 seconds
to provide a comfortable margin for handshake retries.

Note: If the upstream preference is to not hardcode 20 seconds globally,
I would be happy to submit a v5 that exposes this as a configurable
module parameter (e.g., `le_conn_timeout`).
---
 net/bluetooth/hci_conn.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index a47f5daffdbf..7edce4126900 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1436,7 +1436,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 	}
 
 	conn->sec_level = BT_SECURITY_LOW;
-	conn->conn_timeout = conn_timeout;
+	conn->conn_timeout = msecs_to_jiffies(20000);
 	conn->le_adv_phy = phy;
 	conn->le_adv_sec_phy = sec_phy;
 
@@ -1664,7 +1664,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
 	set_bit(HCI_CONN_SCANNING, &conn->flags);
 	conn->sec_level = BT_SECURITY_LOW;
 	conn->pending_sec_level = sec_level;
-	conn->conn_timeout = conn_timeout;
+	conn->conn_timeout = msecs_to_jiffies(20000);
 	conn->conn_reason = conn_reason;
 
 	hci_update_passive_scan(hdev);
-- 
2.34.1


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

end of thread, other threads:[~2026-03-10 17:43 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 23:37 [PATCH v4] Bluetooth: Increase LE connection timeout for industrial sensors Dajid MOREL
2026-03-03  0:11 ` [v4] " bluez.test.bot
2026-03-03 17:24 ` [PATCH v4] " Luiz Augusto von Dentz
2026-03-03 18:57   ` Dajid Morel
2026-03-03 19:26     ` Luiz Augusto von Dentz
2026-03-03 20:30       ` Dajid Morel
2026-03-03 21:12         ` Luiz Augusto von Dentz
2026-03-06  7:15           ` Dajid Morel
2026-03-06 14:26             ` Luiz Augusto von Dentz
     [not found]               ` <CAM8DPm2z-6xUm3SyFJ9umn4=o9bBov6PhKV0TEDCBc14eMFSew@mail.gmail.com>
2026-03-06 15:57                 ` Luiz Augusto von Dentz
2026-03-06 17:54                   ` Dajid Morel
2026-03-06 18:20                     ` Dajid Morel
2026-03-06 18:27                     ` Luiz Augusto von Dentz
2026-03-09 10:02                       ` Dajid Morel
2026-03-09 16:02                         ` Paul Menzel
2026-03-09 17:37                           ` Dajid Morel
2026-03-09 18:03                             ` Luiz Augusto von Dentz
2026-03-10 13:10                               ` Dajid Morel
2026-03-10 13:47                                 ` Luiz Augusto von Dentz
2026-03-10 14:04                                   ` Paul Menzel
2026-03-10 14:19                                     ` Luiz Augusto von Dentz
2026-03-10 17:42                                       ` Dajid Morel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox