Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH] Bluetooth: Use GFP_KERNEL when cloning SKB in a workqueue
From: Johan Hedberg @ 2013-09-06 10:41 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1378257067-52933-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Tue, Sep 03, 2013, Marcel Holtmann wrote:
> There is no need to use GFP_ATOMIC with skb_clone() when the code is
> executed in a workqueue.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Johan Hedberg <johan.hedberg@intel.com>

Johan

^ permalink raw reply

* Re: [PATCH] hog: ignore UHID-setup events and document why
From: Johan Hedberg @ 2013-09-06 10:38 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, Marcel Holtmann
In-Reply-To: <1378123089-3980-1-git-send-email-dh.herrmann@gmail.com>

Hi David,

On Mon, Sep 02, 2013, David Herrmann wrote:
> The UHID_{START,STOP,OPEN,CLOSE} events should be ignored by us to avoid
> triggering the warn(). It is safe to do that. Add few comments that
> explain why we don't have to handle these.
> ---
>  profiles/input/hog.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/2] Bluetooth: Disable upper layer connections when user channel is active
From: Johan Hedberg @ 2013-09-06  9:06 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1378256918-50836-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Tue, Sep 03, 2013, Marcel Holtmann wrote:
> When the device has the user channel flag set, it means it is driven by
> an user application. In that case do not allow any connections from
> L2CAP or SCO sockets.
> 
> This is the same situation as when the device has the raw flag set and
> it will then return EHOSTUNREACH.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_conn.c | 1 +
>  1 file changed, 1 insertion(+)

Acked-by: Johan Hedberg <johan.hedberg@intel.com>

Johan

^ permalink raw reply

* [PATCH] build: use -lrt for clock_gettime on glibc < 2.17
From: Dirk-Jan C. Binnema @ 2013-09-06  8:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dirk-Jan C. Binnema
In-Reply-To: <52E3B66B-DC7A-4225-8779-8C1E9B0FC15E@holtmann.org>

From: "Dirk-Jan C. Binnema" <djcb@djcbsoftware.nl>

glibc before 2.17 (e.g., fedora 18) requires -lrt for clock_gettime;
add -lrt where needed in that case.
---
 Makefile.am  | 2 +-
 configure.ac | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 61daec4..8069af2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -152,7 +152,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
 			src/shared/util.h src/shared/util.c \
 			src/shared/mgmt.h src/shared/mgmt.c
 src_bluetoothd_LDADD = lib/libbluetooth-internal.la gdbus/libgdbus-internal.la \
-			@GLIB_LIBS@ @DBUS_LIBS@ -ldl -lrt
+			@GLIB_LIBS@ @DBUS_LIBS@ @RT_LIBS@ -ldl
 src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \
 				-Wl,--version-script=$(srcdir)/src/bluetooth.ver
 
diff --git a/configure.ac b/configure.ac
index 050d30d..e7a7b85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,8 +40,10 @@ AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
 AC_CHECK_FUNC(signalfd, dummy=yes,
 			AC_MSG_ERROR(signalfd support is required))
 
-AC_CHECK_FUNC(clock_gettime, dummy=yes,
-			AC_MSG_ERROR(realtime clock support is required))
+AC_CHECK_FUNC(clock_gettime, [], [
+  AC_CHECK_LIB(rt, clock_gettime, RT_LIBS="-lrt",
+    AC_MSG_ERROR(realtime clock support is required))])
+AC_SUBST(RT_LIBS)
 
 AC_CHECK_LIB(pthread, pthread_create, dummy=yes,
 			AC_MSG_ERROR(posix thread support is required))
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH] build: use -lrt for clock_gettime on glibc < 2.17
From: Dirk-Jan C. Binnema @ 2013-09-06  8:07 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <52E3B66B-DC7A-4225-8779-8C1E9B0FC15E@holtmann.org>

Hi Marcel,

marcel@holtmann.org writes:

> Hi Dirk-Jan,,
>
>> glibc before 2.17 (e.g., fedora 18) requires -lrt for clock_gettime.
>> AC_SEARCH_LIBS adds it to LIBS in that case
>> ---
>> configure.ac | 1 +
>> 1 file changed, 1 insertion(+)
>> 
>> diff --git a/configure.ac b/configure.ac
>> index 050d30d..403e323 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -40,6 +40,7 @@ AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
>> AC_CHECK_FUNC(signalfd, dummy=yes,
>> 			AC_MSG_ERROR(signalfd support is required))
>> 
>> +AC_SEARCH_LIBS(clock_gettime,rt)
>
> I do like this since this now it links everything with -lrt even if it is not needed.

Hmm, I suppose there's a missing 'not'...

Note, AC_SEARCH_LIBS tries without rt first, and only adds -lrt if
clock_gettime is not defined without it.

Or did you mean building parts of bluez without -lrt in the glibc < 2.17
case? If so, please see my next patch, which only uses -lrt (if needed)
for bluetoothd.

Cheers,
Dirk.


-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb@djcbsoftware.nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

^ permalink raw reply

* [PATCH 2/2] Change __FUNCTION__ to __func__
From: Andrei Emeltchenko @ 2013-09-06  8:02 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1378454530-24686-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

checkpatch.pl recommends to use __func__ instead of __FUNCTION__.
---
 attrib/gattrib.c    | 2 +-
 gobex/gobex-debug.h | 2 +-
 obexd/src/log.h     | 2 +-
 src/log.h           | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index c662ace..609b908 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -718,7 +718,7 @@ gboolean g_attrib_unregister(GAttrib *attrib, guint id)
 	GSList *l;
 
 	if (id == 0) {
-		warn("%s: invalid id", __FUNCTION__);
+		warn("%s: invalid id", __func__);
 		return FALSE;
 	}
 
diff --git a/gobex/gobex-debug.h b/gobex/gobex-debug.h
index 688466e..a98653d 100644
--- a/gobex/gobex-debug.h
+++ b/gobex/gobex-debug.h
@@ -40,7 +40,7 @@ extern guint gobex_debug;
 #define g_obex_debug(level, format, ...) \
 	if (gobex_debug & level) \
 		g_log("gobex", G_LOG_LEVEL_DEBUG, "%s:%s() " format, __FILE__, \
-						__FUNCTION__, ## __VA_ARGS__)
+						__func__, ## __VA_ARGS__)
 
 static inline void g_obex_dump(guint level, const char *prefix,
 					const void *buf, gsize len)
diff --git a/obexd/src/log.h b/obexd/src/log.h
index 1bf1b05..d9fb867 100644
--- a/obexd/src/log.h
+++ b/obexd/src/log.h
@@ -52,5 +52,5 @@ struct obex_debug_desc {
 		.file = __FILE__, .flags = OBEX_DEBUG_FLAG_DEFAULT, \
 	}; \
 	if (__obex_debug_desc.flags & OBEX_DEBUG_FLAG_PRINT) \
-		obex_debug("%s:%s() " fmt,  __FILE__, __FUNCTION__ , ## arg); \
+		obex_debug("%s:%s() " fmt,  __FILE__, __func__ , ## arg); \
 } while (0)
diff --git a/src/log.h b/src/log.h
index 3d34fa3..bf9eac2 100644
--- a/src/log.h
+++ b/src/log.h
@@ -55,5 +55,5 @@ void __btd_enable_debug(struct btd_debug_desc *start,
 		.file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
 	}; \
 	if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
-		btd_debug("%s:%s() " fmt,  __FILE__, __FUNCTION__ , ## arg); \
+		btd_debug("%s:%s() " fmt,  __FILE__, __func__ , ## arg); \
 } while (0)
-- 
1.8.1.2


^ permalink raw reply related

* [PATCH 1/2] Fix crash setting NULL name
From: Andrei Emeltchenko @ 2013-09-06  8:02 UTC (permalink / raw)
  To: linux-bluetooth

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

set_name might be invoked with name argument as shown below:
set_name(adapter, btd_adapter_get_name(adapter)) and
btd_adapter_get_name may return NULL. Add check to prevent crash.
---
 src/adapter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 17f5508..7291a6d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -643,6 +643,9 @@ static int set_name(struct btd_adapter *adapter, const char *name)
 	struct mgmt_cp_set_local_name cp;
 	char maxname[MAX_NAME_LENGTH + 1];
 
+	if (name == NULL)
+		return -EINVAL;
+
 	memset(maxname, 0, sizeof(maxname));
 	strncpy(maxname, name, MAX_NAME_LENGTH);
 
-- 
1.8.1.2


^ permalink raw reply related

* [PATCH] build: use -lrt for clock_gettime on glibc < 2.17
From: Dirk-Jan C. Binnema @ 2013-09-06  6:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dirk-Jan C. Binnema

From: "Dirk-Jan C. Binnema" <djcb@djcbsoftware.nl>

glibc before 2.17 (e.g., fedora 18) requires -lrt for clock_gettime.
AC_SEARCH_LIBS adds it to LIBS in that case
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure.ac b/configure.ac
index 050d30d..403e323 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,7 @@ AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
 AC_CHECK_FUNC(signalfd, dummy=yes,
 			AC_MSG_ERROR(signalfd support is required))
 
+AC_SEARCH_LIBS(clock_gettime,rt)
 AC_CHECK_FUNC(clock_gettime, dummy=yes,
 			AC_MSG_ERROR(realtime clock support is required))
 
-- 
1.8.3.1


^ permalink raw reply related

* Re: Linux Wireless Mini-Summit in New Orleans -- 19-20 September (6 weeks from today!)
From: Dan Williams @ 2013-09-05 16:04 UTC (permalink / raw)
  To: John W. Linville
  Cc: linux-wireless, johannes, marcel, Samuel Ortiz, Gustavo Padovan,
	linux-bluetooth, linux-nfc
In-Reply-To: <20130905133907.GE1947@tuxdriver.com>

On Thu, 2013-09-05 at 09:39 -0400, John W. Linville wrote:
> On Thu, Aug 08, 2013 at 03:04:29PM -0400, John W. Linville wrote:
> > Sorry, forgot to copy linux-bluetooth and linux-nfc...
> > 
> > On Thu, Aug 08, 2013 at 02:54:11PM -0400, John W. Linville wrote:
> > > Greetings!
> > > 
> > > This is a reminder that we will have a Linux Wireless Mini-Summit in
> > > New Orleans this year on 19-20 September.  This will immediately follow
> > > LinuxCon and will run concurrently with Linux Plumber's Conference.
> > > This event includes Linux developers for wireless LAN (802.11),
> > > Bluetooth, and NFC technologies.  Both kernel and userland developers
> > > are welcomed and heartily encouraged to attend!
> > > 
> > > 	http://wireless.kernel.org/en/developers/Summits/New-Orleans-2013
> > > 
> > > The link above is a Wiki.  We are using it to collect discussion
> > > topics and to negotiate agenda/scheduling options for the event.
> > > Please go there to record your intent to attend the event and to
> > > propopse topics for discussion.
> > > 
> > > Please be aware that in order to attend the event above one must
> > > register for either LinuxCon or for Linux Plumbers Conference.
> > > Act now, before those events fill-up and close their registrations!
> > > 
> > > We are allotted one "large" room (up to ~80 people "theater style"), and
> > > two "small" rooms (up to ~25 people) for this event.  Based on history
> > > and the numbers of contributors, the larger room will primarily be
> > > for the 802.11 discussions and any "plenary" topics while the smaller
> > > rooms will be for Bluetooth, NFC, and any "breakout" topics.
> > > 
> > > So...thoughts?  Topics to discuss?
> 
> Ping?  We're now just 2 weeks away!
> 
> Is our topic list complete?  It looks a bit light...
> 
> Anyone have any input on scheduling the topics?  Are there any
> overlapping LPC sessions that it would make sense to work around?

I'm attending though I haven't put my name on the wiki yet.

Random thoughts; it doesn't look like any of these are covered in the
regular LinuxConf or LPC sessions.

1) State of the Union (maybe by multiple people in the same session per
their expertise), since perhaps not everyone doing eg 802.11 stuff knows
what's happening in BT or NFC land, or not everyone working on a
specific driver may know what new stuff their driver might need to be
fixed up for.  Maybe 5 minutes or less for things like:

  * what's under the most active development right now?
  * upcoming new driver, hardware, and new capabilities
  * new 802.11 standards
  * and what's coming up in the next year from the standards orgs
  * what people will start working on soon
  * what will 3.13 or 3.14 look like from a wireless perspective?
  * 11s mesh status?
  * anything interesting in wpa_supplicant land?
  * anything new/interesting on the Android front?

2) Bluetooth - update about what's new and what's coming up in Bluez
land, and interaction with kernel 802.11 if any, 

3) NFC - update about what's new and what's coming up in NFC land, where
it's getting used, what the stack looks like

4) What are users having the most problems with and how these problems
be fixed better/more quickly?  Are they driver bugs?  Are they stack
bugs?  Supplicant bugs?  NM/GUI/etc bugs?  Is there anything in our
development processes that's not working as smoothly as it could be?

Dan

^ permalink raw reply

* Re: Linux Wireless Mini-Summit in New Orleans -- 19-20 September (6 weeks from today!)
From: John W. Linville @ 2013-09-05 13:39 UTC (permalink / raw)
  To: linux-wireless
  Cc: johannes, marcel, Samuel Ortiz, Gustavo Padovan, linux-bluetooth,
	linux-nfc
In-Reply-To: <20130808190428.GF30925@tuxdriver.com>

On Thu, Aug 08, 2013 at 03:04:29PM -0400, John W. Linville wrote:
> Sorry, forgot to copy linux-bluetooth and linux-nfc...
> 
> On Thu, Aug 08, 2013 at 02:54:11PM -0400, John W. Linville wrote:
> > Greetings!
> > 
> > This is a reminder that we will have a Linux Wireless Mini-Summit in
> > New Orleans this year on 19-20 September.  This will immediately follow
> > LinuxCon and will run concurrently with Linux Plumber's Conference.
> > This event includes Linux developers for wireless LAN (802.11),
> > Bluetooth, and NFC technologies.  Both kernel and userland developers
> > are welcomed and heartily encouraged to attend!
> > 
> > 	http://wireless.kernel.org/en/developers/Summits/New-Orleans-2013
> > 
> > The link above is a Wiki.  We are using it to collect discussion
> > topics and to negotiate agenda/scheduling options for the event.
> > Please go there to record your intent to attend the event and to
> > propopse topics for discussion.
> > 
> > Please be aware that in order to attend the event above one must
> > register for either LinuxCon or for Linux Plumbers Conference.
> > Act now, before those events fill-up and close their registrations!
> > 
> > We are allotted one "large" room (up to ~80 people "theater style"), and
> > two "small" rooms (up to ~25 people) for this event.  Based on history
> > and the numbers of contributors, the larger room will primarily be
> > for the 802.11 discussions and any "plenary" topics while the smaller
> > rooms will be for Bluetooth, NFC, and any "breakout" topics.
> > 
> > So...thoughts?  Topics to discuss?

Ping?  We're now just 2 weeks away!

Is our topic list complete?  It looks a bit light...

Anyone have any input on scheduling the topics?  Are there any
overlapping LPC sessions that it would make sense to work around?

John
-- 
John W. Linville		Someday the world will need a hero, and you
linville@tuxdriver.com			might be all we have.  Be ready.

^ permalink raw reply

* [PATCH BlueZ 5/5] gdbus/client: Use g_dbus_add_properties_watch to track properties
From: Luiz Augusto von Dentz @ 2013-09-04 19:04 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1378321471-9043-1-git-send-email-luiz.dentz@gmail.com>

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

This make the handling much simpler and avoids duplicates of the same
match rule.
---
 gdbus/client.c | 135 ++++++++++++++++++++++++---------------------------------
 1 file changed, 56 insertions(+), 79 deletions(-)

diff --git a/gdbus/client.c b/gdbus/client.c
index f1e6946..bd0eadc 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -67,7 +67,7 @@ struct GDBusProxy {
 	char *obj_path;
 	char *interface;
 	GHashTable *prop_list;
-	char *match_rule;
+	guint watch;
 	GDBusPropertyFunction prop_func;
 	void *prop_data;
 	GDBusProxyFunction removed_func;
@@ -358,6 +358,52 @@ static GDBusProxy *proxy_lookup(GDBusClient *client, const char *path,
 	return NULL;
 }
 
+static gboolean properties_changed(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
+{
+	GDBusProxy *proxy = user_data;
+	GDBusClient *client = proxy->client;
+	DBusMessageIter iter, entry;
+	const char *interface;
+
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		return TRUE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &interface);
+	dbus_message_iter_next(&iter);
+
+	update_properties(proxy, &iter, TRUE);
+
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return TRUE;
+
+	dbus_message_iter_recurse(&iter, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *name;
+
+		dbus_message_iter_get_basic(&entry, &name);
+
+		g_hash_table_remove(proxy->prop_list, name);
+
+		if (proxy->prop_func)
+			proxy->prop_func(proxy, name, NULL, proxy->prop_data);
+
+		if (client->property_changed)
+			client->property_changed(proxy, name, NULL,
+							client->user_data);
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return TRUE;
+}
+
 static GDBusProxy *proxy_new(GDBusClient *client, const char *path,
 						const char *interface)
 {
@@ -373,14 +419,12 @@ static GDBusProxy *proxy_new(GDBusClient *client, const char *path,
 
 	proxy->prop_list = g_hash_table_new_full(g_str_hash, g_str_equal,
 							NULL, prop_entry_free);
-
-	proxy->match_rule = g_strdup_printf("type='signal',"
-				"sender='%s',path='%s',interface='%s',"
-				"member='PropertiesChanged',arg0='%s'",
-				client->service_name, proxy->obj_path,
-				DBUS_INTERFACE_PROPERTIES, proxy->interface);
-
-	modify_match(client->dbus_conn, "AddMatch", proxy->match_rule);
+	proxy->watch = g_dbus_add_properties_watch(client->dbus_conn,
+							client->service_name,
+							proxy->obj_path,
+							proxy->interface,
+							properties_changed,
+							proxy, NULL);
 
 	return g_dbus_proxy_ref(proxy);
 }
@@ -395,11 +439,7 @@ static void proxy_free(gpointer data)
 		if (client->proxy_removed)
 			client->proxy_removed(proxy, client->user_data);
 
-		modify_match(client->dbus_conn, "RemoveMatch",
-							proxy->match_rule);
-
-		g_free(proxy->match_rule);
-		proxy->match_rule = NULL;
+		g_dbus_remove_watch(client->dbus_conn, proxy->watch);
 
 		g_hash_table_remove_all(proxy->prop_list);
 
@@ -800,64 +840,6 @@ static void refresh_properties(GDBusClient *client)
         }
 }
 
-static void properties_changed(GDBusClient *client, const char *path,
-							DBusMessage *msg)
-{
-	GDBusProxy *proxy = NULL;
-	DBusMessageIter iter, entry;
-	const char *interface;
-	GList *list;
-
-	if (dbus_message_iter_init(msg, &iter) == FALSE)
-		return;
-
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-		return;
-
-	dbus_message_iter_get_basic(&iter, &interface);
-	dbus_message_iter_next(&iter);
-
-	for (list = g_list_first(client->proxy_list); list;
-						list = g_list_next(list)) {
-		GDBusProxy *data = list->data;
-
-		if (g_str_equal(data->interface, interface) == TRUE &&
-				g_str_equal(data->obj_path, path) == TRUE) {
-			proxy = data;
-			break;
-		}
-	}
-
-	if (proxy == NULL)
-		return;
-
-	update_properties(proxy, &iter, TRUE);
-
-	dbus_message_iter_next(&iter);
-
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
-		return;
-
-	dbus_message_iter_recurse(&iter, &entry);
-
-	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
-		const char *name;
-
-		dbus_message_iter_get_basic(&entry, &name);
-
-		g_hash_table_remove(proxy->prop_list, name);
-
-		if (proxy->prop_func)
-			proxy->prop_func(proxy, name, NULL, proxy->prop_data);
-
-		if (client->property_changed)
-			client->property_changed(proxy, name, NULL,
-							client->user_data);
-
-		dbus_message_iter_next(&entry);
-	}
-}
-
 static void parse_properties(GDBusClient *client, const char *path,
 				const char *interface, DBusMessageIter *iter)
 {
@@ -1095,7 +1077,7 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	GDBusClient *client = user_data;
-	const char *sender, *path, *interface, *member;
+	const char *sender, *path, *interface;
 
 	if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -1106,17 +1088,12 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 
 	path = dbus_message_get_path(message);
 	interface = dbus_message_get_interface(message);
-	member = dbus_message_get_member(message);
 
 	if (g_str_has_prefix(path, client->base_path) == FALSE)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-	if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE) {
-		if (g_str_equal(member, "PropertiesChanged") == TRUE)
-			properties_changed(client, path, message);
-
+	if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	}
 
 	if (client->signal_func)
 		client->signal_func(connection, message, client->signal_data);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH BlueZ 4/5] gdbus/client: Use g_dbus_add_signal_watch to track signals
From: Luiz Augusto von Dentz @ 2013-09-04 19:04 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1378321471-9043-1-git-send-email-luiz.dentz@gmail.com>

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

This make the handling much simpler and avoids duplicates of the same
match rule.
---
 gdbus/client.c | 73 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 37 insertions(+), 36 deletions(-)

diff --git a/gdbus/client.c b/gdbus/client.c
index 7a14d7e..f1e6946 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -25,6 +25,7 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
 #include <glib.h>
 #include <dbus/dbus.h>
 
@@ -32,12 +33,18 @@
 
 #define METHOD_CALL_TIMEOUT (300 * 1000)
 
+#ifndef DBUS_INTERFACE_OBJECT
+#define DBUS_INTERFACE_OBJECT_MANAGER DBUS_INTERFACE_DBUS ".ObjectManager"
+#endif
+
 struct GDBusClient {
 	int ref_count;
 	DBusConnection *dbus_conn;
 	char *service_name;
 	char *base_path;
 	guint watch;
+	guint added_watch;
+	guint removed_watch;
 	GPtrArray *match_rules;
 	DBusPendingCall *pending_call;
 	DBusPendingCall *get_objects_call;
@@ -908,16 +915,18 @@ static void parse_interfaces(GDBusClient *client, const char *path,
 	}
 }
 
-static void interfaces_added(GDBusClient *client, DBusMessage *msg)
+static gboolean interfaces_added(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
 {
+	GDBusClient *client = user_data;
 	DBusMessageIter iter;
 	const char *path;
 
 	if (dbus_message_iter_init(msg, &iter) == FALSE)
-		return;
+		return TRUE;
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
-		return;
+		return TRUE;
 
 	dbus_message_iter_get_basic(&iter, &path);
 	dbus_message_iter_next(&iter);
@@ -927,24 +936,28 @@ static void interfaces_added(GDBusClient *client, DBusMessage *msg)
 	parse_interfaces(client, path, &iter);
 
 	g_dbus_client_unref(client);
+
+	return TRUE;
 }
 
-static void interfaces_removed(GDBusClient *client, DBusMessage *msg)
+static gboolean interfaces_removed(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
 {
+	GDBusClient *client = user_data;
 	DBusMessageIter iter, entry;
 	const char *path;
 
 	if (dbus_message_iter_init(msg, &iter) == FALSE)
-		return;
+		return TRUE;
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
-		return;
+		return TRUE;
 
 	dbus_message_iter_get_basic(&iter, &path);
 	dbus_message_iter_next(&iter);
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
-		return;
+		return TRUE;
 
 	dbus_message_iter_recurse(&iter, &entry);
 
@@ -959,6 +972,8 @@ static void interfaces_removed(GDBusClient *client, DBusMessage *msg)
 	}
 
 	g_dbus_client_unref(client);
+
+	return TRUE;
 }
 
 static void parse_managed_objects(GDBusClient *client, DBusMessage *msg)
@@ -1093,24 +1108,6 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 	interface = dbus_message_get_interface(message);
 	member = dbus_message_get_member(message);
 
-	if (g_str_equal(path, "/") == TRUE) {
-		if (g_str_equal(interface, DBUS_INTERFACE_DBUS
-						".ObjectManager") == FALSE)
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-		if (g_str_equal(member, "InterfacesAdded") == TRUE) {
-			interfaces_added(client, message);
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-		}
-
-		if (g_str_equal(member, "InterfacesRemoved") == TRUE) {
-			interfaces_removed(client, message);
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-		}
-
-		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	}
-
 	if (g_str_has_prefix(path, client->base_path) == FALSE)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
@@ -1150,23 +1147,25 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
 	client->service_name = g_strdup(service);
 	client->base_path = g_strdup(path);
 
-	client->match_rules = g_ptr_array_sized_new(3);
+	client->match_rules = g_ptr_array_sized_new(1);
 	g_ptr_array_set_free_func(client->match_rules, g_free);
 
 	client->watch = g_dbus_add_service_watch(connection, service,
 						service_connect,
 						service_disconnect,
 						client, NULL);
-	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
-				"sender='%s',"
-				"path='/',interface='%s.ObjectManager',"
-				"member='InterfacesAdded'",
-				client->service_name, DBUS_INTERFACE_DBUS));
-	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
-				"sender='%s',"
-				"path='/',interface='%s.ObjectManager',"
-				"member='InterfacesRemoved'",
-				client->service_name, DBUS_INTERFACE_DBUS));
+	client->added_watch = g_dbus_add_signal_watch(connection, service,
+						"/",
+						DBUS_INTERFACE_OBJECT_MANAGER,
+						"InterfacesAdded",
+						interfaces_added,
+						client, NULL);
+	client->removed_watch = g_dbus_add_signal_watch(connection, service,
+						"/",
+						DBUS_INTERFACE_OBJECT_MANAGER,
+						"InterfacesRemoved",
+						interfaces_removed,
+						client, NULL);
 	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
 				"sender='%s',path_namespace='%s'",
 				client->service_name, client->base_path));
@@ -1225,6 +1224,8 @@ void g_dbus_client_unref(GDBusClient *client)
 		client->disconn_func(client->dbus_conn, client->disconn_data);
 
 	g_dbus_remove_watch(client->dbus_conn, client->watch);
+	g_dbus_remove_watch(client->dbus_conn, client->added_watch);
+	g_dbus_remove_watch(client->dbus_conn, client->removed_watch);
 
 	dbus_connection_unref(client->dbus_conn);
 
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH BlueZ 3/5] gdbus/client: Use g_dbus_add_service_watch to track services
From: Luiz Augusto von Dentz @ 2013-09-04 19:04 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1378321471-9043-1-git-send-email-luiz.dentz@gmail.com>

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

This make the handling much simpler and avoids duplicates of the same
match rule.
---
 gdbus/client.c | 173 +++++++++++++--------------------------------------------
 1 file changed, 38 insertions(+), 135 deletions(-)

diff --git a/gdbus/client.c b/gdbus/client.c
index 8ebfaad..7a14d7e 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -36,8 +36,8 @@ struct GDBusClient {
 	int ref_count;
 	DBusConnection *dbus_conn;
 	char *service_name;
-	char *unique_name;
 	char *base_path;
+	guint watch;
 	GPtrArray *match_rules;
 	DBusPendingCall *pending_call;
 	DBusPendingCall *get_objects_call;
@@ -1051,74 +1051,36 @@ static void get_managed_objects(GDBusClient *client)
 	dbus_message_unref(msg);
 }
 
-static void get_name_owner_reply(DBusPendingCall *call, void *user_data)
+static void service_connect(DBusConnection *conn, void *user_data)
 {
 	GDBusClient *client = user_data;
-	DBusMessage *reply = dbus_pending_call_steal_reply(call);
-	DBusError error;
-	const char *name;
 
 	g_dbus_client_ref(client);
 
-	dbus_error_init(&error);
-
-	if (dbus_set_error_from_message(&error, reply) == TRUE) {
-		dbus_error_free(&error);
-		goto done;
-	}
-
-	if (dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &name,
-						DBUS_TYPE_INVALID) == FALSE)
-		goto done;
-
-	if (client->unique_name == NULL) {
-		client->unique_name = g_strdup(name);
-
-		if (client->connect_func)
-			client->connect_func(client->dbus_conn,
-							client->connect_data);
-
-		get_managed_objects(client);
-	}
-
-done:
-	dbus_message_unref(reply);
+	if (client->connect_func)
+		client->connect_func(conn, client->connect_data);
 
-	dbus_pending_call_unref(client->pending_call);
-	client->pending_call = NULL;
+	get_managed_objects(client);
 
 	g_dbus_client_unref(client);
 }
 
-static void get_name_owner(GDBusClient *client, const char *name)
+static void service_disconnect(DBusConnection *conn, void *user_data)
 {
-	DBusMessage *msg;
-
-	msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
-					DBUS_INTERFACE_DBUS, "GetNameOwner");
-	if (msg == NULL)
-		return;
-
-	dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
-						DBUS_TYPE_INVALID);
-
-	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
-					&client->pending_call, -1) == FALSE) {
-		dbus_message_unref(msg);
-		return;
-	}
+	GDBusClient *client = user_data;
 
-	dbus_pending_call_set_notify(client->pending_call,
-					get_name_owner_reply, client, NULL);
+	g_list_free_full(client->proxy_list, proxy_free);
+	client->proxy_list = NULL;
 
-	dbus_message_unref(msg);
+	if (client->disconn_func)
+		client->disconn_func(conn, client->disconn_data);
 }
 
 static DBusHandlerResult message_filter(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	GDBusClient *client = user_data;
-	const char *sender;
+	const char *sender, *path, *interface, *member;
 
 	if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -1127,98 +1089,41 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 	if (sender == NULL)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-	if (g_str_equal(sender, DBUS_SERVICE_DBUS) == TRUE) {
-		const char *interface, *member;
-		const char *name, *old, *new;
+	path = dbus_message_get_path(message);
+	interface = dbus_message_get_interface(message);
+	member = dbus_message_get_member(message);
 
-		interface = dbus_message_get_interface(message);
-
-		if (g_str_equal(interface, DBUS_INTERFACE_DBUS) == FALSE)
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-		member = dbus_message_get_member(message);
-
-		if (g_str_equal(member, "NameOwnerChanged") == FALSE)
+	if (g_str_equal(path, "/") == TRUE) {
+		if (g_str_equal(interface, DBUS_INTERFACE_DBUS
+						".ObjectManager") == FALSE)
 			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-		if (dbus_message_get_args(message, NULL,
-						DBUS_TYPE_STRING, &name,
-						DBUS_TYPE_STRING, &old,
-						DBUS_TYPE_STRING, &new,
-						DBUS_TYPE_INVALID) == FALSE)
+		if (g_str_equal(member, "InterfacesAdded") == TRUE) {
+			interfaces_added(client, message);
 			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+		}
 
-		if (g_str_equal(name, client->service_name) == FALSE)
+		if (g_str_equal(member, "InterfacesRemoved") == TRUE) {
+			interfaces_removed(client, message);
 			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-		if (*new == '\0' && client->unique_name != NULL &&
-				g_str_equal(old, client->unique_name) == TRUE) {
-
-			g_list_free_full(client->proxy_list, proxy_free);
-			client->proxy_list = NULL;
-
-			if (client->disconn_func)
-				client->disconn_func(client->dbus_conn,
-							client->disconn_data);
-
-			g_free(client->unique_name);
-			client->unique_name = NULL;
-		} else if (*old == '\0' && client->unique_name == NULL) {
-			client->unique_name = g_strdup(new);
-
-			if (client->connect_func)
-				client->connect_func(client->dbus_conn,
-							client->connect_data);
-
-			get_managed_objects(client);
 		}
 
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
 
-	if (client->unique_name == NULL)
+	if (g_str_has_prefix(path, client->base_path) == FALSE)
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-	if (g_str_equal(sender, client->unique_name) == TRUE) {
-		const char *path, *interface, *member;
-
-		path = dbus_message_get_path(message);
-		interface = dbus_message_get_interface(message);
-		member = dbus_message_get_member(message);
-
-		if (g_str_equal(path, "/") == TRUE) {
-			if (g_str_equal(interface, DBUS_INTERFACE_DBUS
-						".ObjectManager") == FALSE)
-				return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-			if (g_str_equal(member, "InterfacesAdded") == TRUE) {
-				interfaces_added(client, message);
-				return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-			}
-
-			if (g_str_equal(member, "InterfacesRemoved") == TRUE) {
-				interfaces_removed(client, message);
-				return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-			}
+	if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE) {
+		if (g_str_equal(member, "PropertiesChanged") == TRUE)
+			properties_changed(client, path, message);
 
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-		}
-
-		if (g_str_has_prefix(path, client->base_path) == FALSE)
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-		if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE) {
-			if (g_str_equal(member, "PropertiesChanged") == TRUE)
-				properties_changed(client, path, message);
-
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-		}
-
-		if (client->signal_func)
-			client->signal_func(client->dbus_conn,
-					message, client->signal_data);
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
 
+	if (client->signal_func)
+		client->signal_func(connection, message, client->signal_data);
+
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
@@ -1245,16 +1150,13 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
 	client->service_name = g_strdup(service);
 	client->base_path = g_strdup(path);
 
-	get_name_owner(client, client->service_name);
-
-	client->match_rules = g_ptr_array_sized_new(4);
+	client->match_rules = g_ptr_array_sized_new(3);
 	g_ptr_array_set_free_func(client->match_rules, g_free);
 
-	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
-				"sender='%s',path='%s',interface='%s',"
-				"member='NameOwnerChanged',arg0='%s'",
-				DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
-				DBUS_INTERFACE_DBUS, client->service_name));
+	client->watch = g_dbus_add_service_watch(connection, service,
+						service_connect,
+						service_disconnect,
+						client, NULL);
 	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
 				"sender='%s',"
 				"path='/',interface='%s.ObjectManager',"
@@ -1322,10 +1224,11 @@ void g_dbus_client_unref(GDBusClient *client)
 	if (client->disconn_func)
 		client->disconn_func(client->dbus_conn, client->disconn_data);
 
+	g_dbus_remove_watch(client->dbus_conn, client->watch);
+
 	dbus_connection_unref(client->dbus_conn);
 
 	g_free(client->service_name);
-	g_free(client->unique_name);
 	g_free(client->base_path);
 
 	g_free(client);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH BlueZ 2/5] gdbus/watch: Fix aborting when removing D-Bus filter
From: Luiz Augusto von Dentz @ 2013-09-04 19:04 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1378321471-9043-1-git-send-email-luiz.dentz@gmail.com>

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

In case of filter_data having a watch to a service name it may call
dbus_connection_remove_filter twice causing libdbus to abort:

process 24723: Attempt to remove filter function 0x4063e0 user data (nil), but no such filter has been added

To fix this the code will now only attempt to call
dbus_connection_remove_filter once in filter_data_free which is the
counterpart of filter_data_get where dbus_connection_add_filter is called.
---
 gdbus/watch.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index d334580..a918535 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -281,6 +281,11 @@ static void filter_data_free(struct filter_data *data)
 {
 	GSList *l;
 
+	/* Remove filter if there are no listeners left for the connection */
+	if (filter_data_find(data->connection) == NULL)
+		dbus_connection_remove_filter(data->connection, message_filter,
+									NULL);
+
 	for (l = data->callbacks; l != NULL; l = l->next)
 		g_free(l->data);
 
@@ -360,8 +365,6 @@ static void service_data_free(struct service_data *data)
 static gboolean filter_data_remove_callback(struct filter_data *data,
 						struct filter_callback *cb)
 {
-	DBusConnection *connection;
-
 	data->callbacks = g_slist_remove(data->callbacks, cb);
 	data->processed = g_slist_remove(data->processed, cb);
 
@@ -385,16 +388,8 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
 	if (data->registered && !remove_match(data))
 		return FALSE;
 
-	connection = dbus_connection_ref(data->connection);
 	listeners = g_slist_remove(listeners, data);
-
-	/* Remove filter if there are no listeners left for the connection */
-	if (filter_data_find(connection) == NULL)
-		dbus_connection_remove_filter(connection, message_filter,
-						NULL);
-
 	filter_data_free(data);
-	dbus_connection_unref(connection);
 
 	return TRUE;
 }
@@ -563,6 +558,9 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 								current);
 	}
 
+	if (delete_listener == NULL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
 	for (current = delete_listener; current != NULL;
 					current = delete_listener->next) {
 		GSList *l = current->data;
@@ -581,11 +579,6 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
 
 	g_slist_free(delete_listener);
 
-	/* Remove filter if there are no listeners left for the connection */
-	if (filter_data_find(connection) == NULL)
-		dbus_connection_remove_filter(connection, message_filter,
-						NULL);
-
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
@@ -814,6 +807,4 @@ void g_dbus_remove_all_watches(DBusConnection *connection)
 		listeners = g_slist_remove(listeners, data);
 		filter_data_call_and_free(data);
 	}
-
-	dbus_connection_remove_filter(connection, message_filter, NULL);
 }
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH BlueZ 1/5] gdbus/watch: Fix crash when g_dbus_remove_watch is called from connect callback
From: Luiz Augusto von Dentz @ 2013-09-04 19:04 UTC (permalink / raw)
  To: linux-bluetooth

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

 at 0x40570C: update_service (watch.c:601)
 by 0x40584B: service_reply (watch.c:627)
 by 0x3B0700C511: ??? (in /usr/lib64/libdbus-1.so.3.7.4)
 by 0x3B0700F740: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.4)
 by 0x405167: message_dispatch (mainloop.c:76)
 by 0x3B03C48962: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
 by 0x3B03C47E05: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3600.3)
 by 0x3B03C48157: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
 by 0x3B03C48559: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3600.3)
Address 0x4c58a30 is 32 bytes inside a block of size 56 free'd
 at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
 by 0x3B03C4D9AE: g_free (in /usr/lib64/libglib-2.0.so.0.3600.3)
 by 0x406102: filter_data_remove_callback (watch.c:378)
 by 0x405FC0: g_dbus_remove_watch (watch.c:798)
 by 0x40A22B: g_dbus_client_unref (client.c:1227)
 by 0x40570B: update_service (watch.c:599)
 by 0x40584B: service_reply (watch.c:627)
---
 gdbus/watch.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index 9e4f994..d334580 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -593,12 +593,16 @@ static gboolean update_service(void *user_data)
 {
 	struct service_data *data = user_data;
 	struct filter_callback *cb = data->callback;
+	DBusConnection *conn;
 
 	update_name_cache(data->name, data->owner);
+	conn = dbus_connection_ref(data->conn);
+	service_data_free(cb->data);
+
 	if (cb->conn_func)
-		cb->conn_func(data->conn, cb->user_data);
+		cb->conn_func(conn, cb->user_data);
 
-	service_data_free(data);
+	dbus_connection_unref(conn);
 
 	return FALSE;
 }
-- 
1.8.3.1


^ permalink raw reply related

* Re: Bluetooth regression in 3.10
From: Michael Büsch @ 2013-09-04 16:14 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: johan.hedberg, linux-bluetooth
In-Reply-To: <F0FC77C9-DCEF-48B8-8ABF-12446908AAC4@holtmann.org>

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

On Wed, 4 Sep 2013 08:40:00 -0700
Marcel Holtmann <marcel@holtmann.org> wrote:

> > This is a Broadcom chip based device.
> 
> that device is CSR based and not Broadcom based. Check with hciconfig hci0 version to see what it really is.

I'm pretty sure there is a Broadcom chip in there, because I opened it once.

> Check with hciconfig hci0 version to see what it really is.

$ hciconfig hci0 version | grep Manu
        Manufacturer: Broadcom Corporation (15)

> Can you toy with hcitool cmd to send the HCI_Delete_Stored_Link_Key commands and see what parameters it would accept to delete all keys.

Can you give me a few hints and examples?

-- 
Michael

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: Bluetooth regression in 3.10
From: Marcel Holtmann @ 2013-09-04 15:40 UTC (permalink / raw)
  To: Michael Büsch; +Cc: johan.hedberg, linux-bluetooth
In-Reply-To: <20130904155318.21cb6f37@milhouse>

Hi Michael,

> I noticed the thread "3.10-rc: bluetooth disappeared on thinkpad x60 (regression)"
> on lkml, but unfortunately the resulting patch does not fix the regression
> for me.
> I'm running 3.10.10, so the fix from the thread is applied to my kernel.
> 
> I see similar issues when trying to bring up my Bluetooth dongle:
> 
> $ lsusb | grep Blue
> Bus 004 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
> 
> This is a Broadcom chip based device.

that device is CSR based and not Broadcom based. Check with hciconfig hci0 version to see what it really is.
> 
> $ hciconfig hci0 up                                            
> Can't init device hci0: Operation not supported (95)
> 
> hcidump hci0 -X shows:
> 
> < HCI Command: Delete Stored Link Key (0x03|0x0012) plen 7
>    bdaddr 00:00:00:00:00:00 all 1
>> HCI Event: Command Complete (0x0e) plen 4
>    Delete Stored Link Key (0x03|0x0012) ncmd 1
>    status 0x11 deleted 0
>    Error: Unsupported Feature or Parameter Value
> device: disconnected

And hciconfig hci0 commands tells you that this command is actually supported.

> The following workaround fixes the problem for me:
> 
> Index: linux/net/bluetooth/hci_core.c
> ===================================================================
> --- linux.orig/net/bluetooth/hci_core.c	2013-07-21 17:34:22.749435335 +0200
> +++ linux/net/bluetooth/hci_core.c	2013-09-04 15:39:07.580170034 +0200
> @@ -598,7 +598,7 @@
> 	u8 p;
> 
> 	/* Only send HCI_Delete_Stored_Link_Key if it is supported */
> -	if (hdev->commands[6] & 0x80) {
> +	if (0) {
> 		struct hci_cp_delete_stored_link_key cp;
> 
> 		bacpy(&cp.bdaddr, BDADDR_ANY);

Can you toy with hcitool cmd to send the HCI_Delete_Stored_Link_Key commands and see what parameters it would accept to delete all keys.

Regards

Marcel


^ permalink raw reply

* Bluetooth regression in 3.10
From: Michael Büsch @ 2013-09-04 13:53 UTC (permalink / raw)
  To: johan.hedberg; +Cc: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 1571 bytes --]

Hi Johan,

I noticed the thread "3.10-rc: bluetooth disappeared on thinkpad x60 (regression)"
on lkml, but unfortunately the resulting patch does not fix the regression
for me.
I'm running 3.10.10, so the fix from the thread is applied to my kernel.

I see similar issues when trying to bring up my Bluetooth dongle:

$ lsusb | grep Blue
Bus 004 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

This is a Broadcom chip based device.

$ hciconfig hci0 up                                            
Can't init device hci0: Operation not supported (95)

hcidump hci0 -X shows:

< HCI Command: Delete Stored Link Key (0x03|0x0012) plen 7
    bdaddr 00:00:00:00:00:00 all 1
> HCI Event: Command Complete (0x0e) plen 4
    Delete Stored Link Key (0x03|0x0012) ncmd 1
    status 0x11 deleted 0
    Error: Unsupported Feature or Parameter Value
device: disconnected


The following workaround fixes the problem for me:

Index: linux/net/bluetooth/hci_core.c
===================================================================
--- linux.orig/net/bluetooth/hci_core.c	2013-07-21 17:34:22.749435335 +0200
+++ linux/net/bluetooth/hci_core.c	2013-09-04 15:39:07.580170034 +0200
@@ -598,7 +598,7 @@
 	u8 p;
 
 	/* Only send HCI_Delete_Stored_Link_Key if it is supported */
-	if (hdev->commands[6] & 0x80) {
+	if (0) {
 		struct hci_cp_delete_stored_link_key cp;
 
 		bacpy(&cp.bdaddr, BDADDR_ANY);


This isn't a real solution, of course.
I would be happy to test alternative solutions.

-- 
Michael

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* Re: [BUG bluetoothd] reconnecting input devices results in org.bluez.Error.NotAvailable
From: David Herrmann @ 2013-09-04 13:25 UTC (permalink / raw)
  To: David Herrmann, linux-bluetooth@vger.kernel.org, Johan Hedberg
In-Reply-To: <20130904130832.GA23776@x220.p-661hnu-f1>

Hi

On Wed, Sep 4, 2013 at 3:08 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi David,
>
> On Wed, Sep 04, 2013, David Herrmann wrote:
>> I run the following commands in bluetoothctl on bluez-5.7-1 (but I
>> know this bug since I started using bluetoothctl (probably 5.0 or
>> 5.1), just didn't get around reporting it, yet. Sorry.):
>>   [bluetooth]# power on
>>     [CHG] Controller 00:25:00:50:C4:C9 Class: 0x00010c
>>     Changing power on succeeded
>>     [CHG] Controller 00:25:00:50:C4:C9 Powered: yes
>>   [bluetooth]# connect 00:1E:35:3B:7E:6D
>>     Attempting to connect to 00:1E:35:3B:7E:6D
>>     Connection successful
>>     [CHG] Device 00:1E:35:3B:7E:6D Connected: yes
>>
>> Works just fine. Then I disconnect the device by removing its
>> batteries. bluez notices this and removes the connection:
>>     [CHG] Device 00:1E:35:3B:7E:6D Connected: no
>>
>> However, a following connect always fails immediately:
>>   [bluetooth]# connect 00:1E:35:3B:7E:6D
>>     Attempting to connect to 00:1E:35:3B:7E:6D
>>     Failed to connect: org.bluez.Error.NotAvailable
>>
>> Any following commands, whether "connect" or "info" on the given
>> device result in:
>>   [bluetooth]# info  00:1E:35:3B:7E:6D
>>     Device  00:1E:35:3B:7E:6D not available
>>
>> power off -> power on doesn't help. I need to restart bluetoothd to
>> make it work again. The related debug log is appended below. Any hints
>> where to start debugging is welcome.
>>
>> I tested this with two HIDP devices.
>
> I fixed a few issues like this for 5.8. Could you try with that (or even
> better with latest git) before we proceed further with this.

Hm, I finally got up reporting this issue and then you fix it few days
earlier. Ahh... Sorry for not testing -git before. I thought it was
broken for several releases, so I didn't have to.

Just for the reference: fixed with bluez-git
Didn't do any bisect, though. Might be even fixed with 5.8.

Sorry for the noise, Thanks
David

^ permalink raw reply

* Re: [BUG bluetoothd] reconnecting input devices results in org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2013-09-04 13:08 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CANq1E4ThsLwpWKs2VR+2DT41cDfV+_XX+DdLDF7Yo+Sm+t1ryw@mail.gmail.com>

Hi David,

On Wed, Sep 04, 2013, David Herrmann wrote:
> I run the following commands in bluetoothctl on bluez-5.7-1 (but I
> know this bug since I started using bluetoothctl (probably 5.0 or
> 5.1), just didn't get around reporting it, yet. Sorry.):
>   [bluetooth]# power on
>     [CHG] Controller 00:25:00:50:C4:C9 Class: 0x00010c
>     Changing power on succeeded
>     [CHG] Controller 00:25:00:50:C4:C9 Powered: yes
>   [bluetooth]# connect 00:1E:35:3B:7E:6D
>     Attempting to connect to 00:1E:35:3B:7E:6D
>     Connection successful
>     [CHG] Device 00:1E:35:3B:7E:6D Connected: yes
> 
> Works just fine. Then I disconnect the device by removing its
> batteries. bluez notices this and removes the connection:
>     [CHG] Device 00:1E:35:3B:7E:6D Connected: no
> 
> However, a following connect always fails immediately:
>   [bluetooth]# connect 00:1E:35:3B:7E:6D
>     Attempting to connect to 00:1E:35:3B:7E:6D
>     Failed to connect: org.bluez.Error.NotAvailable
> 
> Any following commands, whether "connect" or "info" on the given
> device result in:
>   [bluetooth]# info  00:1E:35:3B:7E:6D
>     Device  00:1E:35:3B:7E:6D not available
> 
> power off -> power on doesn't help. I need to restart bluetoothd to
> make it work again. The related debug log is appended below. Any hints
> where to start debugging is welcome.
> 
> I tested this with two HIDP devices.

I fixed a few issues like this for 5.8. Could you try with that (or even
better with latest git) before we proceed further with this.

Johan

^ permalink raw reply

* [BUG bluetoothd] reconnecting input devices results in org.bluez.Error.NotAvailable
From: David Herrmann @ 2013-09-04 11:55 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi

I run the following commands in bluetoothctl on bluez-5.7-1 (but I
know this bug since I started using bluetoothctl (probably 5.0 or
5.1), just didn't get around reporting it, yet. Sorry.):
  [bluetooth]# power on
    [CHG] Controller 00:25:00:50:C4:C9 Class: 0x00010c
    Changing power on succeeded
    [CHG] Controller 00:25:00:50:C4:C9 Powered: yes
  [bluetooth]# connect 00:1E:35:3B:7E:6D
    Attempting to connect to 00:1E:35:3B:7E:6D
    Connection successful
    [CHG] Device 00:1E:35:3B:7E:6D Connected: yes

Works just fine. Then I disconnect the device by removing its
batteries. bluez notices this and removes the connection:
    [CHG] Device 00:1E:35:3B:7E:6D Connected: no

However, a following connect always fails immediately:
  [bluetooth]# connect 00:1E:35:3B:7E:6D
    Attempting to connect to 00:1E:35:3B:7E:6D
    Failed to connect: org.bluez.Error.NotAvailable

Any following commands, whether "connect" or "info" on the given
device result in:
  [bluetooth]# info  00:1E:35:3B:7E:6D
    Device  00:1E:35:3B:7E:6D not available

power off -> power on doesn't help. I need to restart bluetoothd to
make it work again. The related debug log is appended below. Any hints
where to start debugging is welcome.

I tested this with two HIDP devices.

Thanks
David

log starts with "power on" in bluetoothctl:

Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:property_set_mode() sending Set Powered command for
index 0
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:dev_class_changed_callback() Class: 0x00010c
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/attrib-server.c:attrib_db_update() handle=0x0008
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:property_set_mode_complete() Success (0x00)
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:new_settings_callback() Settings: 0x000000d3
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:settings_changed() Changed settings: 0x00000001
Sep 04 13:39:03 david-mb bluetoothd[16799]:
src/adapter.c:adapter_start() adapter /org/bluez/hci0 has been enabled
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/device.c:connect_profiles() /org/bluez/hci0/dev_00_1E_35_3B_7E_6D
(all), client :1.13
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/service.c:change_state() 0x93fde0: device 00:1E:35:3B:7E:6D
profile input-hid state changed: disconnected -> connecting (0)
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/adapter.c:connected_callback() hci0 device 00:1E:35:3B:7E:6D
connected eir_len 21
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/service.c:change_state() 0x93fde0: device 00:1E:35:3B:7E:6D
profile input-hid state changed: connecting -> connected (0)
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/device.c:device_profile_connected() input-hid Success (0)
Sep 04 13:39:21 david-mb bluetoothd[16799]:
src/device.c:device_profile_connected() returning response to :1.13

[...kernel HID messages for the device...]

Sep 04 13:39:48 david-mb bluetoothd[16799]:
profiles/input/device.c:ctrl_watch_cb() Device 00:1E:35:3B:7E:6D
disconnected
Sep 04 13:39:48 david-mb bluetoothd[16799]:
profiles/input/device.c:intr_watch_cb() Device 00:1E:35:3B:7E:6D
disconnected
Sep 04 13:39:48 david-mb bluetoothd[16799]:
profiles/input/device.c:input_device_enter_reconnect_mode()
path=/org/bluez/hci0/dev_00_1E_35_3B_7E_6D reconnect_mode=device
Sep 04 13:39:48 david-mb bluetoothd[16799]:
src/adapter.c:dev_disconnected() Device 00:1E:35:3B:7E:6D
disconnected, reason 2
Sep 04 13:39:48 david-mb bluetoothd[16799]:
src/adapter.c:adapter_remove_connection()
Sep 04 13:39:48 david-mb bluetoothd[16799]:
src/adapter.c:bonding_attempt_complete() hci0 bdaddr 00:1E:35:3B:7E:6D
type 0 status 0xe
Sep 04 13:39:48 david-mb bluetoothd[16799]:
src/device.c:device_bonding_complete() bonding (nil) status 0x0e
Sep 04 13:39:48 david-mb bluetoothd[16799]:
src/device.c:device_bonding_failed() status 14
Sep 04 13:39:48 david-mb bluetoothd[16799]: src/adapter.c:resume_discovery()

[any further commands like "connect" result in:]

Sep 04 13:42:06 david-mb bluetoothd[16799]:
src/device.c:connect_profiles() /org/bluez/hci0/dev_00_1E_35_3B_7E_6D
(all), client :1.13

^ permalink raw reply

* [PATCH] Bluetooth: Use GFP_KERNEL when cloning SKB in a workqueue
From: Marcel Holtmann @ 2013-09-04  1:11 UTC (permalink / raw)
  To: linux-bluetooth

There is no need to use GFP_ATOMIC with skb_clone() when the code is
executed in a workqueue.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1b86c78..4dbb6cb 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3537,7 +3537,7 @@ static void hci_cmd_work(struct work_struct *work)
 
 		kfree_skb(hdev->sent_cmd);
 
-		hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC);
+		hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
 		if (hdev->sent_cmd) {
 			atomic_dec(&hdev->cmd_cnt);
 			hci_send_frame(skb);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH 2/2] Bluetooth: Only schedule raw queue when user channel is active
From: Marcel Holtmann @ 2013-09-04  1:08 UTC (permalink / raw)
  To: linux-bluetooth

When the user channel is set and an user application has full control
over the device, do not bother trying to schedule any queues except
the raw queue.

This is an optimization since with user channel, only the raw queue
is in use.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 541f4d5..1b86c78 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3292,15 +3292,13 @@ static void hci_tx_work(struct work_struct *work)
 	BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt,
 	       hdev->sco_cnt, hdev->le_cnt);
 
-	/* Schedule queues and send stuff to HCI driver */
-
-	hci_sched_acl(hdev);
-
-	hci_sched_sco(hdev);
-
-	hci_sched_esco(hdev);
-
-	hci_sched_le(hdev);
+	if (!test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
+		/* Schedule queues and send stuff to HCI driver */
+		hci_sched_acl(hdev);
+		hci_sched_sco(hdev);
+		hci_sched_esco(hdev);
+		hci_sched_le(hdev);
+	}
 
 	/* Send next queued raw (unknown type) packet */
 	while ((skb = skb_dequeue(&hdev->raw_q)))
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Disable upper layer connections when user channel is active
From: Marcel Holtmann @ 2013-09-04  1:08 UTC (permalink / raw)
  To: linux-bluetooth

When the device has the user channel flag set, it means it is driven by
an user application. In that case do not allow any connections from
L2CAP or SCO sockets.

This is the same situation as when the device has the raw flag set and
it will then return EHOSTUNREACH.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_conn.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index f081712..d2380e0 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -518,6 +518,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
 	list_for_each_entry(d, &hci_dev_list, list) {
 		if (!test_bit(HCI_UP, &d->flags) ||
 		    test_bit(HCI_RAW, &d->flags) ||
+		    test_bit(HCI_USER_CHANNEL, &d->dev_flags) ||
 		    d->dev_type != HCI_BREDR)
 			continue;
 
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH bluetooth-next] Bluetooth: Add support for BCM20702A0 [0a5c, 21e6]
From: Dan Aloni @ 2013-09-03 11:42 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: linux-bluetooth, linux-kernel, Gustavo Padovan, Johan Hedberg

Tested with this patch and a Bluetooth mouse on 3.10.10, on ThinkPad W530.

Bus 001 Device 004: ID 0a5c:21e6 Broadcom Corp. BCM20702 Bluetooth 4.0 [ThinkPad]

T:  Bus=01 Lev=02 Prnt=02 Port=03 Cnt=02 Dev#=  4 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=ff(vend.) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=0a5c ProdID=21e6 Rev=01.12
S:  Manufacturer=Broadcom Corp
S:  Product=BCM20702A0
S:  SerialNumber=F4B7E2F6E438
C:  #Ifs= 4 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
I:  If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
I:  If#= 2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
I:  If#= 3 Alt= 0 #EPs= 0 Cls=fe(app. ) Sub=01 Prot=01 Driver=(none)

Signed-off-by: Dan Aloni <alonid@postram.com>
---
 drivers/bluetooth/btusb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index de4cf4d..e6313f8 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -104,6 +104,7 @@ static struct usb_device_id btusb_table[] = {
 	{ USB_DEVICE(0x0b05, 0x17b5) },
 	{ USB_DEVICE(0x04ca, 0x2003) },
 	{ USB_DEVICE(0x0489, 0xe042) },
+	{ USB_DEVICE(0x0a5c, 0x21e6) },
 	{ USB_DEVICE(0x413c, 0x8197) },
 
 	/* Foxconn - Hon Hai */
-- 
1.8.1.4

^ 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