From 4dc25b9feffb5e9bcb38dd7ff818a0eb84fe8e82 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Mar 2008 19:41:53 +0000 Subject: Add directory for plugins --- plugins/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 plugins/Makefile.am (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am new file mode 100644 index 00000000..02742923 --- /dev/null +++ b/plugins/Makefile.am @@ -0,0 +1,2 @@ + +MAINTAINERCLEANFILES = Makefile.in -- cgit From 971ed9531285f7de6b2c7a06095a833f9cbad08a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Mar 2008 20:00:16 +0000 Subject: Add skeleton for the example plugin --- plugins/Makefile.am | 12 ++++++++++++ plugins/echo.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 plugins/echo.c (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 02742923..b6020d05 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,2 +1,14 @@ +plugindir = $(libdir)/bluetooth/plugins + +plugin_LTLIBRARIES = libecho.la + +libecho_la_SOURCES = echo.c + +AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc + +AM_CFLAGS = @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ + +INCLUDES = -I$(top_builddir)/common -I$(top_builddir)/hcid + MAINTAINERCLEANFILES = Makefile.in diff --git a/plugins/echo.c b/plugins/echo.c new file mode 100644 index 00000000..4eaaddb6 --- /dev/null +++ b/plugins/echo.c @@ -0,0 +1,41 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2008 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "plugin.h" + +static int echo_init(void) +{ + return -EIO; +} + +static void echo_exit(void) +{ +} + +BLUETOOTH_PLUGIN_DEFINE("echo", echo_init, echo_exit) -- cgit From f6377c51e8c4de76bbcde216f461551fb7ab7061 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Mar 2008 20:17:58 +0000 Subject: Add some debug output to echo plugin --- plugins/echo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins') diff --git a/plugins/echo.c b/plugins/echo.c index 4eaaddb6..8e06ea75 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -28,14 +28,18 @@ #include #include "plugin.h" +#include "logging.h" static int echo_init(void) { + debug("Setup echo plugin"); + return -EIO; } static void echo_exit(void) { + debug("Cleanup echo plugin"); } BLUETOOTH_PLUGIN_DEFINE("echo", echo_init, echo_exit) -- cgit From 00f67ab2dac3ffbf90c13d3da6008e0e66fca41e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Mar 2008 23:52:47 +0000 Subject: No need for linking the plugins --- plugins/Makefile.am | 2 -- 1 file changed, 2 deletions(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b6020d05..0fb8a135 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -7,8 +7,6 @@ libecho_la_SOURCES = echo.c AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc -AM_CFLAGS = @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ - INCLUDES = -I$(top_builddir)/common -I$(top_builddir)/hcid MAINTAINERCLEANFILES = Makefile.in -- cgit From f2e093403e97b8f17343a0a429237f922f32a57c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 12 Mar 2008 19:23:22 +0000 Subject: Implement probe/remove for the example plugin --- plugins/echo.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/echo.c b/plugins/echo.c index 8e06ea75..81999a64 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -28,18 +28,39 @@ #include #include "plugin.h" +#include "server.h" #include "logging.h" +static int echo_probe(const char *adapter) +{ + debug("echo probe adapter %s", adapter); + + return 0; +} + +static void echo_remove(const char *adapter) +{ + debug("echo remove adapter %s", adapter); +} + +static struct bt_server echo_server = { + .uuid = "00001101-0000-1000-8000-00805F9B34FB", + .probe = echo_probe, + .remove = echo_remove, +}; + static int echo_init(void) { debug("Setup echo plugin"); - return -EIO; + return bt_register_server(&echo_server); } static void echo_exit(void) { debug("Cleanup echo plugin"); + + bt_unregister_server(&echo_server); } BLUETOOTH_PLUGIN_DEFINE("echo", echo_init, echo_exit) -- cgit From fbd60c20356e145a30e7fe7f6e91c9e8cf3c73da Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 12 Mar 2008 21:22:06 +0000 Subject: Add RFCOMM listener to echo plugin --- plugins/Makefile.am | 2 ++ plugins/echo.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0fb8a135..4e2b76a8 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -7,6 +7,8 @@ libecho_la_SOURCES = echo.c AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc +AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ + INCLUDES = -I$(top_builddir)/common -I$(top_builddir)/hcid MAINTAINERCLEANFILES = Makefile.in diff --git a/plugins/echo.c b/plugins/echo.c index 81999a64..ca8c25d4 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -26,21 +26,117 @@ #endif #include +#include +#include + +#include +#include +#include +#include + +#include #include "plugin.h" #include "server.h" #include "logging.h" +static gboolean session_event(GIOChannel *chan, + GIOCondition cond, gpointer data) +{ + unsigned char buf[672]; + gsize len, written; + GIOError err; + + if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) + return FALSE; + + err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len); + if (err == G_IO_ERROR_AGAIN) + return TRUE; + + g_io_channel_write(chan, (const gchar *) buf, len, &written); + + return TRUE; +} + +static gboolean connect_event(GIOChannel *chan, + GIOCondition cond, gpointer data) +{ + GIOChannel *io; + struct sockaddr_rc addr; + socklen_t optlen; + char address[18]; + int sk, nsk; + + sk = g_io_channel_unix_get_fd(chan); + + memset(&addr, 0, sizeof(addr)); + optlen = sizeof(addr); + + nsk = accept(sk, (struct sockaddr *) &addr, &optlen); + if (nsk < 0) + return TRUE; + + io = g_io_channel_unix_new(nsk); + g_io_channel_set_close_on_unref(io, TRUE); + + ba2str(&addr.rc_bdaddr, address); + + g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + session_event, NULL); + + return TRUE; +} + +static GIOChannel *setup_rfcomm(uint8_t channel) +{ + GIOChannel *io; + struct sockaddr_rc addr; + int sk; + + sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if (sk < 0) + return NULL; + + memset(&addr, 0, sizeof(addr)); + addr.rc_family = AF_BLUETOOTH; + bacpy(&addr.rc_bdaddr, BDADDR_ANY); + addr.rc_channel = channel; + + if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + close(sk); + return NULL; + } + + if (listen(sk, 10) < 0) { + close(sk); + return NULL; + } + + io = g_io_channel_unix_new(sk); + g_io_channel_set_close_on_unref(io, TRUE); + + g_io_add_watch(io, G_IO_IN, connect_event, NULL); + + return io; +} + +static GIOChannel *chan = NULL; + static int echo_probe(const char *adapter) { debug("echo probe adapter %s", adapter); + chan = setup_rfcomm(23); + return 0; } static void echo_remove(const char *adapter) { debug("echo remove adapter %s", adapter); + + g_io_channel_unref(chan); } static struct bt_server echo_server = { -- cgit From 201a729d46df51732304d47b7ed6c0bbe891e7d4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 12 Mar 2008 21:30:48 +0000 Subject: Fix include directories for successful make distcheck --- plugins/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4e2b76a8..146a12e6 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -9,6 +9,6 @@ AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ -INCLUDES = -I$(top_builddir)/common -I$(top_builddir)/hcid +INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid MAINTAINERCLEANFILES = Makefile.in -- cgit From 3c63053cdd3c7fa5a681aca562c0bd833947f559 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 21 Mar 2008 23:31:40 +0000 Subject: Don't install example plugin --- plugins/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 146a12e6..b00817d9 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,7 +1,7 @@ plugindir = $(libdir)/bluetooth/plugins -plugin_LTLIBRARIES = libecho.la +noinst_LTLIBRARIES = libecho.la libecho_la_SOURCES = echo.c -- cgit From 24eaef5b7c1bdbaa1d956d7714184ab0a8059185 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Mar 2008 15:49:37 +0000 Subject: Link network and input plugins for easier testing --- plugins/Makefile.am | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b00817d9..ce0cbca6 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -12,3 +12,11 @@ AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid MAINTAINERCLEANFILES = Makefile.in + +all-local: + @$(LN_S) -f $(top_srcdir)/input/.libs/libinput.so + @$(LN_S) -f $(top_srcdir)/network/.libs/libnetwork.so + +clean-local: + @rm -f libnetwork.so + @rm -f libinput.so -- cgit From 30b429c3852bb036dc473b3ff11a278df443026d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Mar 2008 16:12:20 +0000 Subject: Create links for audio and serial plugins --- plugins/Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ce0cbca6..37ca3c01 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -15,8 +15,12 @@ MAINTAINERCLEANFILES = Makefile.in all-local: @$(LN_S) -f $(top_srcdir)/input/.libs/libinput.so + @$(LN_S) -f $(top_srcdir)/audio/.libs/libaudio.so + @$(LN_S) -f $(top_srcdir)/serial/.libs/libserial.so @$(LN_S) -f $(top_srcdir)/network/.libs/libnetwork.so clean-local: @rm -f libnetwork.so + @rm -f libserial.so + @rm -f libaudio.so @rm -f libinput.so -- cgit From f8d4886cb737aadf03e2c9bed2e729f5a8c2728d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 5 Apr 2008 06:37:08 +0000 Subject: Add skeleton for storage plugin --- plugins/Makefile.am | 4 ++++ plugins/storage.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 plugins/storage.c (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 37ca3c01..a2a521dc 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,10 @@ plugindir = $(libdir)/bluetooth/plugins +plugin_LTLIBRARIES = libstorage.la + +libstorage_la_SOURCES = storage.c + noinst_LTLIBRARIES = libecho.la libecho_la_SOURCES = echo.c diff --git a/plugins/storage.c b/plugins/storage.c new file mode 100644 index 00000000..9e65a1ad --- /dev/null +++ b/plugins/storage.c @@ -0,0 +1,42 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2008 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "plugin.h" +#include "logging.h" + +static int storage_init(void) +{ + return 0; +} + +static void storage_exit(void) +{ +} + +BLUETOOTH_PLUGIN_DEFINE("storage", storage_init, storage_exit) -- cgit From 60202f31c998cc68c14f57c91e4b40d2c39f95f2 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 9 Apr 2008 22:00:34 +0000 Subject: Broken build: missing headers --- plugins/echo.c | 1 + plugins/storage.c | 1 + 2 files changed, 2 insertions(+) (limited to 'plugins') diff --git a/plugins/echo.c b/plugins/echo.c index ca8c25d4..153d33e9 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -36,6 +36,7 @@ #include +#include "dbus.h" #include "plugin.h" #include "server.h" #include "logging.h" diff --git a/plugins/storage.c b/plugins/storage.c index 9e65a1ad..7930d268 100644 --- a/plugins/storage.c +++ b/plugins/storage.c @@ -27,6 +27,7 @@ #include +#include "dbus.h" #include "plugin.h" #include "logging.h" -- cgit From 9491a544f622e40453265c30f24ce44a61440cc1 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 1 May 2008 13:52:26 +0000 Subject: Moving authorization code to dbus-service.c --- plugins/echo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/echo.c b/plugins/echo.c index 153d33e9..1aa15681 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -31,12 +31,11 @@ #include #include -#include -#include #include #include "dbus.h" + #include "plugin.h" #include "server.h" #include "logging.h" -- cgit From e7d668ac9e813bc9922ee7d771848bd8822d5d1f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 20:23:45 +0000 Subject: Move D-Bus watch functions into libgdbus --- plugins/Makefile.am | 2 +- plugins/echo.c | 2 +- plugins/storage.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index a2a521dc..c403e835 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -11,7 +11,7 @@ libecho_la_SOURCES = echo.c AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc -AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ +AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid diff --git a/plugins/echo.c b/plugins/echo.c index 1aa15681..2c549089 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -34,7 +34,7 @@ #include -#include "dbus.h" +#include #include "plugin.h" #include "server.h" diff --git a/plugins/storage.c b/plugins/storage.c index 7930d268..9e65a1ad 100644 --- a/plugins/storage.c +++ b/plugins/storage.c @@ -27,7 +27,6 @@ #include -#include "dbus.h" #include "plugin.h" #include "logging.h" -- cgit From f3c0a1a49b0b505b8543b5b3405bd62126be1a24 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 9 May 2008 09:16:32 +0000 Subject: Use -no-undefined for linking plugins --- plugins/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index c403e835..6f07b99a 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -9,7 +9,8 @@ noinst_LTLIBRARIES = libecho.la libecho_la_SOURCES = echo.c -AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc +AM_LDFLAGS = -module -avoid-version -no-undefined \ + -export-symbols-regex bluetooth_plugin_desc AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ -- cgit From 865f1108806df04d4bc1b81d08756924e5d52d6a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 15 May 2008 02:39:26 +0000 Subject: Add initial work for netlink plugin --- plugins/Makefile.am | 20 +++++++++++-- plugins/netlink.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 plugins/netlink.c (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 6f07b99a..2a3212e1 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,7 +1,13 @@ plugindir = $(libdir)/bluetooth/plugins -plugin_LTLIBRARIES = libstorage.la +if NETLINK +netlink_plugins = libnetlink.la +else +netlink_plugins = +endif + +plugin_LTLIBRARIES = libstorage.la $(netlink_plugins) libstorage_la_SOURCES = storage.c @@ -9,16 +15,24 @@ noinst_LTLIBRARIES = libecho.la libecho_la_SOURCES = echo.c +if NETLINK +libnetlink_la_SOURCES = netlink.c + +libnetlink_la_LIBADD = @NETLINK_LIBS@ +endif + AM_LDFLAGS = -module -avoid-version -no-undefined \ -export-symbols-regex bluetooth_plugin_desc -AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ +AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ @NETLINK_CFLAGS@ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid MAINTAINERCLEANFILES = Makefile.in all-local: + @$(LN_S) -f $(top_srcdir)/plugins/.libs/libstorage.so + @$(LN_S) -f $(top_srcdir)/plugins/.libs/libnetlink.so @$(LN_S) -f $(top_srcdir)/input/.libs/libinput.so @$(LN_S) -f $(top_srcdir)/audio/.libs/libaudio.so @$(LN_S) -f $(top_srcdir)/serial/.libs/libserial.so @@ -29,3 +43,5 @@ clean-local: @rm -f libserial.so @rm -f libaudio.so @rm -f libinput.so + @rm -f libnetlink.so + @rm -f libstorage.so diff --git a/plugins/netlink.c b/plugins/netlink.c new file mode 100644 index 00000000..e1b1bb96 --- /dev/null +++ b/plugins/netlink.c @@ -0,0 +1,85 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2008 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include + +#include + +#include "plugin.h" +#include "logging.h" + +static struct nl_handle *handle; +static struct nl_cache *cache; +static struct genl_family *family; + +static int netlink_init(void) +{ + info("Starting experimental netlink support"); + + handle = nl_handle_alloc(); + if (!handle) { + error("Failed to allocate netlink handle"); + return -ENOMEM; + } + + if (genl_connect(handle) < 0) { + error("Failed to connect to generic netlink"); + nl_handle_destroy(handle); + return -ENOLINK; + } + + cache = genl_ctrl_alloc_cache(handle); + if (!cache) { + error("Failed to allocate generic netlink cache"); + return -ENOMEM; + nl_handle_destroy(handle); + } + + family = genl_ctrl_search_by_name(cache, "bluetooth"); + if (!family) { + error("Failed to find Bluetooth netlink family"); + nl_cache_free(cache); + nl_handle_destroy(handle); + return -ENOENT; + } + + return 0; +} + +static void netlink_exit(void) +{ + nl_handle_destroy(handle); + nl_cache_free(cache); + nl_handle_destroy(handle); +} + +BLUETOOTH_PLUGIN_DEFINE("netlink", netlink_init, netlink_exit) -- cgit From 2a3cf9a57e3e6f4a56d309c794999356ab73439c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 15 May 2008 02:54:01 +0000 Subject: Fix typo in cleanup routine --- plugins/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/netlink.c b/plugins/netlink.c index e1b1bb96..51301bfb 100644 --- a/plugins/netlink.c +++ b/plugins/netlink.c @@ -77,7 +77,7 @@ static int netlink_init(void) static void netlink_exit(void) { - nl_handle_destroy(handle); + genl_family_put(family); nl_cache_free(cache); nl_handle_destroy(handle); } -- cgit From c478f8907398cf742b00a4e3043f72efbb7d0801 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 15 May 2008 03:26:35 +0000 Subject: Add IO channel for handling netlink messages --- plugins/netlink.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'plugins') diff --git a/plugins/netlink.c b/plugins/netlink.c index 51301bfb..887b51ea 100644 --- a/plugins/netlink.c +++ b/plugins/netlink.c @@ -34,6 +34,8 @@ #include +#include + #include "plugin.h" #include "logging.h" @@ -41,6 +43,35 @@ static struct nl_handle *handle; static struct nl_cache *cache; static struct genl_family *family; +static GIOChannel *channel; + +static gboolean channel_callback(GIOChannel *chan, + GIOCondition cond, void *user_data) +{ + int err; + + if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) + return FALSE; + + debug("Message available on netlink channel"); + + err = nl_recvmsgs_default(handle); + + return TRUE; +} + +static int create_channel(int fd) +{ + channel = g_io_channel_unix_new(fd); + if (channel == NULL) + return -ENOMEM; + + g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, + channel_callback, NULL); + + return 0; +} + static int netlink_init(void) { info("Starting experimental netlink support"); @@ -72,11 +103,21 @@ static int netlink_init(void) return -ENOENT; } + if (create_channel(nl_socket_get_fd(handle)) < 0) { + error("Failed to create netlink IO channel"); + genl_family_put(family); + nl_cache_free(cache); + nl_handle_destroy(handle); + return -ENOMEM; + } + return 0; } static void netlink_exit(void) { + g_io_channel_unref(channel); + genl_family_put(family); nl_cache_free(cache); nl_handle_destroy(handle); -- cgit From 407a723fbd995760217d837d6bca7d6049d1fdbf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 18 Jun 2008 15:35:40 +0000 Subject: Make netlink support optional and disable storage plugin --- plugins/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2a3212e1..2e23a0a7 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -7,14 +7,14 @@ else netlink_plugins = endif -plugin_LTLIBRARIES = libstorage.la $(netlink_plugins) +plugin_LTLIBRARIES = $(netlink_plugins) -libstorage_la_SOURCES = storage.c - -noinst_LTLIBRARIES = libecho.la +noinst_LTLIBRARIES = libecho.la libstorage.la libecho_la_SOURCES = echo.c +libstorage_la_SOURCES = storage.c + if NETLINK libnetlink_la_SOURCES = netlink.c -- cgit From b468daedba50975703c41e99194d223c540131aa Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 22 Jun 2008 01:51:37 +0000 Subject: Remove unneeded links --- plugins/Makefile.am | 4 ---- 1 file changed, 4 deletions(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2e23a0a7..fac16104 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -31,8 +31,6 @@ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid MAINTAINERCLEANFILES = Makefile.in all-local: - @$(LN_S) -f $(top_srcdir)/plugins/.libs/libstorage.so - @$(LN_S) -f $(top_srcdir)/plugins/.libs/libnetlink.so @$(LN_S) -f $(top_srcdir)/input/.libs/libinput.so @$(LN_S) -f $(top_srcdir)/audio/.libs/libaudio.so @$(LN_S) -f $(top_srcdir)/serial/.libs/libserial.so @@ -43,5 +41,3 @@ clean-local: @rm -f libserial.so @rm -f libaudio.so @rm -f libinput.so - @rm -f libnetlink.so - @rm -f libstorage.so -- cgit From a22a088109b664efdee397affed55b039cb0999b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 30 Jun 2008 05:47:13 +0000 Subject: Don't use lib prefix for plugins --- plugins/Makefile.am | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index fac16104..a8e833d0 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -2,23 +2,23 @@ plugindir = $(libdir)/bluetooth/plugins if NETLINK -netlink_plugins = libnetlink.la +netlink_plugins = netlink.la else netlink_plugins = endif plugin_LTLIBRARIES = $(netlink_plugins) -noinst_LTLIBRARIES = libecho.la libstorage.la +noinst_LTLIBRARIES = echo.la storage.la -libecho_la_SOURCES = echo.c +echo_la_SOURCES = echo.c -libstorage_la_SOURCES = storage.c +storage_la_SOURCES = storage.c if NETLINK -libnetlink_la_SOURCES = netlink.c +netlink_la_SOURCES = netlink.c -libnetlink_la_LIBADD = @NETLINK_LIBS@ +netlink_la_LIBADD = @NETLINK_LIBS@ endif AM_LDFLAGS = -module -avoid-version -no-undefined \ @@ -31,13 +31,13 @@ INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid MAINTAINERCLEANFILES = Makefile.in all-local: - @$(LN_S) -f $(top_srcdir)/input/.libs/libinput.so - @$(LN_S) -f $(top_srcdir)/audio/.libs/libaudio.so - @$(LN_S) -f $(top_srcdir)/serial/.libs/libserial.so - @$(LN_S) -f $(top_srcdir)/network/.libs/libnetwork.so + @$(LN_S) -f $(top_srcdir)/input/.libs/input.so + @$(LN_S) -f $(top_srcdir)/audio/.libs/audio.so + @$(LN_S) -f $(top_srcdir)/serial/.libs/serial.so + @$(LN_S) -f $(top_srcdir)/network/.libs/network.so clean-local: - @rm -f libnetwork.so - @rm -f libserial.so - @rm -f libaudio.so - @rm -f libinput.so + @rm -f network.so + @rm -f serial.so + @rm -f audio.so + @rm -f input.so -- cgit