linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Szatkowski <bulislaw@linux.com>
To: linux-bluetooth@vger.kernel.org
Cc: Bartosz Szatkowski <bulislaw@linux.com>
Subject: [PATCH BlueZ v2 2/3] Add support for OOB data in SetRemoteProperties
Date: Mon, 22 Aug 2011 13:39:15 +0200	[thread overview]
Message-ID: <1314013156-17328-2-git-send-email-bulislaw@linux.com> (raw)
In-Reply-To: <1314013156-17328-1-git-send-email-bulislaw@linux.com>

Now its possible to exchange OOB simple pairing data through DBus API
method with other device properties.
---
 doc/oob-api.txt   |    5 ++++-
 plugins/dbusoob.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/doc/oob-api.txt b/doc/oob-api.txt
index 0324758..500ef15 100644
--- a/doc/oob-api.txt
+++ b/doc/oob-api.txt
@@ -41,11 +41,14 @@ Methods		array{byte} hash, array{byte} randomizer ReadLocalData()
 
 			This method set new properties for device with specified
 			address, to be used when device is created.
-			On success DeviceFound signal will be emitted.
+			On success DeviceFound signal will be emitted (except
+			situations when only hash and randomizer is supplied).
 
 			Currently supported keys:
 
 				Class		uint32
+				Hash		array{byte}
+				Randomizer	array{byte}
 
 			Possible errors: org.bluez.Error.Failed
 					 org.bluez.Error.InvalidArguments
diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index 94aff72..bbe1b1f 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -58,6 +58,8 @@ struct oob_remote_parameters {
 	const char *address;
 	uint32_t class;
 	gboolean device_found;
+	uint8_t *hash;
+	uint8_t *randomizer;
 };
 
 static GSList *oob_requests = NULL;
@@ -217,6 +219,42 @@ static void set_class(struct oob_remote_parameters *params)
 	params->device_found = TRUE;
 }
 
+static DBusMessage *parse_oob_data(DBusMessageIter *value, uint8_t **data,
+							DBusMessage *msg)
+{
+	DBusMessageIter array_iter;
+	int32_t len;
+	uint8_t *tmp;
+
+	if (dbus_message_iter_get_arg_type(value) != DBUS_TYPE_ARRAY)
+		return btd_error_invalid_args(msg);
+
+	dbus_message_iter_recurse(value, &array_iter);
+
+	dbus_message_iter_get_fixed_array(&array_iter, &tmp, &len);
+
+	if (len != 16)
+		return btd_error_invalid_args(msg);
+
+	*data = tmp;
+
+	return NULL;
+}
+
+static void set_oob_data(struct btd_adapter *adapter,
+				struct oob_remote_parameters *parameters)
+{
+	if (parameters->hash == NULL || parameters->randomizer == NULL) {
+		error("OOB data incomplete");
+
+		return;
+	}
+
+	if (btd_adapter_add_remote_oob_data(adapter, &parameters->peer,
+				parameters->hash, parameters->randomizer))
+		error("Adding remote OOB data failed");
+}
+
 static DBusMessage *parse_property(const char *property,
 				DBusMessageIter *value, DBusMessage *msg,
 				struct oob_remote_parameters *params)
@@ -224,6 +262,12 @@ static DBusMessage *parse_property(const char *property,
 	if (g_str_equal("Class", property))
 		return parse_class(value, params, msg);
 
+	if (g_str_equal("Hash", property))
+		return parse_oob_data(value, &params->hash, msg);
+
+	if (g_str_equal("Randomizer", property))
+		return parse_oob_data(value, &params->randomizer, msg);
+
 	return NULL;
 }
 
@@ -233,6 +277,9 @@ static void set_properties(struct btd_adapter *adapter,
 	if (params->class != 0)
 		set_class(params);
 
+	if (parameters->hash != NULL && parameters->randomizer != NULL)
+		set_oob_data(adapter, params);
+
 	if (params->device_found)
 		emit_device_found(adapter_get_path(adapter), params);
 }
-- 
1.7.4.1


  reply	other threads:[~2011-08-22 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-22 11:39 [PATCH BlueZ v2 1/3] Add SetRemoteProperties method for OOB COD setting Bartosz Szatkowski
2011-08-22 11:39 ` Bartosz Szatkowski [this message]
2011-08-22 11:39 ` [PATCH BlueZ v2 3/3] Add support for name in OOB SetRemoteProperties Bartosz Szatkowski
2011-08-22 11:50 ` [PATCH BlueZ v2 1/3] Add SetRemoteProperties method for OOB COD setting Bartosz Szatkowski
  -- strict thread matches above, loose matches on Subject: below --
2011-08-22 12:09 Bartosz Szatkowski
2011-08-22 12:09 ` [PATCH BlueZ v2 2/3] Add support for OOB data in SetRemoteProperties Bartosz Szatkowski

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=1314013156-17328-2-git-send-email-bulislaw@linux.com \
    --to=bulislaw@linux.com \
    --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).