Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5230949pxv; Wed, 28 Jul 2021 06:19:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGlH7y0ZCUkDvCJAZypBIPwqH4gRUw1Nir0QXeoblTcc2waEnvVkHmhCKJTWq+Iv8+BNq9 X-Received: by 2002:a92:d9c6:: with SMTP id n6mr20724508ilq.142.1627478353556; Wed, 28 Jul 2021 06:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627478353; cv=none; d=google.com; s=arc-20160816; b=dEl+/HqC+6wV0uaqX4bJXl9UlEzJkgJ/Cr9+HzqeHJfI4uYCnmHbe/gbN+zeJmvTCl po7Pyn2ta8zIvd6Aqr/o3uqmltM4kkQqnUDBS0WHuBUnCA/vmixK11KtrNQ9sIdoss72 do+BSD93+3nw7yM699ulwLhEfMRqe+1TdMuxkjrSAx95EdzrPqd8C2x2WemuKCpCYjIF C3YT9vf5kKhzFaDZEvD2gWiwmaAdtQt5jBVRaXS29OHIr2T/2NzeiQkOzGZDUWkGiClg nF/Er6wdw9uuAVvJdoYDekMC3j0PBvCyOV97fLyUymFsc7WHQt5B/NDvzTAJFL5otqx8 3ORg== 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=A4c6MpYUECSKm/aYN6hFWhT7ehzXLCabu/7cA+6MNQk=; b=MkmDPjMrAH+Lod/FNxGzLBh+rKfdJfHTGSD3m5ff+apLKP1gdi3TLn0Ama+flU20Oc VnA5IYGvB2r1IVyjOh9FhHZnK3W/YU/fKOhqFL9hNje/oE4zBDCqoOKdv1CiZ1CKPVi9 VWqE6SiJs6Ki4ntM0gkCQv5A8x7K/UsakVj6CJ4lb/hggdaQfgsnOQn+U9kVGdF7sAdo O3aAXL3nr15EpPL7iaHX8Ya2Rez2K+QAUL0IiEZkwV+eO+Vw27T5/D6FtfcZ2tANcHe7 /3zHLdiXbUdq+FVdSXSvM1M+HIGgwduaFW/Wi6r96XBJMn05MSmfLniQtzJPl3YS0UDq 3wbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ycc4bJag; 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 n11si8031652ilt.138.2021.07.28.06.19.01; Wed, 28 Jul 2021 06:19:13 -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=Ycc4bJag; 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 S233315AbhG1NQR (ORCPT + 99 others); Wed, 28 Jul 2021 09:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234771AbhG1NQR (ORCPT ); Wed, 28 Jul 2021 09:16:17 -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 D66C0C061757 for ; Wed, 28 Jul 2021 06:16:15 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id c63-20020a25e5420000b0290580b26e708aso2784580ybh.12 for ; Wed, 28 Jul 2021 06:16:15 -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=A4c6MpYUECSKm/aYN6hFWhT7ehzXLCabu/7cA+6MNQk=; b=Ycc4bJag4XlHtgfPQSkhfYjseANQepcL3OR+OOIERLg+dnkDhpfat0FGrl7GU4Ag9y QJlNcxrf/xBLT+tgBCgatK1X7FoKei2m90NQOUPJcn6KXWDxkHaz3mqzHQUpY7GD9MSh 2ptkhXSy6UuRidV3FyWc231y9h7XzD3DlxPb6Rz7lVxlFR8QY2wrekhoTFiJJN13RNkZ SNEeCgAr0mUX07mFuiQ2TbbKme87+U9r6AnGK0hj42ByMZHcXBJlNvvVJDmThs/Wvjnz zsbs6aNpkTezCe+brltP+otMFhfs8idtSmWllopvU3rnwLgX0vHGSJsrdmMR3u91625o ttTA== 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=A4c6MpYUECSKm/aYN6hFWhT7ehzXLCabu/7cA+6MNQk=; b=HHw/ZZa2AMkfabmWB555sZSA/y7xg0L4BknZmjV3QLe5B/K6Bo8xDK4CelN+7o3KrX ooZe/AX+jWyowHj5Mp061MpgHcWZmbJtCIHA/d0GTEmyeazyzlToyyiA2iTgw7QelsMm FaGQ4vS4E4q2TiP4jm5BLu4E2LXB83sA0BfvrWdYbTQOP66Bmz4yqmiloA2qCkP4yEiE WYWAhS40U8nXR0Blu0z9BoAKSMes/BQ1zDx14t/kYoeOOevHBdwKOywtTH2MbCxRXXlx OQIc8RMrG/m7Wg5D7WbLngzMz9heMgfyKIVYJrqRkHY7umafIA9yN/MAEDK71ulERAck XDcw== X-Gm-Message-State: AOAM532pLyfOFTzLX0aSnq7rlrHAMB46aGbh5vdUrJTpKmpT7TTjKP8a hI15XbMXVm9ekXEEId8cIWWbv+ZhnAFg3X6+daVmOOCpJ3vdRIkQc1L3/MXRZ77OLUcR88y5ELK WWrZNqW+UM44QVxdgbvsESM025x435iXS1/pnamX/EmR3JTm91y4VFQV+cbgAS9XYkPPKiQGC3E 5iOj/IQnTukAs= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:9b6a:9d1f:2f3e:45de]) (user=howardchung job=sendgmr) by 2002:a25:e747:: with SMTP id e68mr5293133ybh.364.1627478175050; Wed, 28 Jul 2021 06:16:15 -0700 (PDT) Date: Wed, 28 Jul 2021 21:15:23 +0800 In-Reply-To: <20210728131529.3310558-1-howardchung@google.com> Message-Id: <20210728211405.Bluez.v3.7.I29607be7ac91b0a494ab51713ba14f583eb858ed@changeid> Mime-Version: 1.0 References: <20210728131529.3310558-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [Bluez PATCH v3 07/13] plugins/admin_policy: 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_policy 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 ++++++++++++++++++++++++++++++++++++++++++ plugins/admin_policy.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/plugins/admin.c b/plugins/admin.c index 42866bcf7..923e08cb8 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, diff --git a/plugins/admin_policy.c b/plugins/admin_policy.c index dd8d89736..2ece87156 100644 --- a/plugins/admin_policy.c +++ b/plugins/admin_policy.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_policy_init(void) { DBG(""); + + return btd_register_adapter_driver(&admin_policy_driver); } static void admin_policy_exit(void) { DBG(""); + + btd_unregister_adapter_driver(&admin_policy_driver); + + if (policy_data) + admin_policy_free(policy_data); } BLUETOOTH_PLUGIN_DEFINE(admin_policy, VERSION, -- 2.32.0.432.gabb21c7263-goog