[PATCH v3 8/8] autopair: Try a fixed pincode for keyboards rejecting random codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux