Commit f712bde1 authored by Pavel Vasilyev's avatar Pavel Vasilyev Committed by Anas Nashif
Browse files

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: default avatarPavel Vasilyev <pavel.vasilyev@nordicsemi.no>
parent 9487952a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -274,6 +274,19 @@ over LE connections. A more detailed description of this layer and the
API reference can be found in the
:ref:`GATT API reference section <bt_gatt>`.

ATT timeout
-----------

If the peer device does not respond to an ATT request (such as read or write)
within the ATT timeout, the host will automatically initiate a disconnect. This
simplifies error handling by reducing rare failure conditions to a common
disconnection, allowing developers to manage unexpected disconnects without
special cases for ATT timeouts.

.. image:: img/att_timeout.svg
  :align: center
  :alt: ATT timeout

Mesh
====

+0 −0

File added.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,8 @@ Bluetooth
  * Added API :c:func:`bt_gatt_get_uatt_mtu` to get current Unenhanced ATT MTU of a given
    connection (experimental).

  * The host now disconnects from the peer upon ATT timeout.

* HCI Drivers

Boards & SoC Support
+12 −1
Original line number Diff line number Diff line
@@ -3135,9 +3135,10 @@ static void att_timeout(struct k_work *work)
	struct k_work_delayable *dwork = k_work_delayable_from_work(work);
	struct bt_att_chan *chan = CONTAINER_OF(dwork, struct bt_att_chan,
						timeout_work);
	int err;

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

	/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 480:
	 *
@@ -3148,6 +3149,16 @@ static void att_timeout(struct k_work *work)
	 * target device on this ATT Bearer.
	 */
	bt_att_disconnected(&chan->chan.chan);

	/* 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, allowing developers
	 * to handle unexpected disconnections without needing special cases for ATT timeouts.
	 */
	err = bt_conn_disconnect(chan->chan.chan.conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
	if (err) {
		LOG_ERR("Disconnecting failed (err %d)", err);
	}
}

static struct bt_att_chan *att_get_fixed_chan(struct bt_conn *conn)