Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4609483iob; Sun, 8 May 2022 19:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGQJWLTpDnzZrhv28o8/4ATPlkDQTltZ9knkUEn7ngvP7+SATgEIiIHDHMFIHhAB5PzGJO X-Received: by 2002:a17:902:bc4c:b0:15f:12dc:7c85 with SMTP id t12-20020a170902bc4c00b0015f12dc7c85mr2883979plz.108.1652061990024; Sun, 08 May 2022 19:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652061990; cv=none; d=google.com; s=arc-20160816; b=fElFQFevi/dXS4RQKlK9mAA2126O254+IGbuDqzHFue6veHyNL7kL0NuD6ZHdP3tp7 JgdwCthdLYR5dnGri7w9w6yvM/Im13trWrMYiGuGJ7O6WXWSC3fhELX0xk7Eoy8355Hn QdbGe175azR/MnlToyhN+79y2CiS/heL4ArKsM3EZ195YnhY8S2/6y97etIYTM+r9hGs r0wo8I+l/NhMmeM5BWN6JI0cb+AIcPl1nnI5w280pk7s8BEQd9YLFH1Mbn8Hg6yBaMKK 2BIIQjPisyus3yiJRbeqbm1nz7+oSriXA0IBIhWXVco1UJmg6zEWctDMYcXwcMsa4Rql EX+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=MWNKAKX9vwd2owSFK0FSrCSLpumWwv3K0/Q5OZyz5qk=; b=kaUJV3zLvvaGglWIznrM8Sfo1+EY3ekBltT2FCnP1iTN953uEXe0c1foglXeYkJM/h hkjbnj/sB8qhAdayExhIZOgRPjbrQhN8obn2NeoXakRp5YT+egiRQb5dodbrvCb77KeV IE2dhH15Cl2K09jh4tcgcnV7qrfrKh7J9FPSPumEFaUduxc6JdqBuqeORACJ8ZPhPvP1 ZH3j0OugX7KrJtyVFTW9mXioofGu35MZgWjLlbrof3m+LSxA7Ju2P/zyNVNwh1Lx13l3 qm5e9kVDvE7aogb1DHUVKfzeAOAyUv9MI0RMKO77qNVTYoAUz2f4He0VjI2VY3w2sbxO 421g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sGs59LiI; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k124-20020a632482000000b0038653b8ab83si12689055pgk.204.2022.05.08.19.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 19:06:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sGs59LiI; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8EDD04CD66; Sun, 8 May 2022 19:05:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378507AbiEDVNo (ORCPT + 99 others); Wed, 4 May 2022 17:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378505AbiEDVNn (ORCPT ); Wed, 4 May 2022 17:13:43 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0B29515B1 for ; Wed, 4 May 2022 14:10:06 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id o7-20020a17090a0a0700b001d93c491131so3457174pjo.6 for ; Wed, 04 May 2022 14:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=MWNKAKX9vwd2owSFK0FSrCSLpumWwv3K0/Q5OZyz5qk=; b=sGs59LiIiKOLTxv/kTkmJ3bKYKBofcYxA2I20ZtZn5abQ8flboigOUii7He9W8ck6n THC3oXmfTFRNcrUoH2ynXZ8KpgC8a9pr/N2ovo72B5L/Ys6ACLr4z2ORQlj4nn8SOpgv vHdUI2NOL4vnyLsy5qt2Ur6G2qoc2wX3vfREZGMbV9u5TUo6/hsMmngsHQtmpBeCPoXD wCW7RaJBu13RXoa9Hh09p9tndI/RqwU6l1sT0to5D1AGQn6iBCULM6z33lsR0U8lUeZt RPJzHmyLPj42flEqCcmxtp6nD9bjAw+clqtpTj/AYu5FpRWVzxnt4jXg1SgJuYEbPj9X DmUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MWNKAKX9vwd2owSFK0FSrCSLpumWwv3K0/Q5OZyz5qk=; b=CqHfAt9ZoIB8cFig/tw0FgX2XFys06vDA92Oowge63yePmi404ewZeNHLQc3j5pRqP aKGRXiGTqqFXfrblBCDmxW0G3ixqyk2J0NKTlhzjDG26A4Q0Fkvyc5SKOcrtc/dLcWjx LcXaFtjp0UM6RznYjQZqGUmeyCHseEogZT4x2ZWJWvM8JaayCsbOD/8AMkZd+7/zxdnb NU5jUsS/xBwVAIOSSqQHaBCK6NM/cP4yTeutAcllV45fTjn9ZFRPxcEUovf3UbOXOVS+ hH3lcImcoGIuNfNbQaSja001CTks6Ty4/1OnXLNIX+iE1eqJyiWhvH3tGY+o6L9vO+hU Zf7w== X-Gm-Message-State: AOAM5306z1noIsDkn5m+f+GmhMIeU30ru5DkWXUqYfgYfcfuB5xVUtXY f/FixxEApKj2cBmJRa9sujHlSZXbqUpPFDTajXkpvJ0wh00I7KdR0h7CVOmwqXKprEkac3QY/sv jy4FbboLdSCrJUCyjwmUILhhNm+DZQkUSTSnygp38rzQfgmHzKiGi9DqD6uFUdSDlH7ihNk2PtW lT X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4c52]) (user=jiangzp job=sendgmr) by 2002:a62:d415:0:b0:50d:baaf:4156 with SMTP id a21-20020a62d415000000b0050dbaaf4156mr22663081pfh.28.1651698606298; Wed, 04 May 2022 14:10:06 -0700 (PDT) Date: Wed, 4 May 2022 14:09:48 -0700 In-Reply-To: <20220504210948.2968827-1-jiangzp@google.com> Message-Id: <20220504140941.Bluez.v3.3.I29a0e38364a8d5854342019b607fa049c74248a3@changeid> Mime-Version: 1.0 References: <20220504210948.2968827-1-jiangzp@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [Bluez PATCH v3 3/3] client: Add filter to devices and show Bonded in info From: Zhengping Jiang To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Zhengping Jiang , Sonny Sasaka , Yun-Hao Chung Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Use the property name as optional filters to the command "devices" and show the "Bonded" property for the command "info". Reviewed-by: Sonny Sasaka Reviewed-by: Yun-Hao Chung Signed-off-by: Zhengping Jiang --- Changes in v3: - Add an optional argument to the devices command to filter device list - Remove paired-devices command Changes in v1: - Show the status of the "Bonded" flag in bluetoothctl - Add option to show list of bonded devices client/main.c | 72 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/client/main.c b/client/main.c index 29a2f882e5c8..58678224f93f 100644 --- a/client/main.c +++ b/client/main.c @@ -95,6 +95,14 @@ static const char *ad_arguments[] = { NULL }; +static const char * const device_arguments[] = { + "Paired", + "Bonded", + "Trusted", + "Connected", + NULL +}; + static void proxy_leak(gpointer data) { printf("Leaking proxy %p\n", data); @@ -929,6 +937,28 @@ static gboolean check_default_ctrl(void) return TRUE; } +static gboolean parse_argument_devices(int argc, char *argv[], + const char * const *arg_table, + const char **option) +{ + const char * const *opt; + + if (argc < 2) { + *option = NULL; + return TRUE; + } + + for (opt = arg_table; opt && *opt; opt++) { + if (strcmp(argv[1], *opt) == 0) { + *option = *opt; + return TRUE; + } + } + + bt_shell_printf("Invalid argument %s\n", argv[1]); + return FALSE; +} + static gboolean parse_argument(int argc, char *argv[], const char **arg_table, const char *msg, dbus_bool_t *value, const char **option) @@ -1068,22 +1098,11 @@ static void cmd_select(int argc, char *argv[]) static void cmd_devices(int argc, char *argv[]) { GList *ll; + const char *property; - 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; - print_device(proxy, NULL); - } - - return bt_shell_noninteractive_quit(EXIT_SUCCESS); -} - -static void cmd_paired_devices(int argc, char *argv[]) -{ - GList *ll; + if (!parse_argument_devices(argc, argv, device_arguments, + &property)) + return bt_shell_noninteractive_quit(EXIT_FAILURE); if (check_default_ctrl() == FALSE) return bt_shell_noninteractive_quit(EXIT_SUCCESS); @@ -1092,15 +1111,17 @@ static void cmd_paired_devices(int argc, char *argv[]) ll; ll = g_list_next(ll)) { GDBusProxy *proxy = ll->data; DBusMessageIter iter; - dbus_bool_t paired; + dbus_bool_t status; - if (g_dbus_proxy_get_property(proxy, "Paired", &iter) == FALSE) - continue; - - dbus_message_iter_get_basic(&iter, &paired); - if (!paired) - continue; + if (property) { + if (g_dbus_proxy_get_property(proxy, + property, &iter) == FALSE) + continue; + dbus_message_iter_get_basic(&iter, &status); + if (!status) + continue; + } print_device(proxy, NULL); } @@ -1787,6 +1808,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"); @@ -3170,9 +3192,9 @@ static const struct bt_shell_menu main_menu = { ctrl_generator }, { "select", "", cmd_select, "Select default controller", ctrl_generator }, - { "devices", NULL, cmd_devices, "List available devices" }, - { "paired-devices", NULL, cmd_paired_devices, - "List paired devices"}, + { "devices", "[Paired/Bonded/Trusted/Connected]", cmd_devices, + "List available devices, with an " + "optional property as the filter" }, { "system-alias", "", cmd_system_alias, "Set controller alias" }, { "reset-alias", NULL, cmd_reset_alias, -- 2.36.0.464.gb9c8b46e94-goog