* [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter
@ 2025-05-22 17:29 Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 2/4] adapter: Implement SetFilterPolicy AutoConnect filter Luiz Augusto von Dentz
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-05-22 17:29 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds AutoConnect filter option to SetDiscoveryFilter which can be
used by application to automatically connect devices found matching a
pattern.
---
doc/org.bluez.Adapter.rst | 42 ++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/doc/org.bluez.Adapter.rst b/doc/org.bluez.Adapter.rst
index 021e4f8e5a9f..c5b8ed8e9132 100644
--- a/doc/org.bluez.Adapter.rst
+++ b/doc/org.bluez.Adapter.rst
@@ -150,29 +150,35 @@ void SetDiscoveryFilter(dict filter)
that don't set any pattern as it work as a logical OR, also
setting empty string "" pattern will match any device found.
- When discovery filter is set, Device objects will be created as
- new devices with matching criteria are discovered regardless of
- they are connectable or discoverable which enables listening to
- non-connectable and non-discoverable devices.
+ :bool AutoConnect (Default false):
- When multiple clients call SetDiscoveryFilter, their filters are
- internally merged, and notifications about new devices are sent
- to all clients. Therefore, each client must check that device
- updates actually match its filter.
+ Connect to discovered devices automatically if a Pattern has
+ been set and it matches the device address or name and it is
+ connectable.
- When SetDiscoveryFilter is called multiple times by the same
- client, last filter passed will be active for given client.
+ When discovery filter is set, Device objects will be created as new
+ devices with matching criteria are discovered regardless of they are
+ connectable or discoverable which enables listening to non-connectable
+ and non-discoverable devices.
- SetDiscoveryFilter can be called before StartDiscovery.
- It is useful when client will create first discovery session,
- to ensure that proper scan will be started right after call to
- StartDiscovery.
+ When multiple clients call SetDiscoveryFilter, their filters are
+ internally merged, and notifications about new devices are sent to all
+ clients. Therefore, each client must check that device updates actually
+ match its filter.
- Possible errors:
+ When SetDiscoveryFilter is called multiple times by the same client,
+ last filter passed will be active for given client.
- :org.bluez.Error.NotReady:
- :org.bluez.Error.NotSupported:
- :org.bluez.Error.Failed:
+ SetDiscoveryFilter can be called before StartDiscovery.
+ It is useful when client will create first discovery session,
+ to ensure that proper scan will be started right after call to
+ StartDiscovery.
+
+ Possible errors:
+
+ :org.bluez.Error.NotReady:
+ :org.bluez.Error.NotSupported:
+ :org.bluez.Error.Failed:
array{string} GetDiscoveryFilters()
```````````````````````````````````
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ v1 2/4] adapter: Implement SetFilterPolicy AutoConnect filter
2025-05-22 17:29 [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter Luiz Augusto von Dentz
@ 2025-05-22 17:29 ` Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 3/4] client: Add scan.auto-connect command Luiz Augusto von Dentz
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-05-22 17:29 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This implements AutoConnect filter option in SetFilterPolicy method
according to its documentation.
---
src/adapter.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index fd425e6d2fe4..328a6baa54d7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -214,6 +214,7 @@ struct discovery_filter {
GSList *uuids;
bool duplicate;
bool discoverable;
+ bool auto_connect;
};
struct discovery_client {
@@ -2697,6 +2698,21 @@ static bool parse_pattern(DBusMessageIter *value,
return true;
}
+static bool parse_auto_connect(DBusMessageIter *value,
+ struct discovery_filter *filter)
+{
+ dbus_bool_t connect;
+
+ if (dbus_message_iter_get_arg_type(value) != DBUS_TYPE_BOOLEAN)
+ return false;
+
+ dbus_message_iter_get_basic(value, &connect);
+
+ filter->auto_connect = connect;
+
+ return true;
+}
+
struct filter_parser {
const char *name;
bool (*func)(DBusMessageIter *iter, struct discovery_filter *filter);
@@ -2708,6 +2724,7 @@ struct filter_parser {
{ "DuplicateData", parse_duplicate_data },
{ "Discoverable", parse_discoverable },
{ "Pattern", parse_pattern },
+ { "AutoConnect", parse_auto_connect },
{ }
};
@@ -7212,7 +7229,7 @@ static void filter_duplicate_data(void *data, void *user_data)
static bool device_is_discoverable(struct btd_adapter *adapter,
struct eir_data *eir, const char *addr,
- uint8_t bdaddr_type)
+ uint8_t bdaddr_type, bool *auto_connect)
{
GSList *l;
bool discoverable;
@@ -7242,15 +7259,21 @@ static bool device_is_discoverable(struct btd_adapter *adapter,
discoverable = false;
pattern_len = strlen(filter->pattern);
- if (!pattern_len)
+ if (!pattern_len) {
+ *auto_connect = filter->auto_connect;
return true;
+ }
- if (!strncmp(filter->pattern, addr, pattern_len))
+ if (!strncmp(filter->pattern, addr, pattern_len)) {
+ *auto_connect = filter->auto_connect;
return true;
+ }
if (eir->name && !strncmp(filter->pattern, eir->name,
- pattern_len))
+ pattern_len)) {
+ *auto_connect = filter->auto_connect;
return true;
+ }
}
return discoverable;
@@ -7274,6 +7297,7 @@ void btd_adapter_device_found(struct btd_adapter *adapter,
bool name_resolve_failed;
bool scan_rsp;
bool duplicate = false;
+ bool auto_connect = false;
struct queue *matched_monitors = NULL;
confirm = (flags & MGMT_DEV_FOUND_CONFIRM_NAME);
@@ -7310,7 +7334,7 @@ void btd_adapter_device_found(struct btd_adapter *adapter,
ba2str(bdaddr, addr);
discoverable = device_is_discoverable(adapter, &eir_data, addr,
- bdaddr_type);
+ bdaddr_type, &auto_connect);
dev = btd_adapter_find_device(adapter, bdaddr, bdaddr_type);
if (!dev) {
@@ -7483,6 +7507,14 @@ connect_le:
if (adapter->connect_le)
return;
+ /* If device has a pattern match and it also set auto-connect then
+ * attempt to connect.
+ */
+ if (auto_connect) {
+ device_connect_le(dev);
+ return;
+ }
+
/*
* If kernel background scan is used then the kernel is
* responsible for connecting.
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ v1 3/4] client: Add scan.auto-connect command
2025-05-22 17:29 [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 2/4] adapter: Implement SetFilterPolicy AutoConnect filter Luiz Augusto von Dentz
@ 2025-05-22 17:29 ` Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 4/4] bluetoothctl-scan: Add documentation for auto-connect command Luiz Augusto von Dentz
2025-05-22 18:59 ` [BlueZ,v1,1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter bluez.test.bot
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-05-22 17:29 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
[bluetoothctl]> scan.auto-connect --help
Set/Get auto-connect filter
Usage:
auto-connect [on/off]
---
client/main.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/client/main.c b/client/main.c
index 5d53a7be11e4..5c31cd8763e2 100644
--- a/client/main.c
+++ b/client/main.c
@@ -161,6 +161,7 @@ static struct set_discovery_filter_args {
size_t uuids_len;
dbus_bool_t duplicate;
dbus_bool_t discoverable;
+ dbus_bool_t auto_connect;
bool set;
bool active;
unsigned int timeout;
@@ -1253,9 +1254,14 @@ static void set_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
DBUS_TYPE_BOOLEAN,
&args->discoverable);
- if (args->pattern != NULL)
+ if (args->pattern != NULL) {
g_dbus_dict_append_entry(&dict, "Pattern", DBUS_TYPE_STRING,
&args->pattern);
+ if (args->auto_connect)
+ g_dbus_dict_append_entry(&dict, "Pattern",
+ DBUS_TYPE_BOOLEAN,
+ &args->auto_connect);
+ }
dbus_message_iter_close_container(iter, &dict);
}
@@ -1492,6 +1498,29 @@ static void cmd_scan_filter_pattern(int argc, char *argv[])
set_discovery_filter(false);
}
+static void cmd_scan_filter_auto_connect(int argc, char *argv[])
+{
+ if (argc < 2 || !strlen(argv[1])) {
+ bt_shell_printf("AutoConnect: %s\n",
+ filter.auto_connect ? "on" : "off");
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+ }
+
+ if (!strcmp(argv[1], "on"))
+ filter.auto_connect = true;
+ else if (!strcmp(argv[1], "off"))
+ filter.auto_connect = false;
+ else {
+ bt_shell_printf("Invalid option: %s\n", argv[1]);
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ filter.set = false;
+
+ if (filter.active)
+ set_discovery_filter(false);
+}
+
static void filter_clear_uuids(void)
{
g_strfreev(filter.uuids);
@@ -1531,6 +1560,11 @@ static void filter_clear_pattern(void)
filter.pattern = NULL;
}
+static void filter_auto_connect(void)
+{
+ filter.auto_connect = false;
+}
+
struct clear_entry {
const char *name;
void (*clear) (void);
@@ -1544,6 +1578,7 @@ static const struct clear_entry filter_clear[] = {
{ "duplicate-data", filter_clear_duplicate },
{ "discoverable", filter_clear_discoverable },
{ "pattern", filter_clear_pattern },
+ { "auto-connect", filter_auto_connect },
{}
};
@@ -3219,6 +3254,9 @@ static const struct bt_shell_menu scan_menu = {
{ "pattern", "[value]", cmd_scan_filter_pattern,
"Set/Get pattern filter",
NULL },
+ { "auto-connect", "[on/off]", cmd_scan_filter_auto_connect,
+ "Set/Get auto-connect filter",
+ NULL },
{ "clear",
"[uuids/rssi/pathloss/transport/duplicate-data/discoverable/pattern]",
cmd_scan_filter_clear,
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ v1 4/4] bluetoothctl-scan: Add documentation for auto-connect command
2025-05-22 17:29 [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 2/4] adapter: Implement SetFilterPolicy AutoConnect filter Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 3/4] client: Add scan.auto-connect command Luiz Augusto von Dentz
@ 2025-05-22 17:29 ` Luiz Augusto von Dentz
2025-05-22 18:59 ` [BlueZ,v1,1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter bluez.test.bot
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-05-22 17:29 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds documentation for auto-connect command.
---
client/bluetoothctl-scan.rst | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/client/bluetoothctl-scan.rst b/client/bluetoothctl-scan.rst
index b4b8315926a2..cee255131622 100644
--- a/client/bluetoothctl-scan.rst
+++ b/client/bluetoothctl-scan.rst
@@ -122,6 +122,16 @@ When set, it disregards device discoverable flags.
:Usage: **> pattern [value]**
+auto-connect
+------------
+
+Set/Get auto-connect filter.
+
+Connect to discovered devices automatically if pattern filter has been set and
+it matches the device address or name and the device is connectable.
+
+:Usage: **> auto-connect [on/off]**
+
clear
-----
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [BlueZ,v1,1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter
2025-05-22 17:29 [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter Luiz Augusto von Dentz
` (2 preceding siblings ...)
2025-05-22 17:29 ` [PATCH BlueZ v1 4/4] bluetoothctl-scan: Add documentation for auto-connect command Luiz Augusto von Dentz
@ 2025-05-22 18:59 ` bluez.test.bot
3 siblings, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2025-05-22 18:59 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]
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=965496
---Test result---
Test Summary:
CheckPatch PENDING 0.23 seconds
GitLint PENDING 0.29 seconds
BuildEll PASS 20.02 seconds
BluezMake PASS 2678.98 seconds
MakeCheck PASS 19.99 seconds
MakeDistcheck PASS 197.25 seconds
CheckValgrind PASS 274.37 seconds
CheckSmatch PASS 300.61 seconds
bluezmakeextell PASS 128.76 seconds
IncrementalBuild PENDING 0.25 seconds
ScanBuild PASS 900.10 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:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-22 18:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 17:29 [PATCH BlueZ v1 1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 2/4] adapter: Implement SetFilterPolicy AutoConnect filter Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 3/4] client: Add scan.auto-connect command Luiz Augusto von Dentz
2025-05-22 17:29 ` [PATCH BlueZ v1 4/4] bluetoothctl-scan: Add documentation for auto-connect command Luiz Augusto von Dentz
2025-05-22 18:59 ` [BlueZ,v1,1/4] org.bluez.Adapter: Add AutoConnect to SetDiscoveryFilter 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