linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott James Remnant <scott@netsplit.com>
To: linux-bluetooth@vger.kernel.org
Cc: keybuk@chromium.org, Scott James Remnant <scott@netsplit.com>
Subject: [PATCHv2 3/4] bonding: retry if callback returns TRUE
Date: Tue, 24 Jan 2012 10:47:57 -0800	[thread overview]
Message-ID: <1327430878-23913-4-git-send-email-scott@netsplit.com> (raw)
In-Reply-To: <1327430878-23913-1-git-send-email-scott@netsplit.com>

When a bonding completes, pass the status to any plugin bonding
callbacks; if any return TRUE than set a timer to retry the bonding
after an appropriate backoff period.
---
 src/device.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/device.c b/src/device.c
index 4e11447..c36173d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2354,6 +2354,44 @@ void btd_device_unregister_bonding_cb(struct btd_device *device,
 						device->bonding_callbacks, cb);
 }
 
+static gboolean device_bonding_retry(gpointer data)
+{
+	struct btd_device *device = data;
+	struct btd_adapter *adapter = device_get_adapter(device);
+	struct bonding_req *bonding = device->bonding;
+	int err;
+
+	if (!bonding)
+		return FALSE;
+
+	DBG("retrying bonding");
+	err = adapter_create_bonding(adapter, &device->bdaddr,
+							bonding->capability);
+	if (err < 0)
+		device_bonding_complete(device, bonding->status);
+
+	bonding->retry_timer = 0;
+	return FALSE;
+}
+
+static gboolean device_bonding_get_retry(struct btd_device *device,
+								uint8_t status)
+{
+	GSList *l;
+	btd_device_bonding_cb_t cb;
+	gboolean retry = FALSE;
+
+	for (l = device->bonding_callbacks; l != NULL; l = g_slist_next(l)) {
+		cb = l->data;
+		retry |= cb(device, TRUE, status);
+	}
+
+	g_slist_free(device->bonding_callbacks);
+	device->bonding_callbacks = NULL;
+
+	return retry;
+}
+
 gboolean device_is_retrying(struct btd_device *device)
 {
 	struct bonding_req *bonding = device->bonding;
@@ -2368,6 +2406,14 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
 
 	DBG("bonding %p status 0x%02x", bonding, status);
 
+	if (device_bonding_get_retry(device, status) && status) {
+		DBG("backing off and retrying");
+		bonding->status = status;
+		bonding->retry_timer = g_timeout_add(3000,
+						device_bonding_retry, device);
+		return;
+	}
+
 	if (auth && auth->type == AUTH_TYPE_NOTIFY && auth->agent)
 		agent_cancel(auth->agent);
 
-- 
1.7.7.3


  parent reply	other threads:[~2012-01-24 18:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 18:47 [PATCHv2 0/4] Add support for bonding callbacks and retrying Scott James Remnant
2012-01-24 18:47 ` [PATCHv2 1/4] Add support for retrying a bonding Scott James Remnant
2012-01-24 18:47 ` [PATCHv2 2/4] plugin: Add bonding callback support for plugins Scott James Remnant
2012-01-24 18:47 ` Scott James Remnant [this message]
2012-01-24 18:47 ` [PATCHv2 4/4] bonding: call plugin callback on cancellation Scott James Remnant
2012-01-30 19:41 ` [PATCHv2 0/4] Add support for bonding callbacks and retrying Marcel Holtmann
2012-01-30 21:38   ` Scott James Remnant
2012-01-30 21:51     ` Marcel Holtmann
2012-01-30 21:57       ` Scott James Remnant
2012-01-30 22:08         ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327430878-23913-4-git-send-email-scott@netsplit.com \
    --to=scott@netsplit.com \
    --cc=keybuk@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).