| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_BLUEZ_H_ | |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_BLUEZ_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "device/bluetooth/bluetooth_device.h" | |
| 12 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" | |
| 13 | |
| 14 namespace bluez { | |
| 15 | |
| 16 class BluetoothDeviceBlueZ; | |
| 17 | |
| 18 // The BluetoothPairingBlueZ class encapsulates the logic for an individual | |
| 19 // device pairing, acting as a bridge between BluetoothAdapterBlueZ which | |
| 20 // communicates with the underlying Controller and Host Subsystem, and | |
| 21 // BluetoothDeviceBlueZ which presents the pairing logic to the application. | |
| 22 class BluetoothPairingBlueZ { | |
| 23 public: | |
| 24 BluetoothPairingBlueZ( | |
| 25 BluetoothDeviceBlueZ* device, | |
| 26 device::BluetoothDevice::PairingDelegate* pairing_delegate); | |
| 27 ~BluetoothPairingBlueZ(); | |
| 28 | |
| 29 // Indicates whether the device is currently pairing and expecting a | |
| 30 // Passkey to be returned. | |
| 31 bool ExpectingPasskey() const; | |
| 32 | |
| 33 // Indicates whether the device is currently pairing and expecting | |
| 34 // confirmation of a displayed passkey. | |
| 35 bool ExpectingConfirmation() const; | |
| 36 | |
| 37 // Requests a PIN code for the current device from the current pairing | |
| 38 // delegate, the SetPinCode(), RejectPairing() and CancelPairing() method | |
| 39 // calls on this object are translated into the appropriate response to | |
| 40 // |callback|. | |
| 41 void RequestPinCode( | |
| 42 const bluez::BluetoothAgentServiceProvider::Delegate::PinCodeCallback& | |
| 43 callback); | |
| 44 | |
| 45 // Indicates whether the device is currently pairing and expecting a | |
| 46 // PIN Code to be returned. | |
| 47 bool ExpectingPinCode() const; | |
| 48 | |
| 49 // Sends the PIN code |pincode| to the remote device during pairing. | |
| 50 // | |
| 51 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | |
| 52 // for which there is no automatic pairing or special handling. | |
| 53 void SetPinCode(const std::string& pincode); | |
| 54 | |
| 55 // Requests a PIN code for the current device be displayed by the current | |
| 56 // pairing delegate. No response is expected from the delegate. | |
| 57 void DisplayPinCode(const std::string& pincode); | |
| 58 | |
| 59 // Requests a Passkey for the current device from the current pairing | |
| 60 // delegate, the SetPasskey(), RejectPairing() and CancelPairing() method | |
| 61 // calls on this object are translated into the appropriate response to | |
| 62 // |callback|. | |
| 63 void RequestPasskey( | |
| 64 const bluez::BluetoothAgentServiceProvider::Delegate::PasskeyCallback& | |
| 65 callback); | |
| 66 | |
| 67 // Sends the Passkey |passkey| to the remote device during pairing. | |
| 68 // | |
| 69 // Passkeys are generally required for Bluetooth 2.1 and later devices | |
| 70 // which cannot provide input or display on their own, and don't accept | |
| 71 // passkey-less pairing, and are a numeric in the range 0-999999. | |
| 72 void SetPasskey(uint32_t passkey); | |
| 73 | |
| 74 // Requests a Passkey for the current device be displayed by the current | |
| 75 // pairing delegate. No response is expected from the delegate. | |
| 76 void DisplayPasskey(uint32_t passkey); | |
| 77 | |
| 78 // Informs the current pairing delegate that |entered| keys have been | |
| 79 // provided to the remote device since the DisplayPasskey() call. No | |
| 80 // response is expected from the delegate. | |
| 81 void KeysEntered(uint16_t entered); | |
| 82 | |
| 83 // Requests confirmation that |passkey| is displayed on the current device | |
| 84 // from the current pairing delegate. The ConfirmPairing(), RejectPairing() | |
| 85 // and CancelPairing() method calls on this object are translated into the | |
| 86 // appropriate response to |callback|. | |
| 87 void RequestConfirmation(uint32_t passkey, | |
| 88 const bluez::BluetoothAgentServiceProvider:: | |
| 89 Delegate::ConfirmationCallback& callback); | |
| 90 | |
| 91 // Requests authorization that the current device be allowed to pair with | |
| 92 // this device from the current pairing delegate. The ConfirmPairing(), | |
| 93 // RejectPairing() and CancelPairing() method calls on this object are | |
| 94 // translated into the appropriate response to |callback|. | |
| 95 void RequestAuthorization(const bluez::BluetoothAgentServiceProvider:: | |
| 96 Delegate::ConfirmationCallback& callback); | |
| 97 | |
| 98 // Confirms to the remote device during pairing that a passkey provided by | |
| 99 // the ConfirmPasskey() delegate call is displayed on both devices. | |
| 100 void ConfirmPairing(); | |
| 101 | |
| 102 // Rejects a pairing or connection request from a remote device, returns | |
| 103 // false if there was no way to reject the pairing. | |
| 104 bool RejectPairing(); | |
| 105 | |
| 106 // Cancels a pairing or connection attempt to a remote device, returns | |
| 107 // false if there was no way to cancel the pairing. | |
| 108 bool CancelPairing(); | |
| 109 | |
| 110 // Returns the pairing delegate being used by this pairing object. | |
| 111 device::BluetoothDevice::PairingDelegate* GetPairingDelegate() const; | |
| 112 | |
| 113 private: | |
| 114 // Internal method to reset the current set of callbacks because a new | |
| 115 // request has arrived that supersedes them. | |
| 116 void ResetCallbacks(); | |
| 117 | |
| 118 // Internal method to respond to the relevant callback for a RejectPairing | |
| 119 // or CancelPairing call. | |
| 120 bool RunPairingCallbacks( | |
| 121 bluez::BluetoothAgentServiceProvider::Delegate::Status status); | |
| 122 | |
| 123 // The underlying BluetoothDeviceBlueZ that owns this pairing context. | |
| 124 BluetoothDeviceBlueZ* device_; | |
| 125 | |
| 126 // UI Pairing Delegate to make method calls on, this must live as long as | |
| 127 // the object capturing the PairingContext. | |
| 128 device::BluetoothDevice::PairingDelegate* pairing_delegate_; | |
| 129 | |
| 130 // Flag to indicate whether any pairing delegate method has been called | |
| 131 // during pairing. Used to determine whether we need to log the | |
| 132 // "no pairing interaction" metric. | |
| 133 bool pairing_delegate_used_; | |
| 134 | |
| 135 // During pairing these callbacks are set to those provided by method calls | |
| 136 // made on the BluetoothAdapterBlueZ instance by its respective | |
| 137 // bluez::BluetoothAgentServiceProvider instance, and are called by our own | |
| 138 // method calls such as SetPinCode() and SetPasskey(). | |
| 139 bluez::BluetoothAgentServiceProvider::Delegate::PinCodeCallback | |
| 140 pincode_callback_; | |
| 141 bluez::BluetoothAgentServiceProvider::Delegate::PasskeyCallback | |
| 142 passkey_callback_; | |
| 143 bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback | |
| 144 confirmation_callback_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingBlueZ); | |
| 147 }; | |
| 148 | |
| 149 } // namespace bluez | |
| 150 | |
| 151 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_BLUEZ_H_ | |
| OLD | NEW |