2022-04-18 20:56:12

by Zhengping Jiang

[permalink] [raw]
Subject: [Bluez PATCH v2 2/2] client: Add bonded-devices and show Bonded flag in info

Add "bonded-devices" to the menu and show the "Bonded" property for
command "info".

Reviewed-by: Sonny Sasaka <[email protected]>
Reviewed-by: Yun-Hao Chung <[email protected]>

Signed-off-by: Zhengping Jiang <[email protected]>
---

(no changes since v1)

Changes in v1:
- Show the status of the "Bonded" flag in bluetoothctl
- Add option to show list of bonded devices

client/main.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/client/main.c b/client/main.c
index 589268c3a68c..45c89a1de37b 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1090,6 +1090,32 @@ static void cmd_paired_devices(int argc, char *argv[])
return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}

+static void cmd_bonded_devices(int argc, char *argv[])
+{
+ GList *ll;
+
+ if (check_default_ctrl() == FALSE)
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+
+ for (ll = g_list_first(default_ctrl->devices);
+ ll; ll = g_list_next(ll)) {
+ GDBusProxy *proxy = ll->data;
+ DBusMessageIter iter;
+ dbus_bool_t bonded;
+
+ if (g_dbus_proxy_get_property(proxy, "Bonded", &iter) == FALSE)
+ continue;
+
+ dbus_message_iter_get_basic(&iter, &bonded);
+ if (!bonded)
+ continue;
+
+ print_device(proxy, NULL);
+ }
+
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
static void generic_callback(const DBusError *error, void *user_data)
{
char *str = user_data;
@@ -1781,6 +1807,7 @@ static void cmd_info(int argc, char *argv[])
print_property(proxy, "Appearance");
print_property(proxy, "Icon");
print_property(proxy, "Paired");
+ print_property(proxy, "Bonded");
print_property(proxy, "Trusted");
print_property(proxy, "Blocked");
print_property(proxy, "Connected");
@@ -3116,6 +3143,8 @@ static const struct bt_shell_menu main_menu = {
{ "devices", NULL, cmd_devices, "List available devices" },
{ "paired-devices", NULL, cmd_paired_devices,
"List paired devices"},
+ { "bonded-devices", NULL, cmd_bonded_devices,
+ "List bonded devices"},
{ "system-alias", "<name>", cmd_system_alias,
"Set controller alias" },
{ "reset-alias", NULL, cmd_reset_alias,
--
2.36.0.rc0.470.gd361397f0d-goog


2022-04-19 18:13:31

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [Bluez PATCH v2 2/2] client: Add bonded-devices and show Bonded flag in info

Hi Zhengping,

On Mon, Apr 18, 2022 at 10:49 AM Zhengping Jiang <[email protected]> wrote:
>
> Add "bonded-devices" to the menu and show the "Bonded" property for
> command "info".
>
> Reviewed-by: Sonny Sasaka <[email protected]>
> Reviewed-by: Yun-Hao Chung <[email protected]>
>
> Signed-off-by: Zhengping Jiang <[email protected]>
> ---
>
> (no changes since v1)
>
> Changes in v1:
> - Show the status of the "Bonded" flag in bluetoothctl
> - Add option to show list of bonded devices
>
> client/main.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/client/main.c b/client/main.c
> index 589268c3a68c..45c89a1de37b 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -1090,6 +1090,32 @@ static void cmd_paired_devices(int argc, char *argv[])
> return bt_shell_noninteractive_quit(EXIT_SUCCESS);
> }
>
> +static void cmd_bonded_devices(int argc, char *argv[])
> +{
> + GList *ll;
> +
> + if (check_default_ctrl() == FALSE)
> + return bt_shell_noninteractive_quit(EXIT_SUCCESS);
> +
> + for (ll = g_list_first(default_ctrl->devices);
> + ll; ll = g_list_next(ll)) {
> + GDBusProxy *proxy = ll->data;
> + DBusMessageIter iter;
> + dbus_bool_t bonded;
> +
> + if (g_dbus_proxy_get_property(proxy, "Bonded", &iter) == FALSE)
> + continue;
> +
> + dbus_message_iter_get_basic(&iter, &bonded);
> + if (!bonded)
> + continue;
> +
> + print_device(proxy, NULL);
> + }
> +
> + return bt_shell_noninteractive_quit(EXIT_SUCCESS);
> +}
> +
> static void generic_callback(const DBusError *error, void *user_data)
> {
> char *str = user_data;
> @@ -1781,6 +1807,7 @@ static void cmd_info(int argc, char *argv[])
> print_property(proxy, "Appearance");
> print_property(proxy, "Icon");
> print_property(proxy, "Paired");
> + print_property(proxy, "Bonded");
> print_property(proxy, "Trusted");
> print_property(proxy, "Blocked");
> print_property(proxy, "Connected");
> @@ -3116,6 +3143,8 @@ static const struct bt_shell_menu main_menu = {
> { "devices", NULL, cmd_devices, "List available devices" },
> { "paired-devices", NULL, cmd_paired_devices,
> "List paired devices"},
> + { "bonded-devices", NULL, cmd_bonded_devices,
> + "List bonded devices"},

I would have done it a little be different, make devices command
create different lists:

bluetoothctl> devices [Trusted/Paired/Bonded/Connected]
Device XX:... Name (Trusted, Paired, Bonded...)
...

That way we don't have to create a command for each possible device filter.


> { "system-alias", "<name>", cmd_system_alias,
> "Set controller alias" },
> { "reset-alias", NULL, cmd_reset_alias,
> --
> 2.36.0.rc0.470.gd361397f0d-goog
>


--
Luiz Augusto von Dentz