linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott James Remnant <keybuk@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Scott James Remnant <keybuk@chromium.org>
Subject: [PATCH 2/2] agent: allow agent to reply to RequestPinCode with bytes
Date: Fri, 13 Jan 2012 17:52:37 -0800	[thread overview]
Message-ID: <1326505957-27555-3-git-send-email-keybuk@chromium.org> (raw)
In-Reply-To: <1326505957-27555-1-git-send-email-keybuk@chromium.org>

Since the specification allows the PIN to be a sequence of arbitrary
octets, and not a UTF-8 string, allow the userspace agent to reply
with such a sequence (as a D-Bus Array of Bytes).

This means a userspace agent can deal with devices that require their
BD_ADDR (or the host's) as a PIN, and take care of trying multiple of
such requirements.
---
 src/agent.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/agent.c b/src/agent.c
index 4477210..3b9e849 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -353,7 +353,8 @@ static void pincode_reply(DBusPendingCall *call, void *user_data)
 	DBusMessage *message;
 	DBusError err;
 	bdaddr_t sba;
-	size_t len;
+	int32_t array_len;
+	ssize_t len;
 	char *pin;
 
 	adapter_get_address(adapter, &sba);
@@ -373,17 +374,24 @@ static void pincode_reply(DBusPendingCall *call, void *user_data)
 	}
 
 	dbus_error_init(&err);
-	if (!dbus_message_get_args(message, &err,
+	if (dbus_message_get_args(message, &err,
 				DBUS_TYPE_STRING, &pin,
 				DBUS_TYPE_INVALID)) {
+		len = strlen(pin);
+
+	} else if (dbus_message_get_args(message, &err,
+				DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pin, &array_len,
+				DBUS_TYPE_INVALID)) {
+		/* convert int32_t to ssize_t (probably the same length) */
+		len = array_len;
+
+	} else {
 		error("Wrong passkey reply signature: %s", err.message);
 		cb(agent, &err, NULL, 0, req->user_data);
 		dbus_error_free(&err);
 		goto done;
 	}
 
-	len = strlen(pin);
-
 	dbus_error_init(&err);
 	if (len > 16 || len < 1) {
 		error("Invalid PIN length (%zu) from agent", len);
-- 
1.7.7.3


  reply	other threads:[~2012-01-14  1:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-14  1:52 [PATCH 1/2] Pass length of PIN through callbacks Scott James Remnant
2012-01-14  1:52 ` Scott James Remnant [this message]
2012-01-14 16:41   ` [PATCH 2/2] agent: allow agent to reply to RequestPinCode with bytes Marcel Holtmann
2012-01-14 20:32     ` Scott James Remnant
2012-01-14 20:34     ` Scott James Remnant
2012-01-16 15:44       ` David Herrmann
2012-01-17  6:23         ` Scott James Remnant
2012-01-17  7:47           ` Marcel Holtmann
2012-01-17  8:30             ` Scott James Remnant
2012-01-17 10:23               ` Marcel Holtmann
2012-01-17 17:57                 ` 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=1326505957-27555-3-git-send-email-keybuk@chromium.org \
    --to=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).