diff mbox series

[BlueZ,3/3] client: Add scan.pattern command

Message ID 20200220002835.8929-3-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series [BlueZ,1/3] doc/adapter-api: Add pattern filter | expand

Commit Message

Luiz Augusto von Dentz Feb. 20, 2020, 12:28 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This uses the new Pattern filter:

[bluetooth]# scan.pattern Living
[bluetooth]# scan on
SetDiscoveryFilter success
Discovery started
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
[NEW] Device XX:XX:XX:XX:XX:XX Living Room TV
---
 client/main.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/client/main.c b/client/main.c
index 8bd0bac9e..422da5593 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1157,6 +1157,7 @@  static void cmd_default_agent(int argc, char *argv[])
 
 static struct set_discovery_filter_args {
 	char *transport;
+	char *pattern;
 	dbus_uint16_t rssi;
 	dbus_int16_t pathloss;
 	char **uuids;
@@ -1241,6 +1242,10 @@  static void set_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
 						DBUS_TYPE_BOOLEAN,
 						&args->discoverable);
 
+	if (args->pattern != NULL)
+		g_dbus_dict_append_entry(&dict, "Pattern", DBUS_TYPE_STRING,
+						&args->pattern);
+
 	dbus_message_iter_close_container(iter, &dict);
 }
 
@@ -1440,6 +1445,22 @@  static void cmd_scan_filter_discoverable(int argc, char *argv[])
 		set_discovery_filter(false);
 }
 
+static void cmd_scan_filter_pattern(int argc, char *argv[])
+{
+	if (argc < 2 || !strlen(argv[1])) {
+		bt_shell_printf("Pattern: %s\n", filter.pattern);
+		return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+	}
+
+	free(filter.pattern);
+	filter.pattern = strdup(argv[1]);
+
+	filter.set = false;
+
+	if (filter.active)
+		set_discovery_filter(false);
+}
+
 static void filter_clear_uuids(void)
 {
 	g_strfreev(filter.uuids);
@@ -1473,6 +1494,12 @@  static void filter_clear_discoverable(void)
 	filter.discoverable = false;
 }
 
+static void filter_clear_pattern(void)
+{
+	free(filter.pattern);
+	filter.pattern = NULL;
+}
+
 struct clear_entry {
 	const char *name;
 	void (*clear) (void);
@@ -1485,6 +1512,7 @@  static const struct clear_entry filter_clear[] = {
 	{ "transport", filter_clear_transport },
 	{ "duplicate-data", filter_clear_duplicate },
 	{ "discoverable", filter_clear_discoverable },
+	{ "pattern", filter_clear_pattern },
 	{}
 };
 
@@ -2639,8 +2667,11 @@  static const struct bt_shell_menu scan_menu = {
 	{ "discoverable", "[on/off]", cmd_scan_filter_discoverable,
 				"Set/Get discoverable filter",
 				NULL },
+	{ "pattern", "[value]", cmd_scan_filter_pattern,
+				"Set/Get pattern filter",
+				NULL },
 	{ "clear",
-		"[uuids/rssi/pathloss/transport/duplicate-data/discoverable]",
+	"[uuids/rssi/pathloss/transport/duplicate-data/discoverable/pattern]",
 				cmd_scan_filter_clear,
 				"Clears discovery filter.",
 				filter_clear_generator },