client: Print a warning when setting discoverable without a timeout
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 12 Sep 2024 20:40:22 +0000 (16:40 -0400)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:22 +0000 (16:43 +0900)
This makes command discoverable to print a warning if
discoverable-timeout is not set(0):

[bluetooth]# discoverable-timeout 0
[bluetooth]# Changing discoverable-timeout 0 succeeded
[bluetooth]# [CHG] Controller 4C:49:6C:44:F5:E7 DiscoverableTimeout: 0x00000000 (0)
[bluetooth]# discoverable on
Warning: setting discoverable while discoverable-timeout not set(0) is not recommended

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
client/main.c

index 8fb5c80ec43ca037583670047bf77d89dc2f28e2..d6bfbec388cfdd98eceb65da5e78a5206fc5cf6e 100644 (file)
@@ -1098,6 +1098,7 @@ static void cmd_pairable(int argc, char *argv[])
 
 static void cmd_discoverable(int argc, char *argv[])
 {
+       DBusMessageIter iter;
        dbus_bool_t discoverable;
        char *str;
 
@@ -1107,6 +1108,18 @@ static void cmd_discoverable(int argc, char *argv[])
        if (check_default_ctrl() == FALSE)
                return bt_shell_noninteractive_quit(EXIT_FAILURE);
 
+       if (discoverable && g_dbus_proxy_get_property(default_ctrl->proxy,
+                                       "DiscoverableTimeout", &iter)) {
+               uint32_t value;
+
+               dbus_message_iter_get_basic(&iter, &value);
+
+               if (!value)
+                       bt_shell_printf("Warning: setting discoverable while "
+                                       "discoverable-timeout not set(0) is not"
+                                       " recommended\n");
+       }
+
        str = g_strdup_printf("discoverable %s",
                                discoverable == TRUE ? "on" : "off");