blob: b9ec6f63542de2023fab1e4eb8872d5539397ad4 [file] [log] [blame]
Jason Glasgow82f9ab32012-04-04 14:27:19 -04001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkovc37a9c42012-09-06 15:28:22 +02005#ifndef SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
6#define SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
Jason Glasgow82f9ab32012-04-04 14:27:19 -04007
8#include <string>
9#include <vector>
10
11#include <base/basictypes.h>
12#include <base/callback.h>
13#include <base/memory/scoped_ptr.h>
14#include <base/memory/weak_ptr.h>
Liam McLoughlin0fec81c2013-02-28 10:31:47 -050015#include <base/gtest_prod_util.h> // for FRIEND_TEST_ALL_PREFIXES
Jason Glasgow82f9ab32012-04-04 14:27:19 -040016#include <gtest/gtest_prod.h> // for FRIEND_TEST
17
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040018#include "shill/cellular.h"
Jason Glasgow82f9ab32012-04-04 14:27:19 -040019#include "shill/cellular_capability.h"
20#include "shill/dbus_properties.h"
21#include "shill/modem_proxy_interface.h"
22#include "shill/modem_simple_proxy_interface.h"
23
24namespace shill {
25
26class Cellular;
27class Error;
28class EventDispatcher;
Darin Petkovc37a9c42012-09-06 15:28:22 +020029class ModemGobiProxyInterface;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070030class ModemInfo;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040031class ProxyFactory;
32
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040033enum ModemClassicState {
34 kModemClassicStateUnknown = 0,
35 kModemClassicStateDisabled = 10,
36 kModemClassicStateDisabling = 20,
37 kModemClassicStateEnabling = 30,
38 kModemClassicStateEnabled = 40,
39 kModemClassicStateSearching = 50,
40 kModemClassicStateRegistered = 60,
41 kModemClassicStateDisconnecting = 70,
42 kModemClassicStateConnecting = 80,
43 kModemClassicStateConnected = 90,
44};
45
Jason Glasgow82f9ab32012-04-04 14:27:19 -040046// CellularCapabilityClassic handles modems using the
47// org.chromium.ModemManager DBUS interface.
48class CellularCapabilityClassic : public CellularCapability {
49 public:
50 static const char kConnectPropertyApn[];
51 static const char kConnectPropertyApnUsername[];
52 static const char kConnectPropertyApnPassword[];
53 static const char kConnectPropertyHomeOnly[];
54 static const char kConnectPropertyPhoneNumber[];
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040055 static const char kModemPropertyEnabled[];
Darin Petkovc37a9c42012-09-06 15:28:22 +020056 static const int kTimeoutSetCarrierMilliseconds;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040057
58 // |cellular| is the parent Cellular device.
Thieu Lece4483e2013-01-23 15:12:03 -080059 CellularCapabilityClassic(Cellular *cellular,
60 ProxyFactory *proxy_factory,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070061 ModemInfo *modem_info);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040062 virtual ~CellularCapabilityClassic();
63
64 virtual void StopModem(Error *error, const ResultCallback &callback);
65 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
66 const ResultCallback &callback);
67 virtual void Disconnect(Error *error, const ResultCallback &callback);
Christopher Wiley8a468902012-11-30 11:52:38 -080068 virtual void DisconnectCleanup();
Jason Glasgow82f9ab32012-04-04 14:27:19 -040069
70 virtual void Activate(const std::string &carrier,
71 Error *error, const ResultCallback &callback);
72
73 // Network registration.
74 virtual void RegisterOnNetwork(const std::string &network_id,
75 Error *error,
76 const ResultCallback &callback);
77
78 // PIN management. The default implementation fails by returning an error.
79 virtual void RequirePIN(const std::string &pin, bool require,
80 Error *error, const ResultCallback &callback);
81 virtual void EnterPIN(const std::string &pin,
82 Error *error, const ResultCallback &callback);
83 virtual void UnblockPIN(const std::string &unblock_code,
84 const std::string &pin,
85 Error *error, const ResultCallback &callback);
86 virtual void ChangePIN(const std::string &old_pin,
87 const std::string &new_pin,
88 Error *error, const ResultCallback &callback);
89
Darin Petkovc37a9c42012-09-06 15:28:22 +020090 virtual void SetCarrier(const std::string &carrier,
91 Error *error, const ResultCallback &callback);
92
Jason Glasgow82f9ab32012-04-04 14:27:19 -040093 virtual void Scan(Error *error, const ResultCallback &callback);
94
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040095 virtual void OnDBusPropertiesChanged(
96 const std::string &interface,
97 const DBusPropertiesMap &properties,
98 const std::vector<std::string> &invalidated_properties);
99
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400100 protected:
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400101 typedef std::vector<base::Closure> CellularTaskList;
102
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400103 virtual void GetRegistrationState() = 0;
104
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400105 // The following five methods are only ever called as
106 // callbacks (from the main loop), which is why they
107 // don't take an Error * argument.
108 virtual void EnableModem(const ResultCallback &callback);
109 virtual void DisableModem(const ResultCallback &callback);
110 virtual void GetModemStatus(const ResultCallback &callback);
111 virtual void GetModemInfo(const ResultCallback &callback);
112 virtual void GetProperties(const ResultCallback &callback) = 0;
113
114 void FinishEnable(const ResultCallback &callback);
115 void FinishDisable(const ResultCallback &callback);
116 virtual void InitProxies();
117 virtual void ReleaseProxies();
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400118 virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400119
120 static void OnUnsupportedOperation(const char *operation, Error *error);
121
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400122 // Runs the next task in a list.
123 // Precondition: |tasks| is not empty.
124 void RunNextStep(CellularTaskList *tasks);
125 // StepCompletedCallback is called after a task completes.
126 // |callback| is the original callback that needs to be invoked when all of
127 // the tasks complete or if there is a failure. |ignore_error| will be set
128 // to true if the next task should be run regardless of the result of the
129 // just-completed task. |tasks| is the list of tasks remaining. |error| is
130 // the result of the just-completed task.
131 void StepCompletedCallback(const ResultCallback &callback, bool ignore_error,
132 CellularTaskList *tasks, const Error &error);
133
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400134 // Properties
135 bool scanning_supported_;
136 std::string meid_;
137 std::string imsi_;
138 std::string imei_;
139 std::string esn_;
140 std::string mdn_;
141 std::string min_;
142 std::string model_id_;
143 std::string manufacturer_;
144 std::string firmware_revision_;
145 std::string hardware_revision_;
146 std::string carrier_;
147
Nathan Williamsb54974f2012-04-19 11:16:30 -0400148 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
149
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400150 private:
151 friend class CellularTest;
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800152 friend class CellularCapabilityCDMATest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400153 friend class CellularCapabilityTest;
154 friend class CellularCapabilityGSMTest;
155 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
156 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
157 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
158 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
159 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
160 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
161 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
162 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
163 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
164 FRIEND_TEST(CellularCapabilityTest, TryApns);
165 FRIEND_TEST(CellularServiceTest, FriendlyName);
166 FRIEND_TEST(CellularTest, StartCDMARegister);
167 FRIEND_TEST(CellularTest, StartConnected);
168 FRIEND_TEST(CellularTest, StartGSMRegister);
169 FRIEND_TEST(CellularTest, StartLinked);
170 FRIEND_TEST(CellularTest, Connect);
Liam McLoughlin0fec81c2013-02-28 10:31:47 -0500171 FRIEND_TEST_ALL_PREFIXES(CellularTest, ConnectAddsTerminationAction);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400172 FRIEND_TEST(CellularTest, ConnectFailure);
Thieu Leb5954a22012-05-18 10:37:34 -0700173 FRIEND_TEST(CellularTest, ConnectFailureNoService);
Thieu Led4974cd2013-05-23 10:39:28 -0700174 FRIEND_TEST(CellularTest, ConnectSuccessNoService);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400175 FRIEND_TEST(CellularTest, Disconnect);
Arman Uguray539c4232012-09-11 10:00:22 -0700176 FRIEND_TEST(CellularTest, DisconnectFailure);
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800177 FRIEND_TEST(CellularTest, DisconnectWithCallback);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400178 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
179 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400180
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400181 // Method reply and signal callbacks from Modem interface
Nathan Williams3022be52012-04-19 17:40:49 -0400182 void OnModemStateChangedSignal(
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400183 uint32 old_state, uint32 new_state, uint32 reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400184 void OnGetModemInfoReply(const ResultCallback &callback,
185 const ModemHardwareInfo &info,
186 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400187
188 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400189 void OnGetModemStatusReply(const ResultCallback &callback,
190 const DBusPropertiesMap &props,
191 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400192
193 Cellular *cellular_;
194 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
195
196 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200197 scoped_ptr<ModemGobiProxyInterface> gobi_proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400198
Darin Petkov1abca3e2012-09-12 11:44:07 +0200199 Strings supported_carriers_;
200
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400201 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
202};
203
204} // namespace shill
205
Darin Petkovc37a9c42012-09-06 15:28:22 +0200206#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_