Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 5 | #ifndef SHILL_DEVICE_H_ |
| 6 | #define SHILL_DEVICE_H_ |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 8 | #include <string> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 14 | #include <base/memory/weak_ptr.h> |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 16 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 17 | #include "shill/adaptor_interfaces.h" |
| 18 | #include "shill/callbacks.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 20 | #include "shill/ip_address.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 21 | #include "shill/ipconfig.h" |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 22 | #include "shill/portal_detector.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 23 | #include "shill/property_store.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 24 | #include "shill/refptr_types.h" |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 25 | #include "shill/service.h" |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 26 | #include "shill/technology.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace shill { |
| 29 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 30 | class ControlInterface; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 31 | class DHCPProvider; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 32 | class DeviceAdaptorInterface; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 33 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 34 | class Error; |
| 35 | class EventDispatcher; |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 36 | class GeolocationInfo; |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 37 | class LinkMonitor; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 38 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 39 | class Metrics; |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 40 | class RTNLHandler; |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 41 | class TrafficMonitor; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 42 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 43 | // Device superclass. Individual network interfaces types will inherit from |
| 44 | // this class. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 45 | class Device : public base::RefCounted<Device> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 46 | public: |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 47 | // Progressively scanning for access points (APs) is done with multiple scans, |
| 48 | // each containing a group of channels. The scans are performed in order of |
| 49 | // decreasing likelihood of connecting on one of the channels in a group |
| 50 | // (the number of channels in a group is a matter for system tuning). Fully |
| 51 | // scanning for APs does a complete scan of all the channels in a single scan. |
| 52 | // Progressive scanning is supported for wifi devices; technologies that |
| 53 | // support scan but don't support progressive scan will always perform a full |
| 54 | // scan, regardless of the requested scan type. |
| 55 | enum ScanType { kProgressiveScan, kFullScan }; |
| 56 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 57 | // A constructor for the Device object |
| 58 | Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 59 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 60 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 61 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 62 | const std::string &link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 63 | const std::string &address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 64 | int interface_index, |
| 65 | Technology::Identifier technology); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 66 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 67 | // Enable or disable the device. This is a convenience method for |
| 68 | // cases where we want to SetEnabledNonPersistent, but don't care |
| 69 | // about the results. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 70 | virtual void SetEnabled(bool enable); |
mukesh agrawal | b113666 | 2013-10-14 16:39:38 -0700 | [diff] [blame] | 71 | // Enable or disable the device. Unlike SetEnabledPersistent, it does not |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 72 | // save the setting in the profile. |
| 73 | // |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 74 | // TODO(quiche): Replace both of the next two methods with calls to |
| 75 | // SetEnabledChecked. |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 76 | virtual void SetEnabledNonPersistent(bool enable, |
| 77 | Error *error, |
| 78 | const ResultCallback &callback); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 79 | // Enable or disable the device, and save the setting in the profile. |
| 80 | // The setting is persisted before the enable or disable operation |
| 81 | // starts, so that even if it fails, the user's intent is still recorded |
| 82 | // for the next time shill restarts. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 83 | virtual void SetEnabledPersistent(bool enable, |
| 84 | Error *error, |
| 85 | const ResultCallback &callback); |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 86 | // Enable or disable the Device, depending on |enable|. |
| 87 | // Save the new setting to the profile, if |persist| is true. |
| 88 | // Report synchronous errors using |error|, and asynchronous completion |
| 89 | // with |callback|. |
| 90 | virtual void SetEnabledChecked(bool enable, |
| 91 | bool persist, |
| 92 | Error *error, |
| 93 | const ResultCallback &callback); |
| 94 | // Similar to SetEnabledChecked, but without sanity checking, and |
| 95 | // without saving the new value of |enable| to the profile. If you |
| 96 | // are sane (i.e. not Cellular), you should use |
| 97 | // SetEnabledChecked instead. |
| 98 | virtual void SetEnabledUnchecked(bool enable, |
| 99 | Error *error, |
| 100 | const ResultCallback &callback); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 101 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 102 | // Returns true if the underlying device reports that it is already enabled. |
| 103 | // Used when the device is registered with the Manager, so that shill can |
| 104 | // sync its state/ with the true state of the device. The default is to |
| 105 | // report false. |
| 106 | virtual bool IsUnderlyingDeviceEnabled() const; |
| 107 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 108 | virtual void LinkEvent(unsigned flags, unsigned change); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 109 | |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 110 | // The default implementation sets |error| to kNotSupported. |
Wade Guthrie | 4823f4f | 2013-07-25 10:03:03 -0700 | [diff] [blame] | 111 | virtual void Scan(ScanType scan_type, Error *error, |
| 112 | const std::string &reason); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 113 | virtual void RegisterOnNetwork(const std::string &network_id, Error *error, |
| 114 | const ResultCallback &callback); |
| 115 | virtual void RequirePIN(const std::string &pin, bool require, |
| 116 | Error *error, const ResultCallback &callback); |
| 117 | virtual void EnterPIN(const std::string &pin, |
| 118 | Error *error, const ResultCallback &callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 119 | virtual void UnblockPIN(const std::string &unblock_code, |
| 120 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 121 | Error *error, const ResultCallback &callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 122 | virtual void ChangePIN(const std::string &old_pin, |
| 123 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 124 | Error *error, const ResultCallback &callback); |
Ben Chan | ad663e1 | 2013-01-08 01:58:47 -0800 | [diff] [blame] | 125 | virtual void Reset(Error *error, const ResultCallback &callback); |
| 126 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 127 | virtual void SetCarrier(const std::string &carrier, |
| 128 | Error *error, const ResultCallback &callback); |
Ben Chan | bcc6e01 | 2013-11-04 14:28:37 -0800 | [diff] [blame] | 129 | |
| 130 | // Returns true if IPv6 is allowed and should be enabled when the device |
| 131 | // tries to acquire an IP configuration. The default implementation allows |
| 132 | // IPv6, which can be overridden by a derived class. |
| 133 | virtual bool IsIPv6Allowed() const; |
| 134 | |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 135 | virtual void DisableIPv6(); |
| 136 | virtual void EnableIPv6(); |
| 137 | virtual void EnableIPv6Privacy(); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 138 | |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 139 | // Request the removal of reverse-path filtering for this interface. |
| 140 | // This will allow packets destined for this interface to be accepted, |
| 141 | // even if this is not the default route for such a packet to arrive. |
| 142 | virtual void DisableReversePathFilter(); |
| 143 | |
| 144 | // Request reverse-path filtering for this interface. |
| 145 | virtual void EnableReversePathFilter(); |
| 146 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 147 | // Returns true if the selected service on the device (if any) is connected. |
| 148 | // Returns false if there is no selected service, or if the selected service |
| 149 | // is not connected. |
| 150 | bool IsConnected() const; |
| 151 | |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 152 | // Called by Device so that subclasses can run hooks on the selected service |
| 153 | // getting an IP. Subclasses should call up to the parent first. |
| 154 | virtual void OnConnected(); |
| 155 | |
Paul Stewart | 8596f9f | 2013-03-14 07:58:26 -0700 | [diff] [blame] | 156 | // Called by the Connection so that the Device can update the service sorting |
| 157 | // after one connection is bound to another. |
| 158 | virtual void OnConnectionUpdated(); |
| 159 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 160 | // Returns true if the selected service on the device (if any) is connected |
| 161 | // and matches the passed-in argument |service|. Returns false if there is |
| 162 | // no connected service, or if it does not match |service|. |
| 163 | virtual bool IsConnectedToService(const ServiceRefPtr &service) const; |
| 164 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 165 | // Returns true if the DHCP parameters provided indicate that we are tethered |
| 166 | // to a mobile device. |
| 167 | virtual bool IsConnectedViaTether() const; |
| 168 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 169 | // Restart the portal detection process on a connected device. This is |
| 170 | // useful if the properties on the connected service have changed in a |
| 171 | // way that may affect the decision to run portal detection at all. |
| 172 | // Returns true if portal detection was started. |
| 173 | virtual bool RestartPortalDetection(); |
| 174 | |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 175 | // Get receive and transmit byte counters. |
| 176 | virtual uint64 GetReceiveByteCount(); |
| 177 | virtual uint64 GetTransmitByteCount(); |
| 178 | |
Paul Stewart | c6fbad9 | 2013-11-13 14:50:52 -0800 | [diff] [blame] | 179 | // Perform a TDLS |operation| on the underlying device, with respect |
| 180 | // to a given |peer|. The string returned is empty for any operation |
| 181 | // other than kTDLSOperationStatus, which returns the state of the |
| 182 | // TDLS link with |peer|. This method is only valid for WiFi devices, |
| 183 | // but needs to be declared here since it is part of the Device RPC |
| 184 | // API. |
| 185 | virtual std::string PerformTDLSOperation(const std::string &operation, |
| 186 | const std::string &peer, |
| 187 | Error *error); |
| 188 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 189 | // Reset the persisted byte counters associated with the device. |
| 190 | void ResetByteCounters(); |
| 191 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 192 | // Requests that portal detection be done, if this device has the default |
| 193 | // connection. Returns true if portal detection was started. |
| 194 | virtual bool RequestPortalDetection(); |
| 195 | |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 196 | std::string GetRpcIdentifier() const; |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 197 | std::string GetStorageIdentifier(); |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 198 | |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 199 | // Returns a list of Geolocation objects. Each object is multiple |
| 200 | // key-value pairs representing one entity that can be used for |
| 201 | // Geolocation. |
| 202 | virtual std::vector<GeolocationInfo> GetGeolocationObjects() const; |
| 203 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 204 | const std::string &address() const { return hardware_address_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 205 | const std::string &link_name() const { return link_name_; } |
| 206 | int interface_index() const { return interface_index_; } |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 207 | const ConnectionRefPtr &connection() const { return connection_; } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 208 | bool enabled() const { return enabled_; } |
| 209 | bool enabled_persistent() const { return enabled_persistent_; } |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 210 | virtual Technology::Identifier technology() const { return technology_; } |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 211 | std::string GetTechnologyString(Error *error); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 212 | |
Thieu Le | 0302666 | 2013-04-04 10:45:11 -0700 | [diff] [blame] | 213 | virtual const IPConfigRefPtr &ipconfig() const { return ipconfig_; } |
Darin Petkov | 31a2eca | 2012-03-14 11:07:18 +0100 | [diff] [blame] | 214 | void set_ipconfig(const IPConfigRefPtr &config) { ipconfig_ = config; } |
| 215 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 216 | const std::string &FriendlyName() const; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 217 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 218 | // Returns a string that is guaranteed to uniquely identify this Device |
| 219 | // instance. |
| 220 | const std::string &UniqueName() const; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 221 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 222 | PropertyStore *mutable_store() { return &store_; } |
| 223 | const PropertyStore &store() const { return store_; } |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 224 | RTNLHandler *rtnl_handler() { return rtnl_handler_; } |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 225 | bool running() const { return running_; } |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 226 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 227 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 228 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 229 | // Load configuration for the device from |storage|. This may include |
| 230 | // instantiating non-visible services for which configuration has been |
| 231 | // stored. |
| 232 | virtual bool Load(StoreInterface *storage); |
| 233 | |
| 234 | // Save configuration for the device to |storage|. |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 235 | virtual bool Save(StoreInterface *storage); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 236 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 237 | void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; } |
| 238 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 239 | DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); } |
| 240 | |
mukesh agrawal | 784566d | 2012-08-08 18:32:58 -0700 | [diff] [blame] | 241 | // Suspend event handler. Called by Manager before the system |
mukesh agrawal | b113666 | 2013-10-14 16:39:38 -0700 | [diff] [blame] | 242 | // suspends. This handler, along with any other suspect handlers, |
| 243 | // will have Manager::kTerminationActionsTimeoutMilliseconds to |
| 244 | // execute before the system enters the suspend state. |
mukesh agrawal | 784566d | 2012-08-08 18:32:58 -0700 | [diff] [blame] | 245 | // |
mukesh agrawal | b113666 | 2013-10-14 16:39:38 -0700 | [diff] [blame] | 246 | // Code that needs to run on exit, as well as on suspend, should use |
| 247 | // Manager::AddTerminationAction, rather than OnBeforeSuspend. |
mukesh agrawal | 784566d | 2012-08-08 18:32:58 -0700 | [diff] [blame] | 248 | virtual void OnBeforeSuspend(); |
| 249 | |
| 250 | // Resume event handler. Called by Manager as the system resumes. |
| 251 | // The base class implementation takes care of renewing a DHCP lease |
| 252 | // (if necessary). Derived classes may implement any technology |
| 253 | // specific requirements by overriding, but should include a call to |
| 254 | // the base class implementation. |
| 255 | virtual void OnAfterResume(); |
| 256 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 257 | // Destroy the lease, if any, with this |name|. |
| 258 | // Called by the service during Unload() as part of the cleanup sequence. |
| 259 | virtual void DestroyIPConfigLease(const std::string &name); |
| 260 | |
Paul Stewart | d55f6ae | 2014-04-24 16:34:21 -0700 | [diff] [blame] | 261 | // Called by DeviceInfo when the kernel adds or removes a globally-scoped |
| 262 | // IPv6 address from this interface. |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 263 | virtual void OnIPv6AddressChanged(); |
Paul Stewart | d55f6ae | 2014-04-24 16:34:21 -0700 | [diff] [blame] | 264 | |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 265 | protected: |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 266 | friend class base::RefCounted<Device>; |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 267 | friend class DeviceHealthCheckerTest; |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 268 | FRIEND_TEST(CellularServiceTest, IsAutoConnectable); |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 269 | FRIEND_TEST(CellularTest, EnableTrafficMonitor); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 270 | FRIEND_TEST(CellularTest, ModemStateChangeDisable); |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 271 | FRIEND_TEST(CellularTest, UseNoArpGateway); |
Darin Petkov | 13e6d55 | 2012-05-09 14:22:23 +0200 | [diff] [blame] | 272 | FRIEND_TEST(ConnectionTest, OnRouteQueryResponse); |
Prathmesh Prabhu | ba99b59 | 2013-04-17 15:13:14 -0700 | [diff] [blame] | 273 | FRIEND_TEST(DeviceHealthCheckerTest, HealthCheckerPersistsAcrossDeviceReset); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 274 | FRIEND_TEST(DeviceHealthCheckerTest, RequestConnectionHealthCheck); |
Prathmesh Prabhu | ba99b59 | 2013-04-17 15:13:14 -0700 | [diff] [blame] | 275 | FRIEND_TEST(DeviceHealthCheckerTest, SetupHealthChecker); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 276 | FRIEND_TEST(DeviceTest, AcquireIPConfig); |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 277 | FRIEND_TEST(DeviceTest, AvailableIPConfigs); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 278 | FRIEND_TEST(DeviceTest, DestroyIPConfig); |
| 279 | FRIEND_TEST(DeviceTest, DestroyIPConfigNULL); |
Ben Chan | bcc6e01 | 2013-11-04 14:28:37 -0800 | [diff] [blame] | 280 | FRIEND_TEST(DeviceTest, EnableIPv6); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 281 | FRIEND_TEST(DeviceTest, GetProperties); |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 282 | FRIEND_TEST(DeviceTest, IsConnectedViaTether); |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 283 | FRIEND_TEST(DeviceTest, Load); |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 284 | FRIEND_TEST(DeviceTest, OnIPv6AddressChanged); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 285 | FRIEND_TEST(DeviceTest, Save); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 286 | FRIEND_TEST(DeviceTest, SelectedService); |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 287 | FRIEND_TEST(DeviceTest, SetEnabledNonPersistent); |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 288 | FRIEND_TEST(DeviceTest, SetEnabledPersistent); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 289 | FRIEND_TEST(DeviceTest, SetServiceConnectedState); |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 290 | FRIEND_TEST(DeviceTest, ShouldUseArpGateway); |
| 291 | FRIEND_TEST(DeviceTest, ShouldUseMinimalDHCPConfig); |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 292 | FRIEND_TEST(DeviceTest, Start); |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 293 | FRIEND_TEST(DeviceTest, StartTrafficMonitor); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 294 | FRIEND_TEST(DeviceTest, Stop); |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 295 | FRIEND_TEST(DeviceTest, StopTrafficMonitor); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 296 | FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 297 | FRIEND_TEST(ManagerTest, ConnectedTechnologies); |
| 298 | FRIEND_TEST(ManagerTest, DefaultTechnology); |
mukesh agrawal | 46c27cc | 2013-07-10 16:39:10 -0700 | [diff] [blame] | 299 | FRIEND_TEST(ManagerTest, SetEnabledStateForTechnology); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 300 | FRIEND_TEST(PPPDeviceTest, UpdateIPConfigFromPPP); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 301 | FRIEND_TEST(WiFiMainTest, Connect); |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 302 | FRIEND_TEST(WiFiMainTest, UseArpGateway); |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 303 | FRIEND_TEST(WiMaxTest, ConnectTimeout); |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 304 | FRIEND_TEST(WiMaxTest, UseNoArpGateway); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 305 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 306 | virtual ~Device(); |
| 307 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 308 | // Each device must implement this method to do the work needed to |
| 309 | // enable the device to operate for establishing network connections. |
| 310 | // The |error| argument, if not NULL, |
| 311 | // will refer to an Error that starts out with the value |
| 312 | // Error::kOperationInitiated. This reflects the assumption that |
| 313 | // enable (and disable) operations will usually be non-blocking, |
| 314 | // and their completion will be indicated by means of an asynchronous |
| 315 | // reply sometime later. There are two circumstances in which a |
| 316 | // device's Start() method may overwrite |error|: |
| 317 | // |
| 318 | // 1. If an early failure is detected, such that the non-blocking |
| 319 | // part of the operation never takes place, then |error| should |
| 320 | // be set to the appropriate value corresponding to the type |
| 321 | // of failure. This is the "immediate failure" case. |
| 322 | // 2. If the device is enabled without performing any non-blocking |
| 323 | // steps, then |error| should be Reset, i.e., its value set |
| 324 | // to Error::kSuccess. This is the "immediate success" case. |
| 325 | // |
| 326 | // In these two cases, because completion is immediate, |callback| |
| 327 | // is not used. If neither of these two conditions holds, then |error| |
| 328 | // should not be modified, and |callback| should be passed to the |
| 329 | // method that will initiate the non-blocking operation. |
| 330 | virtual void Start(Error *error, |
| 331 | const EnabledStateChangedCallback &callback) = 0; |
| 332 | |
| 333 | // Each device must implement this method to do the work needed to |
| 334 | // disable the device, i.e., clear any running state, and make the |
| 335 | // device no longer capable of establishing network connections. |
| 336 | // The discussion for Start() regarding the use of |error| and |
| 337 | // |callback| apply to Stop() as well. |
| 338 | virtual void Stop(Error *error, |
| 339 | const EnabledStateChangedCallback &callback) = 0; |
| 340 | |
| 341 | // The EnabledStateChangedCallback that gets passed to the device's |
| 342 | // Start() and Stop() methods is bound to this method. |callback| |
| 343 | // is the callback that was passed to SetEnabled(). |
| 344 | void OnEnabledStateChanged(const ResultCallback &callback, |
| 345 | const Error &error); |
| 346 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 347 | // Drops the currently selected service along with its IP configuration and |
| 348 | // connection, if any. |
mukesh agrawal | 5d851b1 | 2013-07-11 14:09:41 -0700 | [diff] [blame] | 349 | virtual void DropConnection(); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 350 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 351 | // If there's an IP configuration in |ipconfig_|, releases the IP address and |
| 352 | // destroys the configuration instance. |
| 353 | void DestroyIPConfig(); |
| 354 | |
| 355 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 356 | // requests a new IP configuration. Saves the DHCP lease to the generic |
| 357 | // lease filename based on the interface name. Registers a callback to |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 358 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 359 | // request was successfully sent. |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 360 | bool AcquireIPConfig(); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 361 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 362 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
| 363 | // requests a new IP configuration. Saves the DHCP lease to a filename |
| 364 | // based on the passed-in |lease_name|. Registers a callback to |
| 365 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 366 | // request was successfully sent. |
| 367 | bool AcquireIPConfigWithLeaseName(const std::string &lease_name); |
| 368 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 369 | // Assigns the IP configuration |properties| to |ipconfig_|. |
| 370 | void AssignIPConfig(const IPConfig::Properties &properties); |
| 371 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 372 | // Callback invoked on successful IP configuration updates. |
| 373 | void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig); |
| 374 | |
| 375 | // Callback invoked on IP configuration failures. |
| 376 | void OnIPConfigFailed(const IPConfigRefPtr &ipconfig); |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 377 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 378 | // Callback invoked when "Refresh" is invoked on an IPConfig. This usually |
| 379 | // signals a change in static IP parameters. |
| 380 | void OnIPConfigRefreshed(const IPConfigRefPtr &ipconfig); |
| 381 | |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 382 | // Callback invoked when an IPConfig restarts due to lease expiry. This |
| 383 | // is advisory, since an "Updated" or "Failed" signal is guaranteed to |
| 384 | // follow. |
| 385 | void OnIPConfigExpired(const IPConfigRefPtr &ipconfig); |
| 386 | |
Paul Stewart | f6f9648 | 2013-07-12 12:49:15 -0700 | [diff] [blame] | 387 | // Called by Device so that subclasses can run hooks on the selected service |
| 388 | // failing to get an IP. The default implementation disconnects the selected |
| 389 | // service with Service::kFailureDHCP. |
| 390 | virtual void OnIPConfigFailure(); |
| 391 | |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 392 | // Maintain connection state (Routes, IP Addresses and DNS) in the OS. |
| 393 | void CreateConnection(); |
| 394 | |
| 395 | // Remove connection state |
| 396 | void DestroyConnection(); |
| 397 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 398 | // Selects a service to be "current" -- i.e. link-state or configuration |
| 399 | // events that happen to the device are attributed to this service. |
| 400 | void SelectService(const ServiceRefPtr &service); |
| 401 | |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 402 | // Set the state of the |selected_service_|. |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 403 | virtual void SetServiceState(Service::ConnectState state); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 404 | |
| 405 | // Set the failure of the selected service (implicitly sets the state to |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 406 | // "failure"). |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 407 | virtual void SetServiceFailure(Service::ConnectFailure failure_state); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 408 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 409 | // Records the failure mode and time of the selected service, and |
| 410 | // sets the Service state of the selected service to "Idle". |
| 411 | // Avoids showing a failure mole in the UI. |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 412 | virtual void SetServiceFailureSilent(Service::ConnectFailure failure_state); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 413 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 414 | // Called by the Portal Detector whenever a trial completes. Device |
| 415 | // subclasses that choose unique mappings from portal results to connected |
| 416 | // states can override this method in order to do so. |
| 417 | virtual void PortalDetectorCallback(const PortalDetector::Result &result); |
| 418 | |
| 419 | // Initiate portal detection, if enabled for this device type. |
| 420 | bool StartPortalDetection(); |
| 421 | |
| 422 | // Stop portal detection if it is running. |
| 423 | void StopPortalDetection(); |
| 424 | |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 425 | // Initiate link monitoring, if enabled for this device type. |
| 426 | bool StartLinkMonitor(); |
| 427 | |
| 428 | // Stop link monitoring if it is running. |
| 429 | void StopLinkMonitor(); |
| 430 | |
| 431 | // Respond to a LinkMonitor failure in a Device-specific manner. |
| 432 | virtual void OnLinkMonitorFailure(); |
| 433 | |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 434 | // Respond to a LinkMonitor gateway's MAC address found/change event. |
| 435 | virtual void OnLinkMonitorGatewayChange(); |
Peter Qiu | b5d124f | 2014-04-14 12:05:02 -0700 | [diff] [blame] | 436 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 437 | // Set the state of the selected service, with checks to make sure |
| 438 | // the service is already in a connected state before doing so. |
| 439 | void SetServiceConnectedState(Service::ConnectState state); |
| 440 | |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 441 | // Specifies whether an ARP gateway should be used for the |
| 442 | // device technology. |
| 443 | virtual bool ShouldUseArpGateway() const; |
| 444 | |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 445 | // Specifies whether DHCP replies have not been succeeding or we have |
| 446 | // previously noticed that requesting a minimal DHCP response seems |
| 447 | // to alleviate issues with receiving a reply. |
| 448 | bool ShouldUseMinimalDHCPConfig() const; |
| 449 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 450 | const ServiceRefPtr &selected_service() const { return selected_service_; } |
| 451 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 452 | void HelpRegisterConstDerivedString( |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 453 | const std::string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 454 | std::string(Device::*get)(Error *)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 455 | |
Jason Glasgow | 08afdff | 2012-04-03 10:22:26 -0400 | [diff] [blame] | 456 | void HelpRegisterConstDerivedRpcIdentifiers( |
| 457 | const std::string &name, |
| 458 | RpcIdentifiers(Device::*get)(Error *)); |
| 459 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 460 | void HelpRegisterConstDerivedUint64( |
| 461 | const std::string &name, |
| 462 | uint64(Device::*get)(Error *)); |
| 463 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 464 | // Property getters reserved for subclasses |
| 465 | ControlInterface *control_interface() const { return control_interface_; } |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 466 | Metrics *metrics() const { return metrics_; } |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 467 | Manager *manager() const { return manager_; } |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 468 | const LinkMonitor *link_monitor() const { return link_monitor_.get(); } |
| 469 | void set_link_monitor(LinkMonitor *link_monitor); |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 470 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 471 | private: |
Darin Petkov | 3189a47 | 2012-10-05 09:55:33 +0200 | [diff] [blame] | 472 | friend class CellularCapabilityTest; |
| 473 | friend class CellularTest; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 474 | friend class DeviceAdaptorInterface; |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 475 | friend class DeviceByteCountTest; |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 476 | friend class DevicePortalDetectionTest; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 477 | friend class DeviceTest; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 478 | friend class EthernetTest; |
Darin Petkov | 3189a47 | 2012-10-05 09:55:33 +0200 | [diff] [blame] | 479 | friend class OpenVPNDriverTest; |
Ben Chan | bcc6e01 | 2013-11-04 14:28:37 -0800 | [diff] [blame] | 480 | friend class TestDevice; |
mukesh agrawal | 4a16558 | 2013-08-02 15:58:21 -0700 | [diff] [blame] | 481 | friend class VirtualDeviceTest; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 482 | friend class WiFiObjectTest; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 483 | |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 484 | static const char kIPFlagTemplate[]; |
| 485 | static const char kIPFlagVersion4[]; |
| 486 | static const char kIPFlagVersion6[]; |
| 487 | static const char kIPFlagDisableIPv6[]; |
| 488 | static const char kIPFlagUseTempAddr[]; |
| 489 | static const char kIPFlagUseTempAddrUsedAndDefault[]; |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 490 | static const char kIPFlagReversePathFilter[]; |
| 491 | static const char kIPFlagReversePathFilterEnabled[]; |
| 492 | static const char kIPFlagReversePathFilterLooseMode[]; |
Prathmesh Prabhu | ba99b59 | 2013-04-17 15:13:14 -0700 | [diff] [blame] | 493 | static const char kStoragePowered[]; |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 494 | static const char kStorageReceiveByteCount[]; |
| 495 | static const char kStorageTransmitByteCount[]; |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 496 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 497 | // Configure static IP address parameters if the service provides them. |
| 498 | void ConfigureStaticIPTask(); |
| 499 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 500 | // Right now, Devices reference IPConfigs directly when persisted to disk |
| 501 | // It's not clear that this makes sense long-term, but that's how it is now. |
| 502 | // This call generates a string in the right format for this persisting. |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 503 | // |suffix| is injected into the storage identifier used for the configs. |
| 504 | std::string SerializeIPConfigs(const std::string &suffix); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 505 | |
Ben Chan | bcc6e01 | 2013-11-04 14:28:37 -0800 | [diff] [blame] | 506 | // Set an IP configuration flag on the device. |family| should be "ipv6" or |
| 507 | // "ipv4". |flag| should be the name of the flag to be set and |value| is |
| 508 | // what this flag should be set to. Overridden by unit tests to pretend |
| 509 | // writing to procfs. |
| 510 | virtual bool SetIPFlag(IPAddress::Family family, |
| 511 | const std::string &flag, |
| 512 | const std::string &value); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 513 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 514 | std::vector<std::string> AvailableIPConfigs(Error *error); |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 515 | std::string GetRpcConnectionIdentifier(); |
| 516 | |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 517 | // Get the LinkMonitor's average response time. |
| 518 | uint64 GetLinkMonitorResponseTime(Error *error); |
| 519 | |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 520 | // Get receive and transmit byte counters. These methods simply wrap |
| 521 | // GetReceiveByteCount and GetTransmitByteCount in order to be used by |
| 522 | // HelpRegisterConstDerivedUint64. |
| 523 | uint64 GetReceiveByteCountProperty(Error *error); |
| 524 | uint64 GetTransmitByteCountProperty(Error *error); |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 525 | |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 526 | // Emit a property change signal for the "IPConfigs" property of this device. |
| 527 | void UpdateIPConfigsProperty(); |
| 528 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 529 | // |enabled_persistent_| is the value of the Powered property, as |
| 530 | // read from the profile. If it is not found in the profile, it |
| 531 | // defaults to true. |enabled_| reflects the real-time state of |
| 532 | // the device, i.e., enabled or disabled. |enabled_pending_| reflects |
| 533 | // the target state of the device while an enable or disable operation |
| 534 | // is occurring. |
| 535 | // |
| 536 | // Some typical sequences for these state variables are shown below. |
| 537 | // |
| 538 | // Shill starts up, profile has been read: |
| 539 | // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=false |
| 540 | // |
| 541 | // Shill acts on the value of |enabled_persistent_|, calls SetEnabled(true): |
| 542 | // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=true |
| 543 | // |
| 544 | // SetEnabled completes successfully, device is enabled: |
| 545 | // |enabled_persistent_|=true |enabled_|=true |enabled_pending_|=true |
| 546 | // |
| 547 | // User presses "Disable" button, SetEnabled(false) is called: |
| 548 | // |enabled_persistent_|=false |enabled_|=true |enabled_pending_|=false |
| 549 | // |
| 550 | // SetEnabled completes successfully, device is disabled: |
| 551 | // |enabled_persistent_|=false |enabled_|=false |enabled_pending_|=false |
| 552 | bool enabled_; |
| 553 | bool enabled_persistent_; |
| 554 | bool enabled_pending_; |
| 555 | |
| 556 | // Other properties |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 557 | bool reconnect_; |
| 558 | const std::string hardware_address_; |
| 559 | |
| 560 | PropertyStore store_; |
| 561 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 562 | const int interface_index_; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 563 | bool running_; // indicates whether the device is actually in operation |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 564 | const std::string link_name_; |
| 565 | const std::string unique_id_; |
| 566 | ControlInterface *control_interface_; |
| 567 | EventDispatcher *dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 568 | Metrics *metrics_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 569 | Manager *manager_; |
| 570 | IPConfigRefPtr ipconfig_; |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 571 | IPConfigRefPtr ip6config_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 572 | ConnectionRefPtr connection_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 573 | base::WeakPtrFactory<Device> weak_ptr_factory_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 574 | scoped_ptr<DeviceAdaptorInterface> adaptor_; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 575 | scoped_ptr<PortalDetector> portal_detector_; |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 576 | scoped_ptr<LinkMonitor> link_monitor_; |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 577 | base::Callback<void(const PortalDetector::Result &)> |
| 578 | portal_detector_callback_; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 579 | Technology::Identifier technology_; |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 580 | // The number of portal detection attempts from Connected to Online state. |
| 581 | // This includes all failure/timeout attempts and the final successful |
| 582 | // attempt. |
| 583 | int portal_attempts_to_online_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 584 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 585 | // Keep track of the offset between the interface-reported byte counters |
| 586 | // and our persisted value. |
| 587 | uint64 receive_byte_offset_; |
| 588 | uint64 transmit_byte_offset_; |
| 589 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 590 | // Maintain a reference to the connected / connecting service |
| 591 | ServiceRefPtr selected_service_; |
| 592 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 593 | // Cache singleton pointers for performance and test purposes. |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 594 | DHCPProvider *dhcp_provider_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 595 | RTNLHandler *rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 596 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 597 | DISALLOW_COPY_AND_ASSIGN(Device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 600 | } // namespace shill |
| 601 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 602 | #endif // SHILL_DEVICE_H_ |