From: Scott James Remnant <scott@netsplit.com>
To: linux-bluetooth@vger.kernel.org
Cc: keybuk@chromium.org, Scott James Remnant <scott@netsplit.com>
Subject: [RFC PATCH 3/3] Implement HID profile recommendation for keyboards
Date: Fri, 20 Jan 2012 15:05:44 -0800 [thread overview]
Message-ID: <1327100744-28782-4-git-send-email-scott@netsplit.com> (raw)
In-Reply-To: <1327100744-28782-1-git-send-email-scott@netsplit.com>
The Bluetooth HID profile recommends that for keyboard devices we
generate the PIN ourselves and display it for the user and expecting
them to enter it into the keyboard being paired - rather than
requesting it so that they have to enter it into both devices.
---
src/event.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/event.c b/src/event.c
index 5aa5ef9..26318bd 100644
--- a/src/event.c
+++ b/src/event.c
@@ -27,6 +27,7 @@
#endif
#define _GNU_SOURCE
+#include <time.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
@@ -49,6 +50,7 @@
#include "agent.h"
#include "storage.h"
#include "event.h"
+#include "bt_ids.h"
static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
struct btd_adapter **adapter,
@@ -119,6 +121,7 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
struct btd_device *device;
char pin[17];
ssize_t pinlen;
+ uint32_t class;
if (!get_adapter_and_device(sba, dba, &adapter, &device, TRUE))
return -ENODEV;
@@ -130,6 +133,25 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
return 0;
}
+ if (device_is_bonding(device, NULL) &&
+ read_remote_class(sba, dba, &class) == 0) {
+ switch (BLUETOOTH_DEVICE_CLASS(class)) {
+ case BLUETOOTH_DEVICE_CLASS_PERIPHERAL_KEYBOARD:
+ case BLUETOOTH_DEVICE_CLASS_PERIPHERAL_KEYBOARD_POINTING:
+ /* Generate a PIN in the range 000000-999999 */
+ DBG("Generating pincode for keyboard");
+ srand(time(NULL));
+ snprintf(pin, sizeof pin, "%06d", rand() % 1000000);
+ btd_adapter_pincode_reply(adapter, dba,
+ pin, strlen(pin));
+ return device_request_authentication(device,
+ AUTH_TYPE_NOTIFY_PINCODE, pin,
+ secure, NULL);
+
+ break;
+ }
+ }
+
return device_request_authentication(device, AUTH_TYPE_PINCODE, NULL,
secure, pincode_cb);
}
--
1.7.7.3
next prev parent reply other threads:[~2012-01-20 23:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-20 23:05 [RFC PATCH 0/3] Generate PIN for keyboards inside bluetoothd Scott James Remnant
2012-01-20 23:05 ` [RFC PATCH 1/3] lib: add header of device class constants Scott James Remnant
2012-01-21 16:30 ` Marcel Holtmann
2012-01-21 17:29 ` Scott James Remnant
2012-01-20 23:05 ` [RFC PATCH 2/3] agent: add DisplayPinCode method Scott James Remnant
2012-01-21 16:36 ` Marcel Holtmann
2012-01-23 6:08 ` Scott James Remnant
2012-01-20 23:05 ` Scott James Remnant [this message]
2012-01-23 12:14 ` [RFC PATCH 0/3] Generate PIN for keyboards inside bluetoothd Bastien Nocera
2012-01-23 15:37 ` Scott James Remnant
2012-01-23 16:03 ` Bastien Nocera
2012-01-23 16:10 ` Scott James Remnant
2012-01-23 16:24 ` Bastien Nocera
2012-01-23 16:26 ` Scott James Remnant
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=1327100744-28782-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).