blob: 4aba51ab3981b0f544c016eeff96d21ba001eac1 [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
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -070026class ActivatingIccidStore;
Ben Chan62028b22012-11-05 11:20:02 -080027class CellularOperatorInfo;
Darin Petkov5c97ac52011-07-19 16:30:49 -070028class ControlInterface;
Darin Petkov5c97ac52011-07-19 16:30:49 -070029class EventDispatcher;
30class Manager;
Thieu Le3426c8f2012-01-11 17:35:11 -080031class Metrics;
Darin Petkovab565bb2011-10-06 02:55:51 -070032class ProxyFactory;
Darin Petkov5c97ac52011-07-19 16:30:49 -070033
Darin Petkove0a312e2011-07-20 13:45:28 -070034// Handles an instance of ModemManager.Modem and an instance of a Cellular
35// device.
Jason Glasgow9c09e362012-04-18 15:16:29 -040036class Modem {
Darin Petkov5c97ac52011-07-19 16:30:49 -070037 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070038 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
39 // the ModemManager.Modem DBus object path (e.g.,
40 // "/org/chromium/ModemManager/Gobi/0").
Darin Petkov5c97ac52011-07-19 16:30:49 -070041 Modem(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -040042 const std::string &service,
Darin Petkov5c97ac52011-07-19 16:30:49 -070043 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070044 ModemInfo *modem_info);
Ben Chan62028b22012-11-05 11:20:02 -080045 virtual ~Modem();
Darin Petkov5c97ac52011-07-19 16:30:49 -070046
Ben Chan876efd32012-09-28 15:25:13 -070047 // Asynchronously initializes support for the modem.
48 // If the |properties| are valid and the MAC address is present,
David Rochbergfa1d31d2012-03-20 10:38:07 -040049 // constructs and registers a Cellular device in |device_| based on
Ben Chan876efd32012-09-28 15:25:13 -070050 // |properties|.
David Rochbergfa1d31d2012-03-20 10:38:07 -040051 virtual void CreateDeviceFromModemProperties(
Ben Chan876efd32012-09-28 15:25:13 -070052 const DBusInterfaceToProperties &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_; }
Jason Glasgowa585fc32012-06-06 11:04:09 -040057 const std::string &service() const { return service_; }
David Rochbergfa1d31d2012-03-20 10:38:07 -040058 const std::string &path() const { return path_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070059
David Rochbergfa1d31d2012-03-20 10:38:07 -040060 void set_type(Cellular::Type type) { type_ = type; }
61
62 protected:
Darin Petkove0a312e2011-07-20 13:45:28 -070063 static const char kPropertyLinkName[];
64 static const char kPropertyIPMethod[];
65 static const char kPropertyType[];
Darin Petkove0a312e2011-07-20 13:45:28 -070066
Eric Shienbrood11567d02012-04-10 18:08:49 -040067 virtual void Init();
68
David Rochbergfa1d31d2012-03-20 10:38:07 -040069 CellularRefPtr device() const { return device_; }
Darin Petkove0a312e2011-07-20 13:45:28 -070070
David Rochbergfa1d31d2012-03-20 10:38:07 -040071 virtual Cellular *ConstructCellular(const std::string &link_name,
72 const std::string &device_name,
73 int interface_index);
David Rochbergfa1d31d2012-03-20 10:38:07 -040074 virtual bool GetLinkName(const DBusPropertiesMap &properties,
75 std::string *name) const = 0;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040076 // Returns the name of the DBUS Modem interface.
77 virtual std::string GetModemInterface(void) const = 0;
Darin Petkovc5f56562011-08-06 16:40:05 -070078
David Rochbergfa1d31d2012-03-20 10:38:07 -040079 private:
80 friend class ModemTest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040081 friend class Modem1Test;
82 FRIEND_TEST(Modem1Test, Init);
83 FRIEND_TEST(Modem1Test, CreateDeviceMM1);
David Rochbergfa1d31d2012-03-20 10:38:07 -040084 FRIEND_TEST(ModemManager1Test, Connect);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040085 FRIEND_TEST(ModemManager1Test, AddRemoveInterfaces);
David Rochbergfa1d31d2012-03-20 10:38:07 -040086 FRIEND_TEST(ModemManagerClassicTest, Connect);
87 FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem);
88 FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures);
89 FRIEND_TEST(ModemTest, EarlyDeviceProperties);
90 FRIEND_TEST(ModemTest, Init);
91 FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate);
Darin Petkovab565bb2011-10-06 02:55:51 -070092
Eric Shienbrood11567d02012-04-10 18:08:49 -040093 virtual void OnDBusPropertiesChanged(
94 const std::string &interface,
95 const DBusPropertiesMap &changed_properties,
96 const std::vector<std::string> &invalidated_properties);
97 virtual void OnModemManagerPropertiesChanged(
98 const std::string &interface,
99 const DBusPropertiesMap &properties);
100
101 // A proxy to the org.freedesktop.DBusProperties interface used to obtain
102 // ModemManager.Modem properties and watch for property changes
103 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
104
Ben Chan876efd32012-09-28 15:25:13 -0700105 DBusInterfaceToProperties initial_properties_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700106
Darin Petkove0a312e2011-07-20 13:45:28 -0700107 const std::string owner_;
Jason Glasgowa585fc32012-06-06 11:04:09 -0400108 const std::string service_;
Darin Petkove0a312e2011-07-20 13:45:28 -0700109 const std::string path_;
110
111 CellularRefPtr device_;
112
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700113 ModemInfo *modem_info_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100114 std::string link_name_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400115 Cellular::Type type_;
Darin Petkov41c0e0a2012-01-09 16:38:53 +0100116 bool pending_device_info_;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400117 RTNLHandler *rtnl_handler_;
Darin Petkov5c97ac52011-07-19 16:30:49 -0700118
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400119 // Store cached copies of singletons for speed/ease of testing.
120 ProxyFactory *proxy_factory_;
121
Darin Petkov5c97ac52011-07-19 16:30:49 -0700122 DISALLOW_COPY_AND_ASSIGN(Modem);
123};
124
Eric Shienbrood11567d02012-04-10 18:08:49 -0400125class ModemClassic : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400126 public:
127 ModemClassic(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -0400128 const std::string &service,
David Rochbergfa1d31d2012-03-20 10:38:07 -0400129 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700130 ModemInfo *modem_info);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400131 virtual ~ModemClassic();
132
133 // Gathers information and passes it to CreateDeviceFromModemProperties.
134 void CreateDeviceClassic(const DBusPropertiesMap &modem_properties);
135
David Rochbergfa1d31d2012-03-20 10:38:07 -0400136 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400137 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
138 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400139 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400140
141 private:
142 DISALLOW_COPY_AND_ASSIGN(ModemClassic);
143};
144
145class Modem1 : public Modem {
David Rochbergfa1d31d2012-03-20 10:38:07 -0400146 public:
147 Modem1(const std::string &owner,
Jason Glasgowa585fc32012-06-06 11:04:09 -0400148 const std::string &service,
David Rochbergfa1d31d2012-03-20 10:38:07 -0400149 const std::string &path,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700150 ModemInfo *modem_info);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400151 virtual ~Modem1();
152
153 // Gathers information and passes it to CreateDeviceFromModemProperties.
Ben Chan876efd32012-09-28 15:25:13 -0700154 void CreateDeviceMM1(const DBusInterfaceToProperties &properties);
David Rochbergfa1d31d2012-03-20 10:38:07 -0400155
156 protected:
David Rochbergfa1d31d2012-03-20 10:38:07 -0400157 virtual bool GetLinkName(const DBusPropertiesMap &modem_properties,
158 std::string *name) const;
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400159 virtual std::string GetModemInterface(void) const;
David Rochbergfa1d31d2012-03-20 10:38:07 -0400160
161 private:
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400162 friend class Modem1Test;
163
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800164 base::FilePath netfiles_path_; // Used for testing
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400165
David Rochbergfa1d31d2012-03-20 10:38:07 -0400166 DISALLOW_COPY_AND_ASSIGN(Modem1);
167};
168
Darin Petkov5c97ac52011-07-19 16:30:49 -0700169} // namespace shill
170
Ben Chan876efd32012-09-28 15:25:13 -0700171#endif // SHILL_MODEM_H_