blob: e02289ab69ede6587cc2f2231515f947aff02b5a [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
Ben Chan876efd32012-09-28 15:25:13 -07005#ifndef SHILL_MODEM_H_
6#define SHILL_MODEM_H_
Darin Petkov5c97ac52011-07-19 16:30:49 -07007
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"
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070019#include "shill/modem_info.h"
Darin Petkove0a312e2011-07-20 13:45:28 -070020#include "shill/refptr_types.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -070021
Darin Petkov137884a2011-10-26 18:52:47 +020022struct mobile_provider_db;
23
Darin Petkov5c97ac52011-07-19 16:30:49 -070024namespace shill {
25
Darin Petkovab565bb2011-10-06 02:55:51 -070026class ProxyFactory;
Darin Petkov5c97ac52011-07-19 16:30:49 -070027
Darin Petkove0a312e2011-07-20 13:45:28 -070028// Handles an instance of ModemManager.Modem and an instance of a Cellular
29// device.
Jason Glasgow9c09e362012-04-18 15:16:29 -040030class Modem {
Darin Petkov5c97ac52011-07-19 16:30:49 -070031 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070032 // |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 Petkov5c97ac52011-07-19 16:30:49 -070035 Modem(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -040036 const std::string &service,
Darin Petkov5c97ac52011-07-19 16:30:49 -070037 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070038 ModemInfo *modem_info);
Ben Chan62028b22012-11-05 11:20:02 -080039 virtual ~Modem();
Darin Petkov5c97ac52011-07-19 16:30:49 -070040
Ben Chan876efd32012-09-28 15:25:13 -070041 // Asynchronously initializes support for the modem.
42 // If the |properties| are valid and the MAC address is present,
David Rochbergfa1d31d2012-03-20 10:38:07 -040043 // constructs and registers a Cellular device in |device_| based on
Ben Chan876efd32012-09-28 15:25:13 -070044 // |properties|.
David Rochbergfa1d31d2012-03-20 10:38:07 -040045 virtual void CreateDeviceFromModemProperties(
Ben Chan876efd32012-09-28 15:25:13 -070046 const DBusInterfaceToProperties &properties);
Darin Petkove0a312e2011-07-20 13:45:28 -070047
Darin Petkov41c0e0a2012-01-09 16:38:53 +010048 void OnDeviceInfoAvailable(const std::string &link_name);
49
David Rochbergfa1d31d2012-03-20 10:38:07 -040050 const std::string &owner() const { return owner_; }
Jason Glasgowa585fc32012-06-06 11:04:09 -040051 const std::string &service() const { return service_; }
David Rochbergfa1d31d2012-03-20 10:38:07 -040052 const std::string &path() const { return path_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070053
David Rochbergfa1d31d2012-03-20 10:38:07 -040054 void set_type(Cellular::Type type) { type_ = type; }
55
56 protected:
Darin Petkove0a312e2011-07-20 13:45:28 -070057 static const char kPropertyLinkName[];
58 static const char kPropertyIPMethod[];
59 static const char kPropertyType[];
Darin Petkove0a312e2011-07-20 13:45:28 -070060
Eric Shienbrood11567d02012-04-10 18:08:49 -040061 virtual void Init();
62
David Rochbergfa1d31d2012-03-20 10:38:07 -040063 CellularRefPtr device() const { return device_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070064
David Rochbergfa1d31d2012-03-20 10:38:07 -040065 virtual Cellular *ConstructCellular(const std::string &link_name,
66 const std::string &device_name,
67 int interface_index);
David Rochbergfa1d31d2012-03-20 10:38:07 -040068 virtual bool GetLinkName(const DBusPropertiesMap &properties,
69 std::string *name) const = 0;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040070 // Returns the name of the DBUS Modem interface.
71 virtual std::string GetModemInterface(void) const = 0;
Darin Petkovc5f56562011-08-06 16:40:05 -070072
David Rochbergfa1d31d2012-03-20 10:38:07 -040073 private:
74 friend class ModemTest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040075 friend class Modem1Test;
76 FRIEND_TEST(Modem1Test, Init);
77 FRIEND_TEST(Modem1Test, CreateDeviceMM1);
David Rochbergfa1d31d2012-03-20 10:38:07 -040078 FRIEND_TEST(ModemManager1Test, Connect);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040079 FRIEND_TEST(ModemManager1Test, AddRemoveInterfaces);
David Rochbergfa1d31d2012-03-20 10:38:07 -040080 FRIEND_TEST(ModemManagerClassicTest, Connect);
81 FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem);
82 FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures);
83 FRIEND_TEST(ModemTest, EarlyDeviceProperties);
84 FRIEND_TEST(ModemTest, Init);
85 FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate);
Darin Petkovab565bb2011-10-06 02:55:51 -070086
Eric Shienbrood11567d02012-04-10 18:08:49 -040087 virtual void OnDBusPropertiesChanged(
88 const std::string &interface,
89 const DBusPropertiesMap &changed_properties,
90 const std::vector<std::string> &invalidated_properties);
91 virtual void OnModemManagerPropertiesChanged(
92 const std::string &interface,
93 const DBusPropertiesMap &properties);
94
95 // A proxy to the org.freedesktop.DBusProperties interface used to obtain
96 // ModemManager.Modem properties and watch for property changes
97 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
98
Ben Chan876efd32012-09-28 15:25:13 -070099 DBusInterfaceToProperties initial_properties_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700100
Darin Petkove0a312e2011-07-20 13:45:28 -0700101 const std::string owner_;
Jason Glasgowa585fc32012-06-06 11:04:09 -0400102 const std::string service_;
Darin Petkove0a312e2011-07-20 13:45:28 -0700103 const std::string path_;
104
105 CellularRefPtr device_;
106
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700107 ModemInfo *modem_info_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100108 std::string link_name_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400109 Cellular::Type type_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100110 bool pending_device_info_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400111 RTNLHandler *rtnl_handler_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700112
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400113 // Store cached copies of singletons for speed/ease of testing.
114 ProxyFactory *proxy_factory_;
115
Darin Petkov5c97ac52011-07-19 16:30:49 -0700116 DISALLOW_COPY_AND_ASSIGN(Modem);
117};
118
Eric Shienbrood11567d02012-04-10 18:08:49 -0400119class ModemClassic : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400120 public:
121 ModemClassic(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -0400122 const std::string &service,
David Rochbergfa1d31d2012-03-20 10:38:07 -0400123 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700124 ModemInfo *modem_info);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400125 virtual ~ModemClassic();
126
127 // Gathers information and passes it to CreateDeviceFromModemProperties.
128 void CreateDeviceClassic(const DBusPropertiesMap &modem_properties);
129
David Rochbergfa1d31d2012-03-20 10:38:07 -0400130 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400131 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
132 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400133 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400134
135 private:
136 DISALLOW_COPY_AND_ASSIGN(ModemClassic);
137};
138
139class Modem1 : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400140 public:
141 Modem1(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -0400142 const std::string &service,
David Rochbergfa1d31d2012-03-20 10:38:07 -0400143 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700144 ModemInfo *modem_info);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400145 virtual ~Modem1();
146
147 // Gathers information and passes it to CreateDeviceFromModemProperties.
Ben Chan876efd32012-09-28 15:25:13 -0700148 void CreateDeviceMM1(const DBusInterfaceToProperties &properties);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400149
150 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400151 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
152 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400153 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400154
155 private:
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400156 friend class Modem1Test;
157
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800158 base::FilePath netfiles_path_; // Used for testing
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400159
David Rochbergfa1d31d2012-03-20 10:38:07 -0400160 DISALLOW_COPY_AND_ASSIGN(Modem1);
161};
162
Darin Petkov5c97ac52011-07-19 16:30:49 -0700163} // namespace shill
164
Ben Chan876efd32012-09-28 15:25:13 -0700165#endif // SHILL_MODEM_H_