summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2023-03-06 16:48:43 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2023-03-10 13:41:06 -0800
commit815f779aa8e477e399b78f03c0ea0e75f0270c4a (patch)
treeafbdc72bf65f1206632b6f6543125e0e6f519f07 /client
parent373bafc34ce6ed8a4dbd4276ae0d96d5753147c8 (diff)
downloadbluez-815f779aa8e477e399b78f03c0ea0e75f0270c4a.tar.gz
client: Use AdvertisingFlags when available
This prints devices not discoverable in grey so the user are able to distict when for example set members are actually visible.
Diffstat (limited to 'client')
-rw-r--r--client/main.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/client/main.c b/client/main.c
index e4a39896b..79895015d 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);