Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6055571pxv; Thu, 29 Jul 2021 05:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJTlSrkhNOOoQ+kDKAy9BIpL0B+6AVXGxU0Yk5Yp5/cURfywxBldGW1SUdOr0g5BnMrBkC X-Received: by 2002:a17:906:3041:: with SMTP id d1mr4480117ejd.54.1627561793321; Thu, 29 Jul 2021 05:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627561793; cv=none; d=google.com; s=arc-20160816; b=IgNkrRJ9BJtM8obiPX7fp9alZLS8F7yb44dyentvzsdxqvmv11BweM77HifqwUPyOl 9Fk9o7bhlQOj3hEyBc5U4s4B5g3lOWHRm6S+SXExdLc0FBWknkNTW9KsuRqa0kRJQQeV /SpWMZE7mv9k1qbh2uwylvHLNIoGYU7r4CDECuoAoCtXIyobZJvVuBAF67oGHqOlIviJ kwLzAmQDpZamJ4GKDsBj17FmWsDnZPkZUErc2G8D0OCtqoXGBkrSbkjhbb8h7q6AjT64 cVI+qIe9g8177bY21Z2BSCoHaktYUF6eGVHcoALsnQ+qFEysy4o0WU31pqeE9mMQn4wH ot8Q== 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=o+y00GfnM2qU4s9laxshCMss0MWjMacRQURypGz+84ODASfkDz8FCLSCmN2lEh6fkO MHrTQEO17ukWlF0FnGlYidufyhdTDGeCp8lDTbBxBFHvqne48rHRSkLtrcU68yk6Xt4a U+f3Ilh1Xe/caJ3ws/eqpVkTQyt6x84/7gPdyzjYnbwFuz+cHi+uI0EyfBsenWp/anrP 2mMtsqNYS+O7Q83PlVWaA6lj8INfvZql/jQj/bmAIC3r2tNQAgGuo9d4oAD+6BSGznm1 0K26ABbX8U2D/XBZQBZpPZpBAd7MBeJ0K2ixqdbgBWKPrk4dSsdYr5RIej/KLXnJgFDC 9FFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hcZMh79E; 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 kw22si2672682ejc.489.2021.07.29.05.29.29; Thu, 29 Jul 2021 05:29:53 -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=hcZMh79E; 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 S237089AbhG2M2j (ORCPT + 99 others); Thu, 29 Jul 2021 08:28:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236942AbhG2M2i (ORCPT ); Thu, 29 Jul 2021 08:28:38 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FBFC0613CF for ; Thu, 29 Jul 2021 05:28:35 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id s14-20020ac8528e0000b029025f76cabdfcso2656154qtn.15 for ; Thu, 29 Jul 2021 05:28:35 -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=hcZMh79E9OWIm2eWx6osQS+1cV33cHE4TVbSaBPVx01aT5uNQV8QY5gX+wOzB4yp+D z/S3TN1mWToaNoTDydTga7ys7OHZ+exnhLRcR4Tzmnag8gEziaL5DCJw0m+73o6S140Q w/XOmm4tZTLzBKRN7Nu4tgauIgJgBqqYUDhpaafmO3Y2FX5CFDmcnOEMHw67KN3a410n 34etZ0FcmVfNmKOnqacM8D+0llMrUAO3WfnhNArYhiOslrAPsZvHnIjhE3/jDgd9JUJW 9IeZY5gnAZ1arp4HCNtXHdMsemgrB4T6bWpJMX+Ebhu2pb6ZUaypGbs0L/GdNxTwbbWM /4Fw== 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=FD5Oeqo6WFpqoj3er4tamHbt7CTDakYvm+zLTrUDZ3RF+ZILnNv488VxH/mamgC3GX JK9vzOvz+Z5SWYzaP9/jDJzHUJ5/jk/78dHX8lQ7hUYKlti7MjTylHFkFbZij7Bqj+fh uyyJ/Wcx6Wga0TuzHWGfbJuAsQBFl4BG2rmp4P2dtOfcrv5L8jJd2gzQe56alEn/NEEm MgXzN5JhgjPYIV75ReLDOqf4zA6aHfrC+PTooI94BbDdzP2shTOPvsuXUa8NEM4kyF+z neQr6lQfRE9UoJXO3QtOZjOOWbiF9BKwcJlObldMdpnMF0ZlgAhaQdLyXfhopIrGyDfN u7LQ== X-Gm-Message-State: AOAM530nW9SMZMTWfHueQFq35pv0C18ucZIvHU4rCyWcUlYm/cUa8gbt PzWh37fRc8ulebsHdkseVSqe7LiHMHUnm2IBN5hBHZfR0fUdKUqbBP3IBEE4QcyUUwzZgol84LC 7aHR/wvS8nOmswStzBEt4qIjYDwEB8A9NHuzPXCsy2pP9eqw8zmIHhDRWwDd46EErX9a3sN5Ct+ 3WjmJNlFe6eHk= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ff72:1420:4502:fdaf]) (user=howardchung job=sendgmr) by 2002:a05:6214:b87:: with SMTP id fe7mr985589qvb.39.1627561714943; Thu, 29 Jul 2021 05:28:34 -0700 (PDT) Date: Thu, 29 Jul 2021 20:27:45 +0800 In-Reply-To: <20210729122751.3728885-1-howardchung@google.com> Message-Id: <20210729202648.Bluez.v6.7.I29607be7ac91b0a494ab51713ba14f583eb858ed@changeid> Mime-Version: 1.0 References: <20210729122751.3728885-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v6 07/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