From patchwork Thu Sep 10 04:35:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 11766539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3CCA618 for ; Thu, 10 Sep 2020 04:36:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF6412075E for ; Thu, 10 Sep 2020 04:36:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Jl+1xnuK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725887AbgIJEga (ORCPT ); Thu, 10 Sep 2020 00:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgIJEgW (ORCPT ); Thu, 10 Sep 2020 00:36:22 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F413EC061573 for ; Wed, 9 Sep 2020 21:36:21 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id j7so296378plk.11 for ; Wed, 09 Sep 2020 21:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5aM6VVrTht1FceKkAVmX0ix4M6IUKIpD0QpYq5ZNVn8=; b=Jl+1xnuKFW9ub7ltdSqSvR119Ahfu3I5FYR9J5jAl227l5CdvWp6wgmJW85rYhhTKb 8Kk3HVXVgO+3aMn4rxrC74RKNczyaYVA7cxb47OyLTR06oaZRKbVeBe0ggVPzto9YWAM csH3A/7zWxlg+Y8yfX7V9TMOvx7+6gL/TbrC0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5aM6VVrTht1FceKkAVmX0ix4M6IUKIpD0QpYq5ZNVn8=; b=jlYMVaGmBamdklp5gvXZghd+Wc3YjNjb+h0vBeqDn+dhf4g/gS26l1PEJzlauL05Rs cUpaUw42r/LbSCVz2/W2+qohRnHzczVq1/bFhHg6cze6UqI2c5HY9oXAt81d/ucXsIHO JlP/QcglMYuXc7uJjM0yVFXUoJPQ7aCVaRt/11jImdNoUm2TCKOXaUDY3ZJK/i0FTQfU rtksQTfzggDpuxhBl/FX5M2SUKkzLiHPCwxArmBytqavACf39HVmwP86PDF30cFqv4f+ od4PVcqL+TrJE3YFdxG8YAp1+PUVN1ubZV8Y1X9OttQS9m5l5rYdVuxIcfs2P7toRp+C qc/Q== X-Gm-Message-State: AOAM533tmqKNddpTeTbFrW9AfPcLrPcIBnl7W8p51Oc3ySpEDDuwTdHf sMC9936lTGEdIDAzD7ypxYv934qm6crqqA== X-Google-Smtp-Source: ABdhPJxoLuV75GFsH3LQk38zdw2SofziWDLx6Mg+4cIgoXx8zIxCYBJ7pVqt2ug4IzEpTZGa7HR+aw== X-Received: by 2002:a17:902:b604:: with SMTP id b4mr3689066pls.120.1599712581112; Wed, 09 Sep 2020 21:36:21 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:de4a:3eff:fe75:1314]) by smtp.gmail.com with ESMTPSA id y4sm4149820pfq.215.2020.09.09.21.36.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2020 21:36:20 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Manish Mandlik , Alain Michaud , Howard Chung , Luiz Augusto von Dentz , Miao-chen Chou , Abhishek Pandit-Subedi Subject: [BlueZ PATCH v2 1/7] PRE-UPSTREAM: adv_monitor: Introduce org.bluez.AdvertisementMonitorManager1 interface Date: Wed, 9 Sep 2020 21:35:32 -0700 Message-Id: <20200909213423.BlueZ.v2.1.I205718871f4e636958904f3cfb171cfd381c54b1@changeid> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This introduces the org.bluez.AdvertisementMonitorManager1 without implementing handlers of methods and properties. The following test was performed. - Upon adapter registration, the info line of creating an ADV monitor manager gets printed, and system bus emits the interface events of org.bluez.AdvertisementMonitorManager1. Reviewed-by: Yun-Hao Chung Reviewed-by: Manish Mandlik Reviewed-by: Abhishek Pandit-Subedi --- Changes in v2: -Use new0 instead of g_new0 -Remove the reset of manager members -Make methods/property experimental Makefile.am | 3 +- src/adapter.c | 14 +++++ src/adapter.h | 3 + src/adv_monitor.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++ src/adv_monitor.h | 32 ++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 src/adv_monitor.c create mode 100644 src/adv_monitor.h diff --git a/Makefile.am b/Makefile.am index 7719c06f8..b14ee950e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -293,7 +293,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \ src/gatt-client.h src/gatt-client.c \ src/device.h src/device.c \ src/dbus-common.c src/dbus-common.h \ - src/eir.h src/eir.c + src/eir.h src/eir.c \ + src/adv_monitor.h src/adv_monitor.c src_bluetoothd_LDADD = lib/libbluetooth-internal.la \ gdbus/libgdbus-internal.la \ src/libshared-glib.la \ diff --git a/src/adapter.c b/src/adapter.c index 1435e2bd7..de327dc98 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -77,6 +77,7 @@ #include "attrib-server.h" #include "gatt-database.h" #include "advertising.h" +#include "adv_monitor.h" #include "eir.h" #define ADAPTER_INTERFACE "org.bluez.Adapter1" @@ -272,6 +273,8 @@ struct btd_adapter { struct btd_gatt_database *database; struct btd_adv_manager *adv_manager; + struct btd_adv_monitor_manager *adv_monitor_manager; + gboolean initialized; GSList *pin_callbacks; @@ -6360,6 +6363,9 @@ static void adapter_remove(struct btd_adapter *adapter) btd_adv_manager_destroy(adapter->adv_manager); adapter->adv_manager = NULL; + btd_adv_monitor_manager_destroy(adapter->adv_monitor_manager); + adapter->adv_monitor_manager = NULL; + g_slist_free(adapter->pin_callbacks); adapter->pin_callbacks = NULL; @@ -8633,6 +8639,14 @@ static int adapter_register(struct btd_adapter *adapter) adapter->adv_manager = btd_adv_manager_new(adapter, adapter->mgmt); + adapter->adv_monitor_manager = btd_adv_monitor_manager_create( + adapter, adapter->mgmt); + if (!adapter->adv_monitor_manager) { + btd_error(adapter->dev_id, + "Failed to create Adv Monitor Manager for adapter"); + return -EINVAL; + } + db = btd_gatt_database_get_db(adapter->database); adapter->db_id = gatt_db_register(db, services_modified, services_modified, diff --git a/src/adapter.h b/src/adapter.h index f8ac20261..5cb467141 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -26,6 +26,9 @@ #include #include +#include "lib/bluetooth.h" +#include "lib/sdp.h" + #define MAX_NAME_LENGTH 248 /* Invalid SSP passkey value used to indicate negative replies */ diff --git a/src/adv_monitor.c b/src/adv_monitor.c new file mode 100644 index 000000000..8e7dad8dd --- /dev/null +++ b/src/adv_monitor.c @@ -0,0 +1,148 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2020 Google LLC + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE +#include + +#include +#include +#include + +#include "adapter.h" +#include "dbus-common.h" +#include "log.h" +#include "src/shared/mgmt.h" +#include "src/shared/util.h" + +#include "adv_monitor.h" + +#define ADV_MONITOR_MGR_INTERFACE "org.bluez.AdvertisementMonitorManager1" + +struct btd_adv_monitor_manager { + struct btd_adapter *adapter; + struct mgmt *mgmt; + uint16_t adapter_id; + char *path; +}; + +static const GDBusMethodTable adv_monitor_methods[] = { + { GDBUS_EXPERIMENTAL_METHOD("RegisterMonitor", + GDBUS_ARGS({ "application", "o" }), + NULL, NULL) }, + { GDBUS_EXPERIMENTAL_ASYNC_METHOD("UnregisterMonitor", + GDBUS_ARGS({ "application", "o" }), + NULL, NULL) }, + { } +}; + +static const GDBusPropertyTable adv_monitor_properties[] = { + {"SupportedMonitorTypes", "as", NULL, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL}, + {"SupportedFeatures", "as", NULL, NULL, NULL}, + { } +}; + +/* Allocates a manager object */ +static struct btd_adv_monitor_manager *manager_new( + struct btd_adapter *adapter, + struct mgmt *mgmt) +{ + struct btd_adv_monitor_manager *manager; + + if (!adapter || !mgmt) + return NULL; + + manager = new0(struct btd_adv_monitor_manager, 1); + if (!manager) + return NULL; + + manager->adapter = adapter; + manager->mgmt = mgmt_ref(mgmt); + manager->adapter_id = btd_adapter_get_index(adapter); + manager->path = g_strdup(adapter_get_path(manager->adapter)); + + return manager; +} + +/* Frees a manager object */ +static void manager_free(struct btd_adv_monitor_manager *manager) +{ + mgmt_unref(manager->mgmt); + free(manager->path); + + free(manager); +} + +/* Destroys a manager object and unregisters its D-Bus interface */ +static void manager_destroy(struct btd_adv_monitor_manager *manager) +{ + if (!manager) + return; + + g_dbus_unregister_interface(btd_get_dbus_connection(), + manager->path, + ADV_MONITOR_MGR_INTERFACE); + + manager_free(manager); +} + +/* Creates a manager and registers its D-Bus interface */ +struct btd_adv_monitor_manager *btd_adv_monitor_manager_create( + struct btd_adapter *adapter, + struct mgmt *mgmt) +{ + struct btd_adv_monitor_manager *manager; + + manager = manager_new(adapter, mgmt); + if (!manager) + return NULL; + + if (!g_dbus_register_interface(btd_get_dbus_connection(), manager->path, + ADV_MONITOR_MGR_INTERFACE, + adv_monitor_methods, NULL, + adv_monitor_properties, manager, + NULL)) { + btd_error(manager->adapter_id, + "Failed to register " + ADV_MONITOR_MGR_INTERFACE); + manager_free(manager); + return NULL; + } + + btd_info(manager->adapter_id, + "Adv Monitor Manager created for adapter %s", + adapter_get_path(manager->adapter)); + + return manager; +} + +/* Destroys a manager and unregisters its D-Bus interface */ +void btd_adv_monitor_manager_destroy(struct btd_adv_monitor_manager *manager) +{ + if (!manager) + return; + + btd_info(manager->adapter_id, "Destroy Adv Monitor Manager"); + + manager_destroy(manager); +} diff --git a/src/adv_monitor.h b/src/adv_monitor.h new file mode 100644 index 000000000..69ea348f8 --- /dev/null +++ b/src/adv_monitor.h @@ -0,0 +1,32 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2020 Google LLC + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#ifndef __ADV_MONITOR_H +#define __ADV_MONITOR_H + +struct mgmt; +struct btd_adapter; +struct btd_adv_monitor_manager; + +struct btd_adv_monitor_manager *btd_adv_monitor_manager_create( + struct btd_adapter *adapter, + struct mgmt *mgmt); +void btd_adv_monitor_manager_destroy(struct btd_adv_monitor_manager *manager); + +#endif /* __ADV_MONITOR_H */