All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v3 0/1] Fix unpair device when disconnected for No Bonding
@ 2011-07-11 12:20 Dmitriy Paliy
  2011-07-11 12:20 ` [PATCH BlueZ v3] " Dmitriy Paliy
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitriy Paliy @ 2011-07-11 12:20 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

This version includes the fix regarding comment of Johan. Function
device_set_bonded is created and invoked when link key is stored to
file system which covers both pairing as initiator or acceptor cases.

BR,
Dmitriy


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

* [PATCH BlueZ v3] Fix unpair device when disconnected for No Bonding
  2011-07-11 12:20 [PATCH BlueZ v3 0/1] Fix unpair device when disconnected for No Bonding Dmitriy Paliy
@ 2011-07-11 12:20 ` Dmitriy Paliy
  2011-07-11 12:52   ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitriy Paliy @ 2011-07-11 12:20 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

Fix Paired device property if 'No Bonding' authentication is used. It is
set to be false when device is disconnected and no link key is stored.
Otherwise, there can be cases when device is still valid and being
claimed as paired without available bonding information.

For instanse, use of CreateDevice method call and obex client file
transfer is such use case.
---
 src/device.c |   19 ++++++++++++++++++-
 src/device.h |    1 +
 src/event.c  |    8 ++++++--
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/device.c b/src/device.c
index 82759a4..0230203 100644
--- a/src/device.c
+++ b/src/device.c
@@ -132,6 +132,7 @@ struct btd_device {
 	gboolean	trusted;
 	gboolean	paired;
 	gboolean	blocked;
+	gboolean	bonded;
 
 	gboolean	authorizing;
 	gint		ref;
@@ -824,6 +825,9 @@ void device_remove_connection(struct btd_device *device, DBusConnection *conn)
 		device->disconnects = g_slist_remove(device->disconnects, msg);
 	}
 
+	if (device_is_paired(device) && !device->bonded)
+		device_set_paired(device, FALSE);
+
 	emit_property_changed(conn, device->path,
 					DEVICE_INTERFACE, "Connected",
 					DBUS_TYPE_BOOLEAN, &device->connected);
@@ -906,8 +910,10 @@ struct btd_device *device_create(DBusConnection *conn,
 	if (read_blocked(&src, &device->bdaddr))
 		device_block(conn, device);
 
-	if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0)
+	if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0) {
 		device->paired = TRUE;
+		device_set_bonded(device, TRUE);
+	}
 
 	return btd_device_ref(device);
 }
@@ -958,6 +964,7 @@ void device_remove_bonding(struct btd_device *device)
 
 	/* Delete the link key from storage */
 	textfile_casedel(filename, dstaddr);
+	device_set_bonded(device, FALSE);
 
 	create_name(filename, PATH_MAX, STORAGEDIR, srcaddr,
 						"aliases");
@@ -1792,6 +1799,16 @@ void device_set_temporary(struct btd_device *device, gboolean temporary)
 	device->temporary = temporary;
 }
 
+void device_set_bonded(struct btd_device *device, gboolean bonded)
+{
+	if (!device)
+		return;
+
+	DBG("bonded %d", bonded);
+
+	device->bonded = bonded;
+}
+
 void device_set_type(struct btd_device *device, device_type_t type)
 {
 	if (!device)
diff --git a/src/device.h b/src/device.h
index bd8a431..18b21ae 100644
--- a/src/device.h
+++ b/src/device.h
@@ -72,6 +72,7 @@ gboolean device_is_trusted(struct btd_device *device);
 void device_set_paired(struct btd_device *device, gboolean paired);
 void device_set_temporary(struct btd_device *device, gboolean temporary);
 void device_set_type(struct btd_device *device, device_type_t type);
+void device_set_bonded(struct btd_device *device, gboolean bonded);
 gboolean device_is_connected(struct btd_device *device);
 DBusMessage *device_create_bonding(struct btd_device *device,
 				DBusConnection *conn, DBusMessage *msg,
diff --git a/src/event.c b/src/event.c
index 86a413e..d5462f6 100644
--- a/src/event.c
+++ b/src/event.c
@@ -410,8 +410,12 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
 
 	ret = write_link_key(local, peer, key, key_type, pin_length);
 
-	if (ret == 0 && device_is_temporary(device))
-		device_set_temporary(device, FALSE);
+	if (ret == 0) {
+		device_set_bonded(device, TRUE);
+
+		if (device_is_temporary(device))
+			device_set_temporary(device, FALSE);
+	}
 
 	return ret;
 }
-- 
1.7.4.1


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

* Re: [PATCH BlueZ v3] Fix unpair device when disconnected for No Bonding
  2011-07-11 12:20 ` [PATCH BlueZ v3] " Dmitriy Paliy
@ 2011-07-11 12:52   ` Johan Hedberg
  2011-07-11 17:39     ` Dmitriy Paliy
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2011-07-11 12:52 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi Dmitriy,

On Mon, Jul 11, 2011, Dmitriy Paliy wrote:
> Fix Paired device property if 'No Bonding' authentication is used. It is
> set to be false when device is disconnected and no link key is stored.
> Otherwise, there can be cases when device is still valid and being
> claimed as paired without available bonding information.
> 
> For instanse, use of CreateDevice method call and obex client file
> transfer is such use case.
> ---
>  src/device.c |   19 ++++++++++++++++++-
>  src/device.h |    1 +
>  src/event.c  |    8 ++++++--
>  3 files changed, 25 insertions(+), 3 deletions(-)

Applied, and I also pushed a cleanup patch on top of it because
device_remove_bonding was essentially useless. One thing that I'm
thinking of is maybe it'd be better to get rid of the paired and bonded
booleans have a single enum for them since they are dependent on each
other and one combination of boolean values (!paired && bonded) is not
possible. Maybe something like the following inside struct btd_device:

	enum {
		DEVICE_PAIRING_STATUS_NONE,
		DEVICE_PAIRING_STATUS_PAIRED,
		DEVICE_PAIRING_STATUS_BONDED,
	} pairing_status;

Thoughts?

Johan

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

* Re: [PATCH BlueZ v3] Fix unpair device when disconnected for No Bonding
  2011-07-11 12:52   ` Johan Hedberg
@ 2011-07-11 17:39     ` Dmitriy Paliy
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitriy Paliy @ 2011-07-11 17:39 UTC (permalink / raw)
  To: linux-bluetooth, johan.hedberg

Hi Johan,

On Mon, Jul 11, 2011 at 3:52 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Applied, and I also pushed a cleanup patch on top of it because
> device_remove_bonding was essentially useless. One thing that I'm
> thinking of is maybe it'd be better to get rid of the paired and bonded
> booleans have a single enum for them since they are dependent on each
> other and one combination of boolean values (!paired && bonded) is not
> possible. Maybe something like the following inside struct btd_device:
>
>        enum {
>                DEVICE_PAIRING_STATUS_NONE,
>                DEVICE_PAIRING_STATUS_PAIRED,
>                DEVICE_PAIRING_STATUS_BONDED,
>        } pairing_status;
>
> Thoughts?

Sounds wise, I will check solution for hci_ops and mgmt_ops.

BR,
Dmitriy

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

end of thread, other threads:[~2011-07-11 17:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11 12:20 [PATCH BlueZ v3 0/1] Fix unpair device when disconnected for No Bonding Dmitriy Paliy
2011-07-11 12:20 ` [PATCH BlueZ v3] " Dmitriy Paliy
2011-07-11 12:52   ` Johan Hedberg
2011-07-11 17:39     ` Dmitriy Paliy

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.