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