Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2362043pxy; Tue, 3 Aug 2021 04:46:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGb2XsPraA/wwaemTR0gfVaiDXV0v/SCSFx8lVGKSRA2lkoixFfYixd89O96dpBLgREgOZ X-Received: by 2002:aa7:dd08:: with SMTP id i8mr25031288edv.163.1627991187441; Tue, 03 Aug 2021 04:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627991187; cv=none; d=google.com; s=arc-20160816; b=dat6ci0AtySkAzB2gklqwsQ5245IdV0fAv+n1EfrvDwo7P/5WoCM191d1qirEJb8EF MCk4ztOx1t8bmae25AY5qwuonHWSi1nHmmNnwX/R7LjbRzIRi1XE7Cx3DiFYU9mXI1wh l+uTkax/A/1HMADDpcs5KZBiDchXjELRw77FBOyJFCLnqWDPe6JuT1B0phhBBOw8Qlsa ohhUuV9hyLiSQa/6B59PR4xk0uB3VeuQOWcqKLV6hqreZEUDFbUIMPqluXEzhBMUwJow fcdAWUwy50oTQZi+3B1COBF96LaV57AdaDx8BriJV/guaaUo3Y6p/oY6sPtzPyUsd9p+ WKVA== 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=EijcOXBCRMJ11eK/vhCrpinQrSxWa4fyOdWzKU0bar1HaPCDPwHUlRkHHdact6+iuW BiN5/UP4Dr5/Ohsl7yBjWZISa3EFVNI9OBHovAce8h3lFEu1M6Volja1mpERA7Plu4Nv gS9WwGCyA0LEM8ZC5rHl9qv3Pnug8rU0gZay8xp2JLgxInAUvBxpFFXlUfisV+gSDbh2 +xX+Ae6NJDEqkyY70bzAFszCSDSi3QVsQXKcGjC26jguQfbpx4N83oSY0E+bDVAfYbjh VPExNcKk9468eWI4wTB1gBTLEdfDg4EktMhZ+TgO7jYeMh0jdk1oZQmDuSVlofuX/hFK 1Z4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JZ18kj76; 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 j17si13521502ejm.446.2021.08.03.04.46.03; Tue, 03 Aug 2021 04:46:27 -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=JZ18kj76; 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 S235895AbhHCLom (ORCPT + 99 others); Tue, 3 Aug 2021 07:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235657AbhHCLoA (ORCPT ); Tue, 3 Aug 2021 07:44:00 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5728AC061757 for ; Tue, 3 Aug 2021 04:43:49 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id a17-20020a0cefd10000b0290341c3c56ff4so7931452qvt.19 for ; Tue, 03 Aug 2021 04:43:49 -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=JZ18kj76DRajRy75DTS4X3KCHV+9sNb6aHTMFDiUJMjI96FZzcqqctKri8IQNB7EZZ FuWQM/HACx4eH0IlZGUh7AvH+q+2L8K8vcPNwoEDCueUP06aZpKLl/SjmiLUqrC7BPo3 jacdbAHy5eZnsBP5a2Y8zTNIw6ds0r6qM2r9LEzSaVgeHvtrby3Y9MacHK8A8FC4o1IQ 321SEXYnum27gP9t5/4m5fz5ZxHyKu3OPqyBqMQP8aivVna+qGtK7DyfVXx9ncJsg6ow dd5nleceVmQgqp7OCR69x2RpReacN0LKdkDxUgvwWsgKcndNgyGkK0xy3ocFfNd3SE04 Bwjw== 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=EHc39mPZsdAH7PKW5+VNF6ie6xif8+hPog5d13HWzZkE8+thjVTThTpAzBjrbIsSqm OCLDZfFik8pAP/sM7UOoJU47fD/8A1M4XGxPJb6nqryLZDAp5ibvM/MYC3B60lIKMskQ vx7gp+CAZz3fd0RJMevwW2TmW+VjkVTzZ5tjQhlKa7G8VPp8+Kkf4EMWDvLLZyR6iCvX 9vZIKvCjv8Q1DyDJ2JwmPos8i5sNa1YNyOleC9Cz8RNsPxU9yRDgu7svc3YZjOWa9OAr SM4gB1CHUTguEV85EwQ3aGIflwUWvuFGC9z6Wp9jnJTc9gSI5y0GajM3Dz/GudT0SFFZ DBCQ== X-Gm-Message-State: AOAM532UVqp774HQSWGFPwOGGqQg5PbjClDf4YyIufcG+4Mv4xHrvA1x PwM+EZf90nkDaNXnTWE3QeTHaMY8Ifd/O/Wiri6U1f+IF8FxjqZ3i4iuZgN5/5y4yYotedIXjr4 eBfHavYBYUDhodtn4jvWXQT5JY/GvJ5hcFEweWr5IgrlGCspMRcyjwkeApT7NLA7H4gtDLN3py6 vGY93tAtaOydg= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ef55:8161:c77b:7a8d]) (user=howardchung job=sendgmr) by 2002:a0c:ead1:: with SMTP id y17mr20992154qvp.12.1627991028514; Tue, 03 Aug 2021 04:43:48 -0700 (PDT) Date: Tue, 3 Aug 2021 19:43:10 +0800 In-Reply-To: <20210803114317.801840-1-howardchung@google.com> Message-Id: <20210803194127.Bluez.v9.6.I29607be7ac91b0a494ab51713ba14f583eb858ed@changeid> Mime-Version: 1.0 References: <20210803114317.801840-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v9 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