blob: 3f41e257567829c0207e7f85c9067537f1725b87 [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
5#ifndef SHILL_CELLULAR_CAPABILITY_CLASSIC_
6#define SHILL_CELLULAR_CAPABILITY_CLASSIC_
7
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;
28class ProxyFactory;
29
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040030enum ModemClassicState {
31 kModemClassicStateUnknown = 0,
32 kModemClassicStateDisabled = 10,
33 kModemClassicStateDisabling = 20,
34 kModemClassicStateEnabling = 30,
35 kModemClassicStateEnabled = 40,
36 kModemClassicStateSearching = 50,
37 kModemClassicStateRegistered = 60,
38 kModemClassicStateDisconnecting = 70,
39 kModemClassicStateConnecting = 80,
40 kModemClassicStateConnected = 90,
41};
42
Jason Glasgow82f9ab32012-04-04 14:27:19 -040043// CellularCapabilityClassic handles modems using the
44// org.chromium.ModemManager DBUS interface.
45class CellularCapabilityClassic : public CellularCapability {
46 public:
47 static const char kConnectPropertyApn[];
48 static const char kConnectPropertyApnUsername[];
49 static const char kConnectPropertyApnPassword[];
50 static const char kConnectPropertyHomeOnly[];
51 static const char kConnectPropertyPhoneNumber[];
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040052 static const char kModemPropertyEnabled[];
Jason Glasgow82f9ab32012-04-04 14:27:19 -040053
54 // |cellular| is the parent Cellular device.
55 CellularCapabilityClassic(Cellular *cellular, ProxyFactory *proxy_factory);
56 virtual ~CellularCapabilityClassic();
57
58 virtual void StopModem(Error *error, const ResultCallback &callback);
59 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
60 const ResultCallback &callback);
61 virtual void Disconnect(Error *error, const ResultCallback &callback);
62
63 virtual void Activate(const std::string &carrier,
64 Error *error, const ResultCallback &callback);
65
66 // Network registration.
67 virtual void RegisterOnNetwork(const std::string &network_id,
68 Error *error,
69 const ResultCallback &callback);
70
71 // PIN management. The default implementation fails by returning an error.
72 virtual void RequirePIN(const std::string &pin, bool require,
73 Error *error, const ResultCallback &callback);
74 virtual void EnterPIN(const std::string &pin,
75 Error *error, const ResultCallback &callback);
76 virtual void UnblockPIN(const std::string &unblock_code,
77 const std::string &pin,
78 Error *error, const ResultCallback &callback);
79 virtual void ChangePIN(const std::string &old_pin,
80 const std::string &new_pin,
81 Error *error, const ResultCallback &callback);
82
83 virtual void Scan(Error *error, const ResultCallback &callback);
84
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040085 virtual void OnDBusPropertiesChanged(
86 const std::string &interface,
87 const DBusPropertiesMap &properties,
88 const std::vector<std::string> &invalidated_properties);
89
Jason Glasgow82f9ab32012-04-04 14:27:19 -040090 protected:
Jason Glasgowa0caabf2012-05-04 11:31:41 -040091 typedef std::vector<base::Closure> CellularTaskList;
92
Jason Glasgow4380f0d2012-05-03 18:05:04 -040093 virtual void GetRegistrationState() = 0;
94
Jason Glasgow82f9ab32012-04-04 14:27:19 -040095 // The following five methods are only ever called as
96 // callbacks (from the main loop), which is why they
97 // don't take an Error * argument.
98 virtual void EnableModem(const ResultCallback &callback);
99 virtual void DisableModem(const ResultCallback &callback);
100 virtual void GetModemStatus(const ResultCallback &callback);
101 virtual void GetModemInfo(const ResultCallback &callback);
102 virtual void GetProperties(const ResultCallback &callback) = 0;
103
104 void FinishEnable(const ResultCallback &callback);
105 void FinishDisable(const ResultCallback &callback);
106 virtual void InitProxies();
107 virtual void ReleaseProxies();
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400108 virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400109
110 static void OnUnsupportedOperation(const char *operation, Error *error);
111
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400112 // Runs the next task in a list.
113 // Precondition: |tasks| is not empty.
114 void RunNextStep(CellularTaskList *tasks);
115 // StepCompletedCallback is called after a task completes.
116 // |callback| is the original callback that needs to be invoked when all of
117 // the tasks complete or if there is a failure. |ignore_error| will be set
118 // to true if the next task should be run regardless of the result of the
119 // just-completed task. |tasks| is the list of tasks remaining. |error| is
120 // the result of the just-completed task.
121 void StepCompletedCallback(const ResultCallback &callback, bool ignore_error,
122 CellularTaskList *tasks, const Error &error);
123
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400124 // Properties
125 bool scanning_supported_;
126 std::string meid_;
127 std::string imsi_;
128 std::string imei_;
129 std::string esn_;
130 std::string mdn_;
131 std::string min_;
132 std::string model_id_;
133 std::string manufacturer_;
134 std::string firmware_revision_;
135 std::string hardware_revision_;
136 std::string carrier_;
137
Nathan Williamsb54974f2012-04-19 11:16:30 -0400138 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
139
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400140 private:
141 friend class CellularTest;
142 friend class CellularCapabilityTest;
143 friend class CellularCapabilityGSMTest;
144 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
145 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
146 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
147 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
148 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
149 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
150 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
151 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
152 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
153 FRIEND_TEST(CellularCapabilityTest, TryApns);
154 FRIEND_TEST(CellularServiceTest, FriendlyName);
155 FRIEND_TEST(CellularTest, StartCDMARegister);
156 FRIEND_TEST(CellularTest, StartConnected);
157 FRIEND_TEST(CellularTest, StartGSMRegister);
158 FRIEND_TEST(CellularTest, StartLinked);
159 FRIEND_TEST(CellularTest, Connect);
160 FRIEND_TEST(CellularTest, ConnectFailure);
161 FRIEND_TEST(CellularTest, Disconnect);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400162 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
163 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400164
165 void HelpRegisterDerivedBool(
166 const std::string &name,
167 bool(CellularCapability::*get)(Error *error),
168 void(CellularCapability::*set)(const bool &value, Error *error));
169
170 // Method reply and signal callbacks from Modem interface
Nathan Williams3022be52012-04-19 17:40:49 -0400171 void OnModemStateChangedSignal(
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400172 uint32 old_state, uint32 new_state, uint32 reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400173 void OnGetModemInfoReply(const ResultCallback &callback,
174 const ModemHardwareInfo &info,
175 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400176
177 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400178 void OnGetModemStatusReply(const ResultCallback &callback,
179 const DBusPropertiesMap &props,
180 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400181
182 Cellular *cellular_;
183 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
184
185 scoped_ptr<ModemProxyInterface> proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400186
187 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
188};
189
190} // namespace shill
191
192#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_