Skip to content

Commit 723ca15

Browse files
PavelVPVrlubos
authored andcommitted
[nrf fromtree] bluetooth: host: att: Implement disconnect on ATT timeout
The timeout state is local and can block new ATT operations, but does not affect the remote side. Disconnecting the GATT connection upon ATT timeout simplifies error handling for developers. This reduces rare failure conditions to a common one, without needing special cases for ATT timeouts. Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit f712bde)
1 parent d2db838 commit 723ca15

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

doc/connectivity/bluetooth/bluetooth-le-host.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,19 @@ over LE connections. A more detailed description of this layer and the
274274
API reference can be found in the
275275
:ref:`GATT API reference section <bt_gatt>`.
276276

277+
ATT timeout
278+
-----------
279+
280+
If the peer device does not respond to an ATT request (such as read or write)
281+
within the ATT timeout, the host will automatically initiate a disconnect. This
282+
simplifies error handling by reducing rare failure conditions to a common
283+
disconnection, allowing developers to manage unexpected disconnects without
284+
special cases for ATT timeouts.
285+
286+
.. image:: img/att_timeout.svg
287+
:align: center
288+
:alt: ATT timeout
289+
277290
Mesh
278291
====
279292

doc/connectivity/bluetooth/img/att_timeout.svg

Lines changed: 1 addition & 0 deletions
Loading

doc/releases/release-notes-4.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Bluetooth
9696
* Added API :c:func:`bt_gatt_get_uatt_mtu` to get current Unenhanced ATT MTU of a given
9797
connection (experimental).
9898

99+
* The host now disconnects from the peer upon ATT timeout.
100+
99101
* HCI Drivers
100102

101103
Boards & SoC Support

subsys/bluetooth/host/att.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3150,9 +3150,10 @@ static void att_timeout(struct k_work *work)
31503150
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
31513151
struct bt_att_chan *chan = CONTAINER_OF(dwork, struct bt_att_chan,
31523152
timeout_work);
3153+
int err;
31533154

31543155
bt_addr_le_to_str(bt_conn_get_dst(chan->att->conn), addr, sizeof(addr));
3155-
LOG_ERR("ATT Timeout for device %s", addr);
3156+
LOG_ERR("ATT Timeout for device %s. Disconnecting...", addr);
31563157

31573158
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 480:
31583159
*
@@ -3163,6 +3164,16 @@ static void att_timeout(struct k_work *work)
31633164
* target device on this ATT Bearer.
31643165
*/
31653166
bt_att_disconnected(&chan->chan.chan);
3167+
3168+
/* The timeout state is local and can block new ATT operations, but does not affect the
3169+
* remote side. Disconnecting the GATT connection upon ATT timeout simplifies error handling
3170+
* for developers. This reduces rare failure conditions to a common one, allowing developers
3171+
* to handle unexpected disconnections without needing special cases for ATT timeouts.
3172+
*/
3173+
err = bt_conn_disconnect(chan->chan.chan.conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
3174+
if (err) {
3175+
LOG_ERR("Disconnecting failed (err %d)", err);
3176+
}
31663177
}
31673178

31683179
static struct bt_att_chan *att_get_fixed_chan(struct bt_conn *conn)

0 commit comments

Comments
 (0)