Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -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 | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 5 | #ifndef SHILL_MODEM_H_ |
| 6 | #define SHILL_MODEM_H_ |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 9 | #include <vector> |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/basictypes.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 12 | #include <base/file_util.h> |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 15 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 16 | #include "shill/cellular.h" |
| 17 | #include "shill/dbus_objectmanager_proxy_interface.h" |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 18 | #include "shill/dbus_properties_proxy_interface.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 19 | #include "shill/modem_info.h" |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 20 | #include "shill/refptr_types.h" |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 21 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 22 | struct mobile_provider_db; |
| 23 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 24 | namespace shill { |
| 25 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 26 | class ProxyFactory; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 27 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 28 | // Handles an instance of ModemManager.Modem and an instance of a Cellular |
| 29 | // device. |
Jason Glasgow | 9c09e36 | 2012-04-18 15:16:29 -0400 | [diff] [blame] | 30 | class Modem { |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 31 | public: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 32 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 33 | // the ModemManager.Modem DBus object path (e.g., |
| 34 | // "/org/chromium/ModemManager/Gobi/0"). |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 35 | Modem(const std::string &owner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 36 | const std::string &service, |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 37 | const std::string &path, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 38 | ModemInfo *modem_info); |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 39 | virtual ~Modem(); |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 40 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 41 | // Asynchronously initializes support for the modem. |
| 42 | // If the |properties| are valid and the MAC address is present, |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 43 | // constructs and registers a Cellular device in |device_| based on |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 44 | // |properties|. |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 45 | virtual void CreateDeviceFromModemProperties( |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 46 | const DBusInterfaceToProperties &properties); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 47 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 48 | void OnDeviceInfoAvailable(const std::string &link_name); |
| 49 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 50 | const std::string &owner() const { return owner_; } |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 51 | const std::string &service() const { return service_; } |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 52 | const std::string &path() const { return path_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 53 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 54 | void set_type(Cellular::Type type) { type_ = type; } |
| 55 | |
| 56 | protected: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 57 | static const char kPropertyLinkName[]; |
| 58 | static const char kPropertyIPMethod[]; |
| 59 | static const char kPropertyType[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 60 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 61 | virtual void Init(); |
| 62 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 63 | CellularRefPtr device() const { return device_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 64 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 65 | virtual Cellular *ConstructCellular(const std::string &link_name, |
| 66 | const std::string &device_name, |
| 67 | int interface_index); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 68 | virtual bool GetLinkName(const DBusPropertiesMap &properties, |
| 69 | std::string *name) const = 0; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 70 | // Returns the name of the DBUS Modem interface. |
| 71 | virtual std::string GetModemInterface(void) const = 0; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 72 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 73 | private: |
| 74 | friend class ModemTest; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 75 | friend class Modem1Test; |
| 76 | FRIEND_TEST(Modem1Test, Init); |
| 77 | FRIEND_TEST(Modem1Test, CreateDeviceMM1); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 78 | FRIEND_TEST(ModemManager1Test, Connect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 79 | FRIEND_TEST(ModemManager1Test, AddRemoveInterfaces); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 80 | FRIEND_TEST(ModemManagerClassicTest, Connect); |
| 81 | FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem); |
| 82 | FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 83 | FRIEND_TEST(ModemTest, CreateDevicePPP); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 84 | FRIEND_TEST(ModemTest, EarlyDeviceProperties); |
mukesh agrawal | 12533ad | 2013-08-01 15:43:23 -0700 | [diff] [blame] | 85 | FRIEND_TEST(ModemTest, GetDeviceParams); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 86 | FRIEND_TEST(ModemTest, Init); |
| 87 | FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate); |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 88 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 89 | // Constants associated with fake network devices for PPP dongles. |
| 90 | // See |fake_dev_serial_|, below, for more info. |
| 91 | static const char kFakeDevNameFormat[]; |
| 92 | static const char kFakeDevAddress[]; |
| 93 | static const int kFakeDevInterfaceIndex; |
| 94 | |
| 95 | // Find the |mac_address| and |interface_index| for the kernel |
| 96 | // network device with name |link_name|. Returns true iff both |
mukesh agrawal | 12533ad | 2013-08-01 15:43:23 -0700 | [diff] [blame] | 97 | // |mac_address| and |interface_index| were found. Modifies |
| 98 | // |interface_index| even on failure. |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 99 | virtual bool GetDeviceParams(std::string *mac_address, int *interface_index); |
| 100 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 101 | virtual void OnDBusPropertiesChanged( |
| 102 | const std::string &interface, |
| 103 | const DBusPropertiesMap &changed_properties, |
| 104 | const std::vector<std::string> &invalidated_properties); |
| 105 | virtual void OnModemManagerPropertiesChanged( |
| 106 | const std::string &interface, |
| 107 | const DBusPropertiesMap &properties); |
| 108 | |
| 109 | // A proxy to the org.freedesktop.DBusProperties interface used to obtain |
| 110 | // ModemManager.Modem properties and watch for property changes |
| 111 | scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_; |
| 112 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 113 | DBusInterfaceToProperties initial_properties_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 114 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 115 | const std::string owner_; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 116 | const std::string service_; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 117 | const std::string path_; |
| 118 | |
| 119 | CellularRefPtr device_; |
| 120 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 121 | ModemInfo *modem_info_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 122 | std::string link_name_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 123 | Cellular::Type type_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 124 | bool pending_device_info_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 125 | RTNLHandler *rtnl_handler_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 126 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 127 | // Store cached copies of singletons for speed/ease of testing. |
| 128 | ProxyFactory *proxy_factory_; |
| 129 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 130 | // Serial number used to uniquify fake device names for Cellular |
| 131 | // devices that don't have network devices. (Names must be unique |
| 132 | // for D-Bus, and PPP dongles don't have network devices.) |
| 133 | static size_t fake_dev_serial_; |
| 134 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 135 | DISALLOW_COPY_AND_ASSIGN(Modem); |
| 136 | }; |
| 137 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 138 | class ModemClassic : public Modem { |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 139 | public: |
| 140 | ModemClassic(const std::string &owner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 141 | const std::string &service, |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 142 | const std::string &path, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 143 | ModemInfo *modem_info); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 144 | virtual ~ModemClassic(); |
| 145 | |
| 146 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
| 147 | void CreateDeviceClassic(const DBusPropertiesMap &modem_properties); |
| 148 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 149 | protected: |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 150 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 151 | std::string *name) const; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 152 | virtual std::string GetModemInterface(void) const; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 153 | |
| 154 | private: |
| 155 | DISALLOW_COPY_AND_ASSIGN(ModemClassic); |
| 156 | }; |
| 157 | |
| 158 | class Modem1 : public Modem { |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 159 | public: |
| 160 | Modem1(const std::string &owner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 161 | const std::string &service, |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 162 | const std::string &path, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 163 | ModemInfo *modem_info); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 164 | virtual ~Modem1(); |
| 165 | |
| 166 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 167 | void CreateDeviceMM1(const DBusInterfaceToProperties &properties); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 168 | |
| 169 | protected: |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 170 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 171 | std::string *name) const; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 172 | virtual std::string GetModemInterface(void) const; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 173 | |
| 174 | private: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 175 | friend class Modem1Test; |
| 176 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 177 | base::FilePath netfiles_path_; // Used for testing |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 178 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 179 | DISALLOW_COPY_AND_ASSIGN(Modem1); |
| 180 | }; |
| 181 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 182 | } // namespace shill |
| 183 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 184 | #endif // SHILL_MODEM_H_ |