Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Szymon Janc @ 2012-11-30 11:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

This makes adaptername plugin properly cleanup its fds on exit. Fixes
following warnings from valgrind:

16 bytes in 1 blocks are still reachable in loss record 42 of 221
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E93ABD: g_slist_prepend (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78350: g_source_add_poll (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5E32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565FA: adaptername_init (adaptername.c:302)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)

18 bytes in 1 blocks are still reachable in loss record 58 of 221
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78A69: g_source_set_name (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5E0B: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565FA: adaptername_init (adaptername.c:302)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)

32 bytes in 1 blocks are still reachable in loss record 86 of 221
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78722: g_source_set_callback (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0DB: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565FA: adaptername_init (adaptername.c:302)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)

32 bytes in 1 blocks are still reachable in loss record 87 of 221
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E77285: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E775AF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78115: g_source_attach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0E5: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565FA: adaptername_init (adaptername.c:302)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)

120 bytes in 1 blocks are still reachable in loss record 167 of 221
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565A9: adaptername_init (adaptername.c:298)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)

120 bytes in 1 blocks are still reachable in loss record 168 of 221
   at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FAE0: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78044: g_source_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5DF9: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x1565FA: adaptername_init (adaptername.c:302)
   by 0x1712AB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)
---
 plugins/adaptername.c |   60 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 20 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index 2013b7b..bb46c1b 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -50,8 +50,7 @@
 #define MACHINE_INFO_DIR "/etc/"
 #define MACHINE_INFO_FILE "machine-info"
 
-static GIOChannel *inotify = NULL;
-static int watch_d = -1;
+static guint watchid = 0;
 
 /* This file is part of systemd's hostnamed functionality:
  * http://0pointer.de/public/systemd-man/machine-info.html
@@ -266,20 +265,33 @@ static struct btd_adapter_driver adaptername_driver = {
 	.probe	= adaptername_probe,
 };
 
-static int adaptername_init(void)
+struct inotify_data
 {
-	int err;
 	int inot_fd;
-	guint32 mask;
+	int watch_d;
+};
 
-	err = btd_register_adapter_driver(&adaptername_driver);
-	if (err < 0)
-		return err;
+static void destroy_cb(gpointer user_data)
+{
+	struct inotify_data *data = user_data;
+
+	inotify_rm_watch(data->inot_fd, data->watch_d);
+	g_free(data);
+}
+
+static int adaptername_init(void)
+{
+	guint32 mask;
+	GIOChannel *inotify;
+	int inot_fd;
+	int watch_d;
+	struct inotify_data *data;
 
 	inot_fd = inotify_init();
 	if (inot_fd < 0) {
-		error("Failed to setup inotify");
-		return 0;
+		int err = -errno;
+		error("Failed to setup inotify (%d)", err);
+		return err;
 	}
 
 	mask = IN_CLOSE_WRITE;
@@ -290,30 +302,38 @@ static int adaptername_init(void)
 
 	watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
 	if (watch_d < 0) {
-		error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
+		int err = -errno;
+		error("Failed to setup watch for '%s' (%d)", MACHINE_INFO_DIR,
+									err);
 		close(inot_fd);
-		return 0;
+		return err;
 	}
 
+	data = g_new(struct inotify_data, 1);
+	data->inot_fd = inot_fd;
+	data->watch_d = watch_d;
+
 	inotify = g_io_channel_unix_new(inot_fd);
 	g_io_channel_set_close_on_unref(inotify, TRUE);
 	g_io_channel_set_encoding(inotify, NULL, NULL);
 	g_io_channel_set_flags(inotify, G_IO_FLAG_NONBLOCK, NULL);
-	g_io_add_watch(inotify, G_IO_IN, handle_inotify_cb, NULL);
+
+	watchid = g_io_add_watch_full(inotify, G_PRIORITY_DEFAULT, G_IO_IN,
+					handle_inotify_cb, data, destroy_cb);
+
+	g_io_channel_unref(inotify);
+
+	btd_register_adapter_driver(&adaptername_driver);
 
 	return 0;
 }
 
 static void adaptername_exit(void)
 {
-	if (watch_d >= 0 && inotify != NULL) {
-		int inot_fd = g_io_channel_unix_get_fd(inotify);
-		inotify_rm_watch(inot_fd, watch_d);
-	}
 
-	if (inotify != NULL) {
-		g_io_channel_shutdown(inotify, FALSE, NULL);
-		g_io_channel_unref(inotify);
+	if (watchid > 0) {
+		g_source_remove(watchid);
+		watchid = 0;
 	}
 
 	btd_unregister_adapter_driver(&adaptername_driver);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 6/8] core: Free parsed options
From: Szymon Janc @ 2012-11-30 11:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

There is no need to keep already parsed options in memory. This also
fix not freeing options at all.

2 bytes in 1 blocks are still reachable in loss record 1 of 153
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x167333: parse_debug (main.c:425)
   by 0x4E839D8: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E8403F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E85233: g_option_context_parse (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x121084: main (main.c:462)

16 bytes in 2 blocks are still reachable in loss record 39 of 153
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E5D68B: g_convert_with_iconv (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E5D94B: g_convert (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E5DFBA: g_locale_to_utf8 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E837C7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E8403F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E85233: g_option_context_parse (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x121084: main (main.c:462)
---
 src/main.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/main.c b/src/main.c
index ccb5fa5..bc53a8e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -344,6 +344,18 @@ static gboolean option_detach = TRUE;
 static gboolean option_version = FALSE;
 static gboolean option_udev = FALSE;
 
+static void free_options(void)
+{
+	g_free(option_debug);
+	option_debug = NULL;
+
+	g_free(option_plugin);
+	option_plugin = NULL;
+
+	g_free(option_noplugin);
+	option_noplugin = NULL;
+}
+
 static guint last_adapter_timeout = 0;
 
 static gboolean exit_timeout(gpointer data)
@@ -533,6 +545,9 @@ int main(int argc, char *argv[])
 	 * daemon needs to be re-worked. */
 	plugin_init(config, option_plugin, option_noplugin);
 
+	/* no need to keep parsed option in memory */
+	free_options();
+
 	mgmt_err = mgmt_setup();
 	if (mgmt_err < 0) {
 		error("mgmt setup failed: %s", strerror(-mgmt_err));
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 5/8] attrib: Fix possible use after free
From: Szymon Janc @ 2012-11-30 11:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

Move io channels unrefs after last use of channels.
---
 src/attrib-server.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 8e20903..1a9bd69 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -127,13 +127,13 @@ static void gatt_server_free(struct gatt_server *server)
 	g_list_free_full(server->database, attrib_free);
 
 	if (server->l2cap_io != NULL) {
-		g_io_channel_unref(server->l2cap_io);
 		g_io_channel_shutdown(server->l2cap_io, FALSE, NULL);
+		g_io_channel_unref(server->l2cap_io);
 	}
 
 	if (server->le_io != NULL) {
-		g_io_channel_unref(server->le_io);
 		g_io_channel_shutdown(server->le_io, FALSE, NULL);
+		g_io_channel_unref(server->le_io);
 	}
 
 	g_slist_free_full(server->clients, (GDestroyNotify) channel_free);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 4/8] hog: Fix memory leak in suspend-dummy
From: Szymon Janc @ 2012-11-30 11:24 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

g_io_add_watch increase channel ref count but g_io_channel_shutdown
doesn't drop reference nor remove watch. Since close on unref is set
for channel and it is watch we are interested keep watch id and not
channel id and remove watch on exit.

6 bytes in 1 blocks are still reachable in loss record 11 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6CF95: g_io_channel_init (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB66FF: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDC5: fifo_open (suspend.c:109)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

16 bytes in 1 blocks are still reachable in loss record 45 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E93ABD: g_slist_prepend (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78350: g_source_add_poll (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5E32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDF3: fifo_open (suspend.c:112)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

18 bytes in 1 blocks are still reachable in loss record 63 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78A69: g_source_set_name (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5E0B: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDF3: fifo_open (suspend.c:112)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

32 bytes in 1 blocks are still reachable in loss record 93 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78722: g_source_set_callback (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0DB: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDF3: fifo_open (suspend.c:112)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

32 bytes in 1 blocks are still reachable in loss record 94 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E77285: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E775AF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78115: g_source_attach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0E5: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDF3: fifo_open (suspend.c:112)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

120 bytes in 1 blocks are still reachable in loss record 177 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDC5: fifo_open (suspend.c:109)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)

120 bytes in 1 blocks are still reachable in loss record 178 of 235
   at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FAE0: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E78044: g_source_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB5DF9: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x18DDF3: fifo_open (suspend.c:112)
   by 0x18DF95: suspend_init (suspend.c:131)
   by 0x140B53: hog_init (hog_manager.c:133)
   by 0x17127B: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:532)
---
 profiles/input/suspend-dummy.c |   38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/profiles/input/suspend-dummy.c b/profiles/input/suspend-dummy.c
index 58f7b9c..97636ae 100644
--- a/profiles/input/suspend-dummy.c
+++ b/profiles/input/suspend-dummy.c
@@ -44,7 +44,7 @@
 
 static suspend_event suspend_cb = NULL;
 static resume_event resume_cb = NULL;
-static GIOChannel *fifoio = NULL;
+static guint watch = 0;
 
 static int fifo_open(void);
 
@@ -54,8 +54,15 @@ static gboolean read_fifo(GIOChannel *io, GIOCondition cond, gpointer user_data)
 	gsize offset, left, bread;
 	GIOStatus iostatus;
 
-	if (cond & (G_IO_ERR | G_IO_HUP))
-		goto failed;
+	if (cond & (G_IO_ERR | G_IO_HUP)) {
+		/*
+		 * Both ends needs to be open simultaneously before proceeding
+		 * any input or output operation. When the remote closes the
+		 * channel, hup signal is received on this end.
+		 */
+		fifo_open();
+		return FALSE;
+	}
 
 	offset = 0;
 	left = sizeof(buffer) - 1;
@@ -77,25 +84,12 @@ static gboolean read_fifo(GIOChannel *io, GIOCondition cond, gpointer user_data)
 		resume_cb();
 
 	return TRUE;
-
-failed:
-	/*
-	 * Both ends needs to be open simultaneously before proceeding
-	 * any input or output operation. When the remote closes the
-	 * channel, hup signal is received on this end.
-	 */
-
-	g_io_channel_unref(fifoio);
-	fifoio = NULL;
-
-	fifo_open();
-
-	return FALSE;
 }
 
 static int fifo_open(void)
 {
 	GIOCondition condition = G_IO_IN | G_IO_ERR | G_IO_HUP;
+	GIOChannel *fifoio;
 	int fd;
 
 	fd = open(HOG_SUSPEND_FIFO, O_RDONLY | O_NONBLOCK);
@@ -109,7 +103,9 @@ static int fifo_open(void)
 	fifoio = g_io_channel_unix_new(fd);
 	g_io_channel_set_close_on_unref(fifoio, TRUE);
 
-	g_io_add_watch(fifoio, condition, read_fifo, NULL);
+	watch = g_io_add_watch(fifoio, condition, read_fifo, NULL);
+
+	g_io_channel_unref(fifoio);
 
 	return 0;
 }
@@ -137,9 +133,9 @@ int suspend_init(suspend_event suspend, resume_event resume)
 
 void suspend_exit(void)
 {
-	if (fifoio) {
-		g_io_channel_shutdown(fifoio, FALSE, NULL);
-		g_io_channel_unref(fifoio);
+	if (watch) {
+		g_source_remove(watch);
+		watch = 0;
 	}
 
 	remove(HOG_SUSPEND_FIFO);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 3/8] rfkill: Fix memory leak in rfkill_exit
From: Szymon Janc @ 2012-11-30 11:24 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

g_io_add_watch increase channel ref count but g_io_channel_shutdown
doesn't drop reference nor remove watch. Since close on unref is set
for channel and it is watch we are interested keep watch id and not
channel id and remove watch on exit.

120 bytes in 1 blocks are still reachable in loss record 181 of 235
    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x167B8D: rfkill_init (rfkill.c:157)
    by 0x1215E4: main (main.c:540)

6 bytes in 1 blocks are still reachable in loss record 12 of 235
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E6CF95: g_io_channel_init (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4EB66FF: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x167B8D: rfkill_init (rfkill.c:157)
   by 0x1215E4: main (main.c:540)
---
 src/rfkill.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/rfkill.c b/src/rfkill.c
index b40c6e7..a6cd95c 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -139,11 +139,12 @@ static gboolean rfkill_event(GIOChannel *chan,
 	return TRUE;
 }
 
-static GIOChannel *channel = NULL;
+static guint watch = 0;
 
 void rfkill_init(void)
 {
 	int fd;
+	GIOChannel *channel;
 
 	if (!main_opts.remember_powered)
 		return;
@@ -157,17 +158,17 @@ void rfkill_init(void)
 	channel = g_io_channel_unix_new(fd);
 	g_io_channel_set_close_on_unref(channel, TRUE);
 
-	g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+	watch = g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
 							rfkill_event, NULL);
+
+	g_io_channel_unref(channel);
 }
 
 void rfkill_exit(void)
 {
-	if (!channel)
+	if (watch == 0)
 		return;
 
-	g_io_channel_shutdown(channel, TRUE, NULL);
-	g_io_channel_unref(channel);
-
-	channel = NULL;
+	g_source_remove(watch);
+	watch = 0;
 }
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 2/8] doc: Update valgrind.suppressions with some libdbus suppressions
From: Szymon Janc @ 2012-11-30 11:24 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354274703-15604-1-git-send-email-szymon.janc@tieto.com>

Suppress some useless libdbus warnings.
---
 doc/valgrind.suppressions |   81 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 80 insertions(+), 1 deletion(-)

diff --git a/doc/valgrind.suppressions b/doc/valgrind.suppressions
index 5967a15..81d2227 100644
--- a/doc/valgrind.suppressions
+++ b/doc/valgrind.suppressions
@@ -233,4 +233,83 @@
    fun:dbus_connection_send_with_reply_and_block
    fun:dbus_bus_register
 }
-
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:malloc
+   ...
+   obj:/lib/*/libdbus-*
+   ...
+   fun:g_dbus_setup_bus
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:calloc
+   ... 
+   obj:/lib/*/libdbus-*
+   ... 
+   fun:g_dbus_setup_bus
+   fun:connect_dbus
+   ... 
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:realloc
+   ...
+   obj:/lib/*/libdbus-*
+   ...
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_register
+   ...
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:calloc
+   ...
+   obj:/lib/*/libdbus-*
+   ...
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_register
+   ...
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:malloc
+   ...
+   obj:/lib/*/libdbus-*
+   ...
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_register
+   ...
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:calloc
+   ...
+   obj:/lib/*/libdbus-*
+   ...
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_request_name
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:realloc
+   ...
+   obj:/lib/*/libdbus-*        
+   ...
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_request_name
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:realloc
+   ...
+   obj:/lib/*/libdbus-*
+}
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/8] doc: Add valgrind.suppressions
From: Szymon Janc @ 2012-11-30 11:24 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Shamelessly copied from connman.
---
 doc/valgrind.suppressions |  236 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 236 insertions(+)
 create mode 100644 doc/valgrind.suppressions

diff --git a/doc/valgrind.suppressions b/doc/valgrind.suppressions
new file mode 100644
index 0000000..5967a15
--- /dev/null
+++ b/doc/valgrind.suppressions
@@ -0,0 +1,236 @@
+{
+   <syslog error>
+   Memcheck:Cond
+   obj:/lib/libc-*.so
+   ...
+   fun:localtime_r
+   fun:__vsyslog_chk
+   fun:__syslog_chk
+   fun:__connman_log_init
+   ...
+}
+{
+   <iconv open>
+   Memcheck:Addr4
+   obj:/lib/libc-*.so
+   obj:/lib/libglib-2.0.so*
+   fun:g_iconv_open
+   ...
+   fun:g_convert
+   fun:g_locale_to_utf8
+   fun:g_strerror
+   fun:g_key_file_load_from_file
+   ...
+}
+{
+   <ioctl ADDRT/DELRT>
+   Memcheck:Param
+   ioctl(SIOCADDRT/DELRT)
+   obj:/lib/ld-*.so
+   ...
+}
+{
+   <g_main_loop>
+   Memcheck:Leak
+   fun:memalign
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_main_loop_new
+   ...
+}
+{
+   <g_option_context_parse>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_option_context_parse
+   ...
+}
+{
+   <g_key_file_load_from_data>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_key_file_load_from_data
+   ...
+}
+{
+   <g_key_file_new 1>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_key_file_new
+   ...
+}
+{
+   <g_key_file_new 2>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_key_file_new
+   fun:main
+}
+{
+   <connman plugin cleanup>
+   Memcheck:Leak
+   ...
+   fun:__connman_plugin_cleanup
+   ...
+}
+{
+   <cmd line option parsing>
+   Memcheck:Leak
+   fun:malloc
+   fun:g_malloc
+   fun:g_strdup
+   fun:g_set_prgname
+   fun:g_option_context_parse
+   fun:main
+}
+{
+   <dbus system bus setup 1>
+   Memcheck:Leak
+   ...
+   fun:dbus_malloc*
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <dbus system bus setup 2>
+   Memcheck:Leak
+   ...
+   fun:g_malloc*
+   ...
+   fun:dbus_connection_set_watch_functions
+   fun:setup_bus
+   ...
+}
+{
+   <key file get charset>
+   Memcheck:Leak
+   ...
+   fun:g_*alloc*
+   ...
+   fun:g_strerror
+   fun:g_key_file_load_from_file
+   fun:main
+}
+{
+   <dbus disconnect func set>
+   Memcheck:Leak
+   ...
+   fun:filter_data_get
+   fun:g_dbus_add_signal_watch
+   fun:g_dbus_set_disconnect_function
+   fun:main
+}
+{
+   <plugin dlopen>
+   Memcheck:Leak
+   ...
+   fun:dlopen
+   fun:__connman_plugin_init
+   fun:main
+}
+{
+   <dbus system bus setup 3>
+   Memcheck:Leak
+   ...
+   fun:dbus_malloc0
+   ...
+   fun:dbus_parse_address
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <libdbus internals 1>
+   Memcheck:Leak
+   fun:*malloc
+   ...
+   obj:/lib/libdbus-1.so.3.5.3
+}
+{
+   <dbus system bus setup 4>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:dbus_*alloc*
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <dbus system bus setup 5>
+   Memcheck:Leak
+   fun:calloc
+   fun:g_malloc0
+   ...
+   fun:g_dbus_set_disconnect_function
+   fun:main
+}
+{
+   <dbus bus remove match>
+   Memcheck:Leak
+   fun:malloc
+   fun:g_malloc
+   fun:g_source_set_callback
+   fun:g_timeout_add_full
+   fun:g_timeout_add
+   ...
+   fun:dbus_pending_call_block
+   fun:dbus_connection_send_with_reply_and_block
+   ...
+   fun:dbus_bus_remove_match
+}
+{
+   <g_main_loop_run/new>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_main_loop_*
+   fun:main
+}
+{
+   <g_main_context_dispatch>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_main_context_dispatch
+}
+{
+   <libdbus internals 2>
+   Memcheck:Leak
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_message_set_reply_serial
+   fun:dbus_message_new_error
+   ...
+}
+{
+   <libdbus internals 3>
+   Memcheck:Leak
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_message_new_signal
+   ...
+}
+{
+   <dbus_bus_register>
+   Memcheck:Leak
+   fun:malloc
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_pending_call_block
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_register
+}
+
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH BlueZ 1/6] gdbus: Add g_dbus_add_properties_watch function
From: Johan Hedberg @ 2012-11-30  8:31 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1354020685-17028-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Tue, Nov 27, 2012, Luiz Augusto von Dentz wrote:
> Convenient function to create watches for D-Bus properties.
> ---
>  gdbus/gdbus.h |  5 +++++
>  gdbus/watch.c | 28 ++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [RFC v2 00/15] Manager/Adapter transition to ObjectManager
From: Lucas De Marchi @ 2012-11-29 18:12 UTC (permalink / raw)
  To: Mikel Astiz; +Cc: linux-bluetooth, Mikel Astiz
In-Reply-To: <1354193256-30610-1-git-send-email-mikel.astiz.oss@gmail.com>

On Thu, Nov 29, 2012 at 10:47 AM, Mikel Astiz <mikel.astiz.oss@gmail.com> wrote:
> From: Mikel Astiz <mikel.astiz@bmw-carit.de>
>
> Note that this patchset requires the gdbus fix affecting were the ObjectManager gets registered, as submitted by Luiz.

Those were replaced with my patches today.  Do my patches do what you need?

Lucas De Marchi

^ permalink raw reply

* [PATCHv2 4/4] Bluetooth: trivial: Change NO_FCS_RECV to RECV_NO_FCS
From: Andrei Emeltchenko @ 2012-11-29 15:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354203968-1335-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Make code more readable by changing CONF_NO_FCS_RECV which is read
as "No L2CAP FCS option received" to CONF_RECV_NO_FCS which means
"Received L2CAP option NO_FCS". This flag really means that we have
received L2CAP FRAME CHECK SEQUENCE (FCS) OPTION with value "No FCS".

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/l2cap.h |    2 +-
 net/bluetooth/l2cap_core.c    |   10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index f57fab0..7588ef4 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -611,7 +611,7 @@ enum {
 	CONF_MTU_DONE,
 	CONF_MODE_DONE,
 	CONF_CONNECT_PEND,
-	CONF_NO_FCS_RECV,
+	CONF_RECV_NO_FCS,
 	CONF_STATE2_DEVICE,
 	CONF_EWS_RECV,
 	CONF_LOC_CONF_PEND,
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 8c43277..2c78208 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3112,7 +3112,7 @@ done:
 
 		if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
 			if (chan->fcs == L2CAP_FCS_NONE ||
-			    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+			    test_bit(CONF_RECV_NO_FCS, &chan->conf_state)) {
 				chan->fcs = L2CAP_FCS_NONE;
 				l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
 						   chan->fcs);
@@ -3140,7 +3140,7 @@ done:
 
 		if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
 			if (chan->fcs == L2CAP_FCS_NONE ||
-			    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+			    test_bit(CONF_RECV_NO_FCS, &chan->conf_state)) {
 				chan->fcs = L2CAP_FCS_NONE;
 				l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
 						   chan->fcs);
@@ -3196,7 +3196,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
 
 		case L2CAP_CONF_FCS:
 			if (val == L2CAP_FCS_NONE)
-				set_bit(CONF_NO_FCS_RECV, &chan->conf_state);
+				set_bit(CONF_RECV_NO_FCS, &chan->conf_state);
 			break;
 
 		case L2CAP_CONF_EFS:
@@ -3435,7 +3435,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 		case L2CAP_CONF_FCS:
 			if (*result == L2CAP_CONF_PENDING)
 				if (val == L2CAP_FCS_NONE)
-					set_bit(CONF_NO_FCS_RECV,
+					set_bit(CONF_RECV_NO_FCS,
 						&chan->conf_state);
 			break;
 		}
@@ -3807,7 +3807,7 @@ static inline void set_default_fcs(struct l2cap_chan *chan)
 	 */
 	if (chan->mode != L2CAP_MODE_ERTM && chan->mode != L2CAP_MODE_STREAMING)
 		chan->fcs = L2CAP_FCS_NONE;
-	else if (!test_bit(CONF_NO_FCS_RECV, &chan->conf_state))
+	else if (!test_bit(CONF_RECV_NO_FCS, &chan->conf_state))
 		chan->fcs = L2CAP_FCS_CRC16;
 }
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv2 3/4] Bluetooth: Process receiving FCS_NONE in L2CAP Conf Rsp
From: Andrei Emeltchenko @ 2012-11-29 15:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354203968-1335-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Process L2CAP Config rsp Pending with FCS Option 0x00 (No FCS)
which is sent by Motorola Windows 7 Bluetooth stack. The trace
is shown below (all other options are skipped).

...
< ACL data: handle 1 flags 0x00 dlen 48
    L2CAP(s): Config req: dcid 0x0043 flags 0x00 clen 36
      ...
      FCS Option 0x00 (No FCS)
> ACL data: handle 1 flags 0x02 dlen 48
    L2CAP(s): Config req: dcid 0x0041 flags 0x00 clen 36
      ...
      FCS Option 0x01 (CRC16 Check)
< ACL data: handle 1 flags 0x00 dlen 47
    L2CAP(s): Config rsp: scid 0x0043 flags 0x00 result 4 clen 33
      Pending
      ...
> ACL data: handle 1 flags 0x02 dlen 50
    L2CAP(s): Config rsp: scid 0x0041 flags 0x00 result 4 clen 36
      Pending
      ...
      FCS Option 0x00 (No FCS)
< ACL data: handle 1 flags 0x00 dlen 14
    L2CAP(s): Config rsp: scid 0x0043 flags 0x00 result 0 clen 0
      Success
> ACL data: handle 1 flags 0x02 dlen 14
    L2CAP(s): Config rsp: scid 0x0041 flags 0x00 result 0 clen 0
      Success
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d22d183..8c43277 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3431,6 +3431,13 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs),
 					   (unsigned long) &efs);
 			break;
+
+		case L2CAP_CONF_FCS:
+			if (*result == L2CAP_CONF_PENDING)
+				if (val == L2CAP_FCS_NONE)
+					set_bit(CONF_NO_FCS_RECV,
+						&chan->conf_state);
+			break;
 		}
 	}
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv2 2/4] Bluetooth: Fix missing L2CAP EWS Conf parameter
From: Andrei Emeltchenko @ 2012-11-29 15:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354203968-1335-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

If L2CAP_FEAT_FCS is not supported we sould miss EWS option
configuration because of break. Make code more readable by
combining FCS configuration in the single block.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |   32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d8cffdb..d22d183 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3106,18 +3106,17 @@ done:
 		if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
 			l2cap_add_opt_efs(&ptr, chan);
 
-		if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
-			break;
-
-		if (chan->fcs == L2CAP_FCS_NONE ||
-		    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
-			chan->fcs = L2CAP_FCS_NONE;
-			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, chan->fcs);
-		}
-
 		if (test_bit(FLAG_EXT_CTRL, &chan->flags))
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS, 2,
 					   chan->tx_win);
+
+		if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
+			if (chan->fcs == L2CAP_FCS_NONE ||
+			    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+				chan->fcs = L2CAP_FCS_NONE;
+				l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
+						   chan->fcs);
+			}
 		break;
 
 	case L2CAP_MODE_STREAMING:
@@ -3139,14 +3138,13 @@ done:
 		if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
 			l2cap_add_opt_efs(&ptr, chan);
 
-		if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
-			break;
-
-		if (chan->fcs == L2CAP_FCS_NONE ||
-		    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
-			chan->fcs = L2CAP_FCS_NONE;
-			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, chan->fcs);
-		}
+		if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
+			if (chan->fcs == L2CAP_FCS_NONE ||
+			    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+				chan->fcs = L2CAP_FCS_NONE;
+				l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
+						   chan->fcs);
+			}
 		break;
 	}
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv2 1/4] Bluetooth: AMP: Check that AMP is present and active
From: Andrei Emeltchenko @ 2012-11-29 15:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <20121129103405.GC26707@joana>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Before starting quering remote AMP controllers make sure
that there is local active AMP controller.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |   16 ++++++++++++++++
 net/bluetooth/l2cap_core.c       |    1 +
 2 files changed, 17 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 2f2b743..014a2ea 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -779,6 +779,22 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 #define lmp_host_le_capable(dev)   !!((dev)->host_features[0] & LMP_HOST_LE)
 #define lmp_host_le_br_capable(dev) !!((dev)->host_features[0] & LMP_HOST_LE_BREDR)
 
+/* returns true if at least one AMP active */
+static inline bool hci_amp_capable(void)
+{
+	struct hci_dev *hdev;
+	bool ret = false;
+
+	read_lock(&hci_dev_list_lock);
+	list_for_each_entry(hdev, &hci_dev_list, list)
+		if (hdev->amp_type == HCI_AMP &&
+		    test_bit(HCI_UP, &hdev->flags))
+			ret = true;
+	read_unlock(&hci_dev_list_lock);
+
+	return ret;
+}
+
 /* ----- HCI protocols ----- */
 #define HCI_PROTO_DEFER             0x01
 
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index f7ee037..d8cffdb 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1013,6 +1013,7 @@ static bool __amp_capable(struct l2cap_chan *chan)
 	struct l2cap_conn *conn = chan->conn;
 
 	if (enable_hs &&
+	    hci_amp_capable() &&
 	    chan->chan_policy == BT_CHANNEL_POLICY_AMP_PREFERRED &&
 	    conn->fixed_chan_mask & L2CAP_FC_A2MP)
 		return true;
-- 
1.7.10.4


^ permalink raw reply related

* Re: [PATCH BlueZ 1/3] gdbus: Don't register DBus.Properties with no properties
From: Luiz Augusto von Dentz @ 2012-11-29 14:37 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZJVfiD36XrnNyn-5i5MqcOi-LKJ3QMREC6E+XpC9+1CyQ@mail.gmail.com>

Hi Lucas,

On Thu, Nov 29, 2012 at 3:33 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Lucas,
>
> On Thu, Nov 29, 2012 at 3:19 PM, Lucas De Marchi
> <lucas.demarchi@profusion.mobi> wrote:
>> Delay registering DBus.Properties interface until the moment there are
>> properties on that path. This is needed for objects that currently don't
>> expose any property to not export the interface.
>> ---
>>  gdbus/object.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/gdbus/object.c b/gdbus/object.c
>> index 3101ca6..47116bd 100644
>> --- a/gdbus/object.c
>> +++ b/gdbus/object.c
>> @@ -1213,9 +1213,6 @@ static struct generic_data *object_path_ref(DBusConnection *connection,
>>                                         manager_methods, manager_signals,
>>                                         NULL, data, NULL);
>>
>> -       add_interface(data, DBUS_INTERFACE_PROPERTIES, properties_methods,
>> -                                       properties_signals, NULL, data, NULL);
>> -
>>         return data;
>>  }
>>
>> @@ -1336,6 +1333,12 @@ gboolean g_dbus_register_interface(DBusConnection *connection,
>>                 return FALSE;
>>         }
>>
>> +       if (properties != NULL && !find_interface(data->interfaces,
>> +                                               DBUS_INTERFACE_PROPERTIES))
>> +               add_interface(data, DBUS_INTERFACE_PROPERTIES,
>> +                               properties_methods, properties_signals, NULL,
>> +                               data, NULL);
>> +
>>         add_interface(data, name, methods, signals, properties, user_data,
>>                                                                 destroy);
>>
>> --
>> 1.8.0.1
>
> Ack

Patches pushed to BlueZ and obexd. Thanks.


--
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] control: Remove duplicated documentation entry
From: Johan Hedberg @ 2012-11-29 13:59 UTC (permalink / raw)
  To: João Paulo Rechi Vita; +Cc: linux-bluetooth
In-Reply-To: <1354196335-3366-1-git-send-email-jprvita@openbossa.org>

Hi João Paulo,

On Thu, Nov 29, 2012, João Paulo Rechi Vita wrote:
> ---
>  doc/control-api.txt | 4 ----
>  1 file changed, 4 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH BlueZ 3/3] core: Attach and detach object manager
From: Luiz Augusto von Dentz @ 2012-11-29 13:39 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth@vger.kernel.org, Lucas De Marchi
In-Reply-To: <1354195173-12750-3-git-send-email-lucas.demarchi@profusion.mobi>

Hi Lucas,

On Thu, Nov 29, 2012 at 3:19 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> From: Lucas De Marchi <lucas.de.marchi@gmail.com>
>
> ---
>  src/main.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/main.c b/src/main.c
> index 414849a..ccb5fa5 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -381,6 +381,7 @@ static void disconnect_dbus(void)
>         if (!conn || !dbus_connection_get_is_connected(conn))
>                 return;
>
> +       g_dbus_detach_object_manager(conn);
>         set_dbus_connection(NULL);
>
>         dbus_connection_unref(conn);
> @@ -412,6 +413,7 @@ static int connect_dbus(void)
>         set_dbus_connection(conn);
>
>         g_dbus_set_disconnect_function(conn, disconnected_dbus, NULL, NULL);
> +       g_dbus_attach_object_manager(conn);
>
>         return 0;
>  }
> --
> 1.8.0.1

Ack.


--
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH BlueZ 2/3] gdbus: Don't automatically attach ObjectManager
From: Luiz Augusto von Dentz @ 2012-11-29 13:39 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth@vger.kernel.org, Lucas De Marchi
In-Reply-To: <1354195173-12750-2-git-send-email-lucas.demarchi@profusion.mobi>

Hi Lucas,

On Thu, Nov 29, 2012 at 3:19 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> From: Lucas De Marchi <lucas.de.marchi@gmail.com>
>
> Let each project attach the object manager interface instead of
> registering it automatically.
> ---
>  gdbus/gdbus.h  |  3 +++
>  gdbus/object.c | 54 +++++++++++++++++++++++++++++++++---------------------
>  2 files changed, 36 insertions(+), 21 deletions(-)
>
> diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
> index ba49621..6aafc61 100644
> --- a/gdbus/gdbus.h
> +++ b/gdbus/gdbus.h
> @@ -257,6 +257,9 @@ void g_dbus_emit_property_changed(DBusConnection *connection,
>  gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
>                                 const char *interface, DBusMessageIter *iter);
>
> +gboolean g_dbus_attach_object_manager(DBusConnection *connection);
> +gboolean g_dbus_detach_object_manager(DBusConnection *connection);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/gdbus/object.c b/gdbus/object.c
> index 47116bd..7cbd612 100644
> --- a/gdbus/object.c
> +++ b/gdbus/object.c
> @@ -84,6 +84,8 @@ struct property_data {
>         DBusMessage *message;
>  };
>
> +static struct generic_data *root;
> +
>  static gboolean process_changes(gpointer user_data);
>  static void process_properties_from_interface(struct generic_data *data,
>                                                 struct interface_data *iface);
> @@ -569,16 +571,11 @@ static void emit_interfaces_added(struct generic_data *data)
>  {
>         DBusMessage *signal;
>         DBusMessageIter iter, array;
> -       struct generic_data *parent = data->parent;
>
> -       if (parent == NULL)
> +       if (root == NULL || data == root)
>                 return;
>
> -       /* Find root data */
> -       while (parent->parent)
> -               parent = parent->parent;
> -
> -       signal = dbus_message_new_signal(parent->path,
> +       signal = dbus_message_new_signal(root->path,
>                                         DBUS_INTERFACE_OBJECT_MANAGER,
>                                         "InterfacesAdded");
>         if (signal == NULL)
> @@ -943,16 +940,11 @@ static void emit_interfaces_removed(struct generic_data *data)
>  {
>         DBusMessage *signal;
>         DBusMessageIter iter, array;
> -       struct generic_data *parent = data->parent;
>
> -       if (parent == NULL)
> +       if (root == NULL || data == root)
>                 return;
>
> -       /* Find root data */
> -       while (parent->parent)
> -               parent = parent->parent;
> -
> -       signal = dbus_message_new_signal(parent->path,
> +       signal = dbus_message_new_signal(root->path,
>                                         DBUS_INTERFACE_OBJECT_MANAGER,
>                                         "InterfacesRemoved");
>         if (signal == NULL)
> @@ -1207,12 +1199,6 @@ static struct generic_data *object_path_ref(DBusConnection *connection,
>         add_interface(data, DBUS_INTERFACE_INTROSPECTABLE, introspect_methods,
>                                                 NULL, NULL, data, NULL);
>
> -       /* Only root path export ObjectManager interface */
> -       if (data->parent == NULL)
> -               add_interface(data, DBUS_INTERFACE_OBJECT_MANAGER,
> -                                       manager_methods, manager_signals,
> -                                       NULL, data, NULL);
> -
>         return data;
>  }
>
> @@ -1234,7 +1220,6 @@ static void object_path_unref(DBusConnection *connection, const char *path)
>
>         remove_interface(data, DBUS_INTERFACE_INTROSPECTABLE);
>         remove_interface(data, DBUS_INTERFACE_PROPERTIES);
> -       remove_interface(data, DBUS_INTERFACE_OBJECT_MANAGER);
>
>         invalidate_parent_data(data->conn, data->path);
>
> @@ -1645,3 +1630,30 @@ gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
>
>         return TRUE;
>  }
> +
> +gboolean g_dbus_attach_object_manager(DBusConnection *connection)
> +{
> +       struct generic_data *data;
> +
> +       data = object_path_ref(connection, "/");
> +       if (data == NULL)
> +               return FALSE;
> +
> +       add_interface(data, DBUS_INTERFACE_OBJECT_MANAGER,
> +                                       manager_methods, manager_signals,
> +                                       NULL, data, NULL);
> +       root = data;
> +
> +       return TRUE;
> +}
> +
> +gboolean g_dbus_detach_object_manager(DBusConnection *connection)
> +{
> +       if (!g_dbus_unregister_interface(connection, "/",
> +                                       DBUS_INTERFACE_OBJECT_MANAGER))
> +               return FALSE;
> +
> +       root = NULL;
> +
> +       return TRUE;
> +}
> --
> 1.8.0.1

Looks good, ack.

--
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH] control: Remove duplicated documentation entry
From: João Paulo Rechi Vita @ 2012-11-29 13:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: João Paulo Rechi Vita

---
 doc/control-api.txt | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/doc/control-api.txt b/doc/control-api.txt
index a16ee7d..e0ed04a 100644
--- a/doc/control-api.txt
+++ b/doc/control-api.txt
@@ -32,10 +32,6 @@ Methods		void Play()
 
 			Previous item.
 
-		void VolumeDown()
-
-			Adjust remote volume one step down
-
 		void VolumeUp()
 
 			Adjust remote volume one step up
-- 
1.7.11.7


^ permalink raw reply related

* Re: [PATCH BlueZ 1/3] gdbus: Don't register DBus.Properties with no properties
From: Luiz Augusto von Dentz @ 2012-11-29 13:33 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1354195173-12750-1-git-send-email-lucas.demarchi@profusion.mobi>

Hi Lucas,

On Thu, Nov 29, 2012 at 3:19 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> Delay registering DBus.Properties interface until the moment there are
> properties on that path. This is needed for objects that currently don't
> expose any property to not export the interface.
> ---
>  gdbus/object.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/gdbus/object.c b/gdbus/object.c
> index 3101ca6..47116bd 100644
> --- a/gdbus/object.c
> +++ b/gdbus/object.c
> @@ -1213,9 +1213,6 @@ static struct generic_data *object_path_ref(DBusConnection *connection,
>                                         manager_methods, manager_signals,
>                                         NULL, data, NULL);
>
> -       add_interface(data, DBUS_INTERFACE_PROPERTIES, properties_methods,
> -                                       properties_signals, NULL, data, NULL);
> -
>         return data;
>  }
>
> @@ -1336,6 +1333,12 @@ gboolean g_dbus_register_interface(DBusConnection *connection,
>                 return FALSE;
>         }
>
> +       if (properties != NULL && !find_interface(data->interfaces,
> +                                               DBUS_INTERFACE_PROPERTIES))
> +               add_interface(data, DBUS_INTERFACE_PROPERTIES,
> +                               properties_methods, properties_signals, NULL,
> +                               data, NULL);
> +
>         add_interface(data, name, methods, signals, properties, user_data,
>                                                                 destroy);
>
> --
> 1.8.0.1

Ack


--
Luiz Augusto von Dentz

^ permalink raw reply

* Re: OPP test program
From: Johan Hedberg @ 2012-11-29 13:31 UTC (permalink / raw)
  To: Koustuv Ghosh; +Cc: linux-bluetooth
In-Reply-To: <CAB6wy+b4GD8XSNHceEPm-UFdcm4=4nrrZtoPMr+aABu2D7tOvw@mail.gmail.com>

Hi Koustuv,

On Thu, Nov 29, 2012, Koustuv Ghosh wrote:
> I have seen there is no OPP client or server,  test program in bluez
> release. Although obxd projects provides it separately using python
> script+ dbus mechanism.
> 
> In my case , I have developed a simple command line OPP client
> program( takes the remote BD Address and path of the file as arguments
> ) which gets compilied with bluez itself. This test progrm can also be
> interfaced with Dbus.
> 
> Is it allowable that if I want to contribute this test program to
> community , obviously by flowing community protocol.

BlueZ hasn't traditionally had any OBEX code. This has been taken care
of by a separate project called obexd and you can find both release
announcements of it as well as its git tree in the same place you can
find BlueZ. The obexd project has both client and server implementations
for most of the known OBEX-based profiles, including OPP. It's worth
noting thought that starting with BlueZ 5 will will merge the obexd tree
into the BlueZ one any new obexd releases will come together with the
usual BlueZ 5.x releases.

Johan

^ permalink raw reply

* OPP test program
From: Koustuv Ghosh @ 2012-11-29 13:24 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

I have seen there is no OPP client or server,  test program in bluez
release. Although obxd projects provides it separately using python
script+ dbus mechanism.

In my case , I have developed a simple command line OPP client
program( takes the remote BD Address and path of the file as arguments
) which gets compilied with bluez itself. This test progrm can also be
interfaced with Dbus.

Is it allowable that if I want to contribute this test program to
community , obviously by flowing community protocol.

rgds
Koustuv

^ permalink raw reply

* [PATCH BlueZ 3/3] core: Attach and detach object manager
From: Lucas De Marchi @ 2012-11-29 13:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi
In-Reply-To: <1354195173-12750-1-git-send-email-lucas.demarchi@profusion.mobi>

From: Lucas De Marchi <lucas.de.marchi@gmail.com>

---
 src/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main.c b/src/main.c
index 414849a..ccb5fa5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -381,6 +381,7 @@ static void disconnect_dbus(void)
 	if (!conn || !dbus_connection_get_is_connected(conn))
 		return;
 
+	g_dbus_detach_object_manager(conn);
 	set_dbus_connection(NULL);
 
 	dbus_connection_unref(conn);
@@ -412,6 +413,7 @@ static int connect_dbus(void)
 	set_dbus_connection(conn);
 
 	g_dbus_set_disconnect_function(conn, disconnected_dbus, NULL, NULL);
+	g_dbus_attach_object_manager(conn);
 
 	return 0;
 }
-- 
1.8.0.1


^ permalink raw reply related

* [PATCH BlueZ 2/3] gdbus: Don't automatically attach ObjectManager
From: Lucas De Marchi @ 2012-11-29 13:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi
In-Reply-To: <1354195173-12750-1-git-send-email-lucas.demarchi@profusion.mobi>

From: Lucas De Marchi <lucas.de.marchi@gmail.com>

Let each project attach the object manager interface instead of
registering it automatically.
---
 gdbus/gdbus.h  |  3 +++
 gdbus/object.c | 54 +++++++++++++++++++++++++++++++++---------------------
 2 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index ba49621..6aafc61 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -257,6 +257,9 @@ void g_dbus_emit_property_changed(DBusConnection *connection,
 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
 				const char *interface, DBusMessageIter *iter);
 
+gboolean g_dbus_attach_object_manager(DBusConnection *connection);
+gboolean g_dbus_detach_object_manager(DBusConnection *connection);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/gdbus/object.c b/gdbus/object.c
index 47116bd..7cbd612 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -84,6 +84,8 @@ struct property_data {
 	DBusMessage *message;
 };
 
+static struct generic_data *root;
+
 static gboolean process_changes(gpointer user_data);
 static void process_properties_from_interface(struct generic_data *data,
 						struct interface_data *iface);
@@ -569,16 +571,11 @@ static void emit_interfaces_added(struct generic_data *data)
 {
 	DBusMessage *signal;
 	DBusMessageIter iter, array;
-	struct generic_data *parent = data->parent;
 
-	if (parent == NULL)
+	if (root == NULL || data == root)
 		return;
 
-	/* Find root data */
-	while (parent->parent)
-		parent = parent->parent;
-
-	signal = dbus_message_new_signal(parent->path,
+	signal = dbus_message_new_signal(root->path,
 					DBUS_INTERFACE_OBJECT_MANAGER,
 					"InterfacesAdded");
 	if (signal == NULL)
@@ -943,16 +940,11 @@ static void emit_interfaces_removed(struct generic_data *data)
 {
 	DBusMessage *signal;
 	DBusMessageIter iter, array;
-	struct generic_data *parent = data->parent;
 
-	if (parent == NULL)
+	if (root == NULL || data == root)
 		return;
 
-	/* Find root data */
-	while (parent->parent)
-		parent = parent->parent;
-
-	signal = dbus_message_new_signal(parent->path,
+	signal = dbus_message_new_signal(root->path,
 					DBUS_INTERFACE_OBJECT_MANAGER,
 					"InterfacesRemoved");
 	if (signal == NULL)
@@ -1207,12 +1199,6 @@ static struct generic_data *object_path_ref(DBusConnection *connection,
 	add_interface(data, DBUS_INTERFACE_INTROSPECTABLE, introspect_methods,
 						NULL, NULL, data, NULL);
 
-	/* Only root path export ObjectManager interface */
-	if (data->parent == NULL)
-		add_interface(data, DBUS_INTERFACE_OBJECT_MANAGER,
-					manager_methods, manager_signals,
-					NULL, data, NULL);
-
 	return data;
 }
 
@@ -1234,7 +1220,6 @@ static void object_path_unref(DBusConnection *connection, const char *path)
 
 	remove_interface(data, DBUS_INTERFACE_INTROSPECTABLE);
 	remove_interface(data, DBUS_INTERFACE_PROPERTIES);
-	remove_interface(data, DBUS_INTERFACE_OBJECT_MANAGER);
 
 	invalidate_parent_data(data->conn, data->path);
 
@@ -1645,3 +1630,30 @@ gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
 
 	return TRUE;
 }
+
+gboolean g_dbus_attach_object_manager(DBusConnection *connection)
+{
+	struct generic_data *data;
+
+	data = object_path_ref(connection, "/");
+	if (data == NULL)
+		return FALSE;
+
+	add_interface(data, DBUS_INTERFACE_OBJECT_MANAGER,
+					manager_methods, manager_signals,
+					NULL, data, NULL);
+	root = data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_detach_object_manager(DBusConnection *connection)
+{
+	if (!g_dbus_unregister_interface(connection, "/",
+					DBUS_INTERFACE_OBJECT_MANAGER))
+		return FALSE;
+
+	root = NULL;
+
+	return TRUE;
+}
-- 
1.8.0.1


^ permalink raw reply related

* [PATCH BlueZ 1/3] gdbus: Don't register DBus.Properties with no properties
From: Lucas De Marchi @ 2012-11-29 13:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi

Delay registering DBus.Properties interface until the moment there are
properties on that path. This is needed for objects that currently don't
expose any property to not export the interface.
---
 gdbus/object.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 3101ca6..47116bd 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -1213,9 +1213,6 @@ static struct generic_data *object_path_ref(DBusConnection *connection,
 					manager_methods, manager_signals,
 					NULL, data, NULL);
 
-	add_interface(data, DBUS_INTERFACE_PROPERTIES, properties_methods,
-					properties_signals, NULL, data, NULL);
-
 	return data;
 }
 
@@ -1336,6 +1333,12 @@ gboolean g_dbus_register_interface(DBusConnection *connection,
 		return FALSE;
 	}
 
+	if (properties != NULL && !find_interface(data->interfaces,
+						DBUS_INTERFACE_PROPERTIES))
+		add_interface(data, DBUS_INTERFACE_PROPERTIES,
+				properties_methods, properties_signals, NULL,
+				data, NULL);
+
 	add_interface(data, name, methods, signals, properties, user_data,
 								destroy);
 
-- 
1.8.0.1


^ permalink raw reply related

* Re: [PATCH BlueZ 1/6] gdbus: Add g_dbus_add_properties_watch function
From: Lucas De Marchi @ 2012-11-29 13:10 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org, Marcel Holtmann
In-Reply-To: <CABBYNZL0pBd9FCVr1M3A1iEVde8QrW=hxLNCrOSYyTYEZgVGjw@mail.gmail.com>

On Thu, Nov 29, 2012 at 6:52 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Lucas, Marcel,
>
> On Tue, Nov 27, 2012 at 2:51 PM, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> Convenient function to create watches for D-Bus properties.
>> ---
>>  gdbus/gdbus.h |  5 +++++
>>  gdbus/watch.c | 28 ++++++++++++++++++++++++++++
>>  2 files changed, 33 insertions(+)
>>
>> diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
>> index ba49621..8b6dfe5 100644
>> --- a/gdbus/gdbus.h
>> +++ b/gdbus/gdbus.h
>> @@ -243,6 +243,11 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
>>                                 const char *interface, const char *member,
>>                                 GDBusSignalFunction function, void *user_data,
>>                                 GDBusDestroyFunction destroy);
>> +guint g_dbus_add_properties_watch(DBusConnection *connection,
>> +                               const char *sender, const char *path,
>> +                               const char *interface,
>> +                               GDBusSignalFunction function, void *user_data,
>> +                               GDBusDestroyFunction destroy);
>>  gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
>>  void g_dbus_remove_all_watches(DBusConnection *connection);
>>
>> diff --git a/gdbus/watch.c b/gdbus/watch.c
>> index 1cd1211..9e4f994 100644
>> --- a/gdbus/watch.c
>> +++ b/gdbus/watch.c
>> @@ -752,6 +752,34 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
>>         return cb->id;
>>  }
>>
>> +guint g_dbus_add_properties_watch(DBusConnection *connection,
>> +                               const char *sender, const char *path,
>> +                               const char *interface,
>> +                               GDBusSignalFunction function, void *user_data,
>> +                               GDBusDestroyFunction destroy)
>> +{
>> +       struct filter_data *data;
>> +       struct filter_callback *cb;
>> +
>> +       data = filter_data_get(connection, signal_filter, sender, path,
>> +                               DBUS_INTERFACE_PROPERTIES, "PropertiesChanged",
>> +                               interface);
>> +       if (data == NULL)
>> +               return 0;
>> +
>> +       cb = filter_data_add_callback(data, NULL, NULL, function, destroy,
>> +                                       user_data);
>> +       if (cb == NULL)
>> +               return 0;
>> +
>> +       if (data->name != NULL && data->name_watch == 0)
>> +               data->name_watch = g_dbus_add_service_watch(connection,
>> +                                                       data->name, NULL,
>> +                                                       NULL, NULL, NULL);
>> +
>> +       return cb->id;
>> +}
>> +
>>  gboolean g_dbus_remove_watch(DBusConnection *connection, guint id)
>>  {
>>         struct filter_data *data;
>> --
>> 1.7.11.7
>
> Anything regarding this function? The point here is to be able to
> listen to properties specific to one interface which is not possible
> with g_dbus_add_signal_watch.

Ack

Lucas De Marchi

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox