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