blob: 48ed2b2e95167100be512f4ffb0abb63a81dec9f [file] [log] [blame]
Darin Petkovc64fe5e2012-01-11 12:46:13 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkov2b8e44e2012-06-25 15:13:26 +02005#ifndef SHILL_DEVICE_H_
6#define SHILL_DEVICE_H_
Paul Stewart75897df2011-04-27 09:05:53 -07007
Chris Masone46eaaf52011-05-24 13:08:30 -07008#include <string>
Chris Masone9be4a9d2011-05-16 15:44:09 -07009#include <vector>
10
Chris Masone8fe2c7e2011-06-09 15:51:19 -070011#include <base/basictypes.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070012#include <base/memory/ref_counted.h>
Paul Stewartb50f0b92011-05-16 16:31:42 -070013#include <base/memory/scoped_ptr.h>
Eric Shienbrood9a245532012-03-07 14:20:39 -050014#include <base/memory/weak_ptr.h>
Darin Petkovafa6fc42011-06-21 16:21:08 -070015#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewartd5843772011-05-11 15:40:42 -070016
Eric Shienbrood9a245532012-03-07 14:20:39 -050017#include "shill/adaptor_interfaces.h"
18#include "shill/callbacks.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070019#include "shill/event_dispatcher.h"
Paul Stewart2bf1d352011-12-06 15:02:55 -080020#include "shill/ip_address.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070021#include "shill/ipconfig.h"
Paul Stewart20088d82012-02-16 06:58:55 -080022#include "shill/portal_detector.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070023#include "shill/property_store.h"
Chris Masone2b105542011-06-22 10:58:09 -070024#include "shill/refptr_types.h"
Paul Stewart03dba0b2011-08-22 16:32:45 -070025#include "shill/service.h"
Paul Stewartfdd16072011-09-16 12:41:35 -070026#include "shill/technology.h"
Paul Stewart75897df2011-04-27 09:05:53 -070027
28namespace shill {
29
Chris Masone9be4a9d2011-05-16 15:44:09 -070030class ControlInterface;
Darin Petkov77cb6812011-08-15 16:19:41 -070031class DHCPProvider;
Chris Masone9be4a9d2011-05-16 15:44:09 -070032class DeviceAdaptorInterface;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070033class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070034class Error;
35class EventDispatcher;
Paul Stewart036dba02012-08-07 12:34:41 -070036class LinkMonitor;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070037class Manager;
Thieu Le3426c8f2012-01-11 17:35:11 -080038class Metrics;
Thieu Lefb46caf2012-03-08 11:57:15 -080039class RTNLHandler;
Chris Masone9be4a9d2011-05-16 15:44:09 -070040
Paul Stewart75897df2011-04-27 09:05:53 -070041// Device superclass. Individual network interfaces types will inherit from
42// this class.
Chris Masone27c4aa52011-07-02 13:10:14 -070043class Device : public base::RefCounted<Device> {
Paul Stewart75897df2011-04-27 09:05:53 -070044 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070045 // A constructor for the Device object
46 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070047 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080048 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070049 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070050 const std::string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070051 const std::string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080052 int interface_index,
53 Technology::Identifier technology);
Chris Masone9be4a9d2011-05-16 15:44:09 -070054
Eric Shienbrood9a245532012-03-07 14:20:39 -050055 // Enable or disable the device.
56 virtual void SetEnabled(bool enable);
57 // Enable or disable the device, and save the setting in the profile.
58 // The setting is persisted before the enable or disable operation
59 // starts, so that even if it fails, the user's intent is still recorded
60 // for the next time shill restarts.
Jason Glasgowdf7c5532012-05-14 14:41:45 -040061 virtual void SetEnabledPersistent(bool enable,
62 Error *error,
63 const ResultCallback &callback);
Gaurav Shah435de2c2011-11-17 19:01:07 -080064
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040065 // Returns true if the underlying device reports that it is already enabled.
66 // Used when the device is registered with the Manager, so that shill can
67 // sync its state/ with the true state of the device. The default is to
68 // report false.
69 virtual bool IsUnderlyingDeviceEnabled() const;
70
Paul Stewartf1ce5d22011-05-19 13:10:20 -070071 virtual void LinkEvent(unsigned flags, unsigned change);
Paul Stewart75897df2011-04-27 09:05:53 -070072
Darin Petkov9ae310f2011-08-30 15:41:13 -070073 // The default implementation sets |error| to kNotSupported.
Darin Petkovc0865312011-09-16 15:31:20 -070074 virtual void Scan(Error *error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050075 virtual void RegisterOnNetwork(const std::string &network_id, Error *error,
76 const ResultCallback &callback);
77 virtual void RequirePIN(const std::string &pin, bool require,
78 Error *error, const ResultCallback &callback);
79 virtual void EnterPIN(const std::string &pin,
80 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070081 virtual void UnblockPIN(const std::string &unblock_code,
82 const std::string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050083 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070084 virtual void ChangePIN(const std::string &old_pin,
85 const std::string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050086 Error *error, const ResultCallback &callback);
Paul Stewart2bf1d352011-12-06 15:02:55 -080087 virtual void DisableIPv6();
88 virtual void EnableIPv6();
89 virtual void EnableIPv6Privacy();
Darin Petkov9ae310f2011-08-30 15:41:13 -070090
Paul Stewartc8f4bef2011-12-13 09:45:51 -080091 // Request the removal of reverse-path filtering for this interface.
92 // This will allow packets destined for this interface to be accepted,
93 // even if this is not the default route for such a packet to arrive.
94 virtual void DisableReversePathFilter();
95
96 // Request reverse-path filtering for this interface.
97 virtual void EnableReversePathFilter();
98
Gaurav Shah435de2c2011-11-17 19:01:07 -080099 // Returns true if the selected service on the device (if any) is connected.
100 // Returns false if there is no selected service, or if the selected service
101 // is not connected.
102 bool IsConnected() const;
103
Paul Stewartd215af62012-04-24 23:25:50 -0700104 // Returns true if the selected service on the device (if any) is connected
105 // and matches the passed-in argument |service|. Returns false if there is
106 // no connected service, or if it does not match |service|.
107 virtual bool IsConnectedToService(const ServiceRefPtr &service) const;
108
109 // Restart the portal detection process on a connected device. This is
110 // useful if the properties on the connected service have changed in a
111 // way that may affect the decision to run portal detection at all.
112 // Returns true if portal detection was started.
113 virtual bool RestartPortalDetection();
114
Paul Stewart6ff27f52012-07-11 06:51:41 -0700115 // Reset the persisted byte counters associated with the device.
116 void ResetByteCounters();
117
Paul Stewartc681fa02012-03-02 19:40:04 -0800118 // Requests that portal detection be done, if this device has the default
119 // connection. Returns true if portal detection was started.
120 virtual bool RequestPortalDetection();
121
Chris Masone27c4aa52011-07-02 13:10:14 -0700122 std::string GetRpcIdentifier();
Chris Masone5dec5f42011-07-22 14:07:55 -0700123 std::string GetStorageIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700124
Chris Masone9d779932011-08-25 16:33:41 -0700125 const std::string &address() const { return hardware_address_; }
Darin Petkove0a312e2011-07-20 13:45:28 -0700126 const std::string &link_name() const { return link_name_; }
127 int interface_index() const { return interface_index_; }
Paul Stewarte6132022011-08-16 09:11:02 -0700128 const ConnectionRefPtr &connection() const { return connection_; }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500129 bool enabled() const { return enabled_; }
130 bool enabled_persistent() const { return enabled_persistent_; }
Gaurav Shah435de2c2011-11-17 19:01:07 -0800131 virtual Technology::Identifier technology() const { return technology_; }
Jason Glasgowb5790052012-01-27 01:03:52 -0500132 std::string GetTechnologyString(Error *error);
Darin Petkove0a312e2011-07-20 13:45:28 -0700133
Darin Petkov31a2eca2012-03-14 11:07:18 +0100134 const IPConfigRefPtr &ipconfig() const { return ipconfig_; }
135 void set_ipconfig(const IPConfigRefPtr &config) { ipconfig_ = config; }
136
Chris Masone19e30402011-07-19 15:48:47 -0700137 const std::string &FriendlyName() const;
Chris Masone27c4aa52011-07-02 13:10:14 -0700138
Darin Petkovafa6fc42011-06-21 16:21:08 -0700139 // Returns a string that is guaranteed to uniquely identify this Device
140 // instance.
141 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -0700142
mukesh agrawalde29fa82011-09-16 16:16:36 -0700143 PropertyStore *mutable_store() { return &store_; }
144 const PropertyStore &store() const { return store_; }
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700145 RTNLHandler *rtnl_handler() { return rtnl_handler_; }
Chris Masone19e30402011-07-19 15:48:47 -0700146
Darin Petkovb05315f2011-11-07 10:14:25 +0100147 EventDispatcher *dispatcher() const { return dispatcher_; }
148
Paul Stewarta41e38d2011-11-11 07:47:29 -0800149 // Load configuration for the device from |storage|. This may include
150 // instantiating non-visible services for which configuration has been
151 // stored.
152 virtual bool Load(StoreInterface *storage);
153
154 // Save configuration for the device to |storage|.
Chris Masone877ff982011-09-21 16:18:24 -0700155 virtual bool Save(StoreInterface *storage);
Chris Masone5dec5f42011-07-22 14:07:55 -0700156
Darin Petkov77cb6812011-08-15 16:19:41 -0700157 void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; }
158
Darin Petkov3cfbf212011-11-21 16:02:09 +0100159 DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); }
160
mukesh agrawal784566d2012-08-08 18:32:58 -0700161 // Suspend event handler. Called by Manager before the system
162 // suspends. For this callback to be useful, the device must specify
163 // a suspend delay. Otherwise, there is no guarantee that the device
164 // will have time to complete its suspend actions, before the system
165 // is suspended.
166 //
167 // TODO(quiche): Add support for suspend delays. crosbug.com/33412
168 virtual void OnBeforeSuspend();
169
170 // Resume event handler. Called by Manager as the system resumes.
171 // The base class implementation takes care of renewing a DHCP lease
172 // (if necessary). Derived classes may implement any technology
173 // specific requirements by overriding, but should include a call to
174 // the base class implementation.
175 virtual void OnAfterResume();
176
Paul Stewartd5843772011-05-11 15:40:42 -0700177 protected:
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200178 friend class base::RefCounted<Device>;
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400179 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Darin Petkov13e6d552012-05-09 14:22:23 +0200180 FRIEND_TEST(ConnectionTest, OnRouteQueryResponse);
Paul Stewart2bf1d352011-12-06 15:02:55 -0800181 FRIEND_TEST(DeviceTest, AcquireIPConfig);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700182 FRIEND_TEST(DeviceTest, DestroyIPConfig);
183 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
Chris Masone95207da2011-06-29 16:50:49 -0700184 FRIEND_TEST(DeviceTest, GetProperties);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700185 FRIEND_TEST(DeviceTest, Load);
Chris Masone5dec5f42011-07-22 14:07:55 -0700186 FRIEND_TEST(DeviceTest, Save);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700187 FRIEND_TEST(DeviceTest, SelectedService);
Darin Petkove7c6ad32012-06-29 10:22:09 +0200188 FRIEND_TEST(DeviceTest, SetEnabledPersistent);
Paul Stewartc681fa02012-03-02 19:40:04 -0800189 FRIEND_TEST(DeviceTest, SetServiceConnectedState);
Paul Stewart8c116a92012-05-02 18:30:03 -0700190 FRIEND_TEST(DeviceTest, Start);
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700191 FRIEND_TEST(DeviceTest, Stop);
Paul Stewarta41e38d2011-11-11 07:47:29 -0800192 FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800193 FRIEND_TEST(ManagerTest, ConnectedTechnologies);
194 FRIEND_TEST(ManagerTest, DefaultTechnology);
Jason Glasgowdf7c5532012-05-14 14:41:45 -0400195 FRIEND_TEST(ManagerTest, EnableTechnology);
196 FRIEND_TEST(ManagerTest, DisableTechnology);
mukesh agrawal32399322011-09-01 10:53:43 -0700197 FRIEND_TEST(WiFiMainTest, Connect);
Darin Petkov3a4100c2012-06-14 11:36:59 +0200198 FRIEND_TEST(WiMaxTest, ConnectTimeout);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700199
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200200 virtual ~Device();
201
Eric Shienbrood9a245532012-03-07 14:20:39 -0500202 // Each device must implement this method to do the work needed to
203 // enable the device to operate for establishing network connections.
204 // The |error| argument, if not NULL,
205 // will refer to an Error that starts out with the value
206 // Error::kOperationInitiated. This reflects the assumption that
207 // enable (and disable) operations will usually be non-blocking,
208 // and their completion will be indicated by means of an asynchronous
209 // reply sometime later. There are two circumstances in which a
210 // device's Start() method may overwrite |error|:
211 //
212 // 1. If an early failure is detected, such that the non-blocking
213 // part of the operation never takes place, then |error| should
214 // be set to the appropriate value corresponding to the type
215 // of failure. This is the "immediate failure" case.
216 // 2. If the device is enabled without performing any non-blocking
217 // steps, then |error| should be Reset, i.e., its value set
218 // to Error::kSuccess. This is the "immediate success" case.
219 //
220 // In these two cases, because completion is immediate, |callback|
221 // is not used. If neither of these two conditions holds, then |error|
222 // should not be modified, and |callback| should be passed to the
223 // method that will initiate the non-blocking operation.
224 virtual void Start(Error *error,
225 const EnabledStateChangedCallback &callback) = 0;
226
227 // Each device must implement this method to do the work needed to
228 // disable the device, i.e., clear any running state, and make the
229 // device no longer capable of establishing network connections.
230 // The discussion for Start() regarding the use of |error| and
231 // |callback| apply to Stop() as well.
232 virtual void Stop(Error *error,
233 const EnabledStateChangedCallback &callback) = 0;
234
235 // The EnabledStateChangedCallback that gets passed to the device's
236 // Start() and Stop() methods is bound to this method. |callback|
237 // is the callback that was passed to SetEnabled().
238 void OnEnabledStateChanged(const ResultCallback &callback,
239 const Error &error);
240
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200241 // Drops the currently selected service along with its IP configuration and
242 // connection, if any.
243 void DropConnection();
244
Darin Petkovafa6fc42011-06-21 16:21:08 -0700245 // If there's an IP configuration in |ipconfig_|, releases the IP address and
246 // destroys the configuration instance.
247 void DestroyIPConfig();
248
249 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
Paul Stewartd408fdf2012-05-07 17:15:57 -0700250 // requests a new IP configuration. Saves the DHCP lease to the generic
251 // lease filename based on the interface name. Registers a callback to
Darin Petkovafa6fc42011-06-21 16:21:08 -0700252 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
253 // request was successfully sent.
Paul Stewart2bf1d352011-12-06 15:02:55 -0800254 bool AcquireIPConfig();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700255
Paul Stewartd408fdf2012-05-07 17:15:57 -0700256 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
257 // requests a new IP configuration. Saves the DHCP lease to a filename
258 // based on the passed-in |lease_name|. Registers a callback to
259 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
260 // request was successfully sent.
261 bool AcquireIPConfigWithLeaseName(const std::string &lease_name);
262
Darin Petkov79d74c92012-03-07 17:20:32 +0100263 // Callback invoked on every IP configuration update.
264 void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success);
265
Paul Stewarte6132022011-08-16 09:11:02 -0700266 // Maintain connection state (Routes, IP Addresses and DNS) in the OS.
267 void CreateConnection();
268
269 // Remove connection state
270 void DestroyConnection();
271
Paul Stewart03dba0b2011-08-22 16:32:45 -0700272 // Selects a service to be "current" -- i.e. link-state or configuration
273 // events that happen to the device are attributed to this service.
274 void SelectService(const ServiceRefPtr &service);
275
276 // Set the state of the selected service
277 void SetServiceState(Service::ConnectState state);
278
279 // Set the failure of the selected service (implicitly sets the state to
280 // "failure")
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400281
Paul Stewart03dba0b2011-08-22 16:32:45 -0700282 void SetServiceFailure(Service::ConnectFailure failure_state);
283
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400284 // Records the failure mode and time of the selected service, and
285 // sets the Service state of the selected service to "Idle".
286 // Avoids showing a failure mole in the UI.
287 void SetServiceFailureSilent(Service::ConnectFailure failure_state);
288
Paul Stewart20088d82012-02-16 06:58:55 -0800289 // Called by the Portal Detector whenever a trial completes. Device
290 // subclasses that choose unique mappings from portal results to connected
291 // states can override this method in order to do so.
292 virtual void PortalDetectorCallback(const PortalDetector::Result &result);
293
294 // Initiate portal detection, if enabled for this device type.
295 bool StartPortalDetection();
296
297 // Stop portal detection if it is running.
298 void StopPortalDetection();
299
Paul Stewart036dba02012-08-07 12:34:41 -0700300 // Initiate link monitoring, if enabled for this device type.
301 bool StartLinkMonitor();
302
303 // Stop link monitoring if it is running.
304 void StopLinkMonitor();
305
306 // Respond to a LinkMonitor failure in a Device-specific manner.
307 virtual void OnLinkMonitorFailure();
308
Paul Stewart20088d82012-02-16 06:58:55 -0800309 // Set the state of the selected service, with checks to make sure
310 // the service is already in a connected state before doing so.
311 void SetServiceConnectedState(Service::ConnectState state);
312
Darin Petkov9893d9c2012-05-17 15:27:31 -0700313 const ServiceRefPtr &selected_service() const { return selected_service_; }
314
Jason Glasgowb5790052012-01-27 01:03:52 -0500315 void HelpRegisterDerivedString(
316 const std::string &name,
317 std::string(Device::*get)(Error *),
318 void(Device::*set)(const std::string&, Error *));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500319
320 void HelpRegisterDerivedStrings(
321 const std::string &name,
322 Strings(Device::*get)(Error *error),
323 void(Device::*set)(const Strings &value, Error *error));
Chris Masoneb925cc82011-06-22 15:39:57 -0700324
Jason Glasgow08afdff2012-04-03 10:22:26 -0400325 void HelpRegisterConstDerivedRpcIdentifiers(
326 const std::string &name,
327 RpcIdentifiers(Device::*get)(Error *));
328
Paul Stewart6ff27f52012-07-11 06:51:41 -0700329 void HelpRegisterConstDerivedUint64(
330 const std::string &name,
331 uint64(Device::*get)(Error *));
332
Paul Stewartac4ac002011-08-26 12:04:26 -0700333 // Property getters reserved for subclasses
334 ControlInterface *control_interface() const { return control_interface_; }
Thieu Le3426c8f2012-01-11 17:35:11 -0800335 Metrics *metrics() const { return metrics_; }
Paul Stewartac4ac002011-08-26 12:04:26 -0700336 Manager *manager() const { return manager_; }
Paul Stewarta41e38d2011-11-11 07:47:29 -0800337 bool running() const { return running_; }
Paul Stewart036dba02012-08-07 12:34:41 -0700338 const LinkMonitor *link_monitor() const { return link_monitor_.get(); }
339 void set_link_monitor(LinkMonitor *link_monitor);
Paul Stewartd5843772011-05-11 15:40:42 -0700340
Paul Stewart75897df2011-04-27 09:05:53 -0700341 private:
Chris Masone413a3192011-05-09 17:10:05 -0700342 friend class DeviceAdaptorInterface;
Paul Stewart6ff27f52012-07-11 06:51:41 -0700343 friend class DeviceByteCountTest;
Paul Stewartc681fa02012-03-02 19:40:04 -0800344 friend class DevicePortalDetectionTest;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700345 friend class DeviceTest;
346 friend class CellularTest;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500347 friend class CellularCapabilityTest;
Paul Stewarte369ece2012-05-22 09:11:03 -0700348 friend class WiFiObjectTest;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700349
Paul Stewart2bf1d352011-12-06 15:02:55 -0800350 static const char kIPFlagTemplate[];
351 static const char kIPFlagVersion4[];
352 static const char kIPFlagVersion6[];
353 static const char kIPFlagDisableIPv6[];
354 static const char kIPFlagUseTempAddr[];
355 static const char kIPFlagUseTempAddrUsedAndDefault[];
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800356 static const char kIPFlagReversePathFilter[];
357 static const char kIPFlagReversePathFilterEnabled[];
358 static const char kIPFlagReversePathFilterLooseMode[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700359 static const char kStoragePowered[];
360 static const char kStorageIPConfigs[];
Paul Stewart6ff27f52012-07-11 06:51:41 -0700361 static const char kStorageReceiveByteCount[];
362 static const char kStorageTransmitByteCount[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700363
Paul Stewart1062d9d2012-04-27 10:42:27 -0700364 // Configure static IP address parameters if the service provides them.
365 void ConfigureStaticIPTask();
366
Eric Shienbrood9a245532012-03-07 14:20:39 -0500367 void SetEnabledInternal(bool enable, bool persist,
368 Error *error, const ResultCallback &callback);
369
Chris Masone5dec5f42011-07-22 14:07:55 -0700370 // Right now, Devices reference IPConfigs directly when persisted to disk
371 // It's not clear that this makes sense long-term, but that's how it is now.
372 // This call generates a string in the right format for this persisting.
Chris Masone34af2182011-08-22 11:59:36 -0700373 // |suffix| is injected into the storage identifier used for the configs.
374 std::string SerializeIPConfigs(const std::string &suffix);
Chris Masone5dec5f42011-07-22 14:07:55 -0700375
Paul Stewart2bf1d352011-12-06 15:02:55 -0800376 // Set an IP configuration flag on the device. |ip_version| should be
377 // "ipv6" or "ipv4". |flag| should be the name of the flag to be set
378 // and |value| is what this flag should be set to.
379 bool SetIPFlag(IPAddress::Family family, const std::string &flag,
380 const std::string &value);
381
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800382 std::vector<std::string> AvailableIPConfigs(Error *error);
Chris Masone4e851612011-07-01 10:46:53 -0700383 std::string GetRpcConnectionIdentifier();
384
Paul Stewart036dba02012-08-07 12:34:41 -0700385 // Get the LinkMonitor's average response time.
386 uint64 GetLinkMonitorResponseTime(Error *error);
387
Paul Stewart6ff27f52012-07-11 06:51:41 -0700388 // Get receive and transmit byte counters.
389 uint64 GetReceiveByteCount(Error *error);
390 uint64 GetTransmitByteCount(Error *error);
391
Eric Shienbrood9a245532012-03-07 14:20:39 -0500392 // |enabled_persistent_| is the value of the Powered property, as
393 // read from the profile. If it is not found in the profile, it
394 // defaults to true. |enabled_| reflects the real-time state of
395 // the device, i.e., enabled or disabled. |enabled_pending_| reflects
396 // the target state of the device while an enable or disable operation
397 // is occurring.
398 //
399 // Some typical sequences for these state variables are shown below.
400 //
401 // Shill starts up, profile has been read:
402 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=false
403 //
404 // Shill acts on the value of |enabled_persistent_|, calls SetEnabled(true):
405 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=true
406 //
407 // SetEnabled completes successfully, device is enabled:
408 // |enabled_persistent_|=true |enabled_|=true |enabled_pending_|=true
409 //
410 // User presses "Disable" button, SetEnabled(false) is called:
411 // |enabled_persistent_|=false |enabled_|=true |enabled_pending_|=false
412 //
413 // SetEnabled completes successfully, device is disabled:
414 // |enabled_persistent_|=false |enabled_|=false |enabled_pending_|=false
415 bool enabled_;
416 bool enabled_persistent_;
417 bool enabled_pending_;
418
419 // Other properties
Paul Stewartac4ac002011-08-26 12:04:26 -0700420 bool reconnect_;
421 const std::string hardware_address_;
422
423 PropertyStore store_;
424
Paul Stewartac4ac002011-08-26 12:04:26 -0700425 const int interface_index_;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800426 bool running_; // indicates whether the device is actually in operation
Paul Stewartac4ac002011-08-26 12:04:26 -0700427 const std::string link_name_;
428 const std::string unique_id_;
429 ControlInterface *control_interface_;
430 EventDispatcher *dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800431 Metrics *metrics_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700432 Manager *manager_;
433 IPConfigRefPtr ipconfig_;
434 ConnectionRefPtr connection_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500435 base::WeakPtrFactory<Device> weak_ptr_factory_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700436 scoped_ptr<DeviceAdaptorInterface> adaptor_;
Paul Stewart20088d82012-02-16 06:58:55 -0800437 scoped_ptr<PortalDetector> portal_detector_;
Paul Stewart036dba02012-08-07 12:34:41 -0700438 scoped_ptr<LinkMonitor> link_monitor_;
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500439 base::Callback<void(const PortalDetector::Result &)>
440 portal_detector_callback_;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800441 Technology::Identifier technology_;
Thieu Le85e050b2012-03-13 15:04:38 -0700442 // The number of portal detection attempts from Connected to Online state.
443 // This includes all failure/timeout attempts and the final successful
444 // attempt.
445 int portal_attempts_to_online_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700446
Paul Stewart6ff27f52012-07-11 06:51:41 -0700447 // Keep track of the offset between the interface-reported byte counters
448 // and our persisted value.
449 uint64 receive_byte_offset_;
450 uint64 transmit_byte_offset_;
451
Paul Stewart03dba0b2011-08-22 16:32:45 -0700452 // Maintain a reference to the connected / connecting service
453 ServiceRefPtr selected_service_;
454
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700455 // Cache singleton pointers for performance and test purposes.
Darin Petkov77cb6812011-08-15 16:19:41 -0700456 DHCPProvider *dhcp_provider_;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700457 RTNLHandler *rtnl_handler_;
Darin Petkov77cb6812011-08-15 16:19:41 -0700458
Chris Masone9be4a9d2011-05-16 15:44:09 -0700459 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700460};
461
Paul Stewart75897df2011-04-27 09:05:53 -0700462} // namespace shill
463
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200464#endif // SHILL_DEVICE_H_