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