Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH bluez] gatt-client: Fix not emitting MTU on reconnection
@ 2026-11-14 15:09 Nebojša Cvetković via B4 Relay
  2026-11-14 17:00 ` [bluez] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Nebojša Cvetković via B4 Relay @ 2026-11-14 15:09 UTC (permalink / raw)
  To: Linux Bluetooth; +Cc: Nebojša Cvetković

From: Nebojša Cvetković <nebkat@gmail.com>

Characteristics kept across a disconnection have their MTU exchange
callback registered on the bt_att of the connection they were created
on, so no PropertiesChanged is emitted for MTU on later connections. As
MTU is omitted while disconnected, a client that enumerated the objects
in between has no MTU for the whole connection, and one that kept them
has the value of the previous connection.

Register the callback on the bt_att of the new connection, and emit MTU
as it is no longer omitted.

Fixes: 3a6b5f5ec14c ("gatt: Emit PropertiesChanged("MTU") when MTU is exchanged")
Assisted-by: Claude:claude-opus-5-5
---
Signed-off-by: Nebojša Cvetković <nebkat@gmail.com>
---
 src/gatt-client.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index d94dc9d..2d58ee2 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -2414,9 +2414,29 @@ void btd_gatt_client_eatt_connect(struct btd_gatt_client *client)
 	}
 }
 
+static void characteristic_attach_att(void *data, void *user_data)
+{
+	struct characteristic *chrc = data;
+	struct bt_att *att = user_data;
+
+	chrc->exchange_id = bt_att_register_exchange(att, att_exchange, chrc,
+									NULL);
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), chrc->path,
+					GATT_CHARACTERISTIC_IFACE, "MTU");
+}
+
+static void service_attach_att(void *data, void *user_data)
+{
+	struct service *service = data;
+
+	queue_foreach(service->chrcs, characteristic_attach_att, user_data);
+}
+
 void btd_gatt_client_connected(struct btd_gatt_client *client)
 {
 	struct bt_gatt_client *gatt;
+	struct bt_att *att;
 
 	gatt = btd_device_get_gatt_client(client->device);
 	if (!gatt) {
@@ -2429,6 +2449,15 @@ void btd_gatt_client_connected(struct btd_gatt_client *client)
 	bt_gatt_client_unref(client->gatt);
 	client->gatt = bt_gatt_client_clone(gatt);
 
+	/*
+	 * Characteristics kept from a previous connection have their exchange
+	 * callback registered on its bt_att, and MTU was omitted while
+	 * disconnected, so register them again and emit MTU.
+	 */
+	att = bt_gatt_client_get_att(client->gatt);
+	if (att)
+		queue_foreach(client->services, service_attach_att, att);
+
 	/*
 	 * Services have already been created before. Re-enable notifications
 	 * for any pre-registered notification sessions.

---
base-commit: 20ffd285b58facfd1f2478d159a5f941b09d5be1
change-id: 20261114-gatt-client-mtu-reconnect-125381776960

Best regards,
--  
Nebojša Cvetković <nebkat@gmail.com>



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

end of thread, other threads:[~2026-11-14 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 15:09 [PATCH bluez] gatt-client: Fix not emitting MTU on reconnection Nebojša Cvetković via B4 Relay
2026-11-14 17:00 ` [bluez] " bluez.test.bot

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