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 v3 8/8] autopair: Try a fixed pincode for keyboards rejecting random codes
Date: Tue, 23 Apr 2013 11:04:07 -0700 [thread overview]
Message-ID: <1366740247-368-9-git-send-email-deymo@chromium.org> (raw)
In-Reply-To: <1366740247-368-1-git-send-email-deymo@chromium.org>
This patch makes the autopair plugin try a fixed "0000" pincode for
keyboards that reject the pincode too fast (less than 500ms). This
too short delay rejecting the pincode means that the user didn't
have time to type the random pincode in the bluetooth keyboard and
was the keyboard who actually rejected it.
---
plugins/autopair.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/plugins/autopair.c b/plugins/autopair.c
index 2b7a5ee..c669fcb 100644
--- a/plugins/autopair.c
+++ b/plugins/autopair.c
@@ -87,8 +87,23 @@ static ssize_t autopair_pincb(struct btd_adapter *adapter,
switch ((class & 0xc0) >> 6) {
case 0x01: /* Keyboard */
case 0x03: /* Combo keyboard/pointing device */
- if (attempt > 1)
+ /* For keyboards rejecting the first random code in less
+ * than 500ms, try a fixed code. */
+ if (attempt > 1 &&
+ device_bonding_last_duration(device) < 500) {
+ /* Don't try more than one dumb code */
+ if (attempt > 2)
+ return 0;
+ /* Try "0000" as the code for the second
+ * attempt. */
+ memcpy(pinbuf, "0000", 4);
+ return 4;
+ }
+
+ /* Never try more than 3 random pincodes. */
+ if (attempt >= 4)
return 0;
+
snprintf(pinstr, sizeof(pinstr), "%06d",
rand() % 1000000);
*display = TRUE;
--
1.8.2.1
prev parent reply other threads:[~2013-04-23 18:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-23 18:03 [PATCH v3 0/8] Autopair plugin Alex Deymo
2013-04-23 18:04 ` [PATCH v3 1/8] core: Convert the pincode callback to an interable list Alex Deymo
2013-04-24 11:24 ` Johan Hedberg
2013-04-24 11:42 ` Johan Hedberg
2013-04-23 18:04 ` [PATCH v3 2/8] plugins: Extend the pin code callback with the call number Alex Deymo
2013-04-23 18:04 ` [PATCH v3 3/8] core: Add support for retrying a bonding Alex Deymo
2013-04-24 11:29 ` Johan Hedberg
2013-04-23 18:04 ` [PATCH v3 4/8] core: retry bonding attempt until the iterator reaches the end Alex Deymo
2013-04-24 11:32 ` Johan Hedberg
2013-04-23 18:04 ` [PATCH v3 5/8] core: Add device_get_class to the public interface Alex Deymo
2013-04-23 18:04 ` [PATCH v3 6/8] autopair: Add the autopair plugin Alex Deymo
2013-04-23 18:04 ` [PATCH v3 7/8] core: Expose the last bonding attempt timeout on retry Alex Deymo
2013-04-24 11:37 ` Johan Hedberg
2013-04-24 14:03 ` Marcel Holtmann
2013-04-23 18:04 ` Alex Deymo [this message]
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=1366740247-368-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox