Linux bluetooth development
 help / color / mirror / Atom feed
From: Kevin Dewald <kevin@simpleble.org>
To: linux-bluetooth@vger.kernel.org
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Kevin Dewald <kevin@simpleble.org>
Subject: [PATCH BlueZ 1/2] device: Add functions to pause and resume auto-connect
Date: Fri,  6 Nov 2026 17:56:48 -0800	[thread overview]
Message-ID: <20261107015649.84892-2-kevin@simpleble.org> (raw)
In-Reply-To: <20261107015649.84892-1-kevin@simpleble.org>

Device1.Disconnect takes a device that is not trusted out of the
auto-connect list, and Device1.Connect and Device1.Pair put it back.
This moves both into functions, so that the LE bearer can do the same.

Assisted-by: Claude:claude-opus-5.5
---
 src/device.c | 42 +++++++++++++++++++++++++-----------------
 src/device.h |  2 ++
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/device.c b/src/device.c
index 6d1e78b0e..36a980d1e 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2369,19 +2369,34 @@ static void device_set_auto_connect(struct btd_device *device, gboolean enable)
 	adapter_connect_list_add(device->adapter, device);
 }
 
+/*
+ * If device is not trusted disable connections through passive scanning
+ * until Connect is called
+ */
+void device_pause_auto_connect(struct btd_device *device)
+{
+	if (!device->auto_connect || device->trusted)
+		return;
+
+	device->disable_auto_connect = TRUE;
+	device_set_auto_connect(device, FALSE);
+}
+
+void device_resume_auto_connect(struct btd_device *device)
+{
+	if (!device->disable_auto_connect)
+		return;
+
+	device->disable_auto_connect = FALSE;
+	device_set_auto_connect(device, TRUE);
+}
+
 static DBusMessage *dev_disconnect(DBusConnection *conn, DBusMessage *msg,
 							void *user_data)
 {
 	struct btd_device *device = user_data;
 
-	/*
-	 * If device is not trusted disable connections through passive
-	 * scanning until Device1.Connect is called
-	 */
-	if (device->auto_connect && !device->trusted) {
-		device->disable_auto_connect = TRUE;
-		device_set_auto_connect(device, FALSE);
-	}
+	device_pause_auto_connect(device);
 
 	device_request_disconnect(device, msg);
 
@@ -2926,11 +2941,7 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
 			return dbus_message_new_method_return(msg);
 
 		btd_device_set_temporary(dev, false);
-
-		if (dev->disable_auto_connect) {
-			dev->disable_auto_connect = FALSE;
-			device_set_auto_connect(dev, TRUE);
-		}
+		device_resume_auto_connect(dev);
 
 		err = device_connect_le(dev);
 		if (err < 0)
@@ -3480,10 +3491,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 	 * this in the ATT connect callback)
 	 */
 	if (bdaddr_type != BDADDR_BREDR) {
-		if (device->disable_auto_connect) {
-			device->disable_auto_connect = FALSE;
-			device_set_auto_connect(device, TRUE);
-		}
+		device_resume_auto_connect(device);
 
 		if (!state->connected && btd_le_connect_before_pairing())
 			err = device_connect_le(device);
diff --git a/src/device.h b/src/device.h
index 6756cb3ab..047a894c3 100644
--- a/src/device.h
+++ b/src/device.h
@@ -206,6 +206,8 @@ void btd_device_set_pnpid(struct btd_device *device, uint16_t source,
 			uint16_t vendor, uint16_t product, uint16_t version);
 
 int device_connect_le(struct btd_device *dev);
+void device_pause_auto_connect(struct btd_device *device);
+void device_resume_auto_connect(struct btd_device *device);
 
 DBusMessage *device_connect_profiles(struct btd_device *dev,
 		uint8_t bdaddr_type, DBusMessage *msg, const char *uuid);
-- 
2.54.0 (Apple Git-157)


  reply	other threads:[~2026-11-07  1:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  1:56 [PATCH BlueZ 0/2] bearer: Fix auto-connect handling of LE Connect and Disconnect Kevin Dewald
2026-11-07  1:56 ` Kevin Dewald [this message]
2026-11-07  8:43   ` bluez.test.bot
2026-11-07  1:56 ` [PATCH BlueZ 2/2] bearer: Fix LE Connect and Disconnect ignoring auto-connect Kevin Dewald
2026-11-09 16:00 ` [PATCH BlueZ 0/2] bearer: Fix auto-connect handling of LE Connect and Disconnect patchwork-bot+bluetooth

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=20261107015649.84892-2-kevin@simpleble.org \
    --to=kevin@simpleble.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /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