All of lore.kernel.org
 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 2/3] Add support for OOB data in SetRemoteProperties
Date: Thu, 11 Aug 2011 13:14:56 +0200	[thread overview]
Message-ID: <1313061297-16884-2-git-send-email-bulislaw@linux.com> (raw)
In-Reply-To: <1313061297-16884-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 |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 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 ca0c635..c6237f9 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -57,6 +57,8 @@ struct oob_remote_parameters {
 	bdaddr_t peer;
 	const char *address;
 	uint32_t class;
+	uint8_t *hash;
+	uint8_t *randomizer;
 };
 
 static GSList *oob_requests = NULL;
@@ -219,6 +221,48 @@ static gboolean set_class(struct oob_remote_parameters *params)
 	return 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)
+		return;
+
+	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");
+
+		return;
+	}
+}
+
 static DBusMessage *parse_property(const char *property,
 				DBusMessageIter *value, DBusMessage *msg,
 				struct oob_remote_parameters *params)
@@ -226,6 +270,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;
 }
 
@@ -237,6 +287,8 @@ static void set_properties(struct btd_adapter *adapter, DBusMessage *msg,
 	if (set_class(params))
 		device_found = TRUE;
 
+	set_oob_data(adapter, params);
+
 	if (device_found)
 		emit_device_found(adapter_get_path(adapter), params);
 }
-- 
1.7.4.1


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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-11 11:14 [PATCH BlueZ 1/3] Add SetRemoteProperties method for OOB COD setting Bartosz Szatkowski
2011-08-11 11:14 ` Bartosz Szatkowski [this message]
2011-08-11 11:14 ` [PATCH BlueZ 3/3] Add support for name in OOB SetRemoteProperties Bartosz Szatkowski
2011-08-11 16:51 ` [PATCH BlueZ 1/3] Add SetRemoteProperties method for OOB COD setting Vinicius Costa Gomes
2011-08-11 19:16   ` Bartosz Szatkowski
2011-08-12  7:15     ` [PATCH " Bartosz Szatkowski
2011-08-22  7:22       ` Johan Hedberg
2011-08-22  8:12         ` 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=1313061297-16884-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.