Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 5 | #ifndef SHILL_DEVICE_H_ |
| 6 | #define SHILL_DEVICE_H_ |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 8 | #include <string> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 14 | #include <base/memory/weak_ptr.h> |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 16 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 17 | #include "shill/adaptor_interfaces.h" |
| 18 | #include "shill/callbacks.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 20 | #include "shill/ip_address.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 21 | #include "shill/ipconfig.h" |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 22 | #include "shill/portal_detector.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 23 | #include "shill/property_store.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 24 | #include "shill/refptr_types.h" |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 25 | #include "shill/service.h" |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 26 | #include "shill/technology.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace shill { |
| 29 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 30 | class ControlInterface; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 31 | class DHCPProvider; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 32 | class DeviceAdaptorInterface; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 33 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 34 | class Error; |
| 35 | class EventDispatcher; |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 36 | class LinkMonitor; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 37 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 38 | class Metrics; |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 39 | class RTNLHandler; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 40 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 41 | // Device superclass. Individual network interfaces types will inherit from |
| 42 | // this class. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 43 | class Device : public base::RefCounted<Device> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | public: |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 45 | // A constructor for the Device object |
| 46 | Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 47 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 48 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 49 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 50 | const std::string &link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 51 | const std::string &address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 52 | int interface_index, |
| 53 | Technology::Identifier technology); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 54 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 55 | // Enable or disable the device. |
| 56 | virtual void SetEnabled(bool enable); |
| 57 | // Enable or disable the device, and save the setting in the profile. |
| 58 | // The setting is persisted before the enable or disable operation |
| 59 | // starts, so that even if it fails, the user's intent is still recorded |
| 60 | // for the next time shill restarts. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 61 | virtual void SetEnabledPersistent(bool enable, |
| 62 | Error *error, |
| 63 | const ResultCallback &callback); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 64 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 65 | // Returns true if the underlying device reports that it is already enabled. |
| 66 | // Used when the device is registered with the Manager, so that shill can |
| 67 | // sync its state/ with the true state of the device. The default is to |
| 68 | // report false. |
| 69 | virtual bool IsUnderlyingDeviceEnabled() const; |
| 70 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 71 | virtual void LinkEvent(unsigned flags, unsigned change); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 72 | |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 73 | // The default implementation sets |error| to kNotSupported. |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 74 | virtual void Scan(Error *error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 75 | virtual void RegisterOnNetwork(const std::string &network_id, Error *error, |
| 76 | const ResultCallback &callback); |
| 77 | virtual void RequirePIN(const std::string &pin, bool require, |
| 78 | Error *error, const ResultCallback &callback); |
| 79 | virtual void EnterPIN(const std::string &pin, |
| 80 | Error *error, const ResultCallback &callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 81 | virtual void UnblockPIN(const std::string &unblock_code, |
| 82 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 83 | Error *error, const ResultCallback &callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 84 | virtual void ChangePIN(const std::string &old_pin, |
| 85 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 86 | Error *error, const ResultCallback &callback); |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 87 | virtual void SetCarrier(const std::string &carrier, |
| 88 | Error *error, const ResultCallback &callback); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 89 | virtual void DisableIPv6(); |
| 90 | virtual void EnableIPv6(); |
| 91 | virtual void EnableIPv6Privacy(); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 92 | |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 93 | // Request the removal of reverse-path filtering for this interface. |
| 94 | // This will allow packets destined for this interface to be accepted, |
| 95 | // even if this is not the default route for such a packet to arrive. |
| 96 | virtual void DisableReversePathFilter(); |
| 97 | |
| 98 | // Request reverse-path filtering for this interface. |
| 99 | virtual void EnableReversePathFilter(); |
| 100 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 101 | // Returns true if the selected service on the device (if any) is connected. |
| 102 | // Returns false if there is no selected service, or if the selected service |
| 103 | // is not connected. |
| 104 | bool IsConnected() const; |
| 105 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 106 | // Returns true if the selected service on the device (if any) is connected |
| 107 | // and matches the passed-in argument |service|. Returns false if there is |
| 108 | // no connected service, or if it does not match |service|. |
| 109 | virtual bool IsConnectedToService(const ServiceRefPtr &service) const; |
| 110 | |
| 111 | // Restart the portal detection process on a connected device. This is |
| 112 | // useful if the properties on the connected service have changed in a |
| 113 | // way that may affect the decision to run portal detection at all. |
| 114 | // Returns true if portal detection was started. |
| 115 | virtual bool RestartPortalDetection(); |
| 116 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 117 | // Reset the persisted byte counters associated with the device. |
| 118 | void ResetByteCounters(); |
| 119 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 120 | // Requests that portal detection be done, if this device has the default |
| 121 | // connection. Returns true if portal detection was started. |
| 122 | virtual bool RequestPortalDetection(); |
| 123 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 124 | std::string GetRpcIdentifier(); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 125 | std::string GetStorageIdentifier(); |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 126 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 127 | const std::string &address() const { return hardware_address_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 128 | const std::string &link_name() const { return link_name_; } |
| 129 | int interface_index() const { return interface_index_; } |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 130 | const ConnectionRefPtr &connection() const { return connection_; } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 131 | bool enabled() const { return enabled_; } |
| 132 | bool enabled_persistent() const { return enabled_persistent_; } |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 133 | virtual Technology::Identifier technology() const { return technology_; } |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 134 | std::string GetTechnologyString(Error *error); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 135 | |
Darin Petkov | 31a2eca | 2012-03-14 11:07:18 +0100 | [diff] [blame] | 136 | const IPConfigRefPtr &ipconfig() const { return ipconfig_; } |
| 137 | void set_ipconfig(const IPConfigRefPtr &config) { ipconfig_ = config; } |
| 138 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 139 | const std::string &FriendlyName() const; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 140 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 141 | // Returns a string that is guaranteed to uniquely identify this Device |
| 142 | // instance. |
| 143 | const std::string &UniqueName() const; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 144 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 145 | PropertyStore *mutable_store() { return &store_; } |
| 146 | const PropertyStore &store() const { return store_; } |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 147 | RTNLHandler *rtnl_handler() { return rtnl_handler_; } |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 148 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 149 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 150 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 151 | // Load configuration for the device from |storage|. This may include |
| 152 | // instantiating non-visible services for which configuration has been |
| 153 | // stored. |
| 154 | virtual bool Load(StoreInterface *storage); |
| 155 | |
| 156 | // Save configuration for the device to |storage|. |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 157 | virtual bool Save(StoreInterface *storage); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 158 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 159 | void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; } |
| 160 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 161 | DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); } |
| 162 | |
mukesh agrawal | 784566d | 2012-08-08 18:32:58 -0700 | [diff] [blame] | 163 | // Suspend event handler. Called by Manager before the system |
| 164 | // suspends. For this callback to be useful, the device must specify |
| 165 | // a suspend delay. Otherwise, there is no guarantee that the device |
| 166 | // will have time to complete its suspend actions, before the system |
| 167 | // is suspended. |
| 168 | // |
| 169 | // TODO(quiche): Add support for suspend delays. crosbug.com/33412 |
| 170 | virtual void OnBeforeSuspend(); |
| 171 | |
| 172 | // Resume event handler. Called by Manager as the system resumes. |
| 173 | // The base class implementation takes care of renewing a DHCP lease |
| 174 | // (if necessary). Derived classes may implement any technology |
| 175 | // specific requirements by overriding, but should include a call to |
| 176 | // the base class implementation. |
| 177 | virtual void OnAfterResume(); |
| 178 | |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 179 | protected: |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 180 | friend class base::RefCounted<Device>; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 181 | FRIEND_TEST(CellularTest, ModemStateChangeDisable); |
Darin Petkov | 13e6d55 | 2012-05-09 14:22:23 +0200 | [diff] [blame] | 182 | FRIEND_TEST(ConnectionTest, OnRouteQueryResponse); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 183 | FRIEND_TEST(DeviceTest, AcquireIPConfig); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 184 | FRIEND_TEST(DeviceTest, DestroyIPConfig); |
| 185 | FRIEND_TEST(DeviceTest, DestroyIPConfigNULL); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 186 | FRIEND_TEST(DeviceTest, GetProperties); |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 187 | FRIEND_TEST(DeviceTest, Load); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 188 | FRIEND_TEST(DeviceTest, Save); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 189 | FRIEND_TEST(DeviceTest, SelectedService); |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 190 | FRIEND_TEST(DeviceTest, SetEnabledPersistent); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 191 | FRIEND_TEST(DeviceTest, SetServiceConnectedState); |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 192 | FRIEND_TEST(DeviceTest, Start); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 193 | FRIEND_TEST(DeviceTest, Stop); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 194 | FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 195 | FRIEND_TEST(ManagerTest, ConnectedTechnologies); |
| 196 | FRIEND_TEST(ManagerTest, DefaultTechnology); |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 197 | FRIEND_TEST(ManagerTest, EnableTechnology); |
| 198 | FRIEND_TEST(ManagerTest, DisableTechnology); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 199 | FRIEND_TEST(WiFiMainTest, Connect); |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 200 | FRIEND_TEST(WiMaxTest, ConnectTimeout); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 201 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 202 | virtual ~Device(); |
| 203 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 204 | // Each device must implement this method to do the work needed to |
| 205 | // enable the device to operate for establishing network connections. |
| 206 | // The |error| argument, if not NULL, |
| 207 | // will refer to an Error that starts out with the value |
| 208 | // Error::kOperationInitiated. This reflects the assumption that |
| 209 | // enable (and disable) operations will usually be non-blocking, |
| 210 | // and their completion will be indicated by means of an asynchronous |
| 211 | // reply sometime later. There are two circumstances in which a |
| 212 | // device's Start() method may overwrite |error|: |
| 213 | // |
| 214 | // 1. If an early failure is detected, such that the non-blocking |
| 215 | // part of the operation never takes place, then |error| should |
| 216 | // be set to the appropriate value corresponding to the type |
| 217 | // of failure. This is the "immediate failure" case. |
| 218 | // 2. If the device is enabled without performing any non-blocking |
| 219 | // steps, then |error| should be Reset, i.e., its value set |
| 220 | // to Error::kSuccess. This is the "immediate success" case. |
| 221 | // |
| 222 | // In these two cases, because completion is immediate, |callback| |
| 223 | // is not used. If neither of these two conditions holds, then |error| |
| 224 | // should not be modified, and |callback| should be passed to the |
| 225 | // method that will initiate the non-blocking operation. |
| 226 | virtual void Start(Error *error, |
| 227 | const EnabledStateChangedCallback &callback) = 0; |
| 228 | |
| 229 | // Each device must implement this method to do the work needed to |
| 230 | // disable the device, i.e., clear any running state, and make the |
| 231 | // device no longer capable of establishing network connections. |
| 232 | // The discussion for Start() regarding the use of |error| and |
| 233 | // |callback| apply to Stop() as well. |
| 234 | virtual void Stop(Error *error, |
| 235 | const EnabledStateChangedCallback &callback) = 0; |
| 236 | |
| 237 | // The EnabledStateChangedCallback that gets passed to the device's |
| 238 | // Start() and Stop() methods is bound to this method. |callback| |
| 239 | // is the callback that was passed to SetEnabled(). |
| 240 | void OnEnabledStateChanged(const ResultCallback &callback, |
| 241 | const Error &error); |
| 242 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 243 | // Drops the currently selected service along with its IP configuration and |
| 244 | // connection, if any. |
| 245 | void DropConnection(); |
| 246 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 247 | // If there's an IP configuration in |ipconfig_|, releases the IP address and |
| 248 | // destroys the configuration instance. |
| 249 | void DestroyIPConfig(); |
| 250 | |
| 251 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 252 | // requests a new IP configuration. Saves the DHCP lease to the generic |
| 253 | // lease filename based on the interface name. Registers a callback to |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 254 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 255 | // request was successfully sent. |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 256 | bool AcquireIPConfig(); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 257 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 258 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
| 259 | // requests a new IP configuration. Saves the DHCP lease to a filename |
| 260 | // based on the passed-in |lease_name|. Registers a callback to |
| 261 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 262 | // request was successfully sent. |
| 263 | bool AcquireIPConfigWithLeaseName(const std::string &lease_name); |
| 264 | |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 265 | // Callback invoked on every IP configuration update. |
| 266 | void OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success); |
| 267 | |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 268 | // Maintain connection state (Routes, IP Addresses and DNS) in the OS. |
| 269 | void CreateConnection(); |
| 270 | |
| 271 | // Remove connection state |
| 272 | void DestroyConnection(); |
| 273 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 274 | // Selects a service to be "current" -- i.e. link-state or configuration |
| 275 | // events that happen to the device are attributed to this service. |
| 276 | void SelectService(const ServiceRefPtr &service); |
| 277 | |
| 278 | // Set the state of the selected service |
| 279 | void SetServiceState(Service::ConnectState state); |
| 280 | |
| 281 | // Set the failure of the selected service (implicitly sets the state to |
| 282 | // "failure") |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 283 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 284 | void SetServiceFailure(Service::ConnectFailure failure_state); |
| 285 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 286 | // Records the failure mode and time of the selected service, and |
| 287 | // sets the Service state of the selected service to "Idle". |
| 288 | // Avoids showing a failure mole in the UI. |
| 289 | void SetServiceFailureSilent(Service::ConnectFailure failure_state); |
| 290 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 291 | // Called by the Portal Detector whenever a trial completes. Device |
| 292 | // subclasses that choose unique mappings from portal results to connected |
| 293 | // states can override this method in order to do so. |
| 294 | virtual void PortalDetectorCallback(const PortalDetector::Result &result); |
| 295 | |
| 296 | // Initiate portal detection, if enabled for this device type. |
| 297 | bool StartPortalDetection(); |
| 298 | |
| 299 | // Stop portal detection if it is running. |
| 300 | void StopPortalDetection(); |
| 301 | |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 302 | // Initiate link monitoring, if enabled for this device type. |
| 303 | bool StartLinkMonitor(); |
| 304 | |
| 305 | // Stop link monitoring if it is running. |
| 306 | void StopLinkMonitor(); |
| 307 | |
| 308 | // Respond to a LinkMonitor failure in a Device-specific manner. |
| 309 | virtual void OnLinkMonitorFailure(); |
| 310 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 311 | // Set the state of the selected service, with checks to make sure |
| 312 | // the service is already in a connected state before doing so. |
| 313 | void SetServiceConnectedState(Service::ConnectState state); |
| 314 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 315 | const ServiceRefPtr &selected_service() const { return selected_service_; } |
| 316 | |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 317 | void HelpRegisterDerivedString( |
| 318 | const std::string &name, |
| 319 | std::string(Device::*get)(Error *), |
| 320 | void(Device::*set)(const std::string&, Error *)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 321 | |
| 322 | void HelpRegisterDerivedStrings( |
| 323 | const std::string &name, |
| 324 | Strings(Device::*get)(Error *error), |
| 325 | void(Device::*set)(const Strings &value, Error *error)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 326 | |
Jason Glasgow | 08afdff | 2012-04-03 10:22:26 -0400 | [diff] [blame] | 327 | void HelpRegisterConstDerivedRpcIdentifiers( |
| 328 | const std::string &name, |
| 329 | RpcIdentifiers(Device::*get)(Error *)); |
| 330 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 331 | void HelpRegisterConstDerivedUint64( |
| 332 | const std::string &name, |
| 333 | uint64(Device::*get)(Error *)); |
| 334 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 335 | // Property getters reserved for subclasses |
| 336 | ControlInterface *control_interface() const { return control_interface_; } |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 337 | Metrics *metrics() const { return metrics_; } |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 338 | Manager *manager() const { return manager_; } |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 339 | bool running() const { return running_; } |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 340 | const LinkMonitor *link_monitor() const { return link_monitor_.get(); } |
| 341 | void set_link_monitor(LinkMonitor *link_monitor); |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 342 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 343 | private: |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 344 | friend class DeviceAdaptorInterface; |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 345 | friend class DeviceByteCountTest; |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 346 | friend class DevicePortalDetectionTest; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 347 | friend class DeviceTest; |
| 348 | friend class CellularTest; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 349 | friend class CellularCapabilityTest; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 350 | friend class WiFiObjectTest; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 351 | |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 352 | static const char kIPFlagTemplate[]; |
| 353 | static const char kIPFlagVersion4[]; |
| 354 | static const char kIPFlagVersion6[]; |
| 355 | static const char kIPFlagDisableIPv6[]; |
| 356 | static const char kIPFlagUseTempAddr[]; |
| 357 | static const char kIPFlagUseTempAddrUsedAndDefault[]; |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 358 | static const char kIPFlagReversePathFilter[]; |
| 359 | static const char kIPFlagReversePathFilterEnabled[]; |
| 360 | static const char kIPFlagReversePathFilterLooseMode[]; |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 361 | static const char kStoragePowered[]; |
| 362 | static const char kStorageIPConfigs[]; |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 363 | static const char kStorageReceiveByteCount[]; |
| 364 | static const char kStorageTransmitByteCount[]; |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 365 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 366 | // Configure static IP address parameters if the service provides them. |
| 367 | void ConfigureStaticIPTask(); |
| 368 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 369 | void SetEnabledInternal(bool enable, bool persist, |
| 370 | Error *error, const ResultCallback &callback); |
| 371 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 372 | // Right now, Devices reference IPConfigs directly when persisted to disk |
| 373 | // It's not clear that this makes sense long-term, but that's how it is now. |
| 374 | // This call generates a string in the right format for this persisting. |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 375 | // |suffix| is injected into the storage identifier used for the configs. |
| 376 | std::string SerializeIPConfigs(const std::string &suffix); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 377 | |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 378 | // Set an IP configuration flag on the device. |ip_version| should be |
| 379 | // "ipv6" or "ipv4". |flag| should be the name of the flag to be set |
| 380 | // and |value| is what this flag should be set to. |
| 381 | bool SetIPFlag(IPAddress::Family family, const std::string &flag, |
| 382 | const std::string &value); |
| 383 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 384 | std::vector<std::string> AvailableIPConfigs(Error *error); |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 385 | std::string GetRpcConnectionIdentifier(); |
| 386 | |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 387 | // Get the LinkMonitor's average response time. |
| 388 | uint64 GetLinkMonitorResponseTime(Error *error); |
| 389 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 390 | // Get receive and transmit byte counters. |
| 391 | uint64 GetReceiveByteCount(Error *error); |
| 392 | uint64 GetTransmitByteCount(Error *error); |
| 393 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 394 | // |enabled_persistent_| is the value of the Powered property, as |
| 395 | // read from the profile. If it is not found in the profile, it |
| 396 | // defaults to true. |enabled_| reflects the real-time state of |
| 397 | // the device, i.e., enabled or disabled. |enabled_pending_| reflects |
| 398 | // the target state of the device while an enable or disable operation |
| 399 | // is occurring. |
| 400 | // |
| 401 | // Some typical sequences for these state variables are shown below. |
| 402 | // |
| 403 | // Shill starts up, profile has been read: |
| 404 | // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=false |
| 405 | // |
| 406 | // Shill acts on the value of |enabled_persistent_|, calls SetEnabled(true): |
| 407 | // |enabled_persistent_|=true |enabled_|=false |enabled_pending_|=true |
| 408 | // |
| 409 | // SetEnabled completes successfully, device is enabled: |
| 410 | // |enabled_persistent_|=true |enabled_|=true |enabled_pending_|=true |
| 411 | // |
| 412 | // User presses "Disable" button, SetEnabled(false) is called: |
| 413 | // |enabled_persistent_|=false |enabled_|=true |enabled_pending_|=false |
| 414 | // |
| 415 | // SetEnabled completes successfully, device is disabled: |
| 416 | // |enabled_persistent_|=false |enabled_|=false |enabled_pending_|=false |
| 417 | bool enabled_; |
| 418 | bool enabled_persistent_; |
| 419 | bool enabled_pending_; |
| 420 | |
| 421 | // Other properties |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 422 | bool reconnect_; |
| 423 | const std::string hardware_address_; |
| 424 | |
| 425 | PropertyStore store_; |
| 426 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 427 | const int interface_index_; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 428 | bool running_; // indicates whether the device is actually in operation |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 429 | const std::string link_name_; |
| 430 | const std::string unique_id_; |
| 431 | ControlInterface *control_interface_; |
| 432 | EventDispatcher *dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 433 | Metrics *metrics_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 434 | Manager *manager_; |
| 435 | IPConfigRefPtr ipconfig_; |
| 436 | ConnectionRefPtr connection_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 437 | base::WeakPtrFactory<Device> weak_ptr_factory_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 438 | scoped_ptr<DeviceAdaptorInterface> adaptor_; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 439 | scoped_ptr<PortalDetector> portal_detector_; |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 440 | scoped_ptr<LinkMonitor> link_monitor_; |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 441 | base::Callback<void(const PortalDetector::Result &)> |
| 442 | portal_detector_callback_; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 443 | Technology::Identifier technology_; |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 444 | // The number of portal detection attempts from Connected to Online state. |
| 445 | // This includes all failure/timeout attempts and the final successful |
| 446 | // attempt. |
| 447 | int portal_attempts_to_online_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 448 | |
Paul Stewart | 6ff27f5 | 2012-07-11 06:51:41 -0700 | [diff] [blame] | 449 | // Keep track of the offset between the interface-reported byte counters |
| 450 | // and our persisted value. |
| 451 | uint64 receive_byte_offset_; |
| 452 | uint64 transmit_byte_offset_; |
| 453 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 454 | // Maintain a reference to the connected / connecting service |
| 455 | ServiceRefPtr selected_service_; |
| 456 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 457 | // Cache singleton pointers for performance and test purposes. |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 458 | DHCPProvider *dhcp_provider_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 459 | RTNLHandler *rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 460 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 461 | DISALLOW_COPY_AND_ASSIGN(Device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 464 | } // namespace shill |
| 465 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 466 | #endif // SHILL_DEVICE_H_ |