Re: [PATCH] Store new local name before writing it to HCI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 30, 2010 at 5:35 PM, Daniel Örstadius
<daniel.orstadius@xxxxxxxxx> wrote:
> Store new local name to the filesystem and emit property changed
> before actually writing the name to the chip.

Resending with amended commit message.
From a10b5170f3ba69d880a8a9cd8737d0545e95b04b Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx>
Date: Mon, 30 Aug 2010 16:54:09 +0300
Subject: [PATCH] Store new local name before writing it to adapter

Store new local name to the file system and emit property changed
before actually writing the name to the adapter.

The reason for the patch is the scenario were an application sets
the name and then immediately turns off the adapter. Previously the
requested name change might not have been properly applied in that
case. The new name was not written to storage until it had been
read from the adapter and the adapter could have been turned off
before the read command was completed.

Avoids writing the name twice by using a boolean variable in the
btd_adapter struct. The name may be changed by using for example
hciconfig and in that case the name needs to be updated to storage
after reading.
---
 src/adapter.c |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 377bacc..0dbb295 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -137,6 +137,8 @@ struct btd_adapter {
 	gint ref;
 
 	GSList *powered_callbacks;
+
+	gboolean name_stored;
 };
 
 static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -950,17 +952,21 @@ void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr)
 
 	strncpy((char *) dev->name, (char *) rp.name, MAX_NAME_LENGTH);
 
-	write_local_name(bdaddr, (char *) dev->name);
+	if (!adapter->name_stored) {
+		write_local_name(bdaddr, (char *) dev->name);
 
-	update_ext_inquiry_response(adapter);
+		name = g_strdup((char *) dev->name);
 
-	name = g_strdup((char *) dev->name);
+		if (connection)
+			emit_property_changed(connection, adapter->path,
+						ADAPTER_INTERFACE, "Name",
+						DBUS_TYPE_STRING, &name);
+		g_free(name);
+	}
 
-	if (connection)
-		emit_property_changed(connection, adapter->path,
-					ADAPTER_INTERFACE, "Name",
-					DBUS_TYPE_STRING, &name);
-	g_free(name);
+	adapter->name_stored = FALSE;
+
+	update_ext_inquiry_response(adapter);
 }
 
 void adapter_setname_complete(bdaddr_t *local, uint8_t status)
@@ -998,16 +1004,18 @@ static DBusMessage *set_name(DBusConnection *conn, DBusMessage *msg,
 	if (strncmp(name, (char *) dev->name, MAX_NAME_LENGTH) == 0)
 		goto done;
 
-	if (!adapter->up) {
-		strncpy((char *) adapter->dev.name, name, MAX_NAME_LENGTH);
-		write_local_name(&adapter->bdaddr, name);
-		emit_property_changed(connection, adapter->path,
+	strncpy((char *) adapter->dev.name, name, MAX_NAME_LENGTH);
+	write_local_name(&adapter->bdaddr, name);
+	emit_property_changed(connection, adapter->path,
 					ADAPTER_INTERFACE, "Name",
 					DBUS_TYPE_STRING, &name);
-	} else {
+
+	if (adapter->up) {
 		int err = adapter_ops->set_name(adapter->dev_id, name);
 		if (err < 0)
 			return failed_strerror(msg, err);
+
+		adapter->name_stored = TRUE;
 	}
 
 done:
@@ -2504,6 +2512,7 @@ int adapter_stop(struct btd_adapter *adapter)
 	adapter->cache_enable = TRUE;
 	adapter->pending_cod = 0;
 	adapter->off_requested = FALSE;
+	adapter->name_stored = FALSE;
 
 	call_adapter_powered_callbacks(adapter, FALSE);
 
-- 
1.6.0.4


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux