All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] bluetooth: use lower case for UUIDs
@ 2011-07-01  7:12 Luiz Augusto von Dentz
  2011-07-01  7:12 ` [PATCH 2/3] bluetooth: make uuid profile detection more generic Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-07-01  7:12 UTC (permalink / raw)
  To: ofono

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

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

BlueZ also uses lower case
---
 plugins/bluetooth.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 505d908..318e4b0 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -27,7 +27,7 @@
 
 #define DBUS_TIMEOUT 15
 
-#define HFP_AG_UUID	"0000111F-0000-1000-8000-00805F9B34FB"
+#define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 
 /* Profiles bitfield */
 #define HFP_AG 0x01
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] bluetooth: make uuid profile detection more generic
  2011-07-01  7:12 [PATCH 1/3] bluetooth: use lower case for UUIDs Luiz Augusto von Dentz
@ 2011-07-01  7:12 ` Luiz Augusto von Dentz
  2011-07-01  8:14   ` Denis Kenzior
  2011-07-01  7:12 ` [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed Luiz Augusto von Dentz
  2011-07-01  8:13 ` [PATCH 1/3] bluetooth: use lower case for UUIDs Denis Kenzior
  2 siblings, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-07-01  7:12 UTC (permalink / raw)
  To: ofono

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

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

---
 plugins/bluetooth.c |   31 ++++++++++++++++++-------------
 plugins/bluetooth.h |    4 +---
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index f9bc0b5..7e0705f 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -226,9 +226,9 @@ done:
 	g_slist_free(prop_handlers);
 }
 
-static void has_uuid(DBusMessageIter *array, gpointer user_data)
+static void parse_uuids(DBusMessageIter *array, gpointer user_data)
 {
-	gboolean *profiles = user_data;
+	GSList **uuids = user_data;
 	DBusMessageIter value;
 
 	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
@@ -241,8 +241,7 @@ static void has_uuid(DBusMessageIter *array, gpointer user_data)
 
 		dbus_message_iter_get_basic(&value, &uuid);
 
-		if (!strcasecmp(uuid, HFP_AG_UUID))
-			*profiles |= HFP_AG;
+		*uuids = g_slist_prepend(*uuids, (char *) uuid);
 
 		dbus_message_iter_next(&value);
 	}
@@ -262,14 +261,13 @@ static void parse_string(DBusMessageIter *iter, gpointer user_data)
 static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusMessage *reply;
-	int have_uuid = 0;
 	const char *path = user_data;
 	const char *adapter = NULL;
 	const char *adapter_addr = NULL;
 	const char *device_addr = NULL;
 	const char *alias = NULL;
-	struct bluetooth_profile *profile;
 	struct DBusError derr;
+	GSList *uuids = NULL;
 
 	reply = dbus_pending_call_steal_reply(call);
 
@@ -284,7 +282,7 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 
 	DBG("");
 
-	bluetooth_parse_properties(reply, "UUIDs", has_uuid, &have_uuid,
+	bluetooth_parse_properties(reply, "UUIDs", parse_uuids, &uuids,
 				"Adapter", parse_string, &adapter,
 				"Address", parse_string, &device_addr,
 				"Alias", parse_string, &alias, NULL);
@@ -293,15 +291,22 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 		adapter_addr = g_hash_table_lookup(adapter_address_hash,
 							adapter);
 
-	if ((have_uuid & HFP_AG) && device_addr && adapter_addr) {
-		profile = g_hash_table_lookup(uuid_hash, HFP_AG_UUID);
+	if (!device_addr && !adapter_addr)
+		goto done;
+
+	for (; uuids; uuids = uuids->next) {
+		struct bluetooth_profile *profile;
+		const char *uuid = uuids->data;
+
+		profile = g_hash_table_lookup(uuid_hash, uuid);
 		if (profile == NULL || profile->create == NULL)
-			goto done;
+			continue;
 
 		profile->create(path, device_addr, adapter_addr, alias);
 	}
 
 done:
+	g_slist_free(uuids);
 	dbus_message_unref(reply);
 }
 
@@ -342,7 +347,7 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
 
 	dbus_message_iter_get_basic(&iter, &property);
 	if (g_str_equal(property, "UUIDs") == TRUE) {
-		int profiles = 0;
+		GSList *uuids = NULL;
 		const char *path = dbus_message_get_path(msg);
 		DBusMessageIter variant;
 
@@ -354,13 +359,13 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
 
 		dbus_message_iter_recurse(&iter, &variant);
 
-		has_uuid(&variant, &profiles);
+		parse_uuids(&variant, &uuids);
 
 		/* We need the full set of properties to be able to create
 		 * the modem properly, including Adapter and Alias, so
 		 * refetch everything again
 		 */
-		if (profiles)
+		if (uuids)
 			bluetooth_send_with_reply(path, BLUEZ_DEVICE_INTERFACE,
 					"GetProperties", device_properties_cb,
 					g_strdup(path), g_free, -1,
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 318e4b0..ff0ea52 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -28,9 +28,7 @@
 #define DBUS_TIMEOUT 15
 
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
-
-/* Profiles bitfield */
-#define HFP_AG 0x01
+#define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
 
 struct bluetooth_profile {
 	const char *name;
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed
  2011-07-01  7:12 [PATCH 1/3] bluetooth: use lower case for UUIDs Luiz Augusto von Dentz
  2011-07-01  7:12 ` [PATCH 2/3] bluetooth: make uuid profile detection more generic Luiz Augusto von Dentz
@ 2011-07-01  7:12 ` Luiz Augusto von Dentz
  2011-07-01  8:21   ` Denis Kenzior
  2011-07-01  8:13 ` [PATCH 1/3] bluetooth: use lower case for UUIDs Denis Kenzior
  2 siblings, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-07-01  7:12 UTC (permalink / raw)
  To: ofono

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

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

If an adapter or device is removed any data associate should be removed,
otherwise the next time they appear/are created the drivers may not
asssociate again.
---
 plugins/bluetooth.c |   79 ++++++++++++++++++++++++++++++++++++--------------
 plugins/bluetooth.h |    4 +-
 plugins/hfp_hf.c    |   30 ++++++++++++-------
 3 files changed, 78 insertions(+), 35 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 7e0705f..1fdb579 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -258,6 +258,28 @@ static void parse_string(DBusMessageIter *iter, gpointer user_data)
 	dbus_message_iter_get_basic(iter, str);
 }
 
+static void bluetooth_probe(GSList *uuids, const char *path,
+				const char *device, const char *adapter,
+				const char *alias)
+{
+	for (; uuids; uuids = uuids->next) {
+		struct bluetooth_profile *driver;
+		const char *uuid = uuids->data;
+		int err;
+
+		driver = g_hash_table_lookup(uuid_hash, uuid);
+		if (driver == NULL)
+			continue;
+
+		err = driver->probe(path, device, adapter, alias);
+		if (err == 0)
+			continue;
+
+		ofono_error("%s probe: %s (%d)", driver->name, strerror(-err),
+									-err);
+	}
+}
+
 static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusMessage *reply;
@@ -291,19 +313,10 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 		adapter_addr = g_hash_table_lookup(adapter_address_hash,
 							adapter);
 
-	if (!device_addr && !adapter_addr)
+	if (!device_addr || !adapter_addr)
 		goto done;
 
-	for (; uuids; uuids = uuids->next) {
-		struct bluetooth_profile *profile;
-		const char *uuid = uuids->data;
-
-		profile = g_hash_table_lookup(uuid_hash, uuid);
-		if (profile == NULL || profile->create == NULL)
-			continue;
-
-		profile->create(path, device_addr, adapter_addr, alias);
-	}
+	bluetooth_probe(uuids, path, device_addr, adapter_addr, alias);
 
 done:
 	g_slist_free(uuids);
@@ -697,14 +710,38 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
 	return TRUE;
 }
 
+static void bluetooth_remove(gpointer key, gpointer value, gpointer user_data)
+{
+	struct bluetooth_profile *profile = value;
+
+	profile->remove(user_data);
+}
+
 static gboolean adapter_removed(DBusConnection *connection,
 				DBusMessage *message, void *user_data)
 {
 	const char *path;
 
 	if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
-				DBUS_TYPE_INVALID) == TRUE)
-		g_hash_table_remove(adapter_address_hash, path);
+				DBUS_TYPE_INVALID) == FALSE)
+		return FALSE;
+
+	g_hash_table_foreach(uuid_hash, bluetooth_remove, (gpointer) path);
+	g_hash_table_remove(adapter_address_hash, path);
+
+	return TRUE;
+}
+
+static gboolean device_removed(DBusConnection *connection,
+				DBusMessage *message, void *user_data)
+{
+	const char *path;
+
+	if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID) == FALSE)
+		return FALSE;
+
+	g_hash_table_foreach(uuid_hash, bluetooth_remove, (gpointer) path);
 
 	return TRUE;
 }
@@ -761,14 +798,6 @@ done:
 	dbus_message_unref(reply);
 }
 
-static void bluetooth_remove_all_modem(gpointer key, gpointer value,
-					gpointer user_data)
-{
-	struct bluetooth_profile *profile = value;
-
-	profile->remove_all();
-}
-
 static void bluetooth_connect(DBusConnection *connection, void *user_data)
 {
 	bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties",
@@ -786,7 +815,7 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
 	if (uuid_hash == NULL)
 		return;
 
-	g_hash_table_foreach(uuid_hash, bluetooth_remove_all_modem, NULL);
+	g_hash_table_foreach(uuid_hash, bluetooth_remove, NULL);
 
 	g_slist_foreach(server_list, (GFunc) remove_service_handle, NULL);
 }
@@ -794,6 +823,7 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
 static guint bluetooth_watch;
 static guint adapter_added_watch;
 static guint adapter_removed_watch;
+static guint device_removed_watch;
 static guint property_watch;
 
 static void bluetooth_ref(void)
@@ -817,6 +847,11 @@ static void bluetooth_ref(void)
 						"AdapterRemoved",
 						adapter_removed, NULL, NULL);
 
+	device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_ADAPTER_INTERFACE,
+						"DeviceRemoved",
+						device_removed, NULL, NULL);
+
 	property_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
 						BLUEZ_DEVICE_INTERFACE,
 						"PropertyChanged",
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index ff0ea52..7f9f810 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -32,9 +32,9 @@
 
 struct bluetooth_profile {
 	const char *name;
-	int (*create)(const char *device, const char *dev_addr,
+	int (*probe)(const char *device, const char *dev_addr,
 			const char *adapter_addr, const char *alias);
-	void (*remove_all)(void);
+	void (*remove)(const char *prefix);
 	void (*set_alias)(const char *device, const char *);
 };
 
diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 8a76701..584d3a7 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -393,7 +393,7 @@ static GDBusMethodTable agent_methods[] = {
 	{ NULL, NULL, NULL, NULL }
 };
 
-static int hfp_create_modem(const char *device, const char *dev_addr,
+static int hfp_hf_probe(const char *device, const char *dev_addr,
 				const char *adapter_addr, const char *alias)
 {
 	struct ofono_modem *modem;
@@ -443,25 +443,33 @@ free:
 	return -ENOMEM;
 }
 
-static gboolean hfp_remove_each_modem(gpointer key, gpointer value,
+static gboolean hfp_remove_modem(gpointer key, gpointer value,
 					gpointer user_data)
 {
 	struct ofono_modem *modem = value;
+	const char *device = key;
+	const char *prefix = user_data;
+
+	if (prefix && g_str_has_prefix(device, prefix) == FALSE)
+		return TRUE;
 
 	ofono_modem_remove(modem);
 
 	return TRUE;
 }
 
-static void hfp_remove_all_modem(void)
+static void hfp_hf_remove(const char *prefix)
 {
+	DBG("%s", prefix);
+
 	if (modem_hash == NULL)
 		return;
 
-	g_hash_table_foreach_remove(modem_hash, hfp_remove_each_modem, NULL);
+	g_hash_table_foreach_remove(modem_hash, hfp_remove_modem,
+							(gpointer) prefix);
 }
 
-static void hfp_set_alias(const char *device, const char *alias)
+static void hfp_hf_set_alias(const char *device, const char *alias)
 {
 	struct ofono_modem *modem;
 
@@ -675,11 +683,11 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
-static struct bluetooth_profile hfp_profile = {
-	.name		= "hfp",
-	.create		= hfp_create_modem,
-	.remove_all	= hfp_remove_all_modem,
-	.set_alias	= hfp_set_alias,
+static struct bluetooth_profile hfp_hf = {
+	.name		= "hfp_hf",
+	.probe		= hfp_hf_probe,
+	.remove		= hfp_hf_remove,
+	.set_alias	= hfp_hf_set_alias,
 };
 
 static int hfp_init(void)
@@ -695,7 +703,7 @@ static int hfp_init(void)
 	if (err < 0)
 		return err;
 
-	err = bluetooth_register_uuid(HFP_AG_UUID, &hfp_profile);
+	err = bluetooth_register_uuid(HFP_AG_UUID, &hfp_hf);
 	if (err < 0) {
 		ofono_modem_driver_unregister(&hfp_driver);
 		return err;
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] bluetooth: use lower case for UUIDs
  2011-07-01  7:12 [PATCH 1/3] bluetooth: use lower case for UUIDs Luiz Augusto von Dentz
  2011-07-01  7:12 ` [PATCH 2/3] bluetooth: make uuid profile detection more generic Luiz Augusto von Dentz
  2011-07-01  7:12 ` [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed Luiz Augusto von Dentz
@ 2011-07-01  8:13 ` Denis Kenzior
  2 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2011-07-01  8:13 UTC (permalink / raw)
  To: ofono

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

Hi Luiz,

On 07/01/2011 02:12 AM, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> BlueZ also uses lower case
> ---
>  plugins/bluetooth.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] bluetooth: make uuid profile detection more generic
  2011-07-01  7:12 ` [PATCH 2/3] bluetooth: make uuid profile detection more generic Luiz Augusto von Dentz
@ 2011-07-01  8:14   ` Denis Kenzior
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2011-07-01  8:14 UTC (permalink / raw)
  To: ofono

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

Hi Luiz,

On 07/01/2011 02:12 AM, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> ---
>  plugins/bluetooth.c |   31 ++++++++++++++++++-------------
>  plugins/bluetooth.h |    4 +---
>  2 files changed, 19 insertions(+), 16 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed
  2011-07-01  7:12 ` [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed Luiz Augusto von Dentz
@ 2011-07-01  8:21   ` Denis Kenzior
  2011-07-02 19:04     ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 7+ messages in thread
From: Denis Kenzior @ 2011-07-01  8:21 UTC (permalink / raw)
  To: ofono

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

Hi Luiz,

On 07/01/2011 02:12 AM, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> If an adapter or device is removed any data associate should be removed,
> otherwise the next time they appear/are created the drivers may not
> asssociate again.
> ---
>  plugins/bluetooth.c |   79 ++++++++++++++++++++++++++++++++++++--------------
>  plugins/bluetooth.h |    4 +-
>  plugins/hfp_hf.c    |   30 ++++++++++++-------
>  3 files changed, 78 insertions(+), 35 deletions(-)

Patch looks good, just one quick question:

> @@ -443,25 +443,33 @@ free:
>  	return -ENOMEM;
>  }
>  
> -static gboolean hfp_remove_each_modem(gpointer key, gpointer value,
> +static gboolean hfp_remove_modem(gpointer key, gpointer value,
>  					gpointer user_data)
>  {
>  	struct ofono_modem *modem = value;
> +	const char *device = key;
> +	const char *prefix = user_data;
> +
> +	if (prefix && g_str_has_prefix(device, prefix) == FALSE)
> +		return TRUE;

Are you sure you want to return TRUE here?  By my reading TRUE should be
removed only if the key should be removed.  That seems not to be what
you want...

>  
>  	ofono_modem_remove(modem);
>  
>  	return TRUE;
>  }
>  

Regards,
-Denis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed
  2011-07-01  8:21   ` Denis Kenzior
@ 2011-07-02 19:04     ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-07-02 19:04 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

On Fri, Jul 1, 2011 at 11:21 AM, Denis Kenzior <denkenz@gmail.com> wrote:
> Hi Luiz,
>
> On 07/01/2011 02:12 AM, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> If an adapter or device is removed any data associate should be removed,
>> otherwise the next time they appear/are created the drivers may not
>> asssociate again.
>> ---
>>  plugins/bluetooth.c |   79 ++++++++++++++++++++++++++++++++++++--------------
>>  plugins/bluetooth.h |    4 +-
>>  plugins/hfp_hf.c    |   30 ++++++++++++-------
>>  3 files changed, 78 insertions(+), 35 deletions(-)
>
> Patch looks good, just one quick question:
>
>> @@ -443,25 +443,33 @@ free:
>>       return -ENOMEM;
>>  }
>>
>> -static gboolean hfp_remove_each_modem(gpointer key, gpointer value,
>> +static gboolean hfp_remove_modem(gpointer key, gpointer value,
>>                                       gpointer user_data)
>>  {
>>       struct ofono_modem *modem = value;
>> +     const char *device = key;
>> +     const char *prefix = user_data;
>> +
>> +     if (prefix && g_str_has_prefix(device, prefix) == FALSE)
>> +             return TRUE;
>
> Are you sure you want to return TRUE here?  By my reading TRUE should be
> removed only if the key should be removed.  That seems not to be what
> you want...

Yep, gonna fix it in v2, thanks for the quick review.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-02 19:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-01  7:12 [PATCH 1/3] bluetooth: use lower case for UUIDs Luiz Augusto von Dentz
2011-07-01  7:12 ` [PATCH 2/3] bluetooth: make uuid profile detection more generic Luiz Augusto von Dentz
2011-07-01  8:14   ` Denis Kenzior
2011-07-01  7:12 ` [PATCH 3/3] bluetooth: fix not removing data when devices/adapters are removed Luiz Augusto von Dentz
2011-07-01  8:21   ` Denis Kenzior
2011-07-02 19:04     ` Luiz Augusto von Dentz
2011-07-01  8:13 ` [PATCH 1/3] bluetooth: use lower case for UUIDs Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.