diff mbox series

[RFC,v2,12/12] client: Use AdvertisingFlags when available

Message ID 20230307222422.2608483-12-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 815f779aa8e477e399b78f03c0ea0e75f0270c4a
Headers show
Series [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz March 7, 2023, 10:24 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This prints devices not discoverable in grey so the user are able to
distict when for example set members are actually visible.
---
 client/main.c | 79 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/client/main.c b/client/main.c
index e4a39896b2c6..79895015d6a6 100644
--- a/client/main.c
+++ b/client/main.c
@@ -24,6 +24,7 @@ 
 
 #include "src/shared/shell.h"
 #include "src/shared/util.h"
+#include "src/shared/ad.h"
 #include "gdbus/gdbus.h"
 #include "print.h"
 #include "agent.h"
@@ -143,10 +144,32 @@  static void print_adapter(GDBusProxy *proxy, const char *description)
 
 }
 
+#define	DISTANCE_VAL_INVALID	0x7FFF
+
+static struct set_discovery_filter_args {
+	char *transport;
+	char *pattern;
+	dbus_uint16_t rssi;
+	dbus_int16_t pathloss;
+	char **uuids;
+	size_t uuids_len;
+	dbus_bool_t duplicate;
+	dbus_bool_t discoverable;
+	bool set;
+	bool active;
+	unsigned int timeout;
+} filter = {
+	.rssi = DISTANCE_VAL_INVALID,
+	.pathloss = DISTANCE_VAL_INVALID,
+	.set = true,
+};
+
 static void print_device(GDBusProxy *proxy, const char *description)
 {
 	DBusMessageIter iter;
 	const char *address, *name;
+	uint8_t *flags;
+	int flags_len = 0;
 
 	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
 		return;
@@ -158,11 +181,39 @@  static void print_device(GDBusProxy *proxy, const char *description)
 	else
 		name = "<unknown>";
 
+	if (g_dbus_proxy_get_property(proxy, "AdvertisingFlags", &iter)) {
+		DBusMessageIter array;
+
+		dbus_message_iter_recurse(&iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &flags, &flags_len);
+	}
+
+	if (!flags_len)
+		goto done;
+
+	if (!(flags[0] & (BT_AD_FLAG_LIMITED | BT_AD_FLAG_GENERAL))) {
+		/* Only print hidden/non-discoverable if filter.discoverable is
+		 * not set.
+		 */
+		if (filter.discoverable)
+			return;
+
+		bt_shell_printf("%s%s%s" COLOR_BOLDGRAY "Device %s %s"
+					COLOR_OFF "\n",
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					address, name);
+
+		return;
+	}
+
+done:
 	bt_shell_printf("%s%s%sDevice %s %s\n",
-				description ? "[" : "",
-				description ? : "",
-				description ? "] " : "",
-				address, name);
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					address, name);
 }
 
 static void print_uuid(const char *label, const char *uuid)
@@ -1133,26 +1184,6 @@  static void cmd_default_agent(int argc, char *argv[])
 	agent_default(dbus_conn, agent_manager);
 }
 
-#define	DISTANCE_VAL_INVALID	0x7FFF
-
-static struct set_discovery_filter_args {
-	char *transport;
-	char *pattern;
-	dbus_uint16_t rssi;
-	dbus_int16_t pathloss;
-	char **uuids;
-	size_t uuids_len;
-	dbus_bool_t duplicate;
-	dbus_bool_t discoverable;
-	bool set;
-	bool active;
-	unsigned int timeout;
-} filter = {
-	.rssi = DISTANCE_VAL_INVALID,
-	.pathloss = DISTANCE_VAL_INVALID,
-	.set = true,
-};
-
 static void start_discovery_reply(DBusMessage *message, void *user_data)
 {
 	dbus_bool_t enable = GPOINTER_TO_UINT(user_data);