blob: 1c57cf450b1eb96b6eea190b94a8aa13657da110 [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 Stewartf1ce5d22011-05-19 13:10:20 -070036class Manager;
Thieu Le3426c8f2012-01-11 17:35:11 -080037class Metrics;
Thieu Lefb46caf2012-03-08 11:57:15 -080038class RTNLHandler;
Chris Masone9be4a9d2011-05-16 15:44:09 -070039
Paul Stewart75897df2011-04-27 09:05:53 -070040// Device superclass. Individual network interfaces types will inherit from
41// this class.
Chris Masone27c4aa52011-07-02 13:10:14 -070042class Device : public base::RefCounted<Device> {
Paul Stewart75897df2011-04-27 09:05:53 -070043 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070044 // A constructor for the Device object
45 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070046 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080047 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070048 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070049 const std::string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070050 const std::string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080051 int interface_index,
52 Technology::Identifier technology);
Chris Masone9be4a9d2011-05-16 15:44:09 -070053
Eric Shienbrood9a245532012-03-07 14:20:39 -050054 // Enable or disable the device.
55 virtual void SetEnabled(bool enable);
56 // Enable or disable the device, and save the setting in the profile.
57 // The setting is persisted before the enable or disable operation
58 // starts, so that even if it fails, the user's intent is still recorded
59 // for the next time shill restarts.
Jason Glasgowdf7c5532012-05-14 14:41:45 -040060 virtual void SetEnabledPersistent(bool enable,
61 Error *error,
62 const ResultCallback &callback);
Gaurav Shah435de2c2011-11-17 19:01:07 -080063
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040064 // Returns true if the underlying device reports that it is already enabled.
65 // Used when the device is registered with the Manager, so that shill can
66 // sync its state/ with the true state of the device. The default is to
67 // report false.
68 virtual bool IsUnderlyingDeviceEnabled() const;
69
Paul Stewartf1ce5d22011-05-19 13:10:20 -070070 virtual void LinkEvent(unsigned flags, unsigned change);
Paul Stewart75897df2011-04-27 09:05:53 -070071
Darin Petkov9ae310f2011-08-30 15:41:13 -070072 // The default implementation sets |error| to kNotSupported.
Darin Petkovc0865312011-09-16 15:31:20 -070073 virtual void Scan(Error *error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050074 virtual void RegisterOnNetwork(const std::string &network_id, Error *error,
75 const ResultCallback &callback);
76 virtual void RequirePIN(const std::string &pin, bool require,
77 Error *error, const ResultCallback &callback);
78 virtual void EnterPIN(const std::string &pin,
79 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070080 virtual void UnblockPIN(const std::string &unblock_code,
81 const std::string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 Error *error, const ResultCallback &callback);
Darin Petkove42e1012011-08-31 12:35:04 -070083 virtual void ChangePIN(const std::string &old_pin,
84 const std::string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050085 Error *error, const ResultCallback &callback);
Paul Stewart2bf1d352011-12-06 15:02:55 -080086 virtual void DisableIPv6();
87 virtual void EnableIPv6();
88 virtual void EnableIPv6Privacy();
Darin Petkov9ae310f2011-08-30 15:41:13 -070089
Paul Stewartc8f4bef2011-12-13 09:45:51 -080090 // Request the removal of reverse-path filtering for this interface.
91 // This will allow packets destined for this interface to be accepted,
92 // even if this is not the default route for such a packet to arrive.
93 virtual void DisableReversePathFilter();
94
95 // Request reverse-path filtering for this interface.
96 virtual void EnableReversePathFilter();
97
Gaurav Shah435de2c2011-11-17 19:01:07 -080098 // Returns true if the selected service on the device (if any) is connected.
99 // Returns false if there is no selected service, or if the selected service
100 // is not connected.
101 bool IsConnected() const;
102
Paul Stewartd215af62012-04-24 23:25:50 -0700103 // Returns true if the selected service on the device (if any) is connected
104 // and matches the passed-in argument |service|. Returns false if there is
105 // no connected service, or if it does not match |service|.
106 virtual bool IsConnectedToService(const ServiceRefPtr &service) const;
107
108 // Restart the portal detection process on a connected device. This is
109 // useful if the properties on the connected service have changed in a
110 // way that may affect the decision to run portal detection at all.
111 // Returns true if portal detection was started.
112 virtual bool RestartPortalDetection();
113
Paul Stewart6ff27f52012-07-11 06:51:41 -0700114 // Reset the persisted byte counters associated with the device.
115 void ResetByteCounters();
116
Paul Stewartc681fa02012-03-02 19:40:04 -0800117 // Requests that portal detection be done, if this device has the default
118 // connection. Returns true if portal detection was started.
119 virtual bool RequestPortalDetection();
120
Chris Masone27c4aa52011-07-02 13:10:14 -0700121 std::string GetRpcIdentifier();
Chris Masone5dec5f42011-07-22 14:07:55 -0700122 std::string GetStorageIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700123
Chris Masone9d779932011-08-25 16:33:41 -0700124 const std::string &address() const { return hardware_address_; }
Darin Petkove0a312e2011-07-20 13:45:28 -0700125 const std::string &link_name() const { return link_name_; }
126 int interface_index() const { return interface_index_; }
Paul Stewarte6132022011-08-16 09:11:02 -0700127 const ConnectionRefPtr &connection() const { return connection_; }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 bool enabled() const { return enabled_; }
129 bool enabled_persistent() const { return enabled_persistent_; }
Gaurav Shah435de2c2011-11-17 19:01:07 -0800130 virtual Technology::Identifier technology() const { return technology_; }
Jason Glasgowb5790052012-01-27 01:03:52 -0500131 std::string GetTechnologyString(Error *error);
Darin Petkove0a312e2011-07-20 13:45:28 -0700132
Darin Petkov31a2eca2012-03-14 11:07:18 +0100133 const IPConfigRefPtr &ipconfig() const { return ipconfig_; }
134 void set_ipconfig(const IPConfigRefPtr &config) { ipconfig_ = config; }
135
Chris Masone19e30402011-07-19 15:48:47 -0700136 const std::string &FriendlyName() const;
Chris Masone27c4aa52011-07-02 13:10:14 -0700137
Darin Petkovafa6fc42011-06-21 16:21:08 -0700138 // Returns a string that is guaranteed to uniquely identify this Device
139 // instance.
140 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -0700141
mukesh agrawalde29fa82011-09-16 16:16:36 -0700142 PropertyStore *mutable_store() { return &store_; }
143 const PropertyStore &store() const { return store_; }
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700144 RTNLHandler *rtnl_handler() { return rtnl_handler_; }
Chris Masone19e30402011-07-19 15:48:47 -0700145
Darin Petkovb05315f2011-11-07 10:14:25 +0100146 EventDispatcher *dispatcher() const { return dispatcher_; }
147
Paul Stewarta41e38d2011-11-11 07:47:29 -0800148 // Load configuration for the device from |storage|. This may include
149 // instantiating non-visible services for which configuration has been
150 // stored.
151 virtual bool Load(StoreInterface *storage);
152
153 // Save configuration for the device to |storage|.
Chris Masone877ff982011-09-21 16:18:24 -0700154 virtual bool Save(StoreInterface *storage);
Chris Masone5dec5f42011-07-22 14:07:55 -0700155
Darin Petkov77cb6812011-08-15 16:19:41 -0700156 void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; }
157
Darin Petkov3cfbf212011-11-21 16:02:09 +0100158 DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); }
159
mukesh agrawal784566d2012-08-08 18:32:58 -0700160 // Suspend event handler. Called by Manager before the system
161 // suspends. For this callback to be useful, the device must specify
162 // a suspend delay. Otherwise, there is no guarantee that the device
163 // will have time to complete its suspend actions, before the system
164 // is suspended.
165 //
166 // TODO(quiche): Add support for suspend delays. crosbug.com/33412
167 virtual void OnBeforeSuspend();
168
169 // Resume event handler. Called by Manager as the system resumes.
170 // The base class implementation takes care of renewing a DHCP lease
171 // (if necessary). Derived classes may implement any technology
172 // specific requirements by overriding, but should include a call to
173 // the base class implementation.
174 virtual void OnAfterResume();
175
Paul Stewartd5843772011-05-11 15:40:42 -0700176 protected:
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200177 friend class base::RefCounted<Device>;
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400178 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Darin Petkov13e6d552012-05-09 14:22:23 +0200179 FRIEND_TEST(ConnectionTest, OnRouteQueryResponse);
Paul Stewart2bf1d352011-12-06 15:02:55 -0800180 FRIEND_TEST(DeviceTest, AcquireIPConfig);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700181 FRIEND_TEST(DeviceTest, DestroyIPConfig);
182 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
Chris Masone95207da2011-06-29 16:50:49 -0700183 FRIEND_TEST(DeviceTest, GetProperties);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700184 FRIEND_TEST(DeviceTest, Load);
Chris Masone5dec5f42011-07-22 14:07:55 -0700185 FRIEND_TEST(DeviceTest, Save);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700186 FRIEND_TEST(DeviceTest, SelectedService);
Darin Petkove7c6ad32012-06-29 10:22:09 +0200187 FRIEND_TEST(DeviceTest, SetEnabledPersistent);
Paul Stewartc681fa02012-03-02 19:40:04 -0800188 FRIEND_TEST(DeviceTest, SetServiceConnectedState);
Paul Stewart8c116a92012-05-02 18:30:03 -0700189 FRIEND_TEST(DeviceTest, Start);
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700190 FRIEND_TEST(DeviceTest, Stop);
Paul Stewarta41e38d2011-11-11 07:47:29 -0800191 FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800192 FRIEND_TEST(ManagerTest, ConnectedTechnologies);
193 FRIEND_TEST(ManagerTest, DefaultTechnology);
Jason Glasgowdf7c5532012-05-14 14:41:45 -0400194 FRIEND_TEST(ManagerTest, EnableTechnology);
195 FRIEND_TEST(ManagerTest, DisableTechnology);
mukesh agrawal32399322011-09-01 10:53:43 -0700196 FRIEND_TEST(WiFiMainTest, Connect);
Darin Petkov3a4100c2012-06-14 11:36:59 +0200197 FRIEND_TEST(WiMaxTest, ConnectTimeout);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700198
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200199 virtual ~Device();
200
Eric Shienbrood9a245532012-03-07 14:20:39 -0500201 // Each device must implement this method to do the work needed to
202 // enable the device to operate for establishing network connections.
203 // The |error| argument, if not NULL,
204 // will refer to an Error that starts out with the value
205 // Error::kOperationInitiated. This reflects the assumption that
206 // enable (and disable) operations will usually be non-blocking,
207 // and their completion will be indicated by means of an asynchronous
208 // reply sometime later. There are two circumstances in which a
209 // device's Start() method may overwrite |error|:
210 //
211 // 1. If an early failure is detected, such that the non-blocking
212 // part of the operation never takes place, then |error| should
213 // be set to the appropriate value corresponding to the type
214 // of failure. This is the "immediate failure" case.
215 // 2. If the device is enabled without performing any non-blocking
216 // steps, then |error| should be Reset, i.e., its value set
217 // to Error::kSuccess. This is the "immediate success" case.
218 //
219 // In these two cases, because completion is immediate, |callback|
220 // is not used. If neither of these two conditions holds, then |error|
221 // should not be modified, and |callback| should be passed to the
222 // method that will initiate the non-blocking operation.
223 virtual void Start(Error *error,
224 const EnabledStateChangedCallback &callback) = 0;
225
226 // Each device must implement this method to do the work needed to
227 // disable the device, i.e., clear any running state, and make the
228 // device no longer capable of establishing network connections.
229 // The discussion for Start() regarding the use of |error| and
230 // |callback| apply to Stop() as well.
231 virtual void Stop(Error *error,
232 const EnabledStateChangedCallback &callback) = 0;
233
234 // The EnabledStateChangedCallback that gets passed to the device's
235 // Start() and Stop() methods is bound to this method. |callback|
236 // is the callback that was passed to SetEnabled().
237 void OnEnabledStateChanged(const ResultCallback &callback,
238 const Error &error);
239
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200240 // Drops the currently selected service along with its IP configuration and
241 // connection, if any.
242 void DropConnection();
243
Darin Petkovafa6fc42011-06-21 16:21:08 -0700244 // If there's an IP configuration in |ipconfig_|, releases the IP address and
245 // destroys the configuration instance.
246 void DestroyIPConfig();
247
248 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
Paul Stewartd408fdf2012-05-07 17:15:57 -0700249 // requests a new IP configuration. Saves the DHCP lease to the generic
250 // lease filename based on the interface name. Registers a callback to
Darin Petkovafa6fc42011-06-21 16:21:08 -0700251 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
252 // request was successfully sent.
Paul Stewart2bf1d352011-12-06 15:02:55 -0800253 bool AcquireIPConfig();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700254
Paul Stewartd408fdf2012-05-07 17:15:57 -0700255 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
256 // requests a new IP configuration. Saves the DHCP lease to a filename
257 // based on the passed-in |lease_name|. Registers a callback to
258 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
259 // request was successfully sent.
260 bool AcquireIPConfigWithLeaseName(const std::string &lease_name);
261
Darin Petkov79d74c92012-03-07 17:20:32 +0100262 // Callback invoked on every IP configuration update.
263 void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success);
264
Paul Stewarte6132022011-08-16 09:11:02 -0700265 // Maintain connection state (Routes, IP Addresses and DNS) in the OS.
266 void CreateConnection();
267
268 // Remove connection state
269 void DestroyConnection();
270
Paul Stewart03dba0b2011-08-22 16:32:45 -0700271 // Selects a service to be "current" -- i.e. link-state or configuration
272 // events that happen to the device are attributed to this service.
273 void SelectService(const ServiceRefPtr &service);
274
275 // Set the state of the selected service
276 void SetServiceState(Service::ConnectState state);
277
278 // Set the failure of the selected service (implicitly sets the state to
279 // "failure")
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400280
Paul Stewart03dba0b2011-08-22 16:32:45 -0700281 void SetServiceFailure(Service::ConnectFailure failure_state);
282
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400283 // Records the failure mode and time of the selected service, and
284 // sets the Service state of the selected service to "Idle".
285 // Avoids showing a failure mole in the UI.
286 void SetServiceFailureSilent(Service::ConnectFailure failure_state);
287
Paul Stewart20088d82012-02-16 06:58:55 -0800288 // Called by the Portal Detector whenever a trial completes. Device
289 // subclasses that choose unique mappings from portal results to connected
290 // states can override this method in order to do so.
291 virtual void PortalDetectorCallback(const PortalDetector::Result &result);
292
293 // Initiate portal detection, if enabled for this device type.
294 bool StartPortalDetection();
295
296 // Stop portal detection if it is running.
297 void StopPortalDetection();
298
299 // Set the state of the selected service, with checks to make sure
300 // the service is already in a connected state before doing so.
301 void SetServiceConnectedState(Service::ConnectState state);
302
Darin Petkov9893d9c2012-05-17 15:27:31 -0700303 const ServiceRefPtr &selected_service() const { return selected_service_; }
304
Jason Glasgowb5790052012-01-27 01:03:52 -0500305 void HelpRegisterDerivedString(
306 const std::string &name,
307 std::string(Device::*get)(Error *),
308 void(Device::*set)(const std::string&, Error *));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500309
310 void HelpRegisterDerivedStrings(
311 const std::string &name,
312 Strings(Device::*get)(Error *error),
313 void(Device::*set)(const Strings &value, Error *error));
Chris Masoneb925cc82011-06-22 15:39:57 -0700314
Jason Glasgow08afdff2012-04-03 10:22:26 -0400315 void HelpRegisterConstDerivedRpcIdentifiers(
316 const std::string &name,
317 RpcIdentifiers(Device::*get)(Error *));
318
Paul Stewart6ff27f52012-07-11 06:51:41 -0700319 void HelpRegisterConstDerivedUint64(
320 const std::string &name,
321 uint64(Device::*get)(Error *));
322
Paul Stewartac4ac002011-08-26 12:04:26 -0700323 // Property getters reserved for subclasses
324 ControlInterface *control_interface() const { return control_interface_; }
Thieu Le3426c8f2012-01-11 17:35:11 -0800325 Metrics *metrics() const { return metrics_; }
Paul Stewartac4ac002011-08-26 12:04:26 -0700326 Manager *manager() const { return manager_; }
Paul Stewarta41e38d2011-11-11 07:47:29 -0800327 bool running() const { return running_; }
Paul Stewartd5843772011-05-11 15:40:42 -0700328
Paul Stewart75897df2011-04-27 09:05:53 -0700329 private:
Chris Masone413a3192011-05-09 17:10:05 -0700330 friend class DeviceAdaptorInterface;
Paul Stewart6ff27f52012-07-11 06:51:41 -0700331 friend class DeviceByteCountTest;
Paul Stewartc681fa02012-03-02 19:40:04 -0800332 friend class DevicePortalDetectionTest;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700333 friend class DeviceTest;
334 friend class CellularTest;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500335 friend class CellularCapabilityTest;
Paul Stewarte369ece2012-05-22 09:11:03 -0700336 friend class WiFiObjectTest;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700337
Paul Stewart2bf1d352011-12-06 15:02:55 -0800338 static const char kIPFlagTemplate[];
339 static const char kIPFlagVersion4[];
340 static const char kIPFlagVersion6[];
341 static const char kIPFlagDisableIPv6[];
342 static const char kIPFlagUseTempAddr[];
343 static const char kIPFlagUseTempAddrUsedAndDefault[];
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800344 static const char kIPFlagReversePathFilter[];
345 static const char kIPFlagReversePathFilterEnabled[];
346 static const char kIPFlagReversePathFilterLooseMode[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700347 static const char kStoragePowered[];
348 static const char kStorageIPConfigs[];
Paul Stewart6ff27f52012-07-11 06:51:41 -0700349 static const char kStorageReceiveByteCount[];
350 static const char kStorageTransmitByteCount[];
Chris Masone5dec5f42011-07-22 14:07:55 -0700351
Paul Stewart1062d9d2012-04-27 10:42:27 -0700352 // Configure static IP address parameters if the service provides them.
353 void ConfigureStaticIPTask();
354
Eric Shienbrood9a245532012-03-07 14:20:39 -0500355 void SetEnabledInternal(bool enable, bool persist,
356 Error *error, const ResultCallback &callback);
357
Chris Masone5dec5f42011-07-22 14:07:55 -0700358 // Right now, Devices reference IPConfigs directly when persisted to disk
359 // It's not clear that this makes sense long-term, but that's how it is now.
360 // This call generates a string in the right format for this persisting.
Chris Masone34af2182011-08-22 11:59:36 -0700361 // |suffix| is injected into the storage identifier used for the configs.
362 std::string SerializeIPConfigs(const std::string &suffix);
Chris Masone5dec5f42011-07-22 14:07:55 -0700363
Paul Stewart2bf1d352011-12-06 15:02:55 -0800364 // Set an IP configuration flag on the device. |ip_version| should be
365 // "ipv6" or "ipv4". |flag| should be the name of the flag to be set
366 // and |value| is what this flag should be set to.
367 bool SetIPFlag(IPAddress::Family family, const std::string &flag,
368 const std::string &value);
369
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800370 std::vector<std::string> AvailableIPConfigs(Error *error);
Chris Masone4e851612011-07-01 10:46:53 -0700371 std::string GetRpcConnectionIdentifier();
372
Paul Stewart6ff27f52012-07-11 06:51:41 -0700373 // Get receive and transmit byte counters.
374 uint64 GetReceiveByteCount(Error *error);
375 uint64 GetTransmitByteCount(Error *error);
376
Eric Shienbrood9a245532012-03-07 14:20:39 -0500377 // |enabled_persistent_| is the value of the Powered property, as
378 // read from the profile. If it is not found in the profile, it
379 // defaults to true. |enabled_| reflects the real-time state of
380 // the device, i.e., enabled or disabled. |enabled_pending_| reflects
381 // the target state of the device while an enable or disable operation
382 // is occurring.
383 //
384 // Some typical sequences for these state variables are shown below.
385 //
386 // Shill starts up, profile has been read:
387 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=false
388 //
389 // Shill acts on the value of |enabled_persistent_|, calls SetEnabled(true):
390 // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=true
391 //
392 // SetEnabled completes successfully, device is enabled:
393 // |enabled_persistent_|=true |enabled_|=true |enabled_pending_|=true
394 //
395 // User presses "Disable" button, SetEnabled(false) is called:
396 // |enabled_persistent_|=false |enabled_|=true |enabled_pending_|=false
397 //
398 // SetEnabled completes successfully, device is disabled:
399 // |enabled_persistent_|=false |enabled_|=false |enabled_pending_|=false
400 bool enabled_;
401 bool enabled_persistent_;
402 bool enabled_pending_;
403
404 // Other properties
Paul Stewartac4ac002011-08-26 12:04:26 -0700405 bool reconnect_;
406 const std::string hardware_address_;
407
408 PropertyStore store_;
409
Paul Stewartac4ac002011-08-26 12:04:26 -0700410 const int interface_index_;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800411 bool running_; // indicates whether the device is actually in operation
Paul Stewartac4ac002011-08-26 12:04:26 -0700412 const std::string link_name_;
413 const std::string unique_id_;
414 ControlInterface *control_interface_;
415 EventDispatcher *dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800416 Metrics *metrics_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700417 Manager *manager_;
418 IPConfigRefPtr ipconfig_;
419 ConnectionRefPtr connection_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500420 base::WeakPtrFactory<Device> weak_ptr_factory_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700421 scoped_ptr<DeviceAdaptorInterface> adaptor_;
Paul Stewart20088d82012-02-16 06:58:55 -0800422 scoped_ptr<PortalDetector> portal_detector_;
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500423 base::Callback<void(const PortalDetector::Result &)>
424 portal_detector_callback_;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800425 Technology::Identifier technology_;
Thieu Le85e050b2012-03-13 15:04:38 -0700426 // The number of portal detection attempts from Connected to Online state.
427 // This includes all failure/timeout attempts and the final successful
428 // attempt.
429 int portal_attempts_to_online_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700430
Paul Stewart6ff27f52012-07-11 06:51:41 -0700431 // Keep track of the offset between the interface-reported byte counters
432 // and our persisted value.
433 uint64 receive_byte_offset_;
434 uint64 transmit_byte_offset_;
435
Paul Stewart03dba0b2011-08-22 16:32:45 -0700436 // Maintain a reference to the connected / connecting service
437 ServiceRefPtr selected_service_;
438
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700439 // Cache singleton pointers for performance and test purposes.
Darin Petkov77cb6812011-08-15 16:19:41 -0700440 DHCPProvider *dhcp_provider_;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700441 RTNLHandler *rtnl_handler_;
Darin Petkov77cb6812011-08-15 16:19:41 -0700442
Chris Masone9be4a9d2011-05-16 15:44:09 -0700443 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700444};
445
Paul Stewart75897df2011-04-27 09:05:53 -0700446} // namespace shill
447
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200448#endif // SHILL_DEVICE_H_