From patchwork Sat Sep 12 06:49:59 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: 11771657 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 C86DC59D for ; Sat, 12 Sep 2020 06:50:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C50F21734 for ; Sat, 12 Sep 2020 06:50:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="knx/vDdp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725814AbgILGuR (ORCPT ); Sat, 12 Sep 2020 02:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgILGuR (ORCPT ); Sat, 12 Sep 2020 02:50:17 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BAB7C061573 for ; Fri, 11 Sep 2020 23:50:17 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 7so7975642pgm.11 for ; Fri, 11 Sep 2020 23:50:16 -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=2F5IK3qZINJFDEk93oe4o+MOz1G8iOkBit6CICWcYW8=; b=knx/vDdp2ikbYFIZuV4k+QJjodS/ahJZgTZuC6ePrx+RE8wliaRTR0Sv1KWnC4uJP2 IvJeb4eycDhGl2bNtaS8F6STBD814f+wH3ivLAXA7kfQaJ3PZVwo0OockY8gX6S79GCT 51yINhH1loU8M9W1VNjkffK7D7ERZKRRAVomA= 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=2F5IK3qZINJFDEk93oe4o+MOz1G8iOkBit6CICWcYW8=; b=b1BzezFiSmu1jLbTRYm2prRYYCBbr08JSb7u7a5w42oGDCXwEbusJVCL1w8Ge2ITEX fX6tTEk59R2IQjcLKbqyAK3T7efu5FQT+3LtO5yv8qU7YiX97sXDYyNuTTigftdpx6Go ngtBiNqfgF/YFRVekyhjQC4PIexu9oOVTHzX6Y7mgIRX42HSscRyxsYQtHZ5EIQOcxp2 JbjrWIixxDYIai1s/RczhxDpfoSBJhEH/jbDXK0rogXEDjLVLpG0OOR37tT6I4bPtrdQ 0tfqVM8FAfD+bRc5xKwQtkLGEGOZVC1y/lbttDZsqPKey2ILJq22OsWK2D947hEnTuLB CnDw== X-Gm-Message-State: AOAM533FPesJUrCsCUDCQ93XZqVxSv2QHePVXquUqmDp7adjzzcfBDiy G6zMy52XEiKVEVoO2123+v0sl4500uzbMA== X-Google-Smtp-Source: ABdhPJwnG3zZJKY82hnEz5p5VNCCWg7/+GghC3lXTlEp/0Shd3k2Df2kpKDe8ZEJ5u87sGhTaISprA== X-Received: by 2002:aa7:9592:0:b029:13e:d13d:a054 with SMTP id z18-20020aa795920000b029013ed13da054mr5286825pfj.26.1599893415956; Fri, 11 Sep 2020 23:50:15 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:de4a:3eff:fe75:1314]) by smtp.gmail.com with ESMTPSA id 131sm4162467pfc.20.2020.09.11.23.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2020 23:50:15 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Alain Michaud , Manish Mandlik , Howard Chung , Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v5 1/8] adapter: Remove indirect dependency of headers Date: Fri, 11 Sep 2020 23:49:59 -0700 Message-Id: <20200911234949.BlueZ.v5.1.Iaa9dc2a66de5fbfa97627e1dbeb800116d3aa91e@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 Given that adapter.h refers symbols from lib/bluetooth.h and lib/sdp.h, these two headers should be included directly in adapter.h. Reviewed-by: Manish Mandlik --- (no changes since v1) src/adapter.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/adapter.h b/src/adapter.h index f8ac20261..c70a7b0da 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -26,6 +26,9 @@ #include #include +#include +#include + #define MAX_NAME_LENGTH 248 /* Invalid SSP passkey value used to indicate negative replies */ From patchwork Sat Sep 12 06:50:01 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: 11771659 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 5D892746 for ; Sat, 12 Sep 2020 06:50:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C3AB20719 for ; Sat, 12 Sep 2020 06:50:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="K72CKhJq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725823AbgILGuj (ORCPT ); Sat, 12 Sep 2020 02:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgILGui (ORCPT ); Sat, 12 Sep 2020 02:50:38 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EAFEC061573 for ; Fri, 11 Sep 2020 23:50:38 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id s65so6926111pgb.0 for ; Fri, 11 Sep 2020 23:50:38 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=6NkIUnCBg/W8FDg9bJf6d5T8R+Lpd4X8IBezpCyIGhk=; b=K72CKhJq0knAwZpQEG9H1GmylENRstHAaG9XcrLIjxX73+IgJzUhpU9hOh9p5CWd3D zGlejHonbgGmI5Tx5D6JwJNBryZXzaRW19aPlHywgSQqnxrF3rSYn7OmZ5cIsPdsk3+b OmMohJc6fUX7xiMUloKqZKZJehGGX8AFy91JY= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=6NkIUnCBg/W8FDg9bJf6d5T8R+Lpd4X8IBezpCyIGhk=; b=Pg+iieSPpsn+CKQRRO51W1/WDUl/+XzRIOLOR6k0ZX8Rvzb7k/p0m9FqyeAfuZwOJK 8Dn2Z85vR1QP4yWRtvMMyS1mXraG437zicbOs4t3CGyS2UJVxXJJNb9WOSIrep3Ud+I1 tBTa7Mex7tLHq4m5e9RkXhcfEuN/bWmBCnu9WzKAjxIERWUUqecmw5f2wrAg5zGa/KjB WDxeMcV5SF6RhRoqqpXf5W9bjmPIZXyvfqZi5uruv+hXWQkLd6Oqvt1I/YI5YpddKNkD b1xozyqTKlzEM36fMDcTKZmPZo+1ZaU1wbhCMyt5krOKOjFzBsMVWvMId7FO8u27Wx+X BFsw== X-Gm-Message-State: AOAM533omLqRi4tbyJPezr2ZcdLJcv2wZWlAXqdjzZwAKLg1DvF2WS8f NCZn9ZxGa25BgAeXsvitqmlRwTbU6DGwHA== X-Google-Smtp-Source: ABdhPJyObEj4fifAF05XHAAWoBOSQdEPZZ3GkE7MoC+k48iCN0EPi1A7sP5hWknXTQBqf6NMOOUVHg== X-Received: by 2002:a63:c705:: with SMTP id n5mr4099523pgg.19.1599893437357; Fri, 11 Sep 2020 23:50:37 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:de4a:3eff:fe75:1314]) by smtp.gmail.com with ESMTPSA id 131sm4162467pfc.20.2020.09.11.23.50.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2020 23:50:36 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Alain Michaud , Manish Mandlik , Howard Chung , Luiz Augusto von Dentz , Miao-chen Chou , Abhishek Pandit-Subedi Subject: [BlueZ PATCH v5 2/8] PRE-UPSTREAM: adv_monitor: Introduce org.bluez.AdvertisementMonitorManager1 interface Date: Fri, 11 Sep 2020 23:50:01 -0700 Message-Id: <20200911234949.BlueZ.v5.2.I205718871f4e636958904f3cfb171cfd381c54b1@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911234949.BlueZ.v5.1.Iaa9dc2a66de5fbfa97627e1dbeb800116d3aa91e@changeid> References: <20200911234949.BlueZ.v5.1.Iaa9dc2a66de5fbfa97627e1dbeb800116d3aa91e@changeid> 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 --- (no changes since v4) Changes in v4: -Create the Adv Monitor Manager only if the experimental flag is in place and mark all properties and methods experimental. 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 | 23 ++++++++ src/adv_monitor.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ src/adv_monitor.h | 32 ++++++++++ 4 files changed, 204 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 725fbe48d..22b4fa30c 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..df628a7fd 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,23 @@ static int adapter_register(struct btd_adapter *adapter) adapter->adv_manager = btd_adv_manager_new(adapter, adapter->mgmt); + if (g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) { + if (adapter->supported_settings & MGMT_SETTING_LE) { + 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; + } + } else { + btd_info(adapter->dev_id, "Adv Monitor Manager " + "skipped, LE unavailable"); + } + } + db = btd_gatt_database_get_db(adapter->database); adapter->db_id = gatt_db_register(db, services_modified, services_modified, diff --git a/src/adv_monitor.c b/src/adv_monitor.c new file mode 100644 index 000000000..ad3f64cbe --- /dev/null +++ b/src/adv_monitor.c @@ -0,0 +1,147 @@ +/* + * + * 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; +}; + +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, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL}, + { } +}; + +/* 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); + + return manager; +} + +/* Frees a manager object */ +static void manager_free(struct btd_adv_monitor_manager *manager) +{ + mgmt_unref(manager->mgmt); + + 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(), + adapter_get_path(manager->adapter), + 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(), + adapter_get_path(manager->adapter), + 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 */