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 | |
| 5 | #ifndef SHILL_MODEM_ |
| 6 | #define SHILL_MODEM_ |
| 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" |
| 19 | #include "shill/refptr_types.h" |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 20 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 21 | struct mobile_provider_db; |
| 22 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 23 | namespace shill { |
| 24 | |
| 25 | class ControlInterface; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 26 | class EventDispatcher; |
| 27 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 28 | class Metrics; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 29 | class ProxyFactory; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 30 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 31 | // Handles an instance of ModemManager.Modem and an instance of a Cellular |
| 32 | // device. |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 33 | class Modem : public DBusPropertiesProxyDelegate { |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 34 | public: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 35 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 36 | // the ModemManager.Modem DBus object path (e.g., |
| 37 | // "/org/chromium/ModemManager/Gobi/0"). |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 38 | Modem(const std::string &owner, |
| 39 | const std::string &path, |
| 40 | ControlInterface *control_interface, |
| 41 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 42 | Metrics *metrics, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 43 | Manager *manager, |
| 44 | mobile_provider_db *provider_db); |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 45 | ~Modem(); |
| 46 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 47 | // Asynchronously initializes support for the modem. If the |
| 48 | // |modem_properties| are valid and the MAC address is present, |
| 49 | // constructs and registers a Cellular device in |device_| based on |
| 50 | // |modem_properties|. |
| 51 | virtual void CreateDeviceFromModemProperties( |
| 52 | const DBusPropertiesMap &modem_properties); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 53 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 54 | void OnDeviceInfoAvailable(const std::string &link_name); |
| 55 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 56 | const std::string &owner() const { return owner_; } |
| 57 | const std::string &path() const { return path_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 58 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 59 | void set_type(Cellular::Type type) { type_ = type; } |
| 60 | |
| 61 | protected: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 62 | static const char kPropertyLinkName[]; |
| 63 | static const char kPropertyIPMethod[]; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 64 | static const char kPropertyState[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 65 | static const char kPropertyType[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 66 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 67 | virtual void Init(); |
| 68 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 69 | ControlInterface *control_interface() const { return control_interface_; } |
| 70 | CellularRefPtr device() const { return device_; } |
| 71 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 72 | Manager *manager() const { return manager_; } |
| 73 | Metrics *metrics() const { return metrics_; } |
| 74 | mobile_provider_db *provider_db() const { return provider_db_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 75 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 76 | virtual Cellular *ConstructCellular(const std::string &link_name, |
| 77 | const std::string &device_name, |
| 78 | int interface_index); |
| 79 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 80 | uint32 input) const = 0; |
| 81 | virtual bool GetLinkName(const DBusPropertiesMap &properties, |
| 82 | std::string *name) const = 0; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 83 | // Returns the name of the DBUS Modem interface. |
| 84 | virtual std::string GetModemInterface(void) const = 0; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 85 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 86 | private: |
| 87 | friend class ModemTest; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 88 | friend class Modem1Test; |
| 89 | FRIEND_TEST(Modem1Test, Init); |
| 90 | FRIEND_TEST(Modem1Test, CreateDeviceMM1); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 91 | FRIEND_TEST(ModemManager1Test, Connect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 92 | FRIEND_TEST(ModemManager1Test, AddRemoveInterfaces); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 93 | FRIEND_TEST(ModemManagerClassicTest, Connect); |
| 94 | FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem); |
| 95 | FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures); |
| 96 | FRIEND_TEST(ModemTest, EarlyDeviceProperties); |
| 97 | FRIEND_TEST(ModemTest, Init); |
| 98 | FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate); |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 99 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 100 | // Signal callbacks inherited from DBusPropertiesProxyDelegate. |
| 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 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 113 | DBusPropertiesMap initial_modem_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_; |
| 116 | const std::string path_; |
| 117 | |
| 118 | CellularRefPtr device_; |
| 119 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 120 | ControlInterface *control_interface_; |
| 121 | EventDispatcher *dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 122 | Metrics *metrics_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 123 | Manager *manager_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 124 | mobile_provider_db *provider_db_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 125 | std::string link_name_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 126 | Cellular::Type type_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 127 | bool pending_device_info_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 128 | RTNLHandler *rtnl_handler_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 129 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 130 | // Store cached copies of singletons for speed/ease of testing. |
| 131 | ProxyFactory *proxy_factory_; |
| 132 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(Modem); |
| 134 | }; |
| 135 | |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 136 | class ModemClassic : public Modem { |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 137 | public: |
| 138 | ModemClassic(const std::string &owner, |
| 139 | const std::string &path, |
| 140 | ControlInterface *control_interface, |
| 141 | EventDispatcher *dispatcher, |
| 142 | Metrics *metrics, |
| 143 | Manager *manager, |
| 144 | mobile_provider_db *provider_db); |
| 145 | virtual ~ModemClassic(); |
| 146 | |
| 147 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
| 148 | void CreateDeviceClassic(const DBusPropertiesMap &modem_properties); |
| 149 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 150 | protected: |
| 151 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 152 | uint32 input) const; |
| 153 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 154 | std::string *name) const; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 155 | virtual std::string GetModemInterface(void) const; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 156 | |
| 157 | private: |
| 158 | DISALLOW_COPY_AND_ASSIGN(ModemClassic); |
| 159 | }; |
| 160 | |
| 161 | class Modem1 : public Modem { |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 162 | public: |
| 163 | Modem1(const std::string &owner, |
| 164 | const std::string &path, |
| 165 | ControlInterface *control_interface, |
| 166 | EventDispatcher *dispatcher, |
| 167 | Metrics *metrics, |
| 168 | Manager *manager, |
| 169 | mobile_provider_db *provider_db); |
| 170 | virtual ~Modem1(); |
| 171 | |
| 172 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
| 173 | void CreateDeviceMM1(const DBusInterfaceToProperties &i_to_p); |
| 174 | |
| 175 | protected: |
| 176 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 177 | uint32 input) const; |
| 178 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 179 | std::string *name) const; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 180 | virtual std::string GetModemInterface(void) const; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 181 | |
| 182 | private: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 183 | friend class Modem1Test; |
| 184 | |
| 185 | FilePath netfiles_path_; // Used for testing |
| 186 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 187 | DISALLOW_COPY_AND_ASSIGN(Modem1); |
| 188 | }; |
| 189 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 190 | } // namespace shill |
| 191 | |
| 192 | #endif // SHILL_MODEM_ |