blob: 7244579081b44c007c8eb604e3c60ca882fc1056 [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>
15#include <gtest/gtest_prod.h> // for FRIEND_TEST
16
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040017#include "shill/cellular.h"
Jason Glasgow82f9ab32012-04-04 14:27:19 -040018#include "shill/cellular_capability.h"
19#include "shill/dbus_properties.h"
20#include "shill/modem_proxy_interface.h"
21#include "shill/modem_simple_proxy_interface.h"
22
23namespace shill {
24
25class Cellular;
26class Error;
27class EventDispatcher;
Darin Petkovc37a9c42012-09-06 15:28:22 +020028class ModemGobiProxyInterface;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040029class ProxyFactory;
30
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040031enum ModemClassicState {
32 kModemClassicStateUnknown = 0,
33 kModemClassicStateDisabled = 10,
34 kModemClassicStateDisabling = 20,
35 kModemClassicStateEnabling = 30,
36 kModemClassicStateEnabled = 40,
37 kModemClassicStateSearching = 50,
38 kModemClassicStateRegistered = 60,
39 kModemClassicStateDisconnecting = 70,
40 kModemClassicStateConnecting = 80,
41 kModemClassicStateConnected = 90,
42};
43
Jason Glasgow82f9ab32012-04-04 14:27:19 -040044// CellularCapabilityClassic handles modems using the
45// org.chromium.ModemManager DBUS interface.
46class CellularCapabilityClassic : public CellularCapability {
47 public:
48 static const char kConnectPropertyApn[];
49 static const char kConnectPropertyApnUsername[];
50 static const char kConnectPropertyApnPassword[];
51 static const char kConnectPropertyHomeOnly[];
52 static const char kConnectPropertyPhoneNumber[];
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040053 static const char kModemPropertyEnabled[];
Darin Petkovc37a9c42012-09-06 15:28:22 +020054 static const int kTimeoutSetCarrierMilliseconds;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040055
56 // |cellular| is the parent Cellular device.
57 CellularCapabilityClassic(Cellular *cellular, ProxyFactory *proxy_factory);
58 virtual ~CellularCapabilityClassic();
59
60 virtual void StopModem(Error *error, const ResultCallback &callback);
61 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
62 const ResultCallback &callback);
63 virtual void Disconnect(Error *error, const ResultCallback &callback);
64
65 virtual void Activate(const std::string &carrier,
66 Error *error, const ResultCallback &callback);
67
68 // Network registration.
69 virtual void RegisterOnNetwork(const std::string &network_id,
70 Error *error,
71 const ResultCallback &callback);
72
73 // PIN management. The default implementation fails by returning an error.
74 virtual void RequirePIN(const std::string &pin, bool require,
75 Error *error, const ResultCallback &callback);
76 virtual void EnterPIN(const std::string &pin,
77 Error *error, const ResultCallback &callback);
78 virtual void UnblockPIN(const std::string &unblock_code,
79 const std::string &pin,
80 Error *error, const ResultCallback &callback);
81 virtual void ChangePIN(const std::string &old_pin,
82 const std::string &new_pin,
83 Error *error, const ResultCallback &callback);
84
Darin Petkovc37a9c42012-09-06 15:28:22 +020085 virtual void SetCarrier(const std::string &carrier,
86 Error *error, const ResultCallback &callback);
87
Jason Glasgow82f9ab32012-04-04 14:27:19 -040088 virtual void Scan(Error *error, const ResultCallback &callback);
89
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040090 virtual void OnDBusPropertiesChanged(
91 const std::string &interface,
92 const DBusPropertiesMap &properties,
93 const std::vector<std::string> &invalidated_properties);
94
Jason Glasgow82f9ab32012-04-04 14:27:19 -040095 protected:
Jason Glasgowa0caabf2012-05-04 11:31:41 -040096 typedef std::vector<base::Closure> CellularTaskList;
97
Jason Glasgow4380f0d2012-05-03 18:05:04 -040098 virtual void GetRegistrationState() = 0;
99
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400100 // The following five methods are only ever called as
101 // callbacks (from the main loop), which is why they
102 // don't take an Error * argument.
103 virtual void EnableModem(const ResultCallback &callback);
104 virtual void DisableModem(const ResultCallback &callback);
105 virtual void GetModemStatus(const ResultCallback &callback);
106 virtual void GetModemInfo(const ResultCallback &callback);
107 virtual void GetProperties(const ResultCallback &callback) = 0;
108
109 void FinishEnable(const ResultCallback &callback);
110 void FinishDisable(const ResultCallback &callback);
111 virtual void InitProxies();
112 virtual void ReleaseProxies();
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400113 virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400114
115 static void OnUnsupportedOperation(const char *operation, Error *error);
116
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400117 // Runs the next task in a list.
118 // Precondition: |tasks| is not empty.
119 void RunNextStep(CellularTaskList *tasks);
120 // StepCompletedCallback is called after a task completes.
121 // |callback| is the original callback that needs to be invoked when all of
122 // the tasks complete or if there is a failure. |ignore_error| will be set
123 // to true if the next task should be run regardless of the result of the
124 // just-completed task. |tasks| is the list of tasks remaining. |error| is
125 // the result of the just-completed task.
126 void StepCompletedCallback(const ResultCallback &callback, bool ignore_error,
127 CellularTaskList *tasks, const Error &error);
128
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400129 // Properties
130 bool scanning_supported_;
131 std::string meid_;
132 std::string imsi_;
133 std::string imei_;
134 std::string esn_;
135 std::string mdn_;
136 std::string min_;
137 std::string model_id_;
138 std::string manufacturer_;
139 std::string firmware_revision_;
140 std::string hardware_revision_;
141 std::string carrier_;
142
Nathan Williamsb54974f2012-04-19 11:16:30 -0400143 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
144
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400145 private:
146 friend class CellularTest;
147 friend class CellularCapabilityTest;
148 friend class CellularCapabilityGSMTest;
149 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
150 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
151 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
152 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
153 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
154 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
155 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
156 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
157 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
158 FRIEND_TEST(CellularCapabilityTest, TryApns);
159 FRIEND_TEST(CellularServiceTest, FriendlyName);
160 FRIEND_TEST(CellularTest, StartCDMARegister);
161 FRIEND_TEST(CellularTest, StartConnected);
162 FRIEND_TEST(CellularTest, StartGSMRegister);
163 FRIEND_TEST(CellularTest, StartLinked);
164 FRIEND_TEST(CellularTest, Connect);
Gary Moraina9fb3252012-05-31 12:05:31 -0700165 FRIEND_TEST(CellularTest, ConnectAddsTerminationAction);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400166 FRIEND_TEST(CellularTest, ConnectFailure);
Thieu Leb5954a22012-05-18 10:37:34 -0700167 FRIEND_TEST(CellularTest, ConnectFailureNoService);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400168 FRIEND_TEST(CellularTest, Disconnect);
Arman Uguray539c4232012-09-11 10:00:22 -0700169 FRIEND_TEST(CellularTest, DisconnectFailure);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400170 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
171 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400172
173 void HelpRegisterDerivedBool(
174 const std::string &name,
175 bool(CellularCapability::*get)(Error *error),
176 void(CellularCapability::*set)(const bool &value, Error *error));
177
178 // Method reply and signal callbacks from Modem interface
Nathan Williams3022be52012-04-19 17:40:49 -0400179 void OnModemStateChangedSignal(
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400180 uint32 old_state, uint32 new_state, uint32 reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400181 void OnGetModemInfoReply(const ResultCallback &callback,
182 const ModemHardwareInfo &info,
183 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400184
185 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400186 void OnGetModemStatusReply(const ResultCallback &callback,
187 const DBusPropertiesMap &props,
188 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400189
190 Cellular *cellular_;
191 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
192
193 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200194 scoped_ptr<ModemGobiProxyInterface> gobi_proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400195
Darin Petkov1abca3e2012-09-12 11:44:07 +0200196 Strings supported_carriers_;
197
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400198 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
199};
200
201} // namespace shill
202
Darin Petkovc37a9c42012-09-06 15:28:22 +0200203#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_