summaryrefslogtreecommitdiff
path: root/plugins/autopair.c
diff options
context:
space:
mode:
authorAlex Deymo <deymo@chromium.org>2013-05-08 17:38:02 -0700
committerJohan Hedberg <johan.hedberg@intel.com>2013-05-10 10:26:19 +0300
commitdc3a5865012d3b70be6c123fdca422becc419db0 (patch)
treeed18439aa84ba4c32f9faba3e4014da42ee84473 /plugins/autopair.c
parent63581e155c94261ed582740a91488849e30014a6 (diff)
downloadbluez-dc3a5865012d3b70be6c123fdca422becc419db0.tar.gz
autopair: Try a fixed pincode for keyboards rejecting random codes
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.
Diffstat (limited to 'plugins/autopair.c')
-rw-r--r--plugins/autopair.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/autopair.c b/plugins/autopair.c
index 4d5e7878b..24af8729a 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;