Skip to contentSkip to conversation

device: Fix btd_device_connect_services not discovering

PATCH Applied Luiz Augusto von Dentz 3 participants 5 messages Apr 8 – Apr 9 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/3 device: Fix btd_device_connect_services not discovering

From: Luiz Augusto von Dentz <[email protected]>

btd_device_connect_services would not attempt to discover in case the selected bearer is BR/EDR and once discover is complete then it shall proceed with connecting the services.

---
 src/adapter.c |  9 ---------
 src/device.c  | 27 +++++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 11 deletions(-)
src/adapter.c +0 -9
index 04568dae6e98..46b89526fcaf 100644
@@ -3686,14 +3686,6 @@ struct device_connect_data {
 	DBusMessage *msg;
 };
 
-static void device_browse_cb(struct btd_device *dev, int err, void *user_data)
-{
-	DBG("err %d (%s)", err, strerror(-err));
-
-	if (!err)
-		btd_device_connect_services(dev, NULL);
-}
-
 static void device_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 {
 	struct device_connect_data *data = user_data;
@@ -3726,7 +3718,6 @@ static void device_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 	}
 
 	device_discover_services(device);
-	device_wait_for_svc_complete(device, device_browse_cb, NULL);
 
 	g_io_channel_unref(io);
 	dbus_message_unref(data->msg);
src/device.c +25 -2
index cfbde307bcc9..e762aea2797c 100644
@@ -2705,6 +2705,17 @@ static uint8_t select_conn_bearer(struct btd_device *dev)
 	return dev->bdaddr_type;
 }
 
+static void device_browse_cb(struct btd_device *dev, int err, void *user_data)
+{
+	DBG("err %d (%s)", err, strerror(-err));
+
+	/* If there are not errors with discovery proceed conecting services */
+	if (!err) {
+		dev->pending = create_pending_list(dev, NULL);
+		connect_next(dev);
+	}
+}
+
 int btd_device_connect_services(struct btd_device *dev, GSList *services)
 {
 	GSList *l;
@@ -2724,8 +2735,20 @@ int btd_device_connect_services(struct btd_device *dev, GSList *services)
 		return device_connect_le(dev);
 	}
 
-	if (!dev->bredr_state.svc_resolved)
-		return -ENOENT;
+	if (!dev->bredr_state.svc_resolved) {
+		int err;
+
+		err = device_discover_services(dev);
+		if (err)
+			return err;
+
+		/* Wait for service discovery to complete before connecting to
+		 * profiles.
+		 */
+		device_wait_for_svc_complete(dev, device_browse_cb, NULL);
+
+		return 0;
+	}
 
 	if (services) {
 		for (l = services; l; l = g_slist_next(l)) {
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v2 2/3 client: Prompt user to start scanning on connect command

From: Luiz Augusto von Dentz <[email protected]>

If connect command don't find the device object make it prompt the user to start scanning and set discovery filter pattern to given address and mark it to auto-connect:

[bluetoothctl]> connect XX:XX:XX:XX:XX:XX
Device XX:XX:XX:XX:XX:XX not available
[XX:XX:XX:XX:XX:XX] Scan and connect (yes,no): y
SetDiscoveryFilter success
Discovery started
[NEW] Device XX:XX:XX:XX:XX:XX
[NEW] BREDR /org/bluez/hci0/dev_XX:XX:XX:XX:XX:XX
[CHG] Device XX:XX:XX:XX:XX:XX Connected: yes
[CHG] BREDR XX:XX:XX:XX:XX:XX Connected: yes

---
 client/main.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
client/main.c +34 -1
index cb016a579f31..c04998bb0a9a 100644
@@ -2210,6 +2210,37 @@ static void connect_reply(DBusMessage *message, void *user_data)
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void prompt_scan_connect(const char *input, void *user_data)
+{
+	char *address = user_data;
+
+	if (!strcmp(input, "yes") || !strcmp(input, "y")) {
+		dbus_bool_t enable = TRUE;
+
+		free(filter.pattern);
+		filter.pattern = address;
+		filter.auto_connect = true;
+
+		filter.set = false;
+		set_discovery_filter(false);
+
+		if (!g_dbus_proxy_method_call(default_ctrl->proxy,
+						"StartDiscovery",
+						NULL, start_discovery_reply,
+						GUINT_TO_POINTER(enable),
+						NULL)) {
+			bt_shell_printf("Failed to start discovery\n");
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		return;
+	}
+
+	free(address);
+
+	return bt_shell_noninteractive_quit(EXIT_FAILURE);
+}
+
 static void cmd_connect(int argc, char *argv[])
 {
 	struct connection_data *data;
@@ -2223,7 +2254,9 @@ static void cmd_connect(int argc, char *argv[])
 	proxy = find_proxy_by_address(default_ctrl->devices, argv[1]);
 	if (!proxy) {
 		bt_shell_printf("Device %s not available\n", argv[1]);
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		bt_shell_prompt_input(argv[1], "Scan and connect (yes,no):",
+				      prompt_scan_connect, strdup(argv[1]));
+		return;
 	}
 
 	data = new0(struct connection_data, 1);
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH v2 3/3 client: Stop discovery when connected with filter.auto_connect

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

If device was connected via filter.auto_connect method (e.g. connect or scan.auto_connect) stop the discovery session after the device connects.

---
 client/main.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
client/main.c +22 -2
index c04998bb0a9a..57fa138880ed 100644
@@ -687,6 +687,14 @@ static GDBusProxy *find_proxies_by_path(GList *source, const char *path)
 	return NULL;
 }
 
+static bool filter_match_pattern(const char *pattern)
+{
+	if (!filter.active || !filter.pattern || !pattern)
+		return false;
+
+	return !strcmp(filter.pattern, pattern);
+}
+
 static void property_changed(GDBusProxy *proxy, const char *name,
 					DBusMessageIter *iter, void *user_data)
 {
@@ -699,12 +707,11 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 		if (default_ctrl && proxy_is_child(proxy,
 					default_ctrl->proxy) == TRUE) {
 			DBusMessageIter addr_iter;
+			const char *address = NULL;
 			char *str;
 
 			if (g_dbus_proxy_get_property(proxy, "Address",
 							&addr_iter) == TRUE) {
-				const char *address;
-
 				dbus_message_iter_get_basic(&addr_iter,
 								&address);
 				str = g_strdup_printf("[" COLORED_CHG
@@ -721,6 +728,19 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 					set_default_device(proxy, NULL);
 				else if (!connected && default_dev == proxy)
 					set_default_device(NULL, NULL);
+
+				/* If the device is connected and the filter
+				 * is auto_connect and it matches the pattern,
+				 * stop discovery.
+				 */
+				if (connected && filter.auto_connect &&
+						filter_match_pattern(address))
+					g_dbus_proxy_method_call(
+							default_ctrl->proxy,
+							"StopDiscovery",
+							NULL, NULL,
+							GUINT_TO_POINTER(false),
+							NULL);
 			}
 
 			print_iter(str, name, iter);
Signature · 1 line
2.53.0
#3 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1078829

---Test result---

Test Summary:

CheckPatch                    PENDING   0.33 seconds
GitLint                       PENDING   0.40 seconds
BuildEll                      PASS      20.33 seconds
BluezMake                     PASS      667.96 seconds
MakeCheck                     PASS      19.13 seconds
MakeDistcheck                 PASS      246.18 seconds
CheckValgrind                 PASS      293.08 seconds
CheckSmatch                   PASS      351.43 seconds
bluezmakeextell               PASS      182.70 seconds
IncrementalBuild              PENDING   0.32 seconds
ScanBuild                     PASS      1031.50 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

https://github.com/bluez/bluez/pull/2024/checks

---
Regards,
Linux Bluetooth

#4 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 9 lines · On Wed, 8 Apr 2026 14:22:21 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

btd_device_connect_services would not attempt to discover in case the selected bearer is BR/EDR and once discover is complete then it shall proceed with connecting the services.

---
 src/adapter.c |  9 ---------
 src/device.c  | 27 +++++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 11 deletions(-)

Here is the summary with links:
- [BlueZ,v2,1/3] device: Fix btd_device_connect_services not discovering

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=418306daec60
  - [BlueZ,v2,2/3] client: Prompt user to start scanning on connect command
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c8527a27723b
  - [BlueZ,v2,3/3] client: Stop discovery when connected with filter.auto_connect
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=44e54e39ae1a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html