Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2253822pxy; Tue, 3 Aug 2021 01:25:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoC8+8LCxCIO7oacw9y5wYnRbVhF/diB7I3lmnCPRUQzfL6GNMmLUMkjzkaF4DcDqWvpwn X-Received: by 2002:a17:907:1190:: with SMTP id uz16mr19570218ejb.543.1627979117775; Tue, 03 Aug 2021 01:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627979117; cv=none; d=google.com; s=arc-20160816; b=nWpro8LrZVUAZKniYV22hlbOJ+TQ/7JUwbotoQg8tZnBh9SUDriNeNRkeQB0hktwiW k+TVIMRlGOnpZjQLlPn1qmayq9dAVZFVc2b7DqPvq7v5OJxys/ibhlFmX4Qbqk5alpwv vi6E3x15NHDFX6ma5xchrPjtjo3dy2kJcaNbKBXnVnFMDoZTo9ipDeVo3+A4Q4Y0mbEG us/4cGWKTfuJqXFfXCGy21PQyFwkPXF8uej/Ft5DNGaOqZPMTeNgeOVLlX+ntP3c1H2U sa7poQLXcR7kce4QwFgMXrn14ooDMySuj6AdtRuB8OcJ1i2puXDEiTUD55HKWPXwygj+ 8+6g== 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=ov+ljL+WLImh2UNgqiJukm2dfT5futa1Kc0R7vlTCyc=; b=AeTg6eKpohu7RsT3KDUBALGfjKAS0Nz+LkmMFfNCDVhLFuBt0vrFQntevxilhiAkrm W6bguJduEPqGwOmtRAy/YRoc9rTuCUDEOGI3hFNRfojiEYfQgmrgJWxs6BylCjFcdHhD DMKtllL3dDvcM5rn8VLAIUTyOpFO71OzB10ipqCfowxga3v1Erzqjp7g0tNbE8akQscN SyU4lQhOCKZxemcHMv87c0YL+jIgwAtqsf8Cxscnn47Rdp76IxzQQt8krcXhb/6y00uw GTJnth6ZWx2WCjumg82pvkhItl3C9GneCV08Xmd8tlcgHi0NbeaSZvxtCajO3LE2ygZK vlFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Un1Nj8F9; 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 l10si12670435edb.184.2021.08.03.01.24.49; Tue, 03 Aug 2021 01:25:17 -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=Un1Nj8F9; 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 S234572AbhHCIXg (ORCPT + 99 others); Tue, 3 Aug 2021 04:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234579AbhHCIXg (ORCPT ); Tue, 3 Aug 2021 04:23:36 -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 C12A1C061764 for ; Tue, 3 Aug 2021 01:23:25 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a6-20020a25ae060000b0290551bbd99700so22164341ybj.6 for ; Tue, 03 Aug 2021 01:23:25 -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=ov+ljL+WLImh2UNgqiJukm2dfT5futa1Kc0R7vlTCyc=; b=Un1Nj8F9VASL8QrrWVLDNJB3gcL2U7EVeYH1dGrP1FgBrEFgSHbjg/g6Yx5Htz90pE ipS8Nhe5r2IO7aDr1wXbY7co8KEz8Hf1ChL5Juv+XV0895wiSvG8kVixTTpfTwM/m8a5 SQPscy+UU6jdnpqXNDPcop88dxbWZVkIRrtTd0vsW3JVMSTmume4NUD+c5mQYHP/lnVl MHuK5oeqwvpQqCnHH+54qZO3wc85U3KlpKSVKA0TBUnkR8t1s2zq+KZ5CpXyeszDsSqT GVnQO44Ja7ZDOPX4Ym1TjM05txODQbWH2BEVfEejbAOE+e2POabkWJBXIL5N6g1itri0 WnXA== 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=ov+ljL+WLImh2UNgqiJukm2dfT5futa1Kc0R7vlTCyc=; b=gw5p9fZUlCRu6OzxX7sg9Pl/RUWY/JfPT0wUHMflMbJJA34xNc1J0b5IRYrxsNTK72 43bH9iaVDggSd9breYuiQznpe7zkowU+gMOM//gJLnaFPuNbE6pC+4PJOEimemiZFL5u OTVtTC4km4L2cG5zY493WVAuoqFpreNHz1CRnHaHmUYVbx6koV66U0w/j0DHnuwwISX7 H/ItkT7eBnML91IqsQsePuN54JGycKFnJpHzde+d4/GfALxqCOuX1d4p64Xm3uq6dPzM VEV+ggre3+5MItztgRlRmNjFFtIeXLYVi9scOemfDF81E1HaVA1YxjZELYDZ8hK31hgx NdjA== X-Gm-Message-State: AOAM533cFMGE+fBrqk9GxgcJD0pxkB8BMhDvnmdH3dCwX13wF5ef6K5V aYZ9BuvGmDms7xy7lHsYpkgxSR4bK55eljY1o27YVqrAaXlntZhP9PfSwqR48iJBuyTUmZoFfuA BzCi33yAu/mcOrJfLGKTao6Ox64KbNg1uR8itivA7wVUYenRBq0ZtN6iQ6THB3eSr0K8Ptm8F8o hl6RdoAprY2fw= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ef55:8161:c77b:7a8d]) (user=howardchung job=sendgmr) by 2002:a25:aaf1:: with SMTP id t104mr27000063ybi.516.1627979004960; Tue, 03 Aug 2021 01:23:24 -0700 (PDT) Date: Tue, 3 Aug 2021 16:22:30 +0800 In-Reply-To: <20210803082237.723766-1-howardchung@google.com> Message-Id: <20210803161319.Bluez.v8.6.I29607be7ac91b0a494ab51713ba14f583eb858ed@changeid> Mime-Version: 1.0 References: <20210803082237.723766-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v8 06/13] plugins/admin: add admin_policy adapter driver 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 admin_policy driver to adapter when admin plugin is enabled. The following test steps were performed: 1. restart bluetoothd 2. check if "Admin Policy is enabled" in system log Reviewed-by: Miao-chen Chou --- (no changes since v1) plugins/admin.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/plugins/admin.c b/plugins/admin.c index 42866bcf7be2..923e08cb836b 100644 --- a/plugins/admin.c +++ b/plugins/admin.c @@ -12,17 +12,84 @@ #include #endif +#include "lib/bluetooth.h" + +#include "src/adapter.h" +#include "src/error.h" #include "src/log.h" #include "src/plugin.h" +#include "src/shared/queue.h" + +/* |policy_data| has the same life cycle as btd_adapter */ +static struct btd_admin_policy { + struct btd_adapter *adapter; + uint16_t adapter_id; +} *policy_data = NULL; + +static struct btd_admin_policy *admin_policy_new(struct btd_adapter *adapter) +{ + struct btd_admin_policy *admin_policy = NULL; + + admin_policy = g_try_malloc(sizeof(*admin_policy)); + if (!admin_policy) { + btd_error(btd_adapter_get_index(adapter), + "Failed to allocate memory for admin_policy"); + return NULL; + } + + admin_policy->adapter = adapter; + admin_policy->adapter_id = btd_adapter_get_index(adapter); + + return admin_policy; +} + +static void admin_policy_free(void *data) +{ + struct btd_admin_policy *admin_policy = data; + + g_free(admin_policy); +} + +static int admin_policy_adapter_probe(struct btd_adapter *adapter) +{ + if (policy_data) { + btd_warn(policy_data->adapter_id, + "Policy data already exists"); + admin_policy_free(policy_data); + policy_data = NULL; + } + + policy_data = admin_policy_new(adapter); + if (!policy_data) + return -ENOMEM; + + btd_info(policy_data->adapter_id, "Admin Policy has been enabled"); + + return 0; +} + +static struct btd_adapter_driver admin_policy_driver = { + .name = "admin_policy", + .probe = admin_policy_adapter_probe, + .resume = NULL, +}; + static int admin_init(void) { DBG(""); + + return btd_register_adapter_driver(&admin_policy_driver); } static void admin_exit(void) { DBG(""); + + btd_unregister_adapter_driver(&admin_policy_driver); + + if (policy_data) + admin_policy_free(policy_data); } BLUETOOTH_PLUGIN_DEFINE(admin, VERSION, -- 2.32.0.554.ge1b32706d8-goog