| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ | 5 #ifndef CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ |
| 6 #define CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ | 6 #define CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
| 13 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
| 14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 // BluetoothAgentServiceProvider is used to provide a D-Bus object that BlueZ | 18 // ExperimentalBluetoothAgentServiceProvider is used to provide a D-Bus object |
| 19 // can communicate with during a remote device pairing request. | 19 // that BlueZ can communicate with during a remote device pairing request. |
| 20 // | 20 // |
| 21 // Instantiate with a chosen D-Bus object path and delegate object, and pass | 21 // Instantiate with a chosen D-Bus object path and delegate object, and pass |
| 22 // the D-Bus object path as the |agent_path| argument to the | 22 // the D-Bus object path as the |agent_path| argument to the |
| 23 // chromeos::BluetoothAdapterClient::CreatePairedDevice() method. Calls made | 23 // chromeos::ExperimentalBluetoothAgentManagerClient::RegisterAgent() method. |
| 24 // to the agent by the Bluetooth daemon will be passed on to your Delegate | 24 // |
| 25 // object for handling, and responses returned using the callbacks supplied | 25 // After initiating the pairing process with a device, using the |
| 26 // to those methods. | 26 // chromeos::ExperimentalBluetoothDeviceClient::Pair() method, the Bluetooth |
| 27 class CHROMEOS_EXPORT BluetoothAgentServiceProvider { | 27 // daemon will make calls to this agent object and they will be passed on to |
| 28 // your Delegate object for handling. Responses should be returned using the |
| 29 // callbacks supplied to those methods. |
| 30 class CHROMEOS_EXPORT ExperimentalBluetoothAgentServiceProvider { |
| 28 public: | 31 public: |
| 29 // Interface for reacting to agent requests. | 32 // Interface for reacting to agent requests. |
| 30 class Delegate { | 33 class Delegate { |
| 31 public: | 34 public: |
| 32 virtual ~Delegate() {} | 35 virtual ~Delegate() {} |
| 33 | 36 |
| 34 // Possible status values that may be returned to callbacks. Success | 37 // Possible status values that may be returned to callbacks. Success |
| 35 // indicates that a pincode or passkey has been obtained, or permission | 38 // indicates that a pincode or passkey has been obtained, or permission |
| 36 // granted; rejected indicates the user rejected the request or denied | 39 // granted; rejected indicates the user rejected the request or denied |
| 37 // permission; cancelled indicates the user cancelled the request | 40 // permission; cancelled indicates the user cancelled the request |
| 38 // without confirming either way. | 41 // without confirming either way. |
| 39 enum Status { | 42 enum Status { |
| 40 SUCCESS, | 43 SUCCESS, |
| 41 REJECTED, | 44 REJECTED, |
| 42 CANCELLED | 45 CANCELLED |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 // Possible values for the |mode| parameter of the ConfirmModeChange() | |
| 46 // method. Off indicates that the adapter is to be turned off, connectable | |
| 47 // indicates that the adapter is to be turned on and accept incoming | |
| 48 // connections, and discoverable indicates the adapter is to be turned | |
| 49 // on and discoverable by remote devices. | |
| 50 enum Mode { | |
| 51 OFF, | |
| 52 CONNECTABLE, | |
| 53 DISCOVERABLE | |
| 54 }; | |
| 55 | |
| 56 // The PinCodeCallback is used for the RequestPinCode() method, it should | 48 // The PinCodeCallback is used for the RequestPinCode() method, it should |
| 57 // be called with two arguments, the |status| of the request (success, | 49 // be called with two arguments, the |status| of the request (success, |
| 58 // rejected or cancelled) and the |pincode| requested. | 50 // rejected or cancelled) and the |pincode| requested. |
| 59 typedef base::Callback<void(Status, const std::string&)> PinCodeCallback; | 51 typedef base::Callback<void(Status, const std::string&)> PinCodeCallback; |
| 60 | 52 |
| 61 // The PasskeyCallback is used for the RequestPasskey() method, it should | 53 // The PasskeyCallback is used for the RequestPasskey() method, it should |
| 62 // be called with two arguments, the |status| of the request (success, | 54 // be called with two arguments, the |status| of the request (success, |
| 63 // rejected or cancelled) and the |passkey| requested, a numeric in the | 55 // rejected or cancelled) and the |passkey| requested, a numeric in the |
| 64 // range 0-999999, | 56 // range 0-999999, |
| 65 typedef base::Callback<void(Status, uint32)> PasskeyCallback; | 57 typedef base::Callback<void(Status, uint32)> PasskeyCallback; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 // This method will be called when the Bluetooth daemon requires a | 69 // This method will be called when the Bluetooth daemon requires a |
| 78 // PIN Code for authentication of the device with object path |device_path|, | 70 // PIN Code for authentication of the device with object path |device_path|, |
| 79 // the agent should obtain the code from the user and call |callback| | 71 // the agent should obtain the code from the user and call |callback| |
| 80 // to provide it, or indicate rejection or cancellation of the request. | 72 // to provide it, or indicate rejection or cancellation of the request. |
| 81 // | 73 // |
| 82 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | 74 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| 83 // for which there is no automatic pairing or special handling. | 75 // for which there is no automatic pairing or special handling. |
| 84 virtual void RequestPinCode(const dbus::ObjectPath& device_path, | 76 virtual void RequestPinCode(const dbus::ObjectPath& device_path, |
| 85 const PinCodeCallback& callback) = 0; | 77 const PinCodeCallback& callback) = 0; |
| 86 | 78 |
| 87 // This method will be called when the Bluetooth daemon requires a | |
| 88 // Passkey for authentication of the device with object path |device_path|, | |
| 89 // the agent should obtain the passkey from the user (a numeric in the | |
| 90 // range 0-999999) and call |callback| to provide it, or indicate | |
| 91 // rejection or cancellation of the request. | |
| 92 // | |
| 93 // Passkeys are generally required for Bluetooth 2.1 and later devices | |
| 94 // which cannot provide input or display on their own, and don't accept | |
| 95 // passkey-less pairing. | |
| 96 virtual void RequestPasskey(const dbus::ObjectPath& device_path, | |
| 97 const PasskeyCallback& callback) = 0; | |
| 98 | |
| 99 // This method will be called when the Bluetooth daemon requires that the | 79 // This method will be called when the Bluetooth daemon requires that the |
| 100 // user enter the PIN code |pincode| into the device with object path | 80 // user enter the PIN code |pincode| into the device with object path |
| 101 // |device_path| so that it may be authenticated. The Cancel() method | 81 // |device_path| so that it may be authenticated. The Cancel() method |
| 102 // will be called to dismiss the display once pairing is complete or | 82 // will be called to dismiss the display once pairing is complete or |
| 103 // cancelled. | 83 // cancelled. |
| 104 // | 84 // |
| 105 // This is used for Bluetooth 2.0 and earlier keyboard devices, the | 85 // This is used for Bluetooth 2.0 and earlier keyboard devices, the |
| 106 // |pincode| will always be a six-digit numeric in the range 000000-999999 | 86 // |pincode| will always be a six-digit numeric in the range 000000-999999 |
| 107 // for compatibilty with later specifications. | 87 // for compatibilty with later specifications. |
| 108 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, | 88 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, |
| 109 const std::string& pincode) = 0; | 89 const std::string& pincode) = 0; |
| 110 | 90 |
| 91 // This method will be called when the Bluetooth daemon requires a |
| 92 // Passkey for authentication of the device with object path |device_path|, |
| 93 // the agent should obtain the passkey from the user (a numeric in the |
| 94 // range 0-999999) and call |callback| to provide it, or indicate |
| 95 // rejection or cancellation of the request. |
| 96 // |
| 97 // Passkeys are generally required for Bluetooth 2.1 and later devices |
| 98 // which cannot provide input or display on their own, and don't accept |
| 99 // passkey-less pairing. |
| 100 virtual void RequestPasskey(const dbus::ObjectPath& device_path, |
| 101 const PasskeyCallback& callback) = 0; |
| 102 |
| 111 // This method will be called when the Bluetooth daemon requires that the | 103 // This method will be called when the Bluetooth daemon requires that the |
| 112 // user enter the Passkey |passkey| into the device with object path | 104 // user enter the Passkey |passkey| into the device with object path |
| 113 // |device_path| so that it may be authenticated. The Cancel() method | 105 // |device_path| so that it may be authenticated. The Cancel() method |
| 114 // will be called to dismiss the display once pairing is complete or | 106 // will be called to dismiss the display once pairing is complete or |
| 115 // cancelled. | 107 // cancelled. |
| 116 // | 108 // |
| 117 // This is used for Bluetooth 2.1 and later devices that support input | 109 // This is used for Bluetooth 2.1 and later devices that support input |
| 118 // but not display, such as keyboards. The Passkey is a numeric in the | 110 // but not display, such as keyboards. The Passkey is a numeric in the |
| 119 // range 0-999999 and should be always presented zero-padded to six | 111 // range 0-999999 and should be always presented zero-padded to six |
| 120 // digits. | 112 // digits. |
| 113 // |
| 114 // As the user enters the passkey onto the device, |entered| will be |
| 115 // updated to reflect the number of digits entered so far. |
| 121 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, | 116 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, |
| 122 uint32 passkey) = 0; | 117 uint32 passkey, int16 entered) = 0; |
| 123 | 118 |
| 124 // This method will be called when the Bluetooth daemon requires that the | 119 // This method will be called when the Bluetooth daemon requires that the |
| 125 // user confirm that the Passkey |passkey| is displayed on the screen | 120 // user confirm that the Passkey |passkey| is displayed on the screen |
| 126 // of the device with object path |object_path| so that it may be | 121 // of the device with object path |object_path| so that it may be |
| 127 // authenticated. The agent should display to the user and ask for | 122 // authenticated. The agent should display to the user and ask for |
| 128 // confirmation, then call |callback| to provide their response (success, | 123 // confirmation, then call |callback| to provide their response (success, |
| 129 // rejected or cancelled). | 124 // rejected or cancelled). |
| 130 // | 125 // |
| 131 // This is used for Bluetooth 2.1 and later devices that support display, | 126 // This is used for Bluetooth 2.1 and later devices that support display, |
| 132 // such as other computers or phones. The Passkey is a numeric in the | 127 // such as other computers or phones. The Passkey is a numeric in the |
| 133 // range 0-999999 and should be always present zero-padded to six | 128 // range 0-999999 and should be always present zero-padded to six |
| 134 // digits. | 129 // digits. |
| 135 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, | 130 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, |
| 136 uint32 passkey, | 131 uint32 passkey, |
| 137 const ConfirmationCallback& callback) = 0; | 132 const ConfirmationCallback& callback) = 0; |
| 138 | 133 |
| 134 // This method will be called when the Bluetooth daemon requires |
| 135 // authorization of an incoming pairing attempt from the device with object |
| 136 // path |device_path| that would have otherwised triggered the just-works |
| 137 // pairing model. |
| 138 // |
| 139 // The agent should confirm the incoming pairing with the user and call |
| 140 // |callback| to provide their response (success, rejected or cancelled). |
| 141 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, |
| 142 const ConfirmationCallback& callback) = 0; |
| 143 |
| 139 // This method will be called when the Bluetooth daemon requires that the | 144 // This method will be called when the Bluetooth daemon requires that the |
| 140 // user confirm that the device with object path |object_path| is | 145 // user confirm that the device with object path |object_path| is |
| 141 // authorized to connect to the service with UUID |uuid|. The agent should | 146 // authorized to connect to the service with UUID |uuid|. The agent should |
| 142 // confirm with the user and call |callback| to provide their response | 147 // confirm with the user and call |callback| to provide their response |
| 143 // (success, rejected or cancelled). | 148 // (success, rejected or cancelled). |
| 144 virtual void Authorize(const dbus::ObjectPath& device_path, | 149 virtual void AuthorizeService(const dbus::ObjectPath& device_path, |
| 145 const std::string& uuid, | 150 const std::string& uuid, |
| 146 const ConfirmationCallback& callback) = 0; | 151 const ConfirmationCallback& callback) = 0; |
| 147 | |
| 148 // This method will be called when the Bluetooth daemon requires that the | |
| 149 // user confirm that the device adapter may switch to mode |mode|. The | |
| 150 // agent should confirm with the user and call |callback| to provide | |
| 151 // their response (success, rejected or cancelled). | |
| 152 virtual void ConfirmModeChange(Mode mode, | |
| 153 const ConfirmationCallback& callback) = 0; | |
| 154 | 152 |
| 155 // This method will be called by the Bluetooth daemon to indicate that | 153 // This method will be called by the Bluetooth daemon to indicate that |
| 156 // the request failed before a reply was returned from the device. | 154 // the request failed before a reply was returned from the device. |
| 157 virtual void Cancel() = 0; | 155 virtual void Cancel() = 0; |
| 158 }; | 156 }; |
| 159 | 157 |
| 160 virtual ~BluetoothAgentServiceProvider(); | 158 virtual ~ExperimentalBluetoothAgentServiceProvider(); |
| 161 | 159 |
| 162 // Creates the instance where |bus| is the D-Bus bus connection to export | 160 // Creates the instance where |bus| is the D-Bus bus connection to export |
| 163 // the object onto, |object_path| is the object path that it should have | 161 // the object onto, |object_path| is the object path that it should have |
| 164 // and |delegate| is the object to which all method calls will be passed | 162 // and |delegate| is the object to which all method calls will be passed |
| 165 // and responses generated from. | 163 // and responses generated from. |
| 166 static BluetoothAgentServiceProvider* Create( | 164 static ExperimentalBluetoothAgentServiceProvider* Create( |
| 167 dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate); | 165 dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate); |
| 168 | 166 |
| 169 protected: | 167 protected: |
| 170 BluetoothAgentServiceProvider(); | 168 ExperimentalBluetoothAgentServiceProvider(); |
| 171 | 169 |
| 172 private: | 170 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProvider); | 171 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAgentServiceProvider); |
| 174 }; | 172 }; |
| 175 | 173 |
| 176 } // namespace chromeos | 174 } // namespace chromeos |
| 177 | 175 |
| 178 #endif // CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ | 176 #endif // CHROMEOS_DBUS_EXPERIMENTAL_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ |
| OLD | NEW |