Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3277840rwb; Mon, 15 Aug 2022 23:03:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR5SL0UY5+6yV+ov3LPsVO8Rq4el4TTb5jQsUHMfq1BMfs9Q0pZnYlwWHcGx4XFuBXoPPt03 X-Received: by 2002:a05:6402:3495:b0:43d:d76e:e9ff with SMTP id v21-20020a056402349500b0043dd76ee9ffmr17809747edc.227.1660629807367; Mon, 15 Aug 2022 23:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660629807; cv=none; d=google.com; s=arc-20160816; b=iCEpjgpNkjTyUhG3+ridAKIQ0I4JdbmGh74rpHs0fX/tURVb+fDZnzOgPBxaG2TVme hPcoG0JQCBIbEvBe/apG2ElbwvWE3rolCfKl41lYFy74cFgVuNwmnqQZ+Kwa4VcnS5HG 4Cy2zjWF9jIR1a9fsbb5Hqwz1YDPNCTy/66GBVd/AlB2Qq08YlrY9vEbK/KNwcv17H/R JEPooI24b9Ufuj4v/7mpCujQJkpJa5PQVPqeqPsDPnyXhzUGpXe7SHhxh4RSkFzipPhx y8zPlFf6lLzTDiQir5gPw6e2aDfL6ul07GEGJhSdi0ChGenXZ6Wudg7PRxCCFI1aR0E3 YeLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=n4peG6lER0isLk6vDkj25mV3GFwO3PVFXZ2sR+VQZFo=; b=aZRgY/hiRVEebHT+P200SKSBodIP12v9njeuSLyRyMxLaAZTKIabJ/kXmgY467J+8x qKxuZsqJMl1av1Dh1qOrIVwxbNtIZ96zblcrITKZJOPsqNYe4ws6rPVpvF7trbq+yLWl Myu8mi61+t8EdQU+3zxwqyedvfMBXdl/rbFO1KSJUBYbK9zv41JYLO1pIHyu7YxBB0hQ kSL16i7O9cqv8Vd343r4Kyy21aVsdKGiZKw7AORJL4LUFQ9ds/I8Gt2rYxesHKt+pu/K W2QW5Ypn/6J8PnK/alJdi/5xRuzJ3bEJyLgKeW0Ib+r3ZTheYXcJJW/lHDc9FUVjGt5P keVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IKEg4Sqk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fu10-20020a170907b00a00b007262b3cd387si7352678ejc.421.2022.08.15.23.03.00; Mon, 15 Aug 2022 23:03:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IKEg4Sqk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiHPGBl (ORCPT + 99 others); Tue, 16 Aug 2022 02:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiHPGBX (ORCPT ); Tue, 16 Aug 2022 02:01:23 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0944486B58 for ; Mon, 15 Aug 2022 16:26:37 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id h21-20020a17090aa89500b001f31a61b91dso15799945pjq.4 for ; Mon, 15 Aug 2022 16:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=n4peG6lER0isLk6vDkj25mV3GFwO3PVFXZ2sR+VQZFo=; b=IKEg4SqkJ5+PRfjtKYVTAvtfib6XMPRB6FBzYIhuNyDhhkZQ6Iiidbz9xUKiO6B37r BcbxJLpVrncdY/S4TlNoHz4E0ZOTvhxpHNgizhpZ8yRPy7H6mgv+KUfDAvTxUQfX9FBL lRG2Nkko8F1ZDVsDFvlkKenydzz0sN3ak12epFUcAhEGayWiIx7TSZBTyu4Ma1BmdF2v Sa1k3DScbmpxrIO/1Np87BPQ/unuFjlDG7lpkEY6C99oJ8Ao7E3YfvVTtvpv7RHFsj2o tQTuTEwc2bbVE+G0nB8mGK1yBSS9Cm5MKRNk7NqcFBEMNzNk6DQkpZCBJH7QesZakFbF rEEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=n4peG6lER0isLk6vDkj25mV3GFwO3PVFXZ2sR+VQZFo=; b=cKZp07cJ1IivMGcGx10yM04oPXJew3rCTawAOugdg4zx9mkzL1/QHuAkdfON4bAQ8n 0TmDaCD9XB/niPEGqLYjyOiHyRMuvpQcSLCgFPf5mKYIAqycxsJ7K3iZD5Wko9/l7J8h EvKehX6vpBMecMjNHlhpL5gQTZvQ+P/Xfmuh84DuNSjrteUPTyIj+Awu9SD7FpW1UVlm 2LFnKj2VOGJg2C8fzE2k4gmGWwK8t+okUniaUNkPqx6XI8ErYkAUeY7e2mOveLGcKo5N RfK/0UzrQZ0NjNOEVVngaXJI29ZpBUyoPWrPgJ3hjU9RSsBz6K54JktuSTd9iW89Z/d3 lX1A== X-Gm-Message-State: ACgBeo3HZ4bAMRT4NSMO8SVxmNoYwhQ39FUgyFSXf/Lrvi1p8w62Xxv5 h/UGL0e3ZFhMdzl7xD7IXuv6J6chA7/Otw== X-Received: by 2002:a17:90a:982:b0:1ef:f525:9801 with SMTP id 2-20020a17090a098200b001eff5259801mr21104732pjo.191.1660605995879; Mon, 15 Aug 2022 16:26:35 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id 6-20020a170902c10600b0016d23e941f2sm7474276pli.258.2022.08.15.16.26.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 16:26:35 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] client: Move admin submenu Date: Mon, 15 Aug 2022 16:26:30 -0700 Message-Id: <20220815232631.1275861-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Luiz Augusto von Dentz This moves admin submenu to admin.c so it is not mixed up with other submenus code. --- client/admin.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++--- client/admin.h | 8 ++--- client/main.c | 82 ++---------------------------------------- 3 files changed, 96 insertions(+), 91 deletions(-) diff --git a/client/admin.c b/client/admin.c index 863590172428..cd9af6f955da 100644 --- a/client/admin.c +++ b/client/admin.c @@ -31,20 +31,22 @@ #include "admin.h" #define _GNU_SOURCE +static DBusConnection *dbus_conn; +static GList *admin_proxies; static GDBusProxy *set_proxy; static GDBusProxy *status_proxy; -void admin_policy_set_set_proxy(GDBusProxy *proxy) +static void admin_policy_set_set_proxy(GDBusProxy *proxy) { set_proxy = proxy; } -void admin_policy_set_status_proxy(GDBusProxy *proxy) +static void admin_policy_set_status_proxy(GDBusProxy *proxy) { status_proxy = proxy; } -void admin_policy_read_service_allowlist(DBusConnection *dbus_conn) +static void admin_policy_read_service_allowlist(DBusConnection *dbus_conn) { DBusMessageIter iter, subiter; char *uuid = NULL; @@ -111,8 +113,7 @@ static void set_service_reply(DBusMessage *message, void *user_data) return bt_shell_noninteractive_quit(EXIT_FAILURE); } -void admin_policy_set_service_allowlist(DBusConnection *dbus_connd, - int argc, char *argv[]) +static void admin_policy_set_service_allowlist(int argc, char *argv[]) { struct uuid_list_data data; @@ -131,3 +132,89 @@ void admin_policy_set_service_allowlist(DBusConnection *dbus_connd, return bt_shell_noninteractive_quit(EXIT_FAILURE); } } + +static void cmd_admin_allow(int argc, char *argv[]) +{ + if (argc <= 1) { + admin_policy_read_service_allowlist(dbus_conn); + return; + } + + if (strcmp(argv[1], "clear") == 0) + argc--; + + admin_policy_set_service_allowlist(argc - 1, argv + 1); +} + +static const struct bt_shell_menu admin_menu = { + .name = "admin", + .desc = "Admin Policy Submenu", + .entries = { + { "allow", "[clear/uuid1 uuid2 ...]", cmd_admin_allow, + "Allow service UUIDs and block rest of them"}, + {} }, +}; + +static void admin_policy_status_added(GDBusProxy *proxy) +{ + admin_proxies = g_list_append(admin_proxies, proxy); + admin_policy_set_status_proxy(proxy); +} + +static void proxy_added(GDBusProxy *proxy, void *user_data) +{ + const char *interface; + + interface = g_dbus_proxy_get_interface(proxy); + + if (!strcmp(interface, "org.bluez.AdminPolicySet1")) + admin_policy_set_set_proxy(proxy); + else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) + admin_policy_status_added(proxy); +} + +static void admin_policy_status_removed(GDBusProxy *proxy) +{ + admin_proxies = g_list_remove(admin_proxies, proxy); + admin_policy_set_status_proxy(NULL); +} + +static void proxy_removed(GDBusProxy *proxy, void *user_data) +{ + const char *interface; + + interface = g_dbus_proxy_get_interface(proxy); + + if (!strcmp(interface, "org.bluez.AdminPolicySet1")) + admin_policy_set_set_proxy(NULL); + else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) + admin_policy_status_removed(proxy); +} + +static GDBusClient *client; + +static void disconnect_handler(DBusConnection *connection, void *user_data) +{ + g_list_free_full(admin_proxies, NULL); + admin_proxies = NULL; +} + +void admin_add_submenu(void) +{ + bt_shell_add_submenu(&admin_menu); + + dbus_conn = bt_shell_get_env("DBUS_CONNECTION"); + if (!dbus_conn || client) + return; + + client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); + g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed, + NULL, NULL); + g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL); +} + +void admin_remove_submenu(void) +{ + g_dbus_client_unref(client); + client = NULL; +} diff --git a/client/admin.h b/client/admin.h index 1c8c2152d59d..4da83e4e36ba 100644 --- a/client/admin.h +++ b/client/admin.h @@ -17,9 +17,5 @@ * */ -void admin_policy_set_set_proxy(GDBusProxy *proxy); -void admin_policy_set_status_proxy(GDBusProxy *proxy); - -void admin_policy_read_service_allowlist(DBusConnection *dbus_conn); -void admin_policy_set_service_allowlist(DBusConnection *dbus_conn, - int argc, char *argv[]); +void admin_add_submenu(void); +void admin_remove_submenu(void); diff --git a/client/main.c b/client/main.c index 1df94f000cea..19139d15b38e 100644 --- a/client/main.c +++ b/client/main.c @@ -57,7 +57,6 @@ static GDBusProxy *default_dev; static GDBusProxy *default_attr; static GList *ctrl_list; static GList *battery_proxies; -static GList *admin_devices_proxies; static const char *agent_arguments[] = { "on", @@ -563,26 +562,6 @@ static void admon_manager_added(GDBusProxy *proxy) adv_monitor_register_app(dbus_conn); } -static void admin_policy_set_added(GDBusProxy *proxy) -{ - admin_policy_set_set_proxy(proxy); -} - -static void admin_policy_status_added(GDBusProxy *proxy) -{ - struct adapter *adapter; - - adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy)); - - if (!adapter) { - admin_devices_proxies = g_list_append(admin_devices_proxies, - proxy); - return; - } - - admin_policy_set_status_proxy(proxy); -} - static void proxy_added(GDBusProxy *proxy, void *user_data) { const char *interface; @@ -618,10 +597,6 @@ static void proxy_added(GDBusProxy *proxy, void *user_data) } else if (!strcmp(interface, "org.bluez.AdvertisementMonitorManager1")) { admon_manager_added(proxy); - } else if (!strcmp(interface, "org.bluez.AdminPolicySet1")) { - admin_policy_set_added(proxy); - } else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) { - admin_policy_status_added(proxy); } } @@ -678,26 +653,6 @@ static void adapter_removed(GDBusProxy *proxy) } } -static void admin_policy_set_removed(GDBusProxy *proxy) -{ - admin_policy_set_set_proxy(NULL); -} - -static void admin_policy_status_removed(GDBusProxy *proxy) -{ - struct adapter *adapter; - - adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy)); - - if (!adapter) { - admin_devices_proxies = g_list_remove(admin_devices_proxies, - proxy); - return; - } - - admin_policy_set_status_proxy(NULL); -} - static void proxy_removed(GDBusProxy *proxy, void *user_data) { const char *interface; @@ -738,10 +693,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data) } else if (!strcmp(interface, "org.bluez.AdvertisementMonitorManager1")) { adv_monitor_remove_manager(dbus_conn); - } else if (!strcmp(interface, "org.bluez.AdminPolicySet1")) { - admin_policy_set_removed(proxy); - } else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) { - admin_policy_status_removed(proxy); } } @@ -1772,7 +1723,6 @@ static struct GDBusProxy *find_device(int argc, char *argv[]) static void cmd_info(int argc, char *argv[]) { GDBusProxy *proxy; - GDBusProxy *admin_proxy; GDBusProxy *battery_proxy; DBusMessageIter iter; const char *address; @@ -1819,12 +1769,8 @@ static void cmd_info(int argc, char *argv[]) battery_proxy = find_proxies_by_path(battery_proxies, g_dbus_proxy_get_path(proxy)); - admin_proxy = find_proxies_by_path(admin_devices_proxies, - g_dbus_proxy_get_path(proxy)); print_property_with_label(battery_proxy, "Percentage", "Battery Percentage"); - print_property_with_label(admin_proxy, "AffectedByPolicy", - "Affected by Policy"); return bt_shell_noninteractive_quit(EXIT_SUCCESS); } @@ -2948,22 +2894,6 @@ static void cmd_adv_monitor_get_supported_info(int argc, char *argv[]) adv_monitor_get_supported_info(); } -static void cmd_admin_allow(int argc, char *argv[]) -{ - if (check_default_ctrl() == FALSE) - return bt_shell_noninteractive_quit(EXIT_FAILURE); - - if (argc <= 1) { - admin_policy_read_service_allowlist(dbus_conn); - return; - } - - if (strcmp(argv[1], "clear") == 0) - argc--; - - admin_policy_set_service_allowlist(dbus_conn, argc - 1, argv + 1); -} - static const struct bt_shell_menu advertise_menu = { .name = "advertise", .desc = "Advertise Options Submenu", @@ -3118,15 +3048,6 @@ static const struct bt_shell_menu gatt_menu = { { } }, }; -static const struct bt_shell_menu admin_menu = { - .name = "admin", - .desc = "Admin Policy Submenu", - .entries = { - { "allow", "[clear/uuid1 uuid2 ...]", cmd_admin_allow, - "Allow service UUIDs and block rest of them"}, - {} }, -}; - static const struct bt_shell_menu main_menu = { .name = "main", .entries = { @@ -3225,7 +3146,6 @@ int main(int argc, char *argv[]) bt_shell_add_submenu(&advertise_monitor_menu); bt_shell_add_submenu(&scan_menu); bt_shell_add_submenu(&gatt_menu); - bt_shell_add_submenu(&admin_menu); bt_shell_set_prompt(PROMPT_OFF); if (agent_option) @@ -3238,6 +3158,7 @@ int main(int argc, char *argv[]) bt_shell_set_env("DBUS_CONNECTION", dbus_conn); + admin_add_submenu(); player_add_submenu(); client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); @@ -3253,6 +3174,7 @@ int main(int argc, char *argv[]) status = bt_shell_run(); + admin_remove_submenu(); player_remove_submenu(); g_dbus_client_unref(client); -- 2.37.2