Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: chromeos/dbus/bluetooth_adapter_client.cc

Issue 10546010: Implement support for the OOB Pairing APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/dbus/bluetooth_adapter_client.cc
diff --git a/chromeos/dbus/bluetooth_adapter_client.cc b/chromeos/dbus/bluetooth_adapter_client.cc
index 566d470f3248b3ababc78ed3e0ca4fa5da6def9d..97ea873cdd705b58dd013bcd243c73b726983285 100644
--- a/chromeos/dbus/bluetooth_adapter_client.cc
+++ b/chromeos/dbus/bluetooth_adapter_client.cc
@@ -5,12 +5,14 @@
#include "chromeos/dbus/bluetooth_adapter_client.h"
#include <map>
+#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "chromeos/dbus/bluetooth_device_client.h"
#include "chromeos/dbus/bluetooth_manager_client.h"
+#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
#include "chromeos/dbus/bluetooth_property.h"
#include "dbus/bus.h"
#include "dbus/message.h"
@@ -298,6 +300,67 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient,
weak_ptr_factory_.GetWeakPtr(), object_path, callback));
}
+ // BluetoothAdapterClient override.
+ virtual void ReadLocalOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const OutOfBandPairingDataCallback& callback) {
+ dbus::MethodCall method_call(
+ bluetooth_outofband::kBluetoothOutOfBandInterface,
+ bluetooth_outofband::kReadLocalData);
+
+ dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
+
+ object_proxy->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BluetoothAdapterClientImpl::OnReadLocalData,
+ weak_ptr_factory_.GetWeakPtr(), object_path, callback));
+ }
+
+ // BluetoothAdapterClient override.
+ virtual void AddRemoteOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const std::string& address,
+ const OutOfBandPairingData& data,
+ const AdapterCallback& callback) {
+ dbus::MethodCall method_call(
+ bluetooth_outofband::kBluetoothOutOfBandInterface,
+ bluetooth_outofband::kAddRemoteData);
+
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(address);
+ writer.AppendArrayOfBytes(data.hash, kOutOfBandPairingDataSize);
+ writer.AppendArrayOfBytes(data.randomizer, kOutOfBandPairingDataSize);
+
+ dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
+
+ object_proxy->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BluetoothAdapterClientImpl::ResponseToAdapterCallback,
+ weak_ptr_factory_.GetWeakPtr(), object_path, callback));
+ }
+
+ virtual void RemoveRemoteOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const std::string& address,
+ const AdapterCallback& callback) {
+ dbus::MethodCall method_call(
+ bluetooth_outofband::kBluetoothOutOfBandInterface,
+ bluetooth_outofband::kRemoveRemoteData);
+
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(address);
+
+ dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
+
+ object_proxy->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BluetoothAdapterClientImpl::ResponseToAdapterCallback,
+ weak_ptr_factory_.GetWeakPtr(), object_path, callback));
+ }
+
private:
// We maintain a collection of dbus object proxies and properties structures
// for each adapter.
@@ -607,6 +670,39 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient,
callback.Run(device_path, success);
}
+ // Called when a response from ReadLocalOutOfBandPairingData() is received.
+ void OnReadLocalData(const dbus::ObjectPath& object_path,
+ const OutOfBandPairingDataCallback& callback,
+ dbus::Response* response) {
+ bool success = false;
+ OutOfBandPairingData data;
+ if (response != NULL) {
+ dbus::MessageReader reader(response);
+ uint8_t* bytes;
+ size_t length = kOutOfBandPairingDataSize;
+ if (reader.PopArrayOfBytes(&bytes, &length)) {
+ if (length == kOutOfBandPairingDataSize) {
+ memcpy(&data.hash, bytes, length);
+ if (reader.PopArrayOfBytes(&bytes, &length)) {
+ if (length == kOutOfBandPairingDataSize) {
+ memcpy(&data.randomizer, bytes, length);
+ success = true;
+ }
+ }
+ }
+ }
+ }
+ callback.Run(data, success);
+ }
+
+ // Translates a dbus::Response to an AdapterCallback by calling |callback|
+ // with |object_path| and assuming success if |response| is not NULL.
+ void ResponseToAdapterCallback(const dbus::ObjectPath& object_path,
+ const AdapterCallback& callback,
+ dbus::Response* response) {
+ callback.Run(object_path, response != NULL);
+ }
+
// Called when a response for CreatePairedDevice() is received.
void OnCreatePairedDevice(const dbus::ObjectPath& object_path,
const DeviceCallback& callback,
@@ -788,6 +884,31 @@ class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient {
<< " " << agent_path.value();
callback.Run(object_path, false);
}
+
+ virtual void ReadLocalOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const OutOfBandPairingDataCallback& callback) {
+ VLOG(1) << "ReadLocalOutOfBandPairingData: " << object_path.value();
+ OutOfBandPairingData data;
+ callback.Run(data, false);
+ }
+
+ virtual void AddRemoteOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const std::string& address,
+ const OutOfBandPairingData& data,
+ const AdapterCallback& callback) {
+ VLOG(1) << "AddRemoteData: " << object_path.value();
+ callback.Run(object_path, false);
+ }
+
+ virtual void RemoveRemoteOutOfBandPairingData(
+ const dbus::ObjectPath& object_path,
+ const std::string& address,
+ const AdapterCallback& callback) {
+ VLOG(1) << "RemoveRemoteData: " << object_path.value();
+ callback.Run(object_path, false);
+ }
};
BluetoothAdapterClient::BluetoothAdapterClient() {

Powered by Google App Engine
This is Rietveld 408576698