blob: 337c81e0829574e2ff4ca0c0786094160def4e78 [file] [log] [blame]
Darin Petkov41c0e0a2012-01-09 16:38:53 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov5c97ac52011-07-19 16:30:49 -07002// 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 Stefanoved2c28c2011-11-29 15:37:30 -08009#include <vector>
Darin Petkov5c97ac52011-07-19 16:30:49 -070010
11#include <base/basictypes.h>
Jason Glasgow82f9ab32012-04-04 14:27:19 -040012#include <base/file_util.h>
Darin Petkov5c97ac52011-07-19 16:30:49 -070013#include <base/memory/scoped_ptr.h>
Darin Petkove0a312e2011-07-20 13:45:28 -070014#include <gtest/gtest_prod.h> // for FRIEND_TEST
15
David Rochbergfa1d31d2012-03-20 10:38:07 -040016#include "shill/cellular.h"
17#include "shill/dbus_objectmanager_proxy_interface.h"
Darin Petkove0a312e2011-07-20 13:45:28 -070018#include "shill/dbus_properties_proxy_interface.h"
19#include "shill/refptr_types.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -070020
Darin Petkov137884a2011-10-26 18:52:47 +020021struct mobile_provider_db;
22
Darin Petkov5c97ac52011-07-19 16:30:49 -070023namespace shill {
24
25class ControlInterface;
Darin Petkov5c97ac52011-07-19 16:30:49 -070026class EventDispatcher;
27class Manager;
Thieu Le3426c8f2012-01-11 17:35:11 -080028class Metrics;
Darin Petkovab565bb2011-10-06 02:55:51 -070029class ProxyFactory;
Darin Petkov5c97ac52011-07-19 16:30:49 -070030
Darin Petkove0a312e2011-07-20 13:45:28 -070031// Handles an instance of ModemManager.Modem and an instance of a Cellular
32// device.
Jason Glasgow9c09e362012-04-18 15:16:29 -040033class Modem {
Darin Petkov5c97ac52011-07-19 16:30:49 -070034 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070035 // |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 Petkov5c97ac52011-07-19 16:30:49 -070038 Modem(const std::string &owner,
39 const std::string &path,
40 ControlInterface *control_interface,
41 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080042 Metrics *metrics,
Darin Petkov137884a2011-10-26 18:52:47 +020043 Manager *manager,
44 mobile_provider_db *provider_db);
Darin Petkov5c97ac52011-07-19 16:30:49 -070045 ~Modem();
46
David Rochbergfa1d31d2012-03-20 10:38:07 -040047 // 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 Petkove0a312e2011-07-20 13:45:28 -070053
Darin Petkov41c0e0a2012-01-09 16:38:53 +010054 void OnDeviceInfoAvailable(const std::string &link_name);
55
David Rochbergfa1d31d2012-03-20 10:38:07 -040056 const std::string &owner() const { return owner_; }
57 const std::string &path() const { return path_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070058
David Rochbergfa1d31d2012-03-20 10:38:07 -040059 void set_type(Cellular::Type type) { type_ = type; }
60
61 protected:
Darin Petkove0a312e2011-07-20 13:45:28 -070062 static const char kPropertyLinkName[];
63 static const char kPropertyIPMethod[];
64 static const char kPropertyType[];
Darin Petkove0a312e2011-07-20 13:45:28 -070065
Eric Shienbrood11567d02012-04-10 18:08:49 -040066 virtual void Init();
67
David Rochbergfa1d31d2012-03-20 10:38:07 -040068 ControlInterface *control_interface() const { return control_interface_; }
69 CellularRefPtr device() const { return device_; }
70 EventDispatcher *dispatcher() const { return dispatcher_; }
71 Manager *manager() const { return manager_; }
72 Metrics *metrics() const { return metrics_; }
73 mobile_provider_db *provider_db() const { return provider_db_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070074
David Rochbergfa1d31d2012-03-20 10:38:07 -040075 virtual Cellular *ConstructCellular(const std::string &link_name,
76 const std::string &device_name,
77 int interface_index);
David Rochbergfa1d31d2012-03-20 10:38:07 -040078 virtual bool GetLinkName(const DBusPropertiesMap &properties,
79 std::string *name) const = 0;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040080 // Returns the name of the DBUS Modem interface.
81 virtual std::string GetModemInterface(void) const = 0;
Darin Petkovc5f56562011-08-06 16:40:05 -070082
David Rochbergfa1d31d2012-03-20 10:38:07 -040083 private:
84 friend class ModemTest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040085 friend class Modem1Test;
86 FRIEND_TEST(Modem1Test, Init);
87 FRIEND_TEST(Modem1Test, CreateDeviceMM1);
David Rochbergfa1d31d2012-03-20 10:38:07 -040088 FRIEND_TEST(ModemManager1Test, Connect);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040089 FRIEND_TEST(ModemManager1Test, AddRemoveInterfaces);
David Rochbergfa1d31d2012-03-20 10:38:07 -040090 FRIEND_TEST(ModemManagerClassicTest, Connect);
91 FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem);
92 FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures);
93 FRIEND_TEST(ModemTest, EarlyDeviceProperties);
94 FRIEND_TEST(ModemTest, Init);
95 FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate);
Darin Petkovab565bb2011-10-06 02:55:51 -070096
Eric Shienbrood11567d02012-04-10 18:08:49 -040097 virtual void OnDBusPropertiesChanged(
98 const std::string &interface,
99 const DBusPropertiesMap &changed_properties,
100 const std::vector<std::string> &invalidated_properties);
101 virtual void OnModemManagerPropertiesChanged(
102 const std::string &interface,
103 const DBusPropertiesMap &properties);
104
105 // A proxy to the org.freedesktop.DBusProperties interface used to obtain
106 // ModemManager.Modem properties and watch for property changes
107 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
108
David Rochbergfa1d31d2012-03-20 10:38:07 -0400109 DBusPropertiesMap initial_modem_properties_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700110
Darin Petkove0a312e2011-07-20 13:45:28 -0700111 const std::string owner_;
112 const std::string path_;
113
114 CellularRefPtr device_;
115
Darin Petkov5c97ac52011-07-19 16:30:49 -0700116 ControlInterface *control_interface_;
117 EventDispatcher *dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800118 Metrics *metrics_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700119 Manager *manager_;
Darin Petkov137884a2011-10-26 18:52:47 +0200120 mobile_provider_db *provider_db_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100121 std::string link_name_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400122 Cellular::Type type_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100123 bool pending_device_info_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400124 RTNLHandler *rtnl_handler_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700125
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400126 // Store cached copies of singletons for speed/ease of testing.
127 ProxyFactory *proxy_factory_;
128
Darin Petkov5c97ac52011-07-19 16:30:49 -0700129 DISALLOW_COPY_AND_ASSIGN(Modem);
130};
131
Eric Shienbrood11567d02012-04-10 18:08:49 -0400132class ModemClassic : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400133 public:
134 ModemClassic(const std::string &owner,
135 const std::string &path,
136 ControlInterface *control_interface,
137 EventDispatcher *dispatcher,
138 Metrics *metrics,
139 Manager *manager,
140 mobile_provider_db *provider_db);
141 virtual ~ModemClassic();
142
143 // Gathers information and passes it to CreateDeviceFromModemProperties.
144 void CreateDeviceClassic(const DBusPropertiesMap &modem_properties);
145
David Rochbergfa1d31d2012-03-20 10:38:07 -0400146 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400147 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
148 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400149 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400150
151 private:
152 DISALLOW_COPY_AND_ASSIGN(ModemClassic);
153};
154
155class Modem1 : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400156 public:
157 Modem1(const std::string &owner,
158 const std::string &path,
159 ControlInterface *control_interface,
160 EventDispatcher *dispatcher,
161 Metrics *metrics,
162 Manager *manager,
163 mobile_provider_db *provider_db);
164 virtual ~Modem1();
165
166 // Gathers information and passes it to CreateDeviceFromModemProperties.
167 void CreateDeviceMM1(const DBusInterfaceToProperties &i_to_p);
168
169 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400170 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
171 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400172 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400173
174 private:
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400175 friend class Modem1Test;
176
177 FilePath netfiles_path_; // Used for testing
178
David Rochbergfa1d31d2012-03-20 10:38:07 -0400179 DISALLOW_COPY_AND_ASSIGN(Modem1);
180};
181
Darin Petkov5c97ac52011-07-19 16:30:49 -0700182} // namespace shill
183
184#endif // SHILL_MODEM_