• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/dbus/dbus_client.h"
13 #include "chromeos/dbus/dbus_method_call_status.h"
14 #include "chromeos/dbus/shill_client_helper.h"
15 
16 namespace dbus {
17 class ObjectPath;
18 }
19 
20 namespace net {
21 class IPEndPoint;
22 }
23 
24 namespace chromeos {
25 
26 class ShillPropertyChangedObserver;
27 
28 // ShillManagerClient is used to communicate with the Shill Manager
29 // service.  All methods should be called from the origin thread which
30 // initializes the DBusThreadManager instance.
31 class CHROMEOS_EXPORT ShillManagerClient : public DBusClient {
32  public:
33   typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler;
34   typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback;
35   typedef ShillClientHelper::ErrorCallback ErrorCallback;
36   typedef ShillClientHelper::StringCallback StringCallback;
37   typedef ShillClientHelper::BooleanCallback BooleanCallback;
38 
39   // Interface for setting up devices, services, and technologies for testing.
40   // Accessed through GetTestInterface(), only implemented in the Stub Impl.
41   class TestInterface {
42    public:
43     virtual void AddDevice(const std::string& device_path) = 0;
44     virtual void RemoveDevice(const std::string& device_path) = 0;
45     virtual void ClearDevices() = 0;
46     virtual void AddTechnology(const std::string& type, bool enabled) = 0;
47     virtual void RemoveTechnology(const std::string& type) = 0;
48     virtual void SetTechnologyInitializing(const std::string& type,
49                                            bool initializing) = 0;
50     virtual void AddGeoNetwork(const std::string& technology,
51                                const base::DictionaryValue& network) = 0;
52 
53     // Does not create an actual profile in the ProfileClient but update the
54     // profiles list and sends a notification to observers. This should only be
55     // called by the ProfileStub. In all other cases, use
56     // ShillProfileClient::TestInterface::AddProfile.
57     virtual void AddProfile(const std::string& profile_path) = 0;
58 
59     // Used to reset all properties; does not notify observers.
60     virtual void ClearProperties() = 0;
61 
62     // Set manager property.
63     virtual void SetManagerProperty(const std::string& key,
64                                     const base::Value& value) = 0;
65 
66     // Modify services in the Manager's list.
67     virtual void AddManagerService(const std::string& service_path,
68                                    bool notify_observers) = 0;
69     virtual void RemoveManagerService(const std::string& service_path) = 0;
70     virtual void ClearManagerServices() = 0;
71 
72     // Called by ShillServiceClient when a service's State property changes,
73     // before notifying observers. Sets the DefaultService property to empty
74     // if the state changes to a non-connected state.
75     virtual void ServiceStateChanged(const std::string& service_path,
76                                      const std::string& state) = 0;
77 
78     // Called by ShillServiceClient when a service's State or Visibile
79     // property changes. If |notify| is true, notifies observers if a list
80     // changed. Services are sorted first by active, inactive, or disabled
81     // state, then by type.
82     virtual void SortManagerServices(bool notify) = 0;
83 
84     // Sets up the default fake environment based on default initial states
85     // or states provided by the command line.
86     virtual void SetupDefaultEnvironment() = 0;
87 
88     // Returns the interactive delay specified on the command line, 0 for none.
89     virtual int GetInteractiveDelay() const = 0;
90 
91     // Sets the 'best' service to connect to on a ConnectToBestServices call.
92     virtual void SetBestServiceToConnect(const std::string& service_path) = 0;
93 
94    protected:
~TestInterface()95     virtual ~TestInterface() {}
96   };
97 
98   // Properties used to verify the origin device.
99   struct VerificationProperties {
100     VerificationProperties();
101     ~VerificationProperties();
102 
103     // A string containing a PEM-encoded X.509 certificate for use in verifying
104     // the signed data.
105     std::string certificate;
106 
107     // A string containing a PEM-encoded RSA public key to be used to compare
108     // with the one in signedData
109     std::string public_key;
110 
111     // A string containing a base64-encoded random binary data for use in
112     // verifying the signed data.
113     std::string nonce;
114 
115     // A string containing the identifying data string signed by the device.
116     std::string signed_data;
117 
118     // A string containing the serial number of the device.
119     std::string device_serial;
120 
121     // A string containing the SSID of the device. Only set if the device has
122     // already been setup once.
123     std::string device_ssid;
124 
125     // A string containing the BSSID of the device. Only set if the device has
126     // already been setup.
127     std::string device_bssid;
128   };
129 
130   virtual ~ShillManagerClient();
131 
132   // Factory function, creates a new instance which is owned by the caller.
133   // For normal usage, access the singleton via DBusThreadManager::Get().
134   static ShillManagerClient* Create();
135 
136   // Adds a property changed |observer|.
137   virtual void AddPropertyChangedObserver(
138       ShillPropertyChangedObserver* observer) = 0;
139 
140   // Removes a property changed |observer|.
141   virtual void RemovePropertyChangedObserver(
142       ShillPropertyChangedObserver* observer) = 0;
143 
144   // Calls GetProperties method.
145   // |callback| is called after the method call succeeds.
146   virtual void GetProperties(const DictionaryValueCallback& callback) = 0;
147 
148   // Calls GetNetworksForGeolocation method.
149   // |callback| is called after the method call succeeds.
150   virtual void GetNetworksForGeolocation(
151       const DictionaryValueCallback& callback) = 0;
152 
153   // Calls SetProperty method.
154   // |callback| is called after the method call succeeds.
155   virtual void SetProperty(const std::string& name,
156                            const base::Value& value,
157                            const base::Closure& callback,
158                            const ErrorCallback& error_callback) = 0;
159 
160   // Calls RequestScan method.
161   // |callback| is called after the method call succeeds.
162   virtual void RequestScan(const std::string& type,
163                            const base::Closure& callback,
164                            const ErrorCallback& error_callback) = 0;
165 
166   // Calls EnableTechnology method.
167   // |callback| is called after the method call succeeds.
168   virtual void EnableTechnology(const std::string& type,
169                                 const base::Closure& callback,
170                                 const ErrorCallback& error_callback) = 0;
171 
172   // Calls DisableTechnology method.
173   // |callback| is called after the method call succeeds.
174   virtual void DisableTechnology(const std::string& type,
175                                  const base::Closure& callback,
176                                  const ErrorCallback& error_callback) = 0;
177 
178   // Calls ConfigureService method.
179   // |callback| is called after the method call succeeds.
180   virtual void ConfigureService(const base::DictionaryValue& properties,
181                                 const ObjectPathCallback& callback,
182                                 const ErrorCallback& error_callback) = 0;
183 
184   // Calls ConfigureServiceForProfile method.
185   // |callback| is called with the created service if the method call succeeds.
186   virtual void ConfigureServiceForProfile(
187       const dbus::ObjectPath& profile_path,
188       const base::DictionaryValue& properties,
189       const ObjectPathCallback& callback,
190       const ErrorCallback& error_callback) = 0;
191 
192   // Calls GetService method.
193   // |callback| is called after the method call succeeds.
194   virtual void GetService(const base::DictionaryValue& properties,
195                           const ObjectPathCallback& callback,
196                           const ErrorCallback& error_callback) = 0;
197 
198   // Verifies that the given data corresponds to a trusted device, and returns
199   // true to the callback if it is.
200   virtual void VerifyDestination(const VerificationProperties& properties,
201                                  const BooleanCallback& callback,
202                                  const ErrorCallback& error_callback) = 0;
203 
204   // Verifies that the given data corresponds to a trusted device, and if it is,
205   // returns the encrypted credentials for connecting to the network represented
206   // by the given |service_path|, encrypted using the |public_key| for the
207   // trusted device. If the device is not trusted, returns the empty string.
208   virtual void VerifyAndEncryptCredentials(
209       const VerificationProperties& properties,
210       const std::string& service_path,
211       const StringCallback& callback,
212       const ErrorCallback& error_callback) = 0;
213 
214   // Verifies that the given data corresponds to a trusted device, and returns
215   // the |data| encrypted using the |public_key| for the trusted device. If the
216   // device is not trusted, returns the empty string.
217   virtual void VerifyAndEncryptData(const VerificationProperties& properties,
218                                     const std::string& data,
219                                     const StringCallback& callback,
220                                     const ErrorCallback& error_callback) = 0;
221 
222   // For each technology present, connects to the "best" service available.
223   // Called once the user is logged in and certificates are loaded.
224   virtual void ConnectToBestServices(const base::Closure& callback,
225                                      const ErrorCallback& error_callback) = 0;
226 
227   // Requests that shill program the NIC so that packets incoming on
228   // |ip_connection| wake up the CPU.
229   virtual void AddWakeOnPacketConnection(
230       const net::IPEndPoint& ip_endpoint,
231       const base::Closure& callback,
232       const ErrorCallback& error_callback) = 0;
233 
234   // Removes a request to wake up on packets coming on |ip_connection|.
235   virtual void RemoveWakeOnPacketConnection(
236       const net::IPEndPoint& ip_endpoint,
237       const base::Closure& callback,
238       const ErrorCallback& error_callback) = 0;
239 
240   // Clears all requests to wake up on packets.
241   virtual void RemoveAllWakeOnPacketConnections(
242       const base::Closure& callback,
243       const ErrorCallback& error_callback) = 0;
244 
245   // Returns an interface for testing (stub only), or returns NULL.
246   virtual TestInterface* GetTestInterface() = 0;
247 
248  protected:
249   friend class ShillManagerClientTest;
250 
251   // Create() should be used instead.
252   ShillManagerClient();
253 
254  private:
255   DISALLOW_COPY_AND_ASSIGN(ShillManagerClient);
256 };
257 
258 }  // namespace chromeos
259 
260 #endif  // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_
261