Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5764824pxv; Wed, 28 Jul 2021 20:15:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTymCyBq5eAy/6tciQBBEVv5OUDLsz9xuv5bxd9r4u3ll4hF4+dXppdSDle88ZPj28VxxO X-Received: by 2002:a05:6e02:1343:: with SMTP id k3mr2175681ilr.216.1627528515666; Wed, 28 Jul 2021 20:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627528515; cv=none; d=google.com; s=arc-20160816; b=05X5uSSBvO937fPIJAg51+T3OZhuL16Nv/Mhf/TbvxlmCMP2sp39ERs3FsgeKsepx3 ocCqvDn2R9A0g1+POjRwHydfIoJFVA08tmeif+MZcpxJawsnMk93Ns47VDHWl3HaxO0J 6xesA2G4fceDShykNxTF+mxG3iX6oRNXDE+IrNlAwphUCg6ZL/cIiTDbPEdQ+wLASdkp c2TpaxScc1L3scl+BE5Wh2t1maR0y4QlT0YueV2tBMgJeOpp4eXpY6MBV6jNaOHJrW8y PHreKgmQL0JbpKnlEcwGGFdMLXHbf947/7gbGxKmMrD+0oz+fA5BoRW275XWyg114mhO 0bTw== 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=AODxBjZj+nI2kbzDyMsrX+mfmhxGjROcT4no+1E+pG8=; b=sd3Lemw1TCUSiSWIOvXI1xUt0KmA5a0FkdlC8zAfiVTyK7ywns5PW536ZMWG19ftXZ 1s/+yefz/FL0wSb+JM1EaMMs6rbJ7fa7VK/mhydV5Pb/56LiD3nTeJOHYzSzbs8Dbgw5 useOGRwhMI2fCJt8NXsMs2sk72JbfHjskDeQEgmBUFrFERshR1vmC1qqIk7yA01uk8cV vr2hSiDWJqBdQFfs0EiXG4q3snr9OSTiHX/tYFQsR1jMRK5XyznC6gxxxvwNGGrBYfDJ yhDCGG4W8hJ44GrcA4FCOCXIA8EtqLVWrZvbbYKb3jx73yaKt7zdTvsCgI+vIJX3ZWC2 0JXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ffBL5nvZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si1995424ilo.17.2021.07.28.20.15.04; Wed, 28 Jul 2021 20:15:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ffBL5nvZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233589AbhG2DOV (ORCPT + 99 others); Wed, 28 Jul 2021 23:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233700AbhG2DOU (ORCPT ); Wed, 28 Jul 2021 23:14:20 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB63C0613C1 for ; Wed, 28 Jul 2021 20:14:09 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id w200-20020a25c7d10000b02905585436b530so5333793ybe.21 for ; Wed, 28 Jul 2021 20:14:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=AODxBjZj+nI2kbzDyMsrX+mfmhxGjROcT4no+1E+pG8=; b=ffBL5nvZOhLj/KuvfMD8g4zqW4VwqpgSCZQdrn3g1p+d/DOnBewLZrX+aPhz3RAb+i xu4RirCyyOKXdXSvBZ9X6dJ8DFvCNp0dYJSVuSuBurDw7rKHFeB5CRwpfc/b+/juLrrP EJpZVOwvBjOz/S1I8ps5c9kPKy2+BRpxD6Tnhd22+7QHEfCOxKWgcYMsbUCwnj6j5wFM EOEDmaDBx5bSkwelvjxpJgPaX89EIqoFqz63OQgxp3TAmfA/PneBDtfu9Z/CTvETVw+O /bkkAB3d99C42vncos2bPLoSTi0NLgd5OHX6ol1CrMqNAcIDegJ0ku14D/iYLmKB6axR y7xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=AODxBjZj+nI2kbzDyMsrX+mfmhxGjROcT4no+1E+pG8=; b=CfJ4bI+MoHUDxBnqmqlEQ8HvxRxi6iVFb3hdhltxcTwVtZr3cmdAne9txZssvliWSi 6I7pGDHWUXYvBB92PUL4lqUN+Y5M6aIgdHrcDkscpI+LlafnWwxZUoCcew41NiMra1tL 7Xn74/mIG4SSpDNvAEeIBd9c3sittdLOf/khgL4QrwhmRqqFUE9uDOsr0zyYrdqjzL5w jbri1yabeS2Ch6dCN+EqQjXfXol12ql4HaP9TUFgUYSFQyyEnJT1DRGKnkylVR8aWFdd DgistI8EtN6848djJknDRJY0tqqbvrWYHtXWfPdxbcxHtkMjhTtJoWDYfWJcBU1Oixfu zGWg== X-Gm-Message-State: AOAM532HVgL+35v9MY0PJPPM2etXOVM3tEwpJqJ6MTdvSvzY8KXUhY/w J/2A925YMvID8QRIr9PszoV2cBSp+N2lU7TSDKKN//UGgfjyDQUItS4EyPOLoZb+lVLd5e6JUpr uvyS19jpSEcWQEUVOVVS0kwFNxm1p+J+Hi5rl2IoQaZ2KXrvBIGZMp/ayIEeNC5nNudZH1RlhJT sq35P0jv7OZpk= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ff72:1420:4502:fdaf]) (user=howardchung job=sendgmr) by 2002:a25:18a:: with SMTP id 132mr3936476ybb.123.1627528448737; Wed, 28 Jul 2021 20:14:08 -0700 (PDT) Date: Thu, 29 Jul 2021 11:12:55 +0800 In-Reply-To: <20210729031258.3391756-1-howardchung@google.com> Message-Id: <20210729110956.Bluez.v4.9.I00fd6c348e4c93501de6de0eae0d23436fd3895b@changeid> Mime-Version: 1.0 References: <20210729031258.3391756-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v4 09/13] plugins/admin: add ServiceAllowList property From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung This adds code to register interface org.bluez.AdminPolicyStatus. The interface will provide read-only properties to indicate the current settings of admin policies. We separate this from AdminPolicySet so that normal clients can check current policy settings while only a few clients can change policies. This patch also adds readonly property ServiceAllowlist to AdminPolicyStatus1, which indicates the current setting of service allowlist. Reviewed-by: Miao-chen Chou --- The following test steps were performed: 1. Set ServiceAllowList to ["1124","180A","180F","1812"] 2. Verify ServiceAllowList is ["1124","180A","180F","1812"] in UUID-128 form 3. Set ServiceAllowList to [] 4. Verify ServiceAllowList is [] (no changes since v1) plugins/admin.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/plugins/admin.c b/plugins/admin.c index 1fe2904d93d9..d89a77c8a123 100644 --- a/plugins/admin.c +++ b/plugins/admin.c @@ -27,6 +27,7 @@ #include "src/shared/queue.h" #define ADMIN_POLICY_SET_INTERFACE "org.bluez.AdminPolicySet1" +#define ADMIN_POLICY_STATUS_INTERFACE "org.bluez.AdminPolicyStatus1" static DBusConnection *dbus_conn; @@ -151,6 +152,11 @@ static DBusMessage *set_service_allowlist(DBusConnection *conn, return btd_error_failed(msg, "service_allowlist_set failed"); } + g_dbus_emit_property_changed(dbus_conn, + adapter_get_path(policy_data->adapter), + ADMIN_POLICY_STATUS_INTERFACE, + "ServiceAllowList"); + return dbus_message_new_method_return(msg); } @@ -160,6 +166,43 @@ static const GDBusMethodTable admin_policy_adapter_methods[] = { { } }; +void append_service_uuid(void *data, void *user_data) +{ + bt_uuid_t *uuid = data; + DBusMessageIter *entry = user_data; + char uuid_str[MAX_LEN_UUID_STR]; + const char *uuid_str_ptr = uuid_str; + + if (!uuid) { + error("Unexpected NULL uuid data in service_allowlist"); + return; + } + + bt_uuid_to_string(uuid, uuid_str, MAX_LEN_UUID_STR); + dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &uuid_str_ptr); +} + +static gboolean property_get_service_allowlist( + const GDBusPropertyTable *property, + DBusMessageIter *iter, void *user_data) +{ + struct btd_admin_policy *admin_policy = user_data; + DBusMessageIter entry; + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &entry); + queue_foreach(admin_policy->service_allowlist, append_service_uuid, + &entry); + dbus_message_iter_close_container(iter, &entry); + + return TRUE; +} + +static const GDBusPropertyTable admin_policy_adapter_properties[] = { + { "ServiceAllowList", "as", property_get_service_allowlist }, + { } +}; + static int admin_policy_adapter_probe(struct btd_adapter *adapter) { const char *adapter_path; @@ -189,6 +232,21 @@ static int admin_policy_adapter_probe(struct btd_adapter *adapter) btd_info(policy_data->adapter_id, "Admin Policy Set interface registered"); + + if (!g_dbus_register_interface(dbus_conn, adapter_path, + ADMIN_POLICY_STATUS_INTERFACE, + NULL, NULL, + admin_policy_adapter_properties, + policy_data, admin_policy_free)) { + btd_error(policy_data->adapter_id, + "Admin Policy Status interface init failed on path %s", + adapter_path); + return -EINVAL; + } + + btd_info(policy_data->adapter_id, + "Admin Policy Status interface registered"); + return 0; } -- 2.32.0.554.ge1b32706d8-goog