Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_DEVICE_INFO_H_ |
| 6 | #define SHILL_DEVICE_INFO_H_ |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 7 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 8 | #include <map> |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 9 | #include <memory> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 10 | #include <set> |
| 11 | #include <string> |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 12 | #include <vector> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 13 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 14 | #include <base/callback.h> |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 15 | #include <base/cancelable_callback.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 16 | #include <base/files/file_path.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 17 | #include <base/memory/ref_counted.h> |
Darin Petkov | 5a85047 | 2012-06-06 15:44:24 +0200 | [diff] [blame] | 18 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 19 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 20 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 21 | #include "shill/device.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 22 | #include "shill/net/byte_string.h" |
| 23 | #include "shill/net/ip_address.h" |
| 24 | #include "shill/net/rtnl_listener.h" |
| 25 | #include "shill/net/shill_time.h" |
Paul Stewart | cba0f7f | 2012-02-29 16:33:05 -0800 | [diff] [blame] | 26 | #include "shill/technology.h" |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 27 | |
| 28 | namespace shill { |
| 29 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 30 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 31 | class Metrics; |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 32 | class NetlinkManager; |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 33 | class Nl80211Message; |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 34 | class RoutingTable; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 35 | class RTNLHandler; |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 36 | class RTNLMessage; |
Gary Morain | 4178023 | 2012-07-31 15:08:31 -0700 | [diff] [blame] | 37 | class Sockets; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 38 | |
Darin Petkov | 5a85047 | 2012-06-06 15:44:24 +0200 | [diff] [blame] | 39 | class DeviceInfo : public base::SupportsWeakPtr<DeviceInfo> { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 40 | public: |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 41 | struct AddressData { |
| 42 | AddressData() |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 43 | : address(IPAddress::kFamilyUnknown), flags(0), scope(0) {} |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 44 | AddressData(const IPAddress &address_in, |
| 45 | unsigned char flags_in, |
| 46 | unsigned char scope_in) |
| 47 | : address(address_in), flags(flags_in), scope(scope_in) {} |
| 48 | IPAddress address; |
| 49 | unsigned char flags; |
| 50 | unsigned char scope; |
| 51 | }; |
| 52 | |
Jason Glasgow | abc5403 | 2012-04-20 16:08:32 -0400 | [diff] [blame] | 53 | // Device name prefix for modem pseudo devices used in testing. |
| 54 | static const char kModemPseudoDeviceNamePrefix[]; |
Christopher Wiley | e049cc5 | 2012-09-10 14:36:57 -0700 | [diff] [blame] | 55 | // Device name prefix for virtual ethernet devices used in testing. |
| 56 | static const char kEthernetPseudoDeviceNamePrefix[]; |
Paul Stewart | 83d6256 | 2015-02-09 19:57:47 -0800 | [diff] [blame] | 57 | // Device name prefix for virtual ethernet devices that should be ignored. |
| 58 | static const char kIgnoredDeviceNamePrefix[]; |
Ben Chan | b061f89 | 2013-02-27 17:46:55 -0800 | [diff] [blame] | 59 | // Time interval for polling for link statistics. |
| 60 | static const int kRequestLinkStatisticsIntervalMilliseconds; |
Jason Glasgow | abc5403 | 2012-04-20 16:08:32 -0400 | [diff] [blame] | 61 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 62 | DeviceInfo(ControlInterface *control_interface, |
| 63 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 64 | Metrics *metrics, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 65 | Manager *manager); |
Darin Petkov | 5a85047 | 2012-06-06 15:44:24 +0200 | [diff] [blame] | 66 | virtual ~DeviceInfo(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 67 | |
Peter Qiu | 7e8b8ee | 2014-11-25 13:55:57 -0800 | [diff] [blame] | 68 | virtual void AddDeviceToBlackList(const std::string &device_name); |
| 69 | virtual void RemoveDeviceFromBlackList(const std::string &device_name); |
mukesh agrawal | 12533ad | 2013-08-01 15:43:23 -0700 | [diff] [blame] | 70 | virtual bool IsDeviceBlackListed(const std::string &device_name); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 71 | void Start(); |
| 72 | void Stop(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 73 | |
Ben Chan | 5086b97 | 2013-01-15 21:51:38 -0800 | [diff] [blame] | 74 | std::vector<std::string> GetUninitializedTechnologies() const; |
| 75 | |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 76 | // Adds |device| to this DeviceInfo instance so that we can handle its link |
| 77 | // messages, and registers it with the manager. |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 78 | virtual void RegisterDevice(const DeviceRefPtr &device); |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 79 | |
Jason Glasgow | e908949 | 2012-02-23 17:57:37 -0500 | [diff] [blame] | 80 | // Remove |device| from this DeviceInfo. This function should only |
| 81 | // be called for cellular devices because the lifetime of the |
| 82 | // cellular devices is controlled by the Modem object and its |
| 83 | // communication to modem manager, rather than by RTNL messages. |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 84 | virtual void DeregisterDevice(const DeviceRefPtr &device); |
Jason Glasgow | e908949 | 2012-02-23 17:57:37 -0500 | [diff] [blame] | 85 | |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 86 | virtual DeviceRefPtr GetDevice(int interface_index) const; |
Paul Stewart | 3285296 | 2011-08-30 14:06:53 -0700 | [diff] [blame] | 87 | virtual bool GetMACAddress(int interface_index, ByteString *address) const; |
Gary Morain | bf74a67 | 2012-07-30 16:27:19 -0700 | [diff] [blame] | 88 | |
| 89 | // Queries the kernel for a MAC address for |interface_index|. Returns an |
| 90 | // empty ByteString on failure. |
| 91 | virtual ByteString GetMACAddressFromKernel(int interface_index) const; |
Gary Morain | 4178023 | 2012-07-31 15:08:31 -0700 | [diff] [blame] | 92 | |
Paul Stewart | 6950ba5 | 2013-12-05 08:28:14 -0800 | [diff] [blame] | 93 | // Queries the kernel for the MAC address of |peer| on |interface_index|. |
| 94 | // Returns true and populates |mac_address| on success, otherwise returns |
| 95 | // false. |
| 96 | virtual bool GetMACAddressOfPeer(int interface_index, |
| 97 | const IPAddress &peer, |
| 98 | ByteString *mac_address) const; |
| 99 | |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 100 | virtual bool GetFlags(int interface_index, unsigned int *flags) const; |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 101 | virtual bool GetByteCounts(int interface_index, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 102 | uint64_t *rx_bytes, uint64_t *tx_bytes) const; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 103 | virtual bool GetAddresses(int interface_index, |
| 104 | std::vector<AddressData> *addresses) const; |
Paul Stewart | a0db0ff | 2013-12-09 09:48:47 -0800 | [diff] [blame] | 105 | |
Paul Stewart | 05a42c2 | 2012-08-02 16:47:21 -0700 | [diff] [blame] | 106 | // Flush all addresses associated with |interface_index|. |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 107 | virtual void FlushAddresses(int interface_index) const; |
Paul Stewart | 05a42c2 | 2012-08-02 16:47:21 -0700 | [diff] [blame] | 108 | // Returns whether this interface does not have |this_address| |
| 109 | // but has another non-temporary address of the same family. |
| 110 | virtual bool HasOtherAddress( |
| 111 | int interface_index, const IPAddress &this_address) const; |
Paul Stewart | d55f6ae | 2014-04-24 16:34:21 -0700 | [diff] [blame] | 112 | |
| 113 | // Get the preferred globally scoped IPv6 address for |interface_index|. |
| 114 | // This method returns true and sets |address| if a primary IPv6 address |
| 115 | // exists. Otherwise it returns false and leaves |address| unmodified. |
Paul Stewart | d4f2648 | 2014-04-25 19:12:03 -0700 | [diff] [blame] | 116 | virtual bool GetPrimaryIPv6Address(int interface_index, IPAddress *address); |
Paul Stewart | d55f6ae | 2014-04-24 16:34:21 -0700 | [diff] [blame] | 117 | |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 118 | // Get the IPv6 DNS server addresses for |interface_index|. This method |
| 119 | // returns true and sets |address_list| and |life_time_seconds| if the IPv6 |
| 120 | // DNS server addresses exists. Otherwise, it returns false and leave |
| 121 | // |address_list| and |life_time_seconds| unmodified. |life_time_seconds| |
| 122 | // indicates the number of the seconds the DNS server is still valid for at |
| 123 | // the time of this function call. Value of 0 means the DNS server is not |
| 124 | // valid anymore, and value of 0xFFFFFFFF means the DNS server is valid |
| 125 | // forever. |
| 126 | virtual bool GetIPv6DnsServerAddresses(int interface_index, |
| 127 | std::vector<IPAddress> *address_list, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 128 | uint32_t *life_time_seconds); |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 129 | |
Paul Stewart | a0db0ff | 2013-12-09 09:48:47 -0800 | [diff] [blame] | 130 | // Returns true if any of the addresses on |interface_index| are on the |
| 131 | // same network prefix as |address|. |
| 132 | virtual bool HasDirectConnectivityTo( |
| 133 | int interface_index, const IPAddress &address) const; |
| 134 | |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 135 | virtual bool CreateTunnelInterface(std::string *interface_name) const; |
Prabhu Kaliamoorthi | 127b341 | 2014-10-16 13:00:25 +0200 | [diff] [blame] | 136 | virtual int OpenTunnelInterface(const std::string &interface_name) const; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 137 | virtual bool DeleteInterface(int interface_index) const; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 138 | |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 139 | // Returns the interface index for |interface_name| or -1 if unknown. |
| 140 | virtual int GetIndex(const std::string &interface_name) const; |
| 141 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 142 | private: |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 143 | friend class DeviceInfoDelayedCreationTest; |
Paul Stewart | ca876ee | 2012-04-21 08:55:58 -0700 | [diff] [blame] | 144 | friend class DeviceInfoTechnologyTest; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 145 | friend class DeviceInfoTest; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 146 | FRIEND_TEST(CellularTest, StartLinked); |
Ben Chan | 4b28586 | 2012-10-10 22:52:16 -0700 | [diff] [blame] | 147 | FRIEND_TEST(DeviceInfoTest, CreateDeviceWiMax); |
Peter Qiu | 9f5159e | 2014-09-12 16:50:14 -0700 | [diff] [blame] | 148 | FRIEND_TEST(DeviceInfoTest, DeviceRemovedEvent); |
Ben Chan | 5086b97 | 2013-01-15 21:51:38 -0800 | [diff] [blame] | 149 | FRIEND_TEST(DeviceInfoTest, GetUninitializedTechnologies); |
Thieu Le | b27beee | 2012-04-20 09:19:06 -0700 | [diff] [blame] | 150 | FRIEND_TEST(DeviceInfoTest, HasSubdir); // For HasSubdir. |
Paul Stewart | d55f6ae | 2014-04-24 16:34:21 -0700 | [diff] [blame] | 151 | FRIEND_TEST(DeviceInfoTest, IPv6AddressChanged); // For infos_. |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 152 | FRIEND_TEST(DeviceInfoTest, RequestLinkStatistics); |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 153 | FRIEND_TEST(DeviceInfoTest, StartStop); |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 154 | FRIEND_TEST(DeviceInfoTest, IPv6DnsServerAddressesChanged); // For infos_. |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 155 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 156 | struct Info { |
Ben Chan | 5086b97 | 2013-01-15 21:51:38 -0800 | [diff] [blame] | 157 | Info() |
| 158 | : flags(0), |
| 159 | rx_bytes(0), |
| 160 | tx_bytes(0), |
| 161 | has_addresses_only(false), |
| 162 | technology(Technology::kUnknown) |
| 163 | {} |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 164 | |
| 165 | DeviceRefPtr device; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 166 | std::string name; |
Paul Stewart | 3285296 | 2011-08-30 14:06:53 -0700 | [diff] [blame] | 167 | ByteString mac_address; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 168 | std::vector<AddressData> ip_addresses; |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 169 | std::vector<IPAddress> ipv6_dns_server_addresses; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 170 | uint32_t ipv6_dns_server_lifetime_seconds; |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 171 | time_t ipv6_dns_server_received_time_seconds; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 172 | unsigned int flags; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 173 | uint64_t rx_bytes; |
| 174 | uint64_t tx_bytes; |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 175 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 176 | // This flag indicates that link information has not been retrieved yet; |
| 177 | // only the ip_addresses field is valid. |
| 178 | bool has_addresses_only; |
Ben Chan | 5086b97 | 2013-01-15 21:51:38 -0800 | [diff] [blame] | 179 | |
| 180 | Technology::Identifier technology; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Paul Stewart | ca876ee | 2012-04-21 08:55:58 -0700 | [diff] [blame] | 183 | // Root of the kernel sysfs directory holding network device info. |
| 184 | static const char kDeviceInfoRoot[]; |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 185 | // Name of the "cdc_ether" driver. This driver is not included in the |
| 186 | // kModemDrivers list because we need to do additional checking. |
| 187 | static const char kDriverCdcEther[]; |
Ben Chan | 4eb4ddf | 2013-06-20 22:16:56 -0700 | [diff] [blame] | 188 | // Name of the "cdc_ncm" driver. This driver is not included in the |
| 189 | // kModemDrivers list because we need to do additional checking. |
| 190 | static const char kDriverCdcNcm[]; |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 191 | // Name of the GDM WiMAX driver. |
| 192 | static const char kDriverGdmWiMax[]; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 193 | // Name of the virtio network driver. |
| 194 | static const char kDriverVirtioNet[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 195 | // Sysfs path to a device uevent file. |
Paul Stewart | bf1861b | 2011-08-23 15:45:35 -0700 | [diff] [blame] | 196 | static const char kInterfaceUevent[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 197 | // Content of a device uevent file that indicates it is a wifi device. |
Paul Stewart | 9364c4c | 2011-12-06 17:12:42 -0800 | [diff] [blame] | 198 | static const char kInterfaceUeventWifiSignature[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 199 | // Sysfs path to a device via its interface name. |
| 200 | static const char kInterfaceDevice[]; |
| 201 | // Sysfs path to the driver of a device via its interface name. |
Paul Stewart | bf1861b | 2011-08-23 15:45:35 -0700 | [diff] [blame] | 202 | static const char kInterfaceDriver[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 203 | // Sysfs path to the file that is used to determine if this is tun device. |
Paul Stewart | cba0f7f | 2012-02-29 16:33:05 -0800 | [diff] [blame] | 204 | static const char kInterfaceTunFlags[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 205 | // Sysfs path to the file that is used to determine if a wifi device is |
| 206 | // operating in monitor mode. |
Paul Stewart | 2001a42 | 2011-12-15 10:20:09 -0800 | [diff] [blame] | 207 | static const char kInterfaceType[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 208 | // Modem drivers that we support. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 209 | static const char *kModemDrivers[]; |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 210 | // Path to the tun device. |
Paul Stewart | cba0f7f | 2012-02-29 16:33:05 -0800 | [diff] [blame] | 211 | static const char kTunDeviceName[]; |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 212 | // Time to wait before registering devices which need extra time to detect. |
| 213 | static const int kDelayedDeviceCreationSeconds; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 214 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 215 | // Create a Device object for the interface named |linkname|, with a |
| 216 | // string-form MAC address |address|, whose kernel interface index |
| 217 | // is |interface_index| and detected technology is |technology|. |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 218 | virtual DeviceRefPtr CreateDevice(const std::string &link_name, |
| 219 | const std::string &address, |
| 220 | int interface_index, |
| 221 | Technology::Identifier technology); |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 222 | |
Paul Stewart | ca876ee | 2012-04-21 08:55:58 -0700 | [diff] [blame] | 223 | // Return the FilePath for a given |path_name| in the device sysinfo for |
| 224 | // a specific interface |iface_name|. |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 225 | base::FilePath GetDeviceInfoPath(const std::string &iface_name, |
Paul Stewart | ca876ee | 2012-04-21 08:55:58 -0700 | [diff] [blame] | 226 | const std::string &path_name); |
| 227 | // Return the contents of the device info file |path_name| for interface |
| 228 | // |iface_name| in output parameter |contents_out|. Returns true if file |
| 229 | // read succeeded, false otherwise. |
| 230 | bool GetDeviceInfoContents(const std::string &iface_name, |
| 231 | const std::string &path_name, |
| 232 | std::string *contents_out); |
| 233 | |
| 234 | // Return the filepath for the target of the device info symbolic link |
| 235 | // |path_name| for interface |iface_name| in output parameter |path_out|. |
| 236 | // Returns true if symbolic link read succeeded, false otherwise. |
| 237 | bool GetDeviceInfoSymbolicLink(const std::string &iface_name, |
| 238 | const std::string &path_name, |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 239 | base::FilePath *path_out); |
Paul Stewart | ca876ee | 2012-04-21 08:55:58 -0700 | [diff] [blame] | 240 | // Classify the device named |iface_name|, and return an identifier |
| 241 | // indicating its type. |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 242 | virtual Technology::Identifier GetDeviceTechnology( |
| 243 | const std::string &iface_name); |
Thieu Le | 8f1c835 | 2012-04-16 11:02:12 -0700 | [diff] [blame] | 244 | // Checks the device specified by |iface_name| to see if it's a modem device. |
| 245 | // This method assumes that |iface_name| has already been determined to be |
Ben Chan | 4eb4ddf | 2013-06-20 22:16:56 -0700 | [diff] [blame] | 246 | // using the cdc_ether / cdc_ncm driver. |
| 247 | bool IsCdcEthernetModemDevice(const std::string &iface_name); |
Thieu Le | b27beee | 2012-04-20 09:19:06 -0700 | [diff] [blame] | 248 | // Returns true if |base_dir| has a subdirectory named |subdir|. |
| 249 | // |subdir| can be an immediate subdirectory of |base_dir| or can be |
| 250 | // several levels deep. |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 251 | static bool HasSubdir(const base::FilePath &base_dir, |
| 252 | const base::FilePath &subdir); |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 253 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 254 | void AddLinkMsgHandler(const RTNLMessage &msg); |
| 255 | void DelLinkMsgHandler(const RTNLMessage &msg); |
| 256 | void LinkMsgHandler(const RTNLMessage &msg); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 257 | void AddressMsgHandler(const RTNLMessage &msg); |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 258 | void RdnssMsgHandler(const RTNLMessage &msg); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 259 | |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 260 | const Info *GetInfo(int interface_index) const; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 261 | void RemoveInfo(int interface_index); |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 262 | void DelayDeviceCreation(int interface_index); |
| 263 | void DelayedDeviceCreationTask(); |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 264 | void RetrieveLinkStatistics(int interface_index, const RTNLMessage &msg); |
| 265 | void RequestLinkStatistics(); |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 266 | |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 267 | // Use nl80211 to get information on |interface_index|. |
| 268 | void GetWiFiInterfaceInfo(int interface_index); |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 269 | void OnWiFiInterfaceInfoReceived(const Nl80211Message &message); |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 270 | |
Gary Morain | 4178023 | 2012-07-31 15:08:31 -0700 | [diff] [blame] | 271 | void set_sockets(Sockets* sockets) { sockets_.reset(sockets); } |
| 272 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 273 | ControlInterface *control_interface_; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 274 | EventDispatcher *dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 275 | Metrics *metrics_; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 276 | Manager *manager_; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 277 | |
| 278 | std::map<int, Info> infos_; // Maps interface index to Info. |
| 279 | std::map<std::string, int> indices_; // Maps interface name to index. |
| 280 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 281 | base::Callback<void(const RTNLMessage &)> link_callback_; |
| 282 | base::Callback<void(const RTNLMessage &)> address_callback_; |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 283 | base::Callback<void(const RTNLMessage &)> rdnss_callback_; |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 284 | std::unique_ptr<RTNLListener> link_listener_; |
| 285 | std::unique_ptr<RTNLListener> address_listener_; |
| 286 | std::unique_ptr<RTNLListener> rdnss_listener_; |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 287 | std::set<std::string> black_list_; |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 288 | base::FilePath device_info_root_; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 289 | |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 290 | // Keep track of devices that require a delayed call to CreateDevice(). |
Paul Stewart | 050cfc0 | 2012-07-06 20:38:54 -0700 | [diff] [blame] | 291 | base::CancelableClosure delayed_devices_callback_; |
| 292 | std::set<int> delayed_devices_; |
| 293 | |
Paul Stewart | 1ac4e84 | 2012-07-10 12:58:12 -0700 | [diff] [blame] | 294 | // Maintain a callback for the periodic link statistics poll task. |
| 295 | base::CancelableClosure request_link_statistics_callback_; |
| 296 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 297 | // Cache copy of singleton pointers. |
| 298 | RoutingTable *routing_table_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 299 | RTNLHandler *rtnl_handler_; |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 300 | NetlinkManager *netlink_manager_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 301 | |
Gary Morain | 4178023 | 2012-07-31 15:08:31 -0700 | [diff] [blame] | 302 | // A member of the class so that a mock can be injected for testing. |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 303 | std::unique_ptr<Sockets> sockets_; |
Gary Morain | 4178023 | 2012-07-31 15:08:31 -0700 | [diff] [blame] | 304 | |
Peter Qiu | 9855170 | 2014-07-28 13:28:53 -0700 | [diff] [blame] | 305 | Time *time_; |
| 306 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 307 | DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 308 | }; |
| 309 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 310 | } // namespace shill |
| 311 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 312 | #endif // SHILL_DEVICE_INFO_H_ |