All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deymo <deymo@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, keybuk@chromium.org,
	Alex Deymo <deymo@chromium.org>
Subject: [PATCH v5 2/8] plugins: Extend the pin code callback with the call number
Date: Wed,  8 May 2013 17:37:56 -0700	[thread overview]
Message-ID: <1368059882-9986-3-git-send-email-deymo@chromium.org> (raw)
In-Reply-To: <1368059882-9986-1-git-send-email-deymo@chromium.org>

The plugin's pin code callback doesn't know about the pairing process. It
just provides a pin code based on the information provided to this function.
Although limited state could be added through other new callbacks, this fix
achieves this by providing more information to the callback itself. The
new argument "attempt" states the pin callback attempt of the particular
plugin for the current pairing of the device. This allows a plugin to try
different pincodes for the same device in the same pairing process.

To signal that the plugin doesn't provide any pin code for the provided device
the current implementation returns 0 (an empty pin code). Analogously, with
this fix, a plugin should return 0 when it doesn't have any other pin code to
provide for the given device.
---
 plugins/wiimote.c | 7 ++++++-
 src/adapter.c     | 2 +-
 src/adapter.h     | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/plugins/wiimote.c b/plugins/wiimote.c
index 90d6d7b..12312b6 100644
--- a/plugins/wiimote.c
+++ b/plugins/wiimote.c
@@ -70,12 +70,17 @@ static const char *wii_names[] = {
 };
 
 static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
-						char *pinbuf, gboolean *display)
+			char *pinbuf, gboolean *display, unsigned int attempt)
 {
 	uint16_t vendor, product;
 	char addr[18], name[25];
 	unsigned int i;
 
+	/* Only try the pin code once per device. If it's not correct then it's
+	 * an unknown device. */
+	if (attempt > 1)
+		return 0;
+
 	ba2str(device_get_address(device), addr);
 
 	vendor = btd_device_get_vendor(device);
diff --git a/src/adapter.c b/src/adapter.c
index b317d47..bf10268 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4795,7 +4795,7 @@ static ssize_t btd_adapter_pin_cb_iter_next(
 
 	while (iter->it != NULL) {
 		cb = iter->it->data;
-		ret = cb(adapter, device, pin_buf, display);
+		ret = cb(adapter, device, pin_buf, display, iter->attempt);
 		iter->attempt++;
 		if (ret > 0)
 			return ret;
diff --git a/src/adapter.h b/src/adapter.h
index 425a11f..09d80c2 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -132,7 +132,8 @@ int btd_cancel_authorization(guint id);
 int btd_adapter_restore_powered(struct btd_adapter *adapter);
 
 typedef ssize_t (*btd_adapter_pin_cb_t) (struct btd_adapter *adapter,
-			struct btd_device *dev, char *out, gboolean *display);
+			struct btd_device *dev, char *out, gboolean *display,
+							unsigned int attempt);
 void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
 						btd_adapter_pin_cb_t cb);
 void btd_adapter_unregister_pin_cb(struct btd_adapter *adapter,
-- 
1.8.2.1

  parent reply	other threads:[~2013-05-09  0:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09  0:37 [PATCH v5 0/8] Autopair Alex Deymo
2013-05-09  0:37 ` [PATCH v5 1/8] core: Convert the pincode callback to an interable list Alex Deymo
2013-05-09  0:37 ` Alex Deymo [this message]
2013-05-09  0:37 ` [PATCH v5 3/8] core: Add support for retrying a bonding Alex Deymo
2013-05-09  0:37 ` [PATCH v5 4/8] core: retry bonding attempt until the iterator reaches the end Alex Deymo
2013-05-09  0:37 ` [PATCH v5 5/8] core: Add device_get_class to the public interface Alex Deymo
2013-05-09  0:38 ` [PATCH v5 6/8] autopair: Add the autopair plugin Alex Deymo
2013-05-09  0:38 ` [PATCH v5 7/8] core: Expose the last bonding attempt timeout on retry Alex Deymo
2013-05-09  0:38 ` [PATCH v5 8/8] autopair: Try a fixed pincode for keyboards rejecting random codes Alex Deymo
2013-05-10  7:39 ` [PATCH v5 0/8] Autopair Johan Hedberg

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=1368059882-9986-3-git-send-email-deymo@chromium.org \
    --to=deymo@chromium.org \
    --cc=keybuk@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.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 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.