Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC V3 04/12] adapter: Add force dir creation to convert_file()
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>

Some device information, like class or device id, should only be
converted if directory for this device has already been created
during previous conversion (from aliases, trusts, blocked, ...
files).
---
 src/adapter.c |   33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8e3251b..a976793 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -34,6 +34,7 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <sys/file.h>
+#include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -2526,6 +2527,7 @@ static void convert_names_entry(char *key, char *value, void *user_data)
 struct device_converter {
 	char *address;
 	void (*cb)(GKeyFile *key_file, void *value);
+	gboolean force;
 };
 
 static void convert_aliases_entry(GKeyFile *key_file, void *value)
@@ -2601,6 +2603,19 @@ static void convert_entry(char *key, char *value, void *user_data)
 	if (bachk(key) != 0)
 		return;
 
+	if (converter->force == FALSE) {
+		struct stat st;
+		int err;
+
+		snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s",
+				converter->address, key);
+		filename[PATH_MAX] = '\0';
+
+		err = stat(filename, &st);
+		if (err || !S_ISDIR(st.st_mode))
+			return;
+	}
+
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
 			converter->address, key);
 	filename[PATH_MAX] = '\0';
@@ -2621,7 +2636,8 @@ static void convert_entry(char *key, char *value, void *user_data)
 }
 
 static void convert_file(char *file, char *address,
-				void (*cb)(GKeyFile *key_file, void *value))
+				void (*cb)(GKeyFile *key_file, void *value),
+				gboolean force)
 {
 	char filename[PATH_MAX + 1];
 	struct device_converter converter;
@@ -2636,6 +2652,7 @@ static void convert_file(char *file, char *address,
 	} else {
 		converter.address = address;
 		converter.cb = cb;
+		converter.force = force;
 
 		textfile_foreach(filename, convert_entry, &converter);
 		textfile_put(filename, "converted", "yes");
@@ -2665,19 +2682,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
 	free(str);
 
 	/* Convert aliases */
-	convert_file("aliases", address, convert_aliases_entry);
+	convert_file("aliases", address, convert_aliases_entry, TRUE);
 
 	/* Convert trusts */
-	convert_file("trusts", address, convert_trusts_entry);
-
-	/* Convert classes */
-	convert_file("classes", address, convert_classes_entry);
+	convert_file("trusts", address, convert_trusts_entry, TRUE);
 
 	/* Convert blocked */
-	convert_file("blocked", address, convert_blocked_entry);
+	convert_file("blocked", address, convert_blocked_entry, TRUE);
+
+	/* Convert classes */
+	convert_file("classes", address, convert_classes_entry, FALSE);
 
 	/* Convert device ids */
-	convert_file("did", address, convert_did_entry);
+	convert_file("did", address, convert_did_entry, FALSE);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [RFC V3 03/12] adapter: Fix device storage creation
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>

Create device storage directory and file only if there
is data to write.
---
 src/adapter.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f134dfe..8e3251b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2604,14 +2604,17 @@ static void convert_entry(char *key, char *value, void *user_data)
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
 			converter->address, key);
 	filename[PATH_MAX] = '\0';
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
 	key_file = g_key_file_new();
 	g_key_file_load_from_file(key_file, filename, 0, NULL);
 	converter->cb(key_file, value);
 
 	data = g_key_file_to_data(key_file, &length, NULL);
-	g_file_set_contents(filename, data, length, NULL);
+	if (length > 0) {
+		create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		g_file_set_contents(filename, data, length, NULL);
+	}
+
 	g_free(data);
 
 	g_key_file_free(key_file);
-- 
1.7.9.5


^ permalink raw reply related

* [RFC V3 02/12] device: Load device info before updating info file
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>

Data in device info file should not be lost during save
even if they are not in device structure (like link key
and long term key).
---
 src/device.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/device.c b/src/device.c
index a99ca34..1db8a48 100644
--- a/src/device.c
+++ b/src/device.c
@@ -217,17 +217,28 @@ static gboolean store_device_info_cb(gpointer user_data)
 
 	device->store_id = 0;
 
+	ba2str(adapter_get_address(device->adapter), adapter_addr);
+	ba2str(&device->bdaddr, device_addr);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+			device_addr);
+	filename[PATH_MAX] = '\0';
+
 	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
 	g_key_file_set_string(key_file, "General", "Name", device->name);
 
 	if (device->alias != NULL)
 		g_key_file_set_string(key_file, "General", "Alias",
 								device->alias);
+	else
+		g_key_file_remove_key(key_file, "General", "Alias", NULL);
 
 	if (device->class) {
 		sprintf(class, "0x%6.6x", device->class);
 		g_key_file_set_string(key_file, "General", "Class", class);
+	} else {
+		g_key_file_remove_key(key_file, "General", "Class", NULL);
 	}
 
 	g_key_file_set_boolean(key_file, "General", "Trusted",
@@ -245,14 +256,10 @@ static gboolean store_device_info_cb(gpointer user_data)
 					device->product);
 		g_key_file_set_integer(key_file, "DeviceID", "Version",
 					device->version);
+	} else {
+		g_key_file_remove_group(key_file, "DeviceID", NULL);
 	}
 
-	ba2str(adapter_get_address(device->adapter), adapter_addr);
-	ba2str(&device->bdaddr, device_addr);
-	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
-			device_addr);
-	filename[PATH_MAX] = '\0';
-
 	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
 	str = g_key_file_to_data(key_file, &length, NULL);
-- 
1.7.9.5


^ permalink raw reply related

* [RFC V3 01/12] doc: Update settings-storage.txt
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
  To: linux-bluetooth

Add missing Master key to LongTermKey group
---
 doc/settings-storage.txt |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 3fdcb03..e7ba89d 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -181,6 +181,8 @@ Long term key) related to a remote device.
   Authenticated		Boolean		True if remote device has been
 					authenticated
 
+  Master		Boolean		True for master key
+
   EncSize		Integer		Encrypted size
 
   EDiv			Integer		Encrypted diversifier
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Szymon Janc @ 2012-11-30 13:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-7-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 |   59 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index 2013b7b..179152f 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,32 @@ static struct btd_adapter_driver adaptername_driver = {
 	.probe	= adaptername_probe,
 };
 
+struct inotify_data {
+	int inot_fd;
+	int watch_d;
+};
+
+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)
 {
-	int err;
-	int inot_fd;
 	guint32 mask;
-
-	err = btd_register_adapter_driver(&adaptername_driver);
-	if (err < 0)
-		return err;
+	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: %s (%d)", strerror(-err), -err);
+		return err;
 	}
 
 	mask = IN_CLOSE_WRITE;
@@ -290,30 +301,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': %s (%d)",
+				MACHINE_INFO_DIR, strerror(-err), -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

* Re: [PATCH 1/4] proximity: Convert reporter properties to DBus.Properties
From: Johan Hedberg @ 2012-11-30 13:26 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1352464401-12702-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Fri, Nov 09, 2012, Andrzej Kaczmarek wrote:
> ---
>  profiles/proximity/immalert.c |  5 ++--
>  profiles/proximity/linkloss.c |  5 ++--
>  profiles/proximity/reporter.c | 62 +++++++++++++++----------------------------
>  3 files changed, 25 insertions(+), 47 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH v2 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Anderson Lizardo @ 2012-11-30 13:22 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1354280264-19036-7-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Fri, Nov 30, 2012 at 8:57 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
>         inot_fd = inotify_init();
>         if (inot_fd < 0) {
> -               error("Failed to setup inotify");
> -               return 0;
> +               int err = errno;
> +               error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
> +               return -err;

Now it is broken :) By convention, "err" should be always negative, so use:

int err = -errno;

when printing the error, you need to make it positive, like above:

error("Failed to setup inotify: %s (%d)", strerror(-err), -err);

then when returning, use:

return err;

See other examples on the bluez code if you have doubts.

> @@ -290,30 +301,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': %s (%d)",
> +                               MACHINE_INFO_DIR, strerror(-err), -err);
>                 close(inot_fd);
> -               return 0;
> +               return -err;
>         }

Same problem here, please fix. (you can send just a v3 of this patch,
it should not conflict with others).

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [PATCH 00/15] thermometer plugin updates
From: Johan Hedberg @ 2012-11-30 13:06 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1352451357-22097-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Fri, Nov 09, 2012, Andrzej Kaczmarek wrote:
> Here are few patches to update thermometer plugin with features already
> implemented in other plugins:
> - store attributes handles directly in thermometer structure instead of
>   nested lists of structures which we need to traverse later (and we
>   only need 3 handles stored to support all use cases)
> - register attio handlers for specific handles instead of one ind and
>   notif handler globally
> - change properties handling to DBus.Properties
> - and some minor fixes
> 
> This is tested with PTS 4.5.3. There's only problem with patch #9 which
> "breaks" testcase TP/THF/CO/BV-09-I - this is because PTS sends invalid
> properties for Measurement Interval characteristic (it does not have
> indicate property so we do not register ind handler for it). I already
> filled issue on PTS.
> 
> Comments are welcome.
> 
> 
> Andrzej Kaczmarek (15):
>   thermometer: Store Temperature Measurement CCC handle in struct
>   thermometer: Store Intermediate Temperature CCC handle in struct
>   thermometer: Store Measurement Interval value handle in struct
>   thermometer: Use dedicated handler for Intermediate Temperature
>   thermometer: Use dedicated handler for Temperature Measurement
>   thermometer: Use dedicated handler for Measurement Interval
>   thermometer: Remove descriptor structure
>   thermometer: Remove storage of all discovered characteristics
>   thermometer: Discover Measurement Interval descriptors only if needed
>   thermometer: Always write CCC value when connecting
>   thermometer: Make temp_type array static
>   thermometer: Add DBus.Properties support
>   thermometer: Remove legacy properties code
>   doc: Update thermometer API document
>   test: Update test-thermometer for DBus.Properties
> 
>  doc/thermometer-api.txt            |   18 -
>  profiles/thermometer/thermometer.c | 1008 +++++++++++++++++-------------------
>  test/test-thermometer              |   13 +-
>  3 files changed, 478 insertions(+), 561 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH v2 8/8] hog: Fix unregistering profile on exit
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>

On exit should call btd_profile_unregister instead of
btd_profile_register. Fixes following:

16 bytes in 1 blocks are still reachable in loss record 54 of 215
   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 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x17F6C2: btd_profile_register (profile.c:533)
   by 0x171456: plugin_cleanup (plugin.c:242)
   by 0x12164F: main (main.c:563)

16 bytes in 1 blocks are still reachable in loss record 37 of 215
   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 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x17F6C2: btd_profile_register (profile.c:533)
   by 0x1712EB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)
---
 profiles/input/hog_manager.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
index 21ceb79..595b160 100644
--- a/profiles/input/hog_manager.c
+++ b/profiles/input/hog_manager.c
@@ -144,7 +144,7 @@ static void hog_manager_exit(void)
 	if (suspend_supported)
 		suspend_exit();
 
-	btd_profile_register(&hog_profile);
+	btd_profile_unregister(&hog_profile);
 }
 
 static int hog_init(void)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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 |   59 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index 2013b7b..018e6f0 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,32 @@ static struct btd_adapter_driver adaptername_driver = {
 	.probe	= adaptername_probe,
 };
 
+struct inotify_data {
+	int inot_fd;
+	int watch_d;
+};
+
+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)
 {
-	int err;
-	int inot_fd;
 	guint32 mask;
-
-	err = btd_register_adapter_driver(&adaptername_driver);
-	if (err < 0)
-		return err;
+	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: %s (%d)", strerror(-err), -err);
+		return -err;
 	}
 
 	mask = IN_CLOSE_WRITE;
@@ -290,30 +301,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': %s (%d)",
+				MACHINE_INFO_DIR, strerror(-err), -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 v2 6/8] core: Free parsed options
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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 v2 5/8] attrib: Fix possible use after free
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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 v2 4/8] hog: Fix memory leak in suspend-dummy
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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..b43946d 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 > 0) {
+		g_source_remove(watch);
+		watch = 0;
 	}
 
 	remove(HOG_SUSPEND_FIFO);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 3/8] rfkill: Fix memory leak in rfkill_exit
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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 |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/rfkill.c b/src/rfkill.c
index b40c6e7..f82596b 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,18 @@ 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,
-							rfkill_event, NULL);
+	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 v2 2/8] doc: Update valgrind.suppressions with some libdbus suppressions
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-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..07f3238 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 v2 1/8] doc: Add valgrind.suppressions
From: Szymon Janc @ 2012-11-30 12:57 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: BLE : SMP pairing + LE_Start_encryption
From: Anderson Lizardo @ 2012-11-30 12:53 UTC (permalink / raw)
  To: Ajay; +Cc: linux-bluetooth
In-Reply-To: <50B6ADE7.3070000@globaledgesoft.com>

Hi Ajay,

On Wed, Nov 28, 2012 at 8:35 PM, Ajay <ajay.kv@globaledgesoft.com> wrote:
>         is it possible to create an l2cap connection with cid 0x06 and psm 0
> ?  , so that i can make use of dedicated smp-l2cap channel for data transfer
> . I wanted to try how the remote device is handling on receiving an
> smp_pairing_request . i have seen in l2cap_core.c  , it is getting handled
> inside a switch case (case cid == L2CAP_CID_SMP).

On Linux, all communication over the LE SMP CID is done on the kernel.
So you need to use either increase socket seclevel using setsockopt()
or using "Pair Device" from mgmt API to send the SMP Pairing Request
from userspace.

I don't know how you can send "raw" SMP requests from userspace.

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* [PATCH BlueZ] control: Add methods FastForward and Rewind
From: Luiz Augusto von Dentz @ 2012-11-30 12:48 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

These method can be used to fast-forward and rewind the playback, their
action will keep active until another method is called.

The commands are reapeated every 2 seconds to conform with AVC spec.
---
 doc/control-api.txt      |  10 ++++
 profiles/audio/avctp.c   | 148 ++++++++++++++++++++++++++++++++++++++++++-----
 profiles/audio/control.c |  14 +++++
 3 files changed, 157 insertions(+), 15 deletions(-)

diff --git a/doc/control-api.txt b/doc/control-api.txt
index e0ed04a..55cebe8 100644
--- a/doc/control-api.txt
+++ b/doc/control-api.txt
@@ -40,6 +40,16 @@ Methods		void Play()
 
 			Adjust remote volume one step down
 
+		void FastForward()
+
+			Fast forward playback, this action is only stopped
+			when another method in this interface is called.
+
+		void Rewind()
+
+			Rewind playback, this action is only stopped
+			when another method in this interface is called.
+
 Properties
 
 		boolean Connected [readonly]
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index e48c257..8693784 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -162,6 +162,11 @@ struct avctp_channel {
 	guint process_id;
 };
 
+struct key_pressed {
+	uint8_t op;
+	guint timer;
+};
+
 struct avctp {
 	struct avctp_server *server;
 	bdaddr_t dst;
@@ -179,6 +184,7 @@ struct avctp {
 	struct avctp_channel *browsing;
 
 	uint8_t key_quirks[256];
+	struct key_pressed *key;
 };
 
 struct avctp_pdu_handler {
@@ -214,6 +220,9 @@ static GSList *servers = NULL;
 
 static void auth_cb(DBusError *derr, void *user_data);
 static gboolean process_queue(gpointer user_data);
+static gboolean avctp_passthrough_rsp(struct avctp *session, uint8_t code,
+					uint8_t subunit, uint8_t *operands,
+					size_t operand_count, void *user_data);
 
 static int send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
@@ -409,6 +418,13 @@ static void avctp_disconnected(struct avctp *session)
 		session->auth_id = 0;
 	}
 
+	if (session->key != NULL) {
+		if (session->key->timer > 0)
+			g_source_remove(session->key->timer);
+		g_free(session->key);
+	}
+
+
 	if (session->uinput >= 0) {
 		char address[18];
 
@@ -1272,6 +1288,116 @@ static int avctp_send_req(struct avctp *session, uint8_t code,
 	return 0;
 }
 
+static char *op2str(uint8_t op)
+{
+	switch (op & 0x7f) {
+	case AVC_VOLUME_UP:
+		return "VOLUME UP";
+	case AVC_VOLUME_DOWN:
+		return "VOLUME DOWN";
+	case AVC_MUTE:
+		return "MUTE";
+	case AVC_PLAY:
+		return "PLAY";
+	case AVC_STOP:
+		return "STOP";
+	case AVC_PAUSE:
+		return "PAUSE";
+	case AVC_RECORD:
+		return "RECORD";
+	case AVC_REWIND:
+		return "REWIND";
+	case AVC_FAST_FORWARD:
+		return "FAST FORWARD";
+	case AVC_EJECT:
+		return "EJECT";
+	case AVC_FORWARD:
+		return "FORWARD";
+	case AVC_BACKWARD:
+		return "BACKWARD";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+static int avctp_passthrough_press(struct avctp *session, uint8_t op)
+{
+	uint8_t operands[2];
+
+	DBG("%s", op2str(op));
+
+	/* Button pressed */
+	operands[0] = op & 0x7f;
+	operands[1] = 0;
+
+	return avctp_send_req(session, AVC_CTYPE_CONTROL,
+				AVC_SUBUNIT_PANEL, AVC_OP_PASSTHROUGH,
+				operands, sizeof(operands),
+				avctp_passthrough_rsp, NULL);
+}
+
+static int avctp_passthrough_release(struct avctp *session, uint8_t op)
+{
+	uint8_t operands[2];
+
+	DBG("%s", op2str(op));
+
+	/* Button released */
+	operands[0] = op | 0x80;
+	operands[1] = 0;
+
+	return avctp_send_req(session, AVC_CTYPE_CONTROL,
+				AVC_SUBUNIT_PANEL, AVC_OP_PASSTHROUGH,
+				operands, sizeof(operands),
+				NULL, NULL);
+}
+
+static gboolean repeat_timeout(gpointer user_data)
+{
+	struct avctp *session = user_data;
+	struct key_pressed *key = session->key;
+
+	avctp_passthrough_release(session, key->op);
+	avctp_passthrough_press(session, key->op);
+
+	return TRUE;
+}
+
+static void release_pressed(struct avctp *session)
+{
+	struct key_pressed *key = session->key;
+
+	avctp_passthrough_release(session, key->op);
+
+	if (key->timer > 0)
+		g_source_remove(key->timer);
+
+	g_free(key);
+	session->key = NULL;
+}
+
+static bool set_pressed(struct avctp *session, uint8_t op)
+{
+	struct key_pressed *key;
+
+	if (session->key != NULL) {
+		if (session->key->op == op)
+			return TRUE;
+		release_pressed(session);
+	}
+
+	if (op != AVC_FAST_FORWARD && op != AVC_REWIND)
+		return FALSE;
+
+	key = g_new0(struct key_pressed, 1);
+	key->op = op;
+	key->timer = g_timeout_add_seconds(2, repeat_timeout, session);
+
+	session->key = key;
+
+	return TRUE;
+}
+
 static gboolean avctp_passthrough_rsp(struct avctp *session, uint8_t code,
 					uint8_t subunit, uint8_t *operands,
 					size_t operand_count, void *user_data)
@@ -1279,29 +1405,21 @@ static gboolean avctp_passthrough_rsp(struct avctp *session, uint8_t code,
 	if (code != AVC_CTYPE_ACCEPTED)
 		return FALSE;
 
-	/* Button release */
-	operands[0] |= 0x80;
+	if (set_pressed(session, operands[0]))
+		return FALSE;
 
-	avctp_send_req(session, AVC_CTYPE_CONTROL,
-				AVC_SUBUNIT_PANEL, AVC_OP_PASSTHROUGH,
-				operands, operand_count,
-				NULL, NULL);
+	avctp_passthrough_release(session, operands[0]);
 
 	return FALSE;
 }
 
 int avctp_send_passthrough(struct avctp *session, uint8_t op)
 {
-	uint8_t operands[2];
-
-	/* Button pressed */
-	operands[0] = op & 0x7f;
-	operands[1] = 0;
+	/* Auto release if key pressed */
+	if (session->key != NULL)
+		release_pressed(session);
 
-	return avctp_send_req(session, AVC_CTYPE_CONTROL,
-				AVC_SUBUNIT_PANEL, AVC_OP_PASSTHROUGH,
-				operands, sizeof(operands),
-				avctp_passthrough_rsp, NULL);
+	return avctp_passthrough_press(session, op);
 }
 
 int avctp_send_vendordep(struct avctp *session, uint8_t transaction,
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index 0013f8d..7299b7e 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
@@ -238,6 +238,18 @@ static DBusMessage *control_previous(DBusConnection *conn, DBusMessage *msg,
 	return key_pressed(conn, msg, AVC_BACKWARD, data);
 }
 
+static DBusMessage *control_fast_forward(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	return key_pressed(conn, msg, AVC_FAST_FORWARD, data);
+}
+
+static DBusMessage *control_rewind(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	return key_pressed(conn, msg, AVC_REWIND, data);
+}
+
 static gboolean control_property_get_connected(
 					const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
@@ -258,6 +270,8 @@ static const GDBusMethodTable control_methods[] = {
 	{ GDBUS_METHOD("Previous", NULL, NULL, control_previous) },
 	{ GDBUS_METHOD("VolumeUp", NULL, NULL, control_volume_up) },
 	{ GDBUS_METHOD("VolumeDown", NULL, NULL, control_volume_down) },
+	{ GDBUS_METHOD("FastForward", NULL, NULL, control_fast_forward) },
+	{ GDBUS_METHOD("Rewind", NULL, NULL, control_rewind) },
 	{ }
 };
 
-- 
1.7.11.7


^ permalink raw reply related

* Re: [RFC v2 02/15] test: Add utility library for python scripts
From: Anderson Lizardo @ 2012-11-30 12:28 UTC (permalink / raw)
  To: Mikel Astiz; +Cc: linux-bluetooth, Mikel Astiz
In-Reply-To: <1354193256-30610-3-git-send-email-mikel.astiz.oss@gmail.com>

Hi Mikel,

On Thu, Nov 29, 2012 at 8:47 AM, Mikel Astiz <mikel.astiz.oss@gmail.com> wrote:
> +def find_adapter_in_objects(objects, pattern=None):
> +       bus = dbus.SystemBus()
> +       for path, ifaces in objects.iteritems():
> +               adapter = ifaces.get(ADAPTER_INTERFACE)
> +               if adapter == None:
> +                       continue

It is usually considered bad to use "== None" in Python. Either use
"adapter is None" or just "not adapter" (which is broader, but is
probably okay in this context).

> +               if (pattern == None or pattern == adapter["Address"] or
> +                                                       path.endswith(pattern)):

Same here, better use "pattern is None" or "not pattern" (which will
also match empty strings, which will always match due to the
"endswith()" usage).

> +                       obj = bus.get_object(SERVICE_NAME, path)
> +                       return dbus.Interface(obj, ADAPTER_INTERFACE)
> +       raise Exception("Bluetooth adapter not found")

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: BLE : SMP pairing + LE_Start_encryption
From: Anderson Lizardo @ 2012-11-30 12:08 UTC (permalink / raw)
  To: Ajay; +Cc: linux-bluetooth
In-Reply-To: <50B681C7.1030207@globaledgesoft.com>

Hi Ajay,

On Wed, Nov 28, 2012 at 5:27 PM, Ajay <ajay.kv@globaledgesoft.com> wrote:
>
> Hi,
>         how do i do smp pairing and ltk key distribution using l2cap socket
> connection?  does bluez provide any tools for LE pairing . my ultimate
> result should be enabling LE_start_encryption , which requires ltk key
> distribution (which is a part of LE_pairing).

Either using mgmt API to do pairing (see mgmt_create_bonding() in
src/mgmt.c from bluez sources and doc/mgmt-api.txt for how to do this)
or increase socket security level to at least medium using
setsockopt() (see set_sec_level() in btio/btio.c for how to do this).

In summary, you will need to use BlueZ code as reference if you want
to do these things on your own. The easier route is to use BlueZ D-Bus
API to do pairing.

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [PATCH 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Anderson Lizardo @ 2012-11-30 11:58 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1354274703-15604-7-git-send-email-szymon.janc@tieto.com>

Ho Szymon,

On Fri, Nov 30, 2012 at 7:25 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> @@ -266,20 +265,33 @@ static struct btd_adapter_driver adaptername_driver = {
>         .probe  = adaptername_probe,
>  };
>
> -static int adaptername_init(void)
> +struct inotify_data
>  {

The opening "{" should be on the same line as "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);

We usually print errors this way:

error("Failed to setup inotify: %s (%d)", strerror(-err), -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);

same here:

error("Failed to setup watch for '%s': %s (%d)", MACHINE_INFO_DIR,
strerror(-err), -err);

>                 close(inot_fd);
> -               return 0;
> +               return err;
>         }

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

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

Hi Szymon,

On Fri, Nov 30, 2012 at 7:24 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> @@ -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) {

By convention, we try to use "if (watch > 0)" or "if (watch == 0)"
when checking whether watches are valid. In this case, "if (watch >
0)" is more appropriate.

> +               g_source_remove(watch);
> +               watch = 0;
>         }
>
>         remove(HOG_SUSPEND_FIFO);

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [RFC v2 00/15] Manager/Adapter transition to ObjectManager
From: Mikel Astiz @ 2012-11-30 11:38 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth, Mikel Astiz
In-Reply-To: <CAMOw1v4hsQa3VNT+qaF9eZPiu88G7cyd0jwTR=Bd1Pnj3yyQWw@mail.gmail.com>

Hi Lucas,

On Thu, Nov 29, 2012 at 7:12 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> 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?

Yes, the patches (which are now pushed) do the job.

So at this point there is no other dependency and thus these patches
can be applied and tested with upstream master.

Cheers,
Mikel

^ permalink raw reply

* [PATCH 8/8] hog: Fix unregistering profile on exit
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>

On exit should call btd_profile_unregister instead of
btd_profile_register. Fixes following:

16 bytes in 1 blocks are still reachable in loss record 54 of 215
   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 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x17F6C2: btd_profile_register (profile.c:533)
   by 0x171456: plugin_cleanup (plugin.c:242)
   by 0x12164F: main (main.c:563)

16 bytes in 1 blocks are still reachable in loss record 37 of 215
   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 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x17F6C2: btd_profile_register (profile.c:533)
   by 0x1712EB: plugin_init (plugin.c:217)
   by 0x1215D2: main (main.c:544)
---
 profiles/input/hog_manager.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
index 21ceb79..595b160 100644
--- a/profiles/input/hog_manager.c
+++ b/profiles/input/hog_manager.c
@@ -144,7 +144,7 @@ static void hog_manager_exit(void)
 	if (suspend_supported)
 		suspend_exit();
 
-	btd_profile_register(&hog_profile);
+	btd_profile_unregister(&hog_profile);
 }
 
 static int hog_init(void)
-- 
1.7.9.5


^ permalink raw reply related

* [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


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