blob: 26b2aa71437bec67720924f51bbb1f4cbe5c5613 [file] [log] [blame]
From 0cd8c8427019cfd7e1c69fb6a5b4261863716d56 Mon Sep 17 00:00:00 2001
From: Scott James Remnant <scott@netsplit.com>
Date: Tue, 24 Jan 2012 10:34:01 -0800
Subject: [PATCH 09/13] Add support for retrying a bonding
In order to retry a bonding we need a timer that will perform the
retry, we need to stash the status and capability of the bonding
request so it can use them again, and in the case of a retrying
bonding attempt we need to not tear down the temporary D-Bus device
object on the adapter.
---
src/adapter.c | 2 +-
src/device.c | 14 ++++++++++++++
src/device.h | 1 +
3 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index ccf7991..f065a5d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2989,7 +2989,7 @@ void adapter_remove_connection(struct btd_adapter *adapter,
if (device_is_authenticating(device))
device_cancel_authentication(device, TRUE);
- if (device_is_temporary(device)) {
+ if (device_is_temporary(device) && !device_is_retrying(device)) {
const char *path = device_get_path(device);
DBG("Removing temporary device %s", path);
diff --git a/src/device.c b/src/device.c
index f32666e..9d4517f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -85,6 +85,9 @@ struct bonding_req {
DBusMessage *msg;
guint listener_id;
struct btd_device *device;
+ uint8_t capability;
+ uint8_t status;
+ guint retry_timer;
};
struct authentication_req {
@@ -2295,6 +2298,9 @@ static void bonding_request_free(struct bonding_req *bonding)
if (bonding->conn)
dbus_connection_unref(bonding->conn);
+ if (bonding->retry_timer)
+ g_source_remove(bonding->retry_timer);
+
device = bonding->device;
g_free(bonding);
@@ -2367,6 +2373,7 @@ proceed:
bonding->conn = dbus_connection_ref(conn);
bonding->msg = dbus_message_ref(msg);
+ bonding->capability = capability;
return bonding;
}
@@ -2469,6 +2476,13 @@ static void device_auth_req_free(struct btd_device *device)
device->authr = NULL;
}
+gboolean device_is_retrying(struct btd_device *device)
+{
+ struct bonding_req *bonding = device->bonding;
+
+ return bonding && bonding->retry_timer != 0;
+}
+
void device_bonding_complete(struct btd_device *device, uint8_t status)
{
struct bonding_req *bonding = device->bonding;
diff --git a/src/device.h b/src/device.h
index 561865c..b957ad6 100644
--- a/src/device.h
+++ b/src/device.h
@@ -75,6 +75,7 @@ void device_set_temporary(struct btd_device *device, gboolean temporary);
void device_set_bonded(struct btd_device *device, gboolean bonded);
void device_set_auto_connect(struct btd_device *device, gboolean enable);
gboolean device_is_connected(struct btd_device *device);
+gboolean device_is_retrying(struct btd_device *device);
DBusMessage *device_create_bonding(struct btd_device *device,
DBusConnection *conn, DBusMessage *msg,
const char *agent_path, uint8_t capability);
--
1.7.7.3