blob: 306f234bb41d0a9f713e54c78c4168eee352f13c [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;
Gaurav Shah6d2c72d2012-10-16 16:30:44 -070036class GeolocationInfo;
Paul Stewart036dba02012-08-07 12:34:41 -070037class LinkMonitor;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070038class Manager;
Thieu Le3426c8f2012-01-11 17:35:11 -080039class Metrics;
Thieu Lefb46caf2012-03-08 11:57:15 -080040class RTNLHandler;
Chris Masone9be4a9d2011-05-16 15:44:09 -070041
Paul Stewart75897df2011-04-27 09:05:53 -070042// Device superclass. Individual network interfaces types will inherit from
43// this class.
Chris Masone27c4aa52011-07-02 13:10:14 -070044class Device : public base::RefCounted<Device> {
Paul Stewart75897df2011-04-27 09:05:53 -070045 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070046 // A constructor for the Device object
47 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070048 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080049 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070050 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070051 const std::string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070052 const std::string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080053 int interface_index,
54 Technology::Identifier technology);
Chris Masone9be4a9d2011-05-16 15:44:09 -070055
Eric Shienbrood9a245532012-03-07 14:20:39 -050056 // Enable or disable the device.
57 virtual void SetEnabled(bool enable);
58 // Enable or disable the device, and save the setting in the profile.
59 // The setting is persisted before the enable or disable operation
60 // starts, so that even if it fails, the user's intent is still recorded
61 // for the next time shill restarts.
Jason Glasgowdf7c5532012-05-14 14:41:45 -040062 virtual void SetEnabledPersistent(bool enable,
63 Error *error,
64 const ResultCallback &callback);
Gaurav Shah435de2c2011-11-17 19:01:07 -080065
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040066 // Returns true if the underlying device reports that it is already enabled.
67 // Used when the device is registered with the Manager, so that shill can
68 // sync its state/ with the true state of the device. The default is to
69 // report false.
70 virtual bool IsUnderlyingDeviceEnabled() const;
71
Paul Stewartf1ce5d22011-05-19 13:10:20 -070072 virtual void LinkEvent(unsigned flags, unsigned change);
Paul Stewart75897df2011-04-27 09:05:53 -070073
Darin Petkov9ae310f2011-08-30 15:41:13 -070074 // The default implementation sets |error| to kNotSupported.
Darin Petkovc0865312011-09-16 15:31:20 -070075 virtual void Scan(Error *error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050076 virtual void RegisterOnNetwork(const std::string &network_id, Error *error,
77 const ResultCallback &callback);
78 virtual void RequirePIN(const std::string &pin, bool require,
79 Error *error, const ResultCallback &callback);
80 virtual void EnterPIN(const std::string &pin,
81 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070082 virtual void UnblockPIN(const std::string &unblock_code,
83 const std::string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050084 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070085 virtual void ChangePIN(const std::string &old_pin,
86 const std::string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050087 Error *error, const ResultCallback &callback);
Darin Petkovc37a9c42012-09-06 15:28:22 +020088 virtual void SetCarrier(const std::string &carrier,
89 Error *error, const ResultCallback &callback);
Paul Stewart2bf1d352011-12-06 15:02:55 -080090 virtual void DisableIPv6();
91 virtual void EnableIPv6();
92 virtual void EnableIPv6Privacy();
Darin Petkov9ae310f2011-08-30 15:41:13 -070093
Paul Stewartc8f4bef2011-12-13 09:45:51 -080094 // Request the removal of reverse-path filtering for this interface.
95 // This will allow packets destined for this interface to be accepted,
96 // even if this is not the default route for such a packet to arrive.
97 virtual void DisableReversePathFilter();
98
99 // Request reverse-path filtering for this interface.
100 virtual void EnableReversePathFilter();
101
Gaurav Shah435de2c2011-11-17 19:01:07 -0800102 // Returns true if the selected service on the device (if any) is connected.
103 // Returns false if there is no selected service, or if the selected service
104 // is not connected.
105 bool IsConnected() const;
106
Paul Stewartd215af62012-04-24 23:25:50 -0700107 // Returns true if the selected service on the device (if any) is connected
108 // and matches the passed-in argument |service|. Returns false if there is
109 // no connected service, or if it does not match |service|.
110 virtual bool IsConnectedToService(const ServiceRefPtr &service) const;
111
112 // Restart the portal detection process on a connected device. This is
113 // useful if the properties on the connected service have changed in a
114 // way that may affect the decision to run portal detection at all.
115 // Returns true if portal detection was started.
116 virtual bool RestartPortalDetection();
117
Paul Stewart6ff27f52012-07-11 06:51:41 -0700118 // Reset the persisted byte counters associated with the device.
119 void ResetByteCounters();
120
Paul Stewartc681fa02012-03-02 19:40:04 -0800121 // Requests that portal detection be done, if this device has the default
122 // connection. Returns true if portal detection was started.
123 virtual bool RequestPortalDetection();
124
Chris Masone27c4aa52011-07-02 13:10:14 -0700125 std::string GetRpcIdentifier();
Chris Masone5dec5f42011-07-22 14:07:55 -0700126 std::string GetStorageIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700127
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700128 // Returns a list of Geolocation objects. Each object is multiple
129 // key-value pairs representing one entity that can be used for
130 // Geolocation.
131 virtual std::vector<GeolocationInfo> GetGeolocationObjects() const;
132
Chris Masone9d779932011-08-25 16:33:41 -0700133 const std::string &address() const { return hardware_address_; }
Darin Petkove0a312e2011-07-20 13:45:28 -0700134 const std::string &link_name() const { return link_name_; }
135 int interface_index() const { return interface_index_; }
Paul Stewarte6132022011-08-16 09:11:02 -0700136 const ConnectionRefPtr &connection() const { return connection_; }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500137 bool enabled() const { return enabled_; }
138 bool enabled_persistent() const { return enabled_persistent_; }
Gaurav Shah435de2c2011-11-17 19:01:07 -0800139 virtual Technology::Identifier technology() const { return technology_; }
Jason Glasgowb5790052012-01-27 01:03:52 -0500140 std::string GetTechnologyString(Error *error);
Darin Petkove0a312e2011-07-20 13:45:28 -0700141
Darin Petkov31a2eca2012-03-14 11:07:18 +0100142 const IPConfigRefPtr &ipconfig() const { return ipconfig_; }
143 void set_ipconfig(const IPConfigRefPtr &config) { ipconfig_ = config; }
144
Chris Masone19e30402011-07-19 15:48:47 -0700145 const std::string &FriendlyName() const;
Chris Masone27c4aa52011-07-02 13:10:14 -0700146
Darin Petkovafa6fc42011-06-21 16:21:08 -0700147 // Returns a string that is guaranteed to uniquely identify this Device
148 // instance.
149 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -0700150
mukesh agrawalde29fa82011-09-16 16:16:36 -0700151 PropertyStore *mutable_store() { return &store_; }
152 const PropertyStore &store() const { return store_; }
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700153 RTNLHandler *rtnl_handler() { return rtnl_handler_; }
Ben Chan19f83972012-10-03 23:25:56 -0700154 bool running() const { return running_; }
Chris Masone19e30402011-07-19 15:48:47 -0700155
Darin Petkovb05315f2011-11-07 10:14:25 +0100156 EventDispatcher *dispatcher() const { return dispatcher_; }
157
Paul Stewarta41e38d2011-11-11 07:47:29 -0800158 // Load configuration for the device from |storage|. This may include
159 // instantiating non-visible services for which configuration has been
160 // stored.
161 virtual bool Load(StoreInterface *storage);
162
163 // Save configuration for the device to |storage|.
Chris Masone877ff982011-09-21 16:18:24 -0700164 virtual bool Save(StoreInterface *storage);
Chris Masone5dec5f42011-07-22 14:07:55 -0700165
Darin Petkov77cb6812011-08-15 16:19:41 -0700166 void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; }
167
Darin Petkov3cfbf212011-11-21 16:02:09 +0100168 DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); }
169
mukesh agrawal784566d2012-08-08 18:32:58 -0700170 // Suspend event handler. Called by Manager before the system
171 // suspends. For this callback to be useful, the device must specify
172 // a suspend delay. Otherwise, there is no guarantee that the device
173 // will have time to complete its suspend actions, before the system
174 // is suspended.
175 //
176 // TODO(quiche): Add support for suspend delays. crosbug.com/33412
177 virtual void OnBeforeSuspend();
178
179 // Resume event handler. Called by Manager as the system resumes.
180 // The base class implementation takes care of renewing a DHCP lease
181 // (if necessary). Derived classes may implement any technology
182 // specific requirements by overriding, but should include a call to
183 // the base class implementation.
184 virtual void OnAfterResume();
185
Paul Stewartd5843772011-05-11 15:40:42 -0700186 protected:
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200187 friend class base::RefCounted<Device>;
Ben Chan19f83972012-10-03 23:25:56 -0700188 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400189 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Darin Petkov13e6d552012-05-09 14:22:23 +0200190 FRIEND_TEST(ConnectionTest, OnRouteQueryResponse);
Paul Stewart2bf1d352011-12-06 15:02:55 -0800191 FRIEND_TEST(DeviceTest, AcquireIPConfig);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700192 FRIEND_TEST(DeviceTest, DestroyIPConfig);
193 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
Chris Masone95207da2011-06-29 16:50:49 -0700194 FRIEND_TEST(DeviceTest, GetProperties);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700195 FRIEND_TEST(DeviceTest, Load);
Chris Masone5dec5f42011-07-22 14:07:55 -0700196 FRIEND_TEST(DeviceTest, Save);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700197 FRIEND_TEST(DeviceTest, SelectedService);
Darin Petkove7c6ad32012-06-29 10:22:09 +0200198 FRIEND_TEST(DeviceTest, SetEnabledPersistent);
Paul Stewartc681fa02012-03-02 19:40:04 -0800199 FRIEND_TEST(DeviceTest, SetServiceConnectedState);
Paul Stewart8c116a92012-05-02 18:30:03 -0700200 FRIEND_TEST(DeviceTest, Start);
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700201 FRIEND_TEST(DeviceTest, Stop);
Paul Stewarta41e38d2011-11-11 07:47:29 -0800202 FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800203 FRIEND_TEST(ManagerTest, ConnectedTechnologies);
204 FRIEND_TEST(ManagerTest, DefaultTechnology);
Jason Glasgowdf7c5532012-05-14 14:41:45 -0400205 FRIEND_TEST(ManagerTest, EnableTechnology);
206 FRIEND_TEST(ManagerTest, DisableTechnology);
mukesh agrawal32399322011-09-01 10:53:43 -0700207 FRIEND_TEST(WiFiMainTest, Connect);
Darin Petkov3a4100c2012-06-14 11:36:59 +0200208 FRIEND_TEST(WiMaxTest, ConnectTimeout);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700209
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200210 virtual ~Device();
211
Eric Shienbrood9a245532012-03-07 14:20:39 -0500212 // Each device must implement this method to do the work needed to
213 // enable the device to operate for establishing network connections.
214 // The |error| argument, if not NULL,
215 // will refer to an Error that starts out with the value
216 // Error::kOperationInitiated. This reflects the assumption that
217 // enable (and disable) operations will usually be non-blocking,
218 // and their completion will be indicated by means of an asynchronous
219 // reply sometime later. There are two circumstances in which a
220 // device's Start() method may overwrite |error|:
221 //
222 // 1. If an early failure is detected, such that the non-blocking
223 // part of the operation never takes place, then |error| should
224 // be set to the appropriate value corresponding to the type
225 // of failure. This is the "immediate failure" case.
226 // 2. If the device is enabled without performing any non-blocking
227 // steps, then |error| should be Reset, i.e., its value set
228 // to Error::kSuccess. This is the "immediate success" case.
229 //
230 // In these two cases, because completion is immediate, |callback|
231 // is not used. If neither of these two conditions holds, then |error|
232 // should not be modified, and |callback| should be passed to the
233 // method that will initiate the non-blocking operation.
234 virtual void Start(Error *error,
235 const EnabledStateChangedCallback &callback) = 0;
236
237 // Each device must implement this method to do the work needed to
238 // disable the device, i.e., clear any running state, and make the
239 // device no longer capable of establishing network connections.
240 // The discussion for Start() regarding the use of |error| and
241 // |callback| apply to Stop() as well.
242 virtual void Stop(Error *error,
243 const EnabledStateChangedCallback &callback) = 0;
244
245 // The EnabledStateChangedCallback that gets passed to the device's
246 // Start() and Stop() methods is bound to this method. |callback|
247 // is the callback that was passed to SetEnabled().
248 void OnEnabledStateChanged(const ResultCallback &callback,
249 const Error &error);
250
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200251 // Drops the currently selected service along with its IP configuration and
252 // connection, if any.
253 void DropConnection();
254
Darin Petkovafa6fc42011-06-21 16:21:08 -0700255 // If there's an IP configuration in |ipconfig_|, releases the IP address and
256 // destroys the configuration instance.
257 void DestroyIPConfig();
258
259 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
Paul Stewartd408fdf2012-05-07 17:15:57 -0700260 // requests a new IP configuration. Saves the DHCP lease to the generic
261 // lease filename based on the interface name. Registers a callback to
Darin Petkovafa6fc42011-06-21 16:21:08 -0700262 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
263 // request was successfully sent.
Paul Stewart2bf1d352011-12-06 15:02:55 -0800264 bool AcquireIPConfig();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700265
Paul Stewartd408fdf2012-05-07 17:15:57 -0700266 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
267 // requests a new IP configuration. Saves the DHCP lease to a filename
268 // based on the passed-in |lease_name|. Registers a callback to
269 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
270 // request was successfully sent.
271 bool AcquireIPConfigWithLeaseName(const std::string &lease_name);
272
Darin Petkov79d74c92012-03-07 17:20:32 +0100273 // Callback invoked on every IP configuration update.
274 void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success);
275
Paul Stewarte6132022011-08-16 09:11:02 -0700276 // Maintain connection state (Routes, IP Addresses and DNS) in the OS.
277 void CreateConnection();
278
279 // Remove connection state
280 void DestroyConnection();
281
Paul Stewart03dba0b2011-08-22 16:32:45 -0700282 // Selects a service to be "current" -- i.e. link-state or configuration
283 // events that happen to the device are attributed to this service.
284 void SelectService(const ServiceRefPtr &service);
285
286 // Set the state of the selected service
287 void SetServiceState(Service::ConnectState state);
288
289 // Set the failure of the selected service (implicitly sets the state to
290 // "failure")
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400291
Paul Stewart03dba0b2011-08-22 16:32:45 -0700292 void SetServiceFailure(Service::ConnectFailure failure_state);
293
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400294 // Records the failure mode and time of the selected service, and
295 // sets the Service state of the selected service to "Idle".
296 // Avoids showing a failure mole in the UI.
297 void SetServiceFailureSilent(Service::ConnectFailure failure_state);
298
Paul Stewart20088d82012-02-16 06:58:55 -0800299 // Called by the Portal Detector whenever a trial completes. Device
300 // subclasses that choose unique mappings from portal results to connected
301 // states can override this method in order to do so.
302 virtual void PortalDetectorCallback(const PortalDetector::Result &result);
303
304 // Initiate portal detection, if enabled for this device type.
305 bool StartPortalDetection();
306
307 // Stop portal detection if it is running.
308 void StopPortalDetection();
309
Paul Stewart036dba02012-08-07 12:34:41 -0700310 // Initiate link monitoring, if enabled for this device type.
311 bool StartLinkMonitor();
312
313 // Stop link monitoring if it is running.
314 void StopLinkMonitor();
315
316 // Respond to a LinkMonitor failure in a Device-specific manner.
317 virtual void OnLinkMonitorFailure();
318
Paul Stewart20088d82012-02-16 06:58:55 -0800319 // Set the state of the selected service, with checks to make sure
320 // the service is already in a connected state before doing so.
321 void SetServiceConnectedState(Service::ConnectState state);
322
Darin Petkov9893d9c2012-05-17 15:27:31 -0700323 const ServiceRefPtr &selected_service() const { return selected_service_; }
324
Jason Glasgowb5790052012-01-27 01:03:52 -0500325 void HelpRegisterDerivedString(
326 const std::string &name,
327 std::string(Device::*get)(Error *),
328 void(Device::*set)(const std::string&, Error *));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500329
330 void HelpRegisterDerivedStrings(
331 const std::string &name,
332 Strings(Device::*get)(Error *error),
333 void(Device::*set)(const Strings &value, Error *error));
Chris Masoneb925cc82011-06-22 15:39:57 -0700334
Jason Glasgow08afdff2012-04-03 10:22:26 -0400335 void HelpRegisterConstDerivedRpcIdentifiers(
336 const std::string &name,
337 RpcIdentifiers(Device::*get)(Error *));
338
Paul Stewart6ff27f52012-07-11 06:51:41 -0700339 void HelpRegisterConstDerivedUint64(
340 const std::string &name,
341 uint64(Device::*get)(Error *));
342
Paul Stewartac4ac002011-08-26 12:04:26 -0700343 // Property getters reserved for subclasses
344 ControlInterface *control_interface() const { return control_interface_; }
Thieu Le3426c8f2012-01-11 17:35:11 -0800345 Metrics *metrics() const { return metrics_; }
Paul Stewartac4ac002011-08-26 12:04:26 -0700346 Manager *manager() const { return manager_; }
Paul Stewart036dba02012-08-07 12:34:41 -0700347 const LinkMonitor *link_monitor() const { return link_monitor_.get(); }
348 void set_link_monitor(LinkMonitor *link_monitor);
Paul Stewartd5843772011-05-11 15:40:42 -0700349
Paul Stewart75897df2011-04-27 09:05:53 -0700350 private:
Darin Petkov3189a472012-10-05 09:55:33 +0200351 friend class CellularCapabilityTest;
352 friend class CellularTest;
Chris Masone413a3192011-05-09 17:10:05 -0700353 friend class DeviceAdaptorInterface;
Paul Stewart6ff27f52012-07-11 06:51:41 -0700354 friend class DeviceByteCountTest;
Paul Stewartc681fa02012-03-02 19:40:04 -0800355 friend class DevicePortalDetectionTest;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700356 friend class DeviceTest;
Darin Petkov3189a472012-10-05 09:55:33 +0200357 friend class OpenVPNDriverTest;
Paul Stewarte369ece2012-05-22 09:11:03 -0700358 friend class WiFiObjectTest;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700359
Paul Stewart2bf1d352011-12-06 15:02:55 -0800360 static const char kIPFlagTemplate[];
361 static const char kIPFlagVersion4[];
362 static const char kIPFlagVersion6[];
363 static const char kIPFlagDisableIPv6[];
364 static const char kIPFlagUseTempAddr[];
365 static const char kIPFlagUseTempAddrUsedAndDefault[];
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800366 static const char kIPFlagReversePathFilter[];
367 static const char kIPFlagReversePathFilterEnabled[];
368 static const char kIPFlagReversePathFilterLooseMode[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700369 static const char kStoragePowered[];
370 static const char kStorageIPConfigs[];
Paul Stewart6ff27f52012-07-11 06:51:41 -0700371 static const char kStorageReceiveByteCount[];
372 static const char kStorageTransmitByteCount[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700373
Paul Stewart1062d9d2012-04-27 10:42:27 -0700374 // Configure static IP address parameters if the service provides them.
375 void ConfigureStaticIPTask();
376
Eric Shienbrood9a245532012-03-07 14:20:39 -0500377 void SetEnabledInternal(bool enable, bool persist,
378 Error *error, const ResultCallback &callback);
379
Chris Masone5dec5f42011-07-22 14:07:55 -0700380 // Right now, Devices reference IPConfigs directly when persisted to disk
381 // It's not clear that this makes sense long-term, but that's how it is now.
382 // This call generates a string in the right format for this persisting.
Chris Masone34af2182011-08-22 11:59:36 -0700383 // |suffix| is injected into the storage identifier used for the configs.
384 std::string SerializeIPConfigs(const std::string &suffix);
Chris Masone5dec5f42011-07-22 14:07:55 -0700385
Paul Stewart2bf1d352011-12-06 15:02:55 -0800386 // Set an IP configuration flag on the device. |ip_version| should be
387 // "ipv6" or "ipv4". |flag| should be the name of the flag to be set
388 // and |value| is what this flag should be set to.
389 bool SetIPFlag(IPAddress::Family family, const std::string &flag,
390 const std::string &value);
391
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800392 std::vector<std::string> AvailableIPConfigs(Error *error);
Chris Masone4e851612011-07-01 10:46:53 -0700393 std::string GetRpcConnectionIdentifier();
394
Paul Stewart036dba02012-08-07 12:34:41 -0700395 // Get the LinkMonitor's average response time.
396 uint64 GetLinkMonitorResponseTime(Error *error);
397
Paul Stewart6ff27f52012-07-11 06:51:41 -0700398 // Get receive and transmit byte counters.
399 uint64 GetReceiveByteCount(Error *error);
400 uint64 GetTransmitByteCount(Error *error);
401
Eric Shienbrood9a245532012-03-07 14:20:39 -0500402 // |enabled_persistent_| is the value of the Powered property, as
403 // read from the profile. If it is not found in the profile, it
404 // defaults to true. |enabled_| reflects the real-time state of
405 // the device, i.e., enabled or disabled. |enabled_pending_| reflects
406 // the target state of the device while an enable or disable operation
407 // is occurring.
408 //
409 // Some typical sequences for these state variables are shown below.
410 //
411 // Shill starts up, profile has been read:
412 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=false
413 //
414 // Shill acts on the value of |enabled_persistent_|, calls SetEnabled(true):
415 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=true
416 //
417 // SetEnabled completes successfully, device is enabled:
418 // |enabled_persistent_|=true |enabled_|=true |enabled_pending_|=true
419 //
420 // User presses "Disable" button, SetEnabled(false) is called:
421 // |enabled_persistent_|=false |enabled_|=true |enabled_pending_|=false
422 //
423 // SetEnabled completes successfully, device is disabled:
424 // |enabled_persistent_|=false |enabled_|=false |enabled_pending_|=false
425 bool enabled_;
426 bool enabled_persistent_;
427 bool enabled_pending_;
428
429 // Other properties
Paul Stewartac4ac002011-08-26 12:04:26 -0700430 bool reconnect_;
431 const std::string hardware_address_;
432
433 PropertyStore store_;
434
Paul Stewartac4ac002011-08-26 12:04:26 -0700435 const int interface_index_;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800436 bool running_; // indicates whether the device is actually in operation
Paul Stewartac4ac002011-08-26 12:04:26 -0700437 const std::string link_name_;
438 const std::string unique_id_;
439 ControlInterface *control_interface_;
440 EventDispatcher *dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800441 Metrics *metrics_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700442 Manager *manager_;
443 IPConfigRefPtr ipconfig_;
444 ConnectionRefPtr connection_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500445 base::WeakPtrFactory<Device> weak_ptr_factory_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700446 scoped_ptr<DeviceAdaptorInterface> adaptor_;
Paul Stewart20088d82012-02-16 06:58:55 -0800447 scoped_ptr<PortalDetector> portal_detector_;
Paul Stewart036dba02012-08-07 12:34:41 -0700448 scoped_ptr<LinkMonitor> link_monitor_;
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500449 base::Callback<void(const PortalDetector::Result &)>
450 portal_detector_callback_;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800451 Technology::Identifier technology_;
Thieu Le85e050b2012-03-13 15:04:38 -0700452 // The number of portal detection attempts from Connected to Online state.
453 // This includes all failure/timeout attempts and the final successful
454 // attempt.
455 int portal_attempts_to_online_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700456
Paul Stewart6ff27f52012-07-11 06:51:41 -0700457 // Keep track of the offset between the interface-reported byte counters
458 // and our persisted value.
459 uint64 receive_byte_offset_;
460 uint64 transmit_byte_offset_;
461
Paul Stewart03dba0b2011-08-22 16:32:45 -0700462 // Maintain a reference to the connected / connecting service
463 ServiceRefPtr selected_service_;
464
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700465 // Cache singleton pointers for performance and test purposes.
Darin Petkov77cb6812011-08-15 16:19:41 -0700466 DHCPProvider *dhcp_provider_;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700467 RTNLHandler *rtnl_handler_;
Darin Petkov77cb6812011-08-15 16:19:41 -0700468
Chris Masone9be4a9d2011-05-16 15:44:09 -0700469 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700470};
471
Paul Stewart75897df2011-04-27 09:05:53 -0700472} // namespace shill
473
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200474#endif // SHILL_DEVICE_H_