From patchwork Wed Jan 24 16:07:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529365 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B237E560 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=Jc1FFsj3igY58YZ1lkHJqIfDycyWbrxaAg3g6PW3FS6BryIAAMEnAuv2K4ePylJ1c1qLSDZPlyUbeOKeGj/vonMWz6jLYOA5t/SU3xULlTb2sPHzvvcozI2fPNzFlk1TSIHe32sxGzKUW+yRij2XyQexYTiMAne6rP0NQk8VaHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=F/HbVo4A4RjQZ+vKiPn5ElqvSWqMFTAmzzmaMvmbiz8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BinmluiXQyQK5Og6kaBhOCd01Zxop5EC1CUurei+qOOxhVux41I2WPaHv//8jkj/xyy4O2K3zRuasmfECdF5N3prZ4exHA6cgSPw4l/uldbezyF/S0ZYhP1TPH1ZWfzcLAUuRoDTmjRfLXJmKSdI4KIsR/M7L79ykXnpqoK+v2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QKsE25AT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QKsE25AT" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2D016C433B1; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=F/HbVo4A4RjQZ+vKiPn5ElqvSWqMFTAmzzmaMvmbiz8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QKsE25ATD28CMFTxE1a+ivL2GMrOjyKDo5J4mutGK3dfLiqKxY4uUpxF/jrQUXmKc anYGWZiqhbKiHh4ZOSiRHinUe9yoRcMm4yXWlPqC+ClOffJEZvJz4AAEEg34NUP7B2 xNlt+GnyGoMQNOl5FH12vqfaYYvt7xPXsNouxxCKoC9kLiARzS+1MJ7xxBt5ScBAy4 dAj79VrgwKsBlKhnRzS2Lc69XmjSmIfvgYRyHw8zdnl5CSpzXT4wlUimCQwaDtD6Y3 VGIDWG7ZuaIsFBN3lq3wLwEmL8w2lMf/uKYesvRMDESv9xkE17PSb8gnsG8/b9Paj5 zzLTleFdnMC5w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 184DCC46CD2; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:07:57 +0000 Subject: [PATCH BlueZ v2 1/8] configure, README: introduce --enable-external-plugins Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-1-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=2129; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=e1EdDSyciHHAaX9NsOJkW3suqFVoEXcg0Cnn7chU+j0=; b=wZYVhXk4d+d1zkJHhssGBaY6vQuhV8G7N+2hDdjZ4AbMKP4XBklm6/NB0S+YGw4naiNCcfYp1 9iEoJaO+Q4dAXGqgVsncGI6PhasTNvUJVlUoT8B35gtqTmUOWvxodpa X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As the README chunk says, disabled by default, since they rely on internal API/ABI and can break at any point. Instead everyone affected should work and upstream their plugin into the bluez project. --- README | 13 +++++++++++++ configure.ac | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/README b/README index 7de7045a8..6c0777046 100644 --- a/README +++ b/README @@ -249,6 +249,19 @@ For a working system, certain configuration options need to be enabled: systems. The behavior of the deprecated tools may be unstable or simply don't work anymore. + --enable-external-plugins + + Enable support for external plugins + + By default external plugins for bluetoothd and obexd are not + supported and thus disabled. + + External plugins require access to internal, undocumented and + unversioned API in said daemons. As such they can break at any + time. If you have such plugins, enable this option and work + actively with the community to make said plugin part of the + upstream bluez project. + --enable-nfc This option enable NFC pairing support. diff --git a/configure.ac b/configure.ac index cab5da581..5e353a1d6 100644 --- a/configure.ac +++ b/configure.ac @@ -364,6 +364,16 @@ AC_ARG_ENABLE(deprecated, AS_HELP_STRING([--enable-deprecated], [enable_deprecated=${enableval}]) AM_CONDITIONAL(DEPRECATED, test "${enable_deprecated}" = "yes") +AC_ARG_ENABLE(external-plugsin, AS_HELP_STRING([--enable-external-plugins], + [enable support for external plugins]), + [enable_external_plugins=${enableval}]) +AM_CONDITIONAL(EXTERNAL_PLUGINS, test "${enable_external_plugins}" = "yes") +if (test "${enable_external_plugins}" = "yes"); then + AC_DEFINE(EXTERNAL_PLUGINS, 1, [Define if external plugin support is required]) +else + AC_DEFINE(EXTERNAL_PLUGINS, 0, [Define if external plugin support is required]) +fi + AC_ARG_ENABLE(sixaxis, AS_HELP_STRING([--enable-sixaxis], [enable sixaxis plugin]), [enable_sixaxis=${enableval}]) AM_CONDITIONAL(SIXAXIS, test "${enable_sixaxis}" = "yes" && From patchwork Wed Jan 24 16:07:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529366 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5877E568 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=Th5+oT/UaOhydi8sTdbPQyfrB+OmxeX016fgv/SIhe6bjLIiPWeq+PMsNB8JyzQQdz0Q0kR8EOkVEVV/uPPtcNpfjaXu/i/6DpQ6Vw/lGhJdIAXnmWAgHGxNnYho8Z+z2JYkJLXnYKNqwrC7zL/aor7bkKQmT8xMoZgFCTdRveY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=MakOcaBw3YSuN3nn/DHr0vOxRiZjIEdQeSW/80o/hfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nmiCMkzD25d5U2yRaWQYSUjNnq4ig3LBGDdteflvweQV5as4qOge8NgdnBb4thlx5gYDhJdN6yaxsWz27RsQI5B/URctQkXNxFrOAMGuvzesAcT8mKYCf6wZzgOrciNWaooUeP/uvg3sZJpKXI6ulROdooAuVZgWrnidwhBXNUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ktD4za5+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ktD4za5+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 36767C43390; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=MakOcaBw3YSuN3nn/DHr0vOxRiZjIEdQeSW/80o/hfg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ktD4za5+LF3DvKmR3ttp0gyNxO1tNCYboArG0uoA1vzE5D+RQImefE2vqgQE0GB+O FoBm9DolF9KGppVuMiC5tDdzZguOSElzyXAoMHYP17tcWMH2jfMdb974FqWzjPVzGh SCuGsK5S30mJDiaIo/zsaLOMeNEGT5AMJmj0ovRneZPIMvfqyt4v4CNKgiZSgsis4X OOXMkt4mPQCJyntYR4NVIwEbP0wLzUVIHoYHd1dgXXtlF5mh8SDq17JwPAEMaLkDqw Wq6tNmifNE9td/ZClswRucF2d9YfpXz00h4h7pzMsNbBBwb3hghPa1K2+vwvRFgyXF i1/QbpmNWUODA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2190CC48260; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:07:58 +0000 Subject: [PATCH BlueZ v2 2/8] obexd: factor out external plugin support Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-2-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=5642; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=pGvGwURoyXDGW5FladnamFTHwTNZsaHX3sUoMvQj5ac=; b=ELogNpQv7uztXa6PHbi8d4EtukomGUD5kdH4WM19I9qSFtW8FeynmhkA8o5RgXBkGv7i8Lyno 5NMcpUsEgqzC7vJh2kHEW23EXS4lYFfxnNBsX49+RU4cbn3FgJxqHmI X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As a whole all plugins should be built-in, otherwise they would be using internal, undocumented, unversioned, unstable API. Flesh out the external plugin support into a few pre-processor blocks and simplify the normal path. Hide the internal API (omit export-dynamic) when built without external plugins. --- Makefile.obexd | 2 ++ obexd/src/obexd.h | 2 +- obexd/src/plugin.c | 93 ++++++++++++++++++++++++++++++++++++------------------ obexd/src/plugin.h | 4 +++ 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/Makefile.obexd b/Makefile.obexd index 5d1a4ff65..9175de2a4 100644 --- a/Makefile.obexd +++ b/Makefile.obexd @@ -86,7 +86,9 @@ obexd_src_obexd_LDADD = lib/libbluetooth-internal.la \ $(ICAL_LIBS) $(DBUS_LIBS) $(LIBEBOOK_LIBS) \ $(LIBEDATASERVER_LIBS) $(GLIB_LIBS) -ldl +if EXTERNAL_PLUGINS obexd_src_obexd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic +endif obexd_src_obexd_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \ $(ICAL_CFLAGS) -DOBEX_PLUGIN_BUILTIN \ diff --git a/obexd/src/obexd.h b/obexd/src/obexd.h index fe312a65b..af5265da5 100644 --- a/obexd/src/obexd.h +++ b/obexd/src/obexd.h @@ -18,7 +18,7 @@ #define OBEX_MAS (1 << 8) #define OBEX_MNS (1 << 9) -gboolean plugin_init(const char *pattern, const char *exclude); +void plugin_init(const char *pattern, const char *exclude); void plugin_cleanup(void); gboolean manager_init(void); diff --git a/obexd/src/plugin.c b/obexd/src/plugin.c index a3eb24753..212299fa5 100644 --- a/obexd/src/plugin.c +++ b/obexd/src/plugin.c @@ -37,11 +37,14 @@ static GSList *plugins = NULL; struct obex_plugin { +#if EXTERNAL_PLUGINS void *handle; +#endif const struct obex_plugin_desc *desc; }; -static gboolean add_plugin(void *handle, const struct obex_plugin_desc *desc) +#if EXTERNAL_PLUGINS +static gboolean add_external_plugin(void *handle, const struct obex_plugin_desc *desc) { struct obex_plugin *plugin; @@ -65,6 +68,26 @@ static gboolean add_plugin(void *handle, const struct obex_plugin_desc *desc) return TRUE; } +#endif + +static void add_plugin(const struct obex_plugin_desc *desc) +{ + struct obex_plugin *plugin; + + plugin = g_try_new0(struct obex_plugin, 1); + if (plugin == NULL) + return; + + plugin->desc = desc; + + if (desc->init() < 0) { + g_free(plugin); + return; + } + + plugins = g_slist_append(plugins, plugin); + DBG("Plugin %s loaded", desc->name); +} static gboolean check_plugin(const struct obex_plugin_desc *desc, char **patterns, char **excludes) @@ -93,42 +116,23 @@ static gboolean check_plugin(const struct obex_plugin_desc *desc, } -#include "builtin.h" - -gboolean plugin_init(const char *pattern, const char *exclude) +static void external_plugin_init(char **patterns, char **excludes) { - char **patterns = NULL; - char **excludes = NULL; +#if EXTERNAL_PLUGINS GDir *dir; const char *file; - unsigned int i; - if (strlen(PLUGINDIR) == 0) - return FALSE; - - if (pattern) - patterns = g_strsplit_set(pattern, ":, ", -1); - - if (exclude) - excludes = g_strsplit_set(exclude, ":, ", -1); - - DBG("Loading builtin plugins"); - - for (i = 0; __obex_builtin[i]; i++) { - if (check_plugin(__obex_builtin[i], - patterns, excludes) == FALSE) - continue; + warn("Using external plugins is not officially supported.\n"); + warn("Consider upstreaming your plugins into the BlueZ project."); - add_plugin(NULL, __obex_builtin[i]); - } + if (strlen(PLUGINDIR) == 0) + return; DBG("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); if (!dir) { - g_strfreev(patterns); - g_strfreev(excludes); - return FALSE; + return; } while ((file = g_dir_read_name(dir)) != NULL) { @@ -164,15 +168,42 @@ gboolean plugin_init(const char *pattern, const char *exclude) continue; } - if (add_plugin(handle, desc) == FALSE) + if (add_external_plugin(handle, desc) == FALSE) dlclose(handle); } g_dir_close(dir); +#endif +} + +#include "builtin.h" + +void plugin_init(const char *pattern, const char *exclude) +{ + char **patterns = NULL; + char **excludes = NULL; + unsigned int i; + + if (pattern) + patterns = g_strsplit_set(pattern, ":, ", -1); + + if (exclude) + excludes = g_strsplit_set(exclude, ":, ", -1); + + DBG("Loading builtin plugins"); + + for (i = 0; __obex_builtin[i]; i++) { + if (check_plugin(__obex_builtin[i], + patterns, excludes) == FALSE) + continue; + + add_plugin(__obex_builtin[i]); + } + + external_plugin_init(patterns, excludes); + g_strfreev(patterns); g_strfreev(excludes); - - return TRUE; } void plugin_cleanup(void) @@ -187,8 +218,10 @@ void plugin_cleanup(void) if (plugin->desc->exit) plugin->desc->exit(); +#if EXTERNAL_PLUGINS if (plugin->handle != NULL) dlclose(plugin->handle); +#endif g_free(plugin); } diff --git a/obexd/src/plugin.h b/obexd/src/plugin.h index a91746cbc..e1756b9bf 100644 --- a/obexd/src/plugin.h +++ b/obexd/src/plugin.h @@ -20,10 +20,14 @@ struct obex_plugin_desc { #name, init, exit \ }; #else +#if EXTERNAL_PLUGINS #define OBEX_PLUGIN_DEFINE(name,init,exit) \ extern struct obex_plugin_desc obex_plugin_desc \ __attribute__ ((visibility("default"))); \ const struct obex_plugin_desc obex_plugin_desc = { \ #name, init, exit \ }; +#else +#error "Requested non built-in plugin, while external plugins is disabled" +#endif #endif From patchwork Wed Jan 24 16:07:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529367 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5387E566 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=XeBJRLJVrIMn/cohyDNC0hE0zRjBQd6fH+37HPVxy73LB870WJPo5j7hlIU8/pfxXqOW/sd7O2nIlN+pQxxrXtAJVvsDriTIq75K7ZJjQKQd4lguIL8mbYtAIj1MjlGw070c9iJLFxtivrVEMOZrPMmWBRRCOfIcRSSSNjQamPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=l4M0CYae6sACNUXdM/RsB3Lv49E/9xZZDseXRMJSHq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pOWCV2a7mx4yZjxs45PyvLNOQnNrl+1njBPeJI9jTZmV3ZgQf8ZBBiRbB/rK0tQTtml6exKuMtBXTuKLZZlmVbjJMRZ/fkLSLcbew/z+JBbgJbAawpILSRrMa+93glL7EDYJouIw2oMSG1q+Kd7ixM2y+IZ5NOmdmtop9Hob3V8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hrIg8Hn9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hrIg8Hn9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 437D4C433B2; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=l4M0CYae6sACNUXdM/RsB3Lv49E/9xZZDseXRMJSHq8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hrIg8Hn9vlUaR9SYp+vjr2aPx3EdQFfz2GziULUwA38wLc31stLHN0CR7/o+pIJz4 IVmRmqkDx/4yzZSlwGqDyudE0V5kyo0RmjMIZGU24zgLprmQWwvZN4JlB4NTHdve1v u+6NNMUWfIOs2eU7aQFG2sfAWnDW8oX+8MhqHToOYhp6O3zF3YNoAZ7mgQzdl5aisk SZ9X+8bQRQtn58oBVdL3HCe3ln0BaFYsKuS/GkSe02S9GHxwxNUhLr8HwASWhAC3LM jxvQAeROQmBSUbrH0pPG67fnGFonqPT87W9STfrvfPbxGyjERXINIUai72E5d6xs/d Wkp9KJIt8E3sg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AB0BC47E49; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:07:59 +0000 Subject: [PATCH BlueZ v2 3/8] bluetoothd: remove external-dummy plugin Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-3-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=1499; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=EjARRPevchGHDkRRE9GXFlLSL06rTs7sjbEgjh12uig=; b=ZIHZDeCR9elO3hjmYcxf38mHEk89NHJwIeNS1CjQ0qMq0osCQhYPhZbpbQZdvd4A5IdK5yhdm WCWyDkf94aBDXrws2HdDq834pFZ5gJqasqnc111rEf6kFGGjsaHbIkp X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov The external plugins infra is getting deprecated and disabled by default. Remove this dummy plugin. --- Makefile.am | 8 -------- plugins/external-dummy.c | 28 ---------------------------- 2 files changed, 36 deletions(-) diff --git a/Makefile.am b/Makefile.am index e738eb3a5..ea51b25cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -293,14 +293,6 @@ builtin_ldadd = include Makefile.plugins -if MAINTAINER_MODE -plugin_LTLIBRARIES += plugins/external-dummy.la -plugins_external_dummy_la_SOURCES = plugins/external-dummy.c -plugins_external_dummy_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ - -no-undefined -plugins_external_dummy_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden -endif - pkglibexec_PROGRAMS += src/bluetoothd src_bluetoothd_SOURCES = $(builtin_sources) \ diff --git a/plugins/external-dummy.c b/plugins/external-dummy.c deleted file mode 100644 index 1c209e8b7..000000000 --- a/plugins/external-dummy.c +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "src/plugin.h" -#include "src/log.h" - -static int dummy_init(void) -{ - DBG(""); - - return 0; -} - -static void dummy_exit(void) -{ - DBG(""); -} - -BLUETOOTH_PLUGIN_DEFINE(external_dummy, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_LOW, dummy_init, dummy_exit) From patchwork Wed Jan 24 16:08:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529368 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AACFF7E56C for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=Wt9Q2Q6WEnQ/jkt7ldLY/DPbbDjAcY45oxsqqLHwCg8viNb+eXymjDSY9zNXvBzdEFPe+dxJZjr2IcobewjfC8BbAJs28EU+uPaRCGgHKxFHeyI4/FAFp49KpYShKlyG03ftx2QoaJYpm0QIsWYJzxbSBpuKOi6O8D+V3NC6KoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=OzzMlvRUPsVuxo2uwdVZjdw1XvEQcNHqU3yi1nNQhrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GRmmtb3DQ3uYlTYceSQGcL+FdCNVG3qhtp5/F2zMSvG6l7Tl+y2SxANXbOnAKyyS21ujpcVlu8wDUhUzow4tS6grUpH+ckVdZvdw3xN3q1oU02yJpxvB3dliyD2F5fTJCY9RVkOoPlI9VW7z4w0Q1ItiUIZWvMBkzaeC7ZUmncA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rZ6dzOII; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rZ6dzOII" Received: by smtp.kernel.org (Postfix) with ESMTPS id 48E04C43330; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=OzzMlvRUPsVuxo2uwdVZjdw1XvEQcNHqU3yi1nNQhrA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rZ6dzOIItjlHhvAGBn52iczO8/L92oPOtkDfgNJUpMCY+Vz77b3jd258ZBolNytMH cXQuAA7gz+liIiVGnuYuaAHHHpj+j/V9S0mrevQSal2MJE5zeLDiiUhMebSDDx4Z2R bAqIiT6k2C3leXMeyTrYlIcmThNEsrDNFWD1+jZXQF5GwaPte0LVD/9nH9SqAcEwGl Tc2tEXXCePXSbNLAzmQYXpFao5FCvCkvhl81q7kbpZZwWhlttyEn/iFXIw6fhuJOFi Whh1SIqNpkjdiimKKWBLCMG8ihv9hA4hiV7v0bvexd2Gle775SbLPl8t57a9eT2QGX tMXdE3JLo8XrA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3973BC48285; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:08:00 +0000 Subject: [PATCH BlueZ v2 4/8] bluetoothd: convert external sixaxis plugin to builtin Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-4-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=1169; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=rf/DV6bb4eocv72jDKDqDG7KvOMIubc6ZBWpK2UcaNg=; b=Py3+JdBHRaqUbOQT2T1Ril4VYqW538IlZ7V5wm902vr4KnNz0UAsfVnImc5t860VfUbGcLQ8o 8MWuUwsJrUVAko0r9mrSAQlsd1VTLKQxFR5pNhLZGwaiGe1D+CJoT8K X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Convert the only known external plugin to built-in. It's a tiny 20K binary that distros ship a separate package for. Make it a builtin, which allows distros to drop the separate package, it also enables us to compile out support for external modules - both in terms of extra code and hide the internal bluetoothd API. This means that libudev.so is pulled in, which is fine since its ABI has been stable for over a decade. --- Makefile.plugins | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile.plugins b/Makefile.plugins index 5880ed0df..7cf66fd59 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -110,11 +110,9 @@ builtin_modules += battery builtin_sources += profiles/battery/battery.c if SIXAXIS -plugin_LTLIBRARIES += plugins/sixaxis.la -plugins_sixaxis_la_SOURCES = plugins/sixaxis.c -plugins_sixaxis_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version -plugins_sixaxis_la_LIBADD = $(UDEV_LIBS) -plugins_sixaxis_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden +builtin_modules += sixaxis +builtin_sources += plugins/sixaxis.c +builtin_ldadd += $(UDEV_LIBS) endif if BAP From patchwork Wed Jan 24 16:08:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529369 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D36AB7E576 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=pJZIqv6Qc5f1oFOq982ubINjaC1owGDvba4ah++pWkPMSkNQlLQn1RvE4iVjW1Ldpo6hez32bSd77dw5cDrIlxI39QOtsfb8xFUrk8FFgh7fyfosM7apDMEbGmYXKAjBx5z0pfexnTrVUsIW21bo4EZ0Uuc4WdduBFDqFQwcrb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=6gXYqDg1iagSWrUXKqg53BuHbuqGR2ccSQ8itNAtFvw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Scka5fsLxjziRMJpA0XV8Puxai1DZUQSdrdU0jecbBkJMrpl5pYv0avN+Rj4rLPstEkCQai/yNKiEhwwjgqm0rZ7yaYZ8bEvUoh67rAXA1hH2A3CPzOmQYD/DzO3GNJyY1gTkWjtXwwyT2Eo0kG45f+q5SEzK5mEl0o2taDe9HY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cxrniDrY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cxrniDrY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4F84AC43601; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=6gXYqDg1iagSWrUXKqg53BuHbuqGR2ccSQ8itNAtFvw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=cxrniDrYIg0PHTai3QgqN2gwgxGsUb+VQzl0rby1sfNZ0d0PMPeclFtU/Qm9bFb5S P8ROjiZtRyOIpT9FpG5GJVVF/x8vR8wm2piJHCskH3g8McLaGWAG3H/FTMMeL48rPq AXoFhEIfEWTifT8EkW1yJwOCJVazJyiLr5nNo0j1rCEdTZjG9z/lsx5WBNayHkvZJc pVU68PKZY1KdxfGdqANgq2AyQnd7+X9O6b5Sez1xkBsCR0JkZiBhN1M2aZ8+Uhg3g1 GPQSbiTXQDY68vUHZNMU6fuBxs5YUl0f8TUqKIh9y/Ki17a9kMfyFV8YE2hLkjOLeA JQMQPpQIws2ew== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42D06C47DDC; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:08:01 +0000 Subject: [PATCH BlueZ v2 5/8] bluetoothd: factor out external plugin support Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-5-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=6433; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=WpwMNuo+0wxS6pXtowstfiORfl+j7pw7iu2tGBo4NYw=; b=9zqnGIfcMpNmBU4MroQ6F4hd481xTp8ZvvcEfJxQfv0C4nzVVVsJ2QMnPV84lnSPiyu7aXhR8 Nt2HnjkllrUB9N19k9Pe1E+vG2EdeYVteGVHOarmmmjX4s3+9gAVtjC X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As a whole all plugins should be built-in, otherwise they would be using internal, undocumented, unversioned, unstable API. Flesh out the external plugin support into a few pre-processor blocks and simplify the normal path. --- Makefile.am | 4 --- src/btd.h | 2 +- src/plugin.c | 97 ++++++++++++++++++++++++++++++++++++++---------------------- src/plugin.h | 16 ++++++++++ 4 files changed, 79 insertions(+), 40 deletions(-) diff --git a/Makefile.am b/Makefile.am index ea51b25cc..1b82e8551 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,11 +51,7 @@ EXTRA_DIST += src/bluetooth.service.in src/org.bluez.service plugindir = $(libdir)/bluetooth/plugins -if MAINTAINER_MODE -build_plugindir = $(abs_top_srcdir)/plugins/.libs -else build_plugindir = $(plugindir) -endif if MANPAGES man_MANS = diff --git a/src/btd.h b/src/btd.h index b7e7ebd61..7166e2168 100644 --- a/src/btd.h +++ b/src/btd.h @@ -155,7 +155,7 @@ struct btd_opts { extern struct btd_opts btd_opts; -gboolean plugin_init(const char *enable, const char *disable); +void plugin_init(const char *enable, const char *disable); void plugin_cleanup(void); void rfkill_init(void); diff --git a/src/plugin.c b/src/plugin.c index 2a29a888e..ae9406375 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -29,7 +29,9 @@ static GSList *plugins = NULL; struct bluetooth_plugin { +#if EXTERNAL_PLUGINS void *handle; +#endif gboolean active; const struct bluetooth_plugin_desc *desc; }; @@ -42,7 +44,8 @@ static int compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } -static gboolean add_plugin(void *handle, +#if EXTERNAL_PLUGINS +static gboolean add_external_plugin(void *handle, const struct bluetooth_plugin_desc *desc) { struct bluetooth_plugin *plugin; @@ -71,6 +74,22 @@ static gboolean add_plugin(void *handle, return TRUE; } +#endif + +static void add_plugin(const struct bluetooth_plugin_desc *desc) +{ + struct bluetooth_plugin *plugin; + + DBG("Loading %s plugin", desc->name); + + plugin = g_try_new0(struct bluetooth_plugin, 1); + if (plugin == NULL) + return; + + plugin->desc = desc; + + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); +} static gboolean enable_plugin(const char *name, char **cli_enable, char **cli_disable) @@ -98,48 +117,24 @@ static gboolean enable_plugin(const char *name, char **cli_enable, return TRUE; } -#include "src/builtin.h" -gboolean plugin_init(const char *enable, const char *disable) +static void external_plugin_init(char **cli_disabled, char **cli_enabled) { - GSList *list; +#if EXTERNAL_PLUGINS GDir *dir; const char *file; - char **cli_disabled, **cli_enabled; - unsigned int i; - - /* Make a call to BtIO API so its symbols got resolved before the - * plugins are loaded. */ - bt_io_error_quark(); - if (enable) - cli_enabled = g_strsplit_set(enable, ", ", -1); - else - cli_enabled = NULL; - - if (disable) - cli_disabled = g_strsplit_set(disable, ", ", -1); - else - cli_disabled = NULL; - - DBG("Loading builtin plugins"); - - for (i = 0; __bluetooth_builtin[i]; i++) { - if (!enable_plugin(__bluetooth_builtin[i]->name, cli_enabled, - cli_disabled)) - continue; - - add_plugin(NULL, __bluetooth_builtin[i]); - } + warn("Using external plugins is not officially supported.\n"); + warn("Consider upstreaming your plugins into the BlueZ project."); if (strlen(PLUGINDIR) == 0) - goto start; + return; DBG("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); if (!dir) - goto start; + return; while ((file = g_dir_read_name(dir)) != NULL) { const struct bluetooth_plugin_desc *desc; @@ -174,13 +169,45 @@ gboolean plugin_init(const char *enable, const char *disable) continue; } - if (add_plugin(handle, desc) == FALSE) + if (add_external_plugin(handle, desc) == FALSE) dlclose(handle); } g_dir_close(dir); +#endif +} + +#include "src/builtin.h" + +void plugin_init(const char *enable, const char *disable) +{ + GSList *list; + char **cli_disabled = NULL; + char **cli_enabled = NULL; + unsigned int i; + + /* Make a call to BtIO API so its symbols got resolved before the + * plugins are loaded. */ + bt_io_error_quark(); + + if (enable) + cli_enabled = g_strsplit_set(enable, ", ", -1); + + if (disable) + cli_disabled = g_strsplit_set(disable, ", ", -1); + + DBG("Loading builtin plugins"); + + for (i = 0; __bluetooth_builtin[i]; i++) { + if (!enable_plugin(__bluetooth_builtin[i]->name, cli_enabled, + cli_disabled)) + continue; + + add_plugin(__bluetooth_builtin[i]); + } + + external_plugin_init(cli_enabled, cli_disabled); -start: for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; int err; @@ -201,8 +228,6 @@ start: g_strfreev(cli_enabled); g_strfreev(cli_disabled); - - return TRUE; } void plugin_cleanup(void) @@ -217,8 +242,10 @@ void plugin_cleanup(void) if (plugin->active == TRUE && plugin->desc->exit) plugin->desc->exit(); +#if EXTERNAL_PLUGINS if (plugin->handle != NULL) dlclose(plugin->handle); +#endif g_free(plugin); } diff --git a/src/plugin.h b/src/plugin.h index 8d0903f2d..a1984d536 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -13,14 +13,19 @@ struct bluetooth_plugin_desc { const char *name; +#if EXTERNAL_PLUGINS const char *version; +#endif int priority; int (*init) (void); void (*exit) (void); +#if EXTERNAL_PLUGINS void *debug_start; void *debug_stop; +#endif }; +#if EXTERNAL_PLUGINS #ifdef BLUETOOTH_PLUGIN_BUILTIN #define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \ const struct bluetooth_plugin_desc \ @@ -41,3 +46,14 @@ struct bluetooth_plugin_desc { __start___debug, __stop___debug \ }; #endif +#else +#ifdef BLUETOOTH_PLUGIN_BUILTIN +#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \ + const struct bluetooth_plugin_desc \ + __bluetooth_builtin_ ## name = { \ + #name, priority, init, exit \ + }; +#else +#error "Requested non built-in plugin, while external plugins is disabled" +#endif +#endif From patchwork Wed Jan 24 16:08:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529370 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D35607E573 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=R9jAu92YCxBMH4QXsHQI60jWUncafBpq79ttHs2y7GtqYVdyMJdiDQ2GJ5LEGRbul3HVu6GvJ6jO575qEj9VOMV69pTrGHwkmcTPZqIYr1HslmzBopr/Sj29e0VfMpO96uzLIwCmIrtDG/fpkuwJzNoFAGVL6Q2MR3lsBZtPGIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=jAEahC6aEhwGsx03XeCGs0r51Ila42pXjrHeGrsvCtM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QgRguZoWq1Rm5vuVEDTsEWoiA/kM9laCGy5Hat+FbeZtS3RmX3yrFv1gCWk9sOn1hSUpEMtgvimrC7CZoD8EyCZHdXUnv0BzYqeksl1Hyk/ze9pVlZaDbgDO4+rdADgEkeifFJXy3qHiJSbvxFAWa/auSaBMH6O061bHTal2unY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q/faLm8L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q/faLm8L" Received: by smtp.kernel.org (Postfix) with ESMTPS id 5860EC43141; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=jAEahC6aEhwGsx03XeCGs0r51Ila42pXjrHeGrsvCtM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=q/faLm8L4EpnthSqOCqqxLyhVGrm0mrrsk4AvQO5Ndo40nE3d8AT4uhuzDglfdM1q mGdZ/g+lJLUxN4zGrdfg9f1DlR7R1nUFX1ItaBPNLL7bl4CGAuRy35v+/+QZJQCfNZ 6P2gr7BsvkMTF8XyOSxdoyKjQnHZVQV/3st1bR6Wkml1f5NtQeQKTcNycLrzAgoGum /ZKwInx2sr87+CAZsvxblMgOhcpy8mGS4jcLDD755yQxcIfa6HVllAB/tZ6fkOlS1N fvclX08RrUXOw8GgcHu25SkiKvOvTI1mlRh8ot+ik4BWdZApKK9OlPhb8EoGNqa/nC 6ZLRi1ZrajC+A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B0A3C48277; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:08:02 +0000 Subject: [PATCH BlueZ v2 6/8] bluetoothd: don't export internal API Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-6-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=1034; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=oJMu/7JQ1+IQo+7iiJJvhOj5+NWG/IUCz9D6MPY+H5E=; b=fi+Ga2uBjswJhuLcwfqrNXKN4gTb6++ttuRLheLaIspBr3aooFyjWU9kCOzqEwtQoP8WX8ZYE +arFE/3cOj+ChkzgiGgPFjFvRZHWCAAZSk3f93RUlEYlkAbVP17v3Cf X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov ... when building without external plugins. --- Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 1b82e8551..b98519e84 100644 --- a/Makefile.am +++ b/Makefile.am @@ -293,7 +293,6 @@ pkglibexec_PROGRAMS += src/bluetoothd src_bluetoothd_SOURCES = $(builtin_sources) \ $(attrib_sources) $(btio_sources) \ - src/bluetooth.ver \ src/main.c src/log.h src/log.c \ src/backtrace.h src/backtrace.c \ src/rfkill.c src/btd.h src/sdpd.h \ @@ -325,8 +324,12 @@ src_bluetoothd_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la \ $(BACKTRACE_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt \ $(builtin_ldadd) + +if EXTERNAL_PLUGINS +src_bluetoothd_SOURCES += src/bluetooth.ver src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \ -Wl,--version-script=$(srcdir)/src/bluetooth.ver +endif src_bluetoothd_DEPENDENCIES = lib/libbluetooth-internal.la \ gdbus/libgdbus-internal.la \ From patchwork Wed Jan 24 16:08:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529372 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D36537E575 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=GpBu02Bi/GSP+FZxNnGbsWcdLATOXdPGhqc6wvWLSjIuetNtte+y9LC9Z8cfT4QiUcEnEwF1LJmredVXi8EBJ7TCplM65fzAgZ41nQMm6jTtq4lTG0W1T+Ono+a8wilIMtg+YhcUsMcCDdYF02R1DDVM/GqKrONZFnLB8uk+e+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=QJg5pixklobSgAARqWUGUlRWGe9HIQqjbwWWEc0VPSg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YWvF4XUjtBAsJ8MWRhKqulfnMoNxdBVy8UNaMYOsQRlU3IFT2bZDc2dbBVSNAlOTT+s8NbL1Y10U7MqMNWs2K7v+Ibw89fo3NlbXTZaQf37zKdxYr2XXsB99gseNmlnLiRyCA/ztgf4WLz6HoqsYYklFeg/pmvr0UQK/3CknHFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t2PnzT+P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t2PnzT+P" Received: by smtp.kernel.org (Postfix) with ESMTPS id 641FAC43143; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=QJg5pixklobSgAARqWUGUlRWGe9HIQqjbwWWEc0VPSg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=t2PnzT+P264tY4C7R3cz8YLdyBxIrEZePXMBwECcn/vN1jw0KXz+3UDrHtZB2ZkCm fnxTfXTqqGaAp1yvmeamPyAqCivywks6egD3uVSGB1eQKuVQHUgC/uN6ecQRqppJKz Ta++McilTDJr0HeC069fscd78tHv73UR7T/lS9RIIEVIxmNr1Gbg1mYb0xLe4m0PEs EP7ROdJ/hSs8s8mS1NnkHVwbq+n9OLP/gWDUQYXc39uondz0R+HPmwoPF1kYzU61nj tOeSHTaDAcpMHtSEfp3AjT3L4qwKO0ayhDigCOss6x/bcEKb7Sgj8tCgme1iYq06Oi qBAb8hfTsZ8YA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53473C46CD2; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:08:03 +0000 Subject: [PATCH BlueZ v2 7/8] bluetoothd: change plugin loading alike obexd Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-7-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=3454; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=lDIlt74J4TxHWA83j/ATOvQ2txmbjUJNdwwnk4TmfAc=; b=n5JPCEWKxvlADNo49MpjCnWsLFcSDxyd2AmTTkJDBDAU3fcWRN8736bJvR1s2poGzOzvJkAyk 958fAnD/MEFB6q/TR23qeAyVWWjcT+HXmBhXO+l2dTURShVDRe7KXUO X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Currently, we print "Loading foobar" for every plugin, before we try the respective init() callback. Instead we handle the latter in a bunch, at the end of the process. Do the init() call early, print "Loaded" once it's actually successful and drop the no-longer "active" tracking. --- src/plugin.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index ae9406375..a1836e10f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -32,7 +32,6 @@ struct bluetooth_plugin { #if EXTERNAL_PLUGINS void *handle; #endif - gboolean active; const struct bluetooth_plugin_desc *desc; }; @@ -44,6 +43,21 @@ static int compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } +static int init_plugin(const struct bluetooth_plugin_desc *desc) +{ + int err; + + err = desc->init(); + if (err < 0) { + if (err == -ENOSYS || err == -ENOTSUP) + warn("System does not support %s plugin", + desc->name); + else + error("Failed to init %s plugin", + desc->name); + } +} + #if EXTERNAL_PLUGINS static gboolean add_external_plugin(void *handle, const struct bluetooth_plugin_desc *desc) @@ -58,19 +72,22 @@ static gboolean add_external_plugin(void *handle, return FALSE; } - DBG("Loading %s plugin", desc->name); - plugin = g_try_new0(struct bluetooth_plugin, 1); if (plugin == NULL) return FALSE; plugin->handle = handle; - plugin->active = FALSE; plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return FALSE; + } + __btd_enable_debug(desc->debug_start, desc->debug_stop); plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); return TRUE; } @@ -88,7 +105,13 @@ static void add_plugin(const struct bluetooth_plugin_desc *desc) plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return; + } + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); } static gboolean enable_plugin(const char *name, char **cli_enable, @@ -181,7 +204,6 @@ static void external_plugin_init(char **cli_disabled, char **cli_enabled) void plugin_init(const char *enable, const char *disable) { - GSList *list; char **cli_disabled = NULL; char **cli_enabled = NULL; unsigned int i; @@ -208,24 +230,6 @@ void plugin_init(const char *enable, const char *disable) external_plugin_init(cli_enabled, cli_disabled); - for (list = plugins; list; list = list->next) { - struct bluetooth_plugin *plugin = list->data; - int err; - - err = plugin->desc->init(); - if (err < 0) { - if (err == -ENOSYS || err == -ENOTSUP) - warn("System does not support %s plugin", - plugin->desc->name); - else - error("Failed to init %s plugin", - plugin->desc->name); - continue; - } - - plugin->active = TRUE; - } - g_strfreev(cli_enabled); g_strfreev(cli_disabled); } @@ -239,7 +243,7 @@ void plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; - if (plugin->active == TRUE && plugin->desc->exit) + if (plugin->desc->exit) plugin->desc->exit(); #if EXTERNAL_PLUGINS From patchwork Wed Jan 24 16:08:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13529371 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D35C87E574 for ; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; cv=none; b=J3BWuBgSlty+7hfhHntKOCLX17GvB/qY2aWUXV3VUnaoemXi44CLz2i4E2fo2+8vPe058Nf1UfW+FA/0/AXlymN7GtfxhG7fRMA9Pzc9QJlRmYxlOdkZp+lIWj0GRRCNDqq23p7XA9HnwCkyCjBKBApUvamUg2HIv0Iq1aeooNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112484; c=relaxed/simple; bh=mb3vibSeCho7dxgk/hsygvpcHcp9zzLKyD4RpuB1Dx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QBckkgin4TWPBRDlw5HWzhbzmP2k7VWxVIpY7MOhIjm7Jdxt0iHrnfETjA3Oh7lsfRszliNMzh4GDdf0fXgga9cgZ4ATqOTdJNLNRV/ITjTu9j00y40/irU1aZ5Ub4FNY2p0RcRmUhSa4w30R/7OOWVBRGFEbBql2KWWKcXTHow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O8f5G2K0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O8f5G2K0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 69EA2C4166B; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706112484; bh=mb3vibSeCho7dxgk/hsygvpcHcp9zzLKyD4RpuB1Dx8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=O8f5G2K0G0fvoTuxZ3B4cTuH99JWMl8ueaN8cM/EFJWpx+cuU3K4tuRxrYvbiOneY //Mh8j2qHhKmFjfbgxfTrNLObpSsFx2kUb+cnpDqlECpz4aNpP1Mgh8tOCLDvySlNB EXoZr/FW93DOBa9Hje2M0DdrjPCiWFO30Yk2oKh4KXFhn8GPn4b0hZtWaFkSL0XcLA 56zn2I9vWUXTnPl2HDZkk4i7yTJBlqocS+rOpS2XyAzaZosa4dZjlPtUuAsw6go8WB cwWC1r9IMgCvOJhhc4lCaG26yp9GhGHrgwtHS8JAEjubWQPV+BI51fuRW+ucbsYzyS xrBaXwhDwBkTg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B91EC47E49; Wed, 24 Jan 2024 16:08:04 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Wed, 24 Jan 2024 16:08:04 +0000 Subject: [PATCH BlueZ v2 8/8] android: export only (android) entrypoint from the modules Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240124-rm-ext-plugins-v2-8-5244906f05ff@gmail.com> References: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> In-Reply-To: <20240124-rm-ext-plugins-v2-0-5244906f05ff@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706112482; l=3016; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=A9wt+5pbCxd+p0NIbARFNH3H5ujiQXTs0z8giNMkb3Y=; b=ITc6p1jQLAbmwB2EdKW21hAv0n7dm3IlquDg+W6O8B6aBYEVagJ5p6E/Y/MxpKWc6rlk3Q0/q KSRSV2MsDQsDeQ7eo5aFr5aHtq5y9TW4RgChpQmpVLZSIqVSTQbzAjx X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov The android specific modules, have a designated HMI entrypoint. Hide everything else with -fvisibility=hidden. --- android/Makefile.am | 3 +++ android/hal-audio.c | 1 + android/hal-bluetooth.c | 1 + android/hal-sco.c | 1 + 4 files changed, 6 insertions(+) diff --git a/android/Makefile.am b/android/Makefile.am index 309910147..e3756e89c 100644 --- a/android/Makefile.am +++ b/android/Makefile.am @@ -96,6 +96,7 @@ android_bluetooth_default_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hal-log.h \ android/hal-ipc.h android/hal-ipc.c \ android/hal-utils.h android/hal-utils.c +android_bluetooth_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_bluetooth_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android android_bluetooth_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ -no-undefined @@ -195,6 +196,7 @@ android_audio_a2dp_default_la_SOURCES = android/audio-msg.h \ android/hardware/audio_effect.h \ android/hardware/hardware.h \ android/system/audio.h +android_audio_a2dp_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_audio_a2dp_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android \ $(SBC_CFLAGS) android_audio_a2dp_default_la_LIBADD = $(SBC_LIBS) -lrt @@ -212,6 +214,7 @@ android_audio_sco_default_la_SOURCES = android/hal-log.h \ android/audio_utils/resampler.c \ android/audio_utils/resampler.h \ android/system/audio.h +android_audio_sco_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_audio_sco_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android android_audio_sco_default_la_LIBADD = $(SPEEXDSP_LIBS) -lrt android_audio_sco_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ diff --git a/android/hal-audio.c b/android/hal-audio.c index d37d6098c..f3d9b40a6 100644 --- a/android/hal-audio.c +++ b/android/hal-audio.c @@ -1618,6 +1618,7 @@ static struct hw_module_methods_t hal_module_methods = { .open = audio_open, }; +__attribute__ ((visibility("default"))) struct audio_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c index d4442e620..7d1e5ac63 100644 --- a/android/hal-bluetooth.c +++ b/android/hal-bluetooth.c @@ -1117,6 +1117,7 @@ static struct hw_module_methods_t bluetooth_module_methods = { .open = open_bluetooth, }; +__attribute__ ((visibility("default"))) struct hw_module_t HAL_MODULE_INFO_SYM = { .tag = HARDWARE_MODULE_TAG, .version_major = 1, diff --git a/android/hal-sco.c b/android/hal-sco.c index d7c08a68b..3d66ad357 100644 --- a/android/hal-sco.c +++ b/android/hal-sco.c @@ -1507,6 +1507,7 @@ static struct hw_module_methods_t hal_module_methods = { .open = sco_open, }; +__attribute__ ((visibility("default"))) struct audio_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG,