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