blob: 18fc52394b1073087bcee011a1ecb0dae7f0bc3f [file] [log] [blame]
Darin Petkovc64fe5e2012-01-11 12:46:13 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovdaf43862011-10-27 11:37:28 +02002// 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_
6#define SHILL_CELLULAR_CAPABILITY_
7
Darin Petkovb05315f2011-11-07 10:14:25 +01008#include <string>
9
Darin Petkovdaf43862011-10-27 11:37:28 +020010#include <base/basictypes.h>
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050011#include <base/memory/scoped_ptr.h>
12#include <base/memory/scoped_vector.h>
13#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkovdaf43862011-10-27 11:37:28 +020014
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050015#include "shill/async_call_handler.h"
Darin Petkovae0c64e2011-11-15 15:50:27 +010016#include "shill/dbus_properties.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050017#include "shill/modem_proxy_interface.h"
18#include "shill/modem_simple_proxy_interface.h"
19
20class Task;
Darin Petkovae0c64e2011-11-15 15:50:27 +010021
Darin Petkovdaf43862011-10-27 11:37:28 +020022namespace shill {
23
24class Cellular;
Darin Petkovb05315f2011-11-07 10:14:25 +010025class Error;
26class EventDispatcher;
Darin Petkovdaf43862011-10-27 11:37:28 +020027class ProxyFactory;
28
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050029// Cellular devices instantiate subclasses of CellularCapability that
30// handle the specific modem technologies and capabilities.
31class CellularCapability : public ModemProxyDelegate,
32 public ModemSimpleProxyDelegate {
Darin Petkovdaf43862011-10-27 11:37:28 +020033 public:
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050034 static const int kTimeoutActivate;
35 static const int kTimeoutConnect;
36 static const int kTimeoutDefault;
37 static const int kTimeoutRegister;
38 static const int kTimeoutScan;
39
40 static const char kConnectPropertyPhoneNumber[];
41 static const char kPropertyIMSI[];
42
43
Darin Petkovdaf43862011-10-27 11:37:28 +020044 // |cellular| is the parent Cellular device.
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050045 CellularCapability(Cellular *cellular, ProxyFactory *proxy_factory);
Darin Petkovdaf43862011-10-27 11:37:28 +020046 virtual ~CellularCapability();
47
48 Cellular *cellular() const { return cellular_; }
49 ProxyFactory *proxy_factory() const { return proxy_factory_; }
Darin Petkov5f316f62011-11-18 12:10:26 +010050
51 // Invoked by the parent Cellular device when a new service is created.
52 virtual void OnServiceCreated() = 0;
Darin Petkovdaf43862011-10-27 11:37:28 +020053
Darin Petkovae0c64e2011-11-15 15:50:27 +010054 virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0;
55
56 virtual void SetupConnectProperties(DBusPropertiesMap *properties) = 0;
57
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050058 bool allow_roaming() const { return allow_roaming_; }
59
60 // StartModem attempts to put the modem in a state in which it is
61 // usable for creating services and establishing connections (if
62 // network conditions permit). It potentially consists of multiple
63 // non-blocking calls to the modem-manager server. After each call,
64 // control is passed back up to the main loop. Each time a reply to
65 // a non-blocking call is received, the operation advances to the next
66 // step, until either an error occurs in one of them, or all the steps
67 // have been completed, at which point StartModem() is finished.
68 virtual void StartModem();
69 virtual void StopModem();
70 // EnableModem ensures that the modem device is powered.
71 virtual void EnableModem(AsyncCallHandler *call_handler);
72 virtual void DisableModem(AsyncCallHandler *call_handler);
73 virtual void GetModemStatus(AsyncCallHandler *call_handler);
74 virtual void GetModemInfo(AsyncCallHandler *call_handler);
75 virtual void Connect(const DBusPropertiesMap &properties);
76 virtual void Disconnect();
77
78 // Activates the modem. Returns an Error on failure.
79 // The default implementation fails by returning a kNotSupported error
80 // to the caller.
81 virtual void Activate(const std::string &carrier,
82 AsyncCallHandler *call_handler);
Darin Petkova3d3be52011-11-14 21:34:16 +010083
Darin Petkov184c54e2011-11-15 12:44:39 +010084 // Network registration.
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050085 virtual void RegisterOnNetwork(const std::string &network_id,
86 AsyncCallHandler *call_handler);
Darin Petkovb72cf402011-11-22 14:51:39 +010087 virtual bool IsRegistered() = 0;
Darin Petkov184c54e2011-11-15 12:44:39 +010088
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050089 virtual void GetProperties(AsyncCallHandler *call_handler) = 0;
Darin Petkov184c54e2011-11-15 12:44:39 +010090
Darin Petkov3e509242011-11-10 14:46:44 +010091 // Retrieves the current cellular signal strength.
92 virtual void GetSignalQuality() = 0;
93
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050094 virtual void GetRegistrationState(AsyncCallHandler *call_handler) = 0;
Darin Petkov184c54e2011-11-15 12:44:39 +010095
Darin Petkovac635a82012-01-10 16:51:58 +010096 virtual std::string CreateFriendlyServiceName() = 0;
97
Darin Petkovc64fe5e2012-01-11 12:46:13 +010098 // PIN management. The default implementation fails by returning an error.
99 virtual void RequirePIN(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500100 const std::string &pin, bool require, AsyncCallHandler *call_handler);
101 virtual void EnterPIN(const std::string &pin, AsyncCallHandler *call_handler);
Darin Petkovb05315f2011-11-07 10:14:25 +0100102 virtual void UnblockPIN(const std::string &unblock_code,
103 const std::string &pin,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500104 AsyncCallHandler *call_handler);
Darin Petkovb05315f2011-11-07 10:14:25 +0100105 virtual void ChangePIN(const std::string &old_pin,
106 const std::string &new_pin,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500107 AsyncCallHandler *call_handler);
Darin Petkovb05315f2011-11-07 10:14:25 +0100108
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500109 // Network scanning. The default implementation fails by invoking
110 // the reply handler with an error.
111 virtual void Scan(AsyncCallHandler *call_handler);
Darin Petkov1272a432011-11-10 15:53:37 +0100112
Darin Petkov20c13ec2011-11-09 15:07:15 +0100113 // Returns an empty string if the network technology is unknown.
114 virtual std::string GetNetworkTechnologyString() const = 0;
115
116 virtual std::string GetRoamingStateString() const = 0;
117
Darin Petkovae0c64e2011-11-15 15:50:27 +0100118 virtual void OnModemManagerPropertiesChanged(
119 const DBusPropertiesMap &properties) = 0;
120
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500121 // Method and signal callbacks inherited from ModemProxyDelegate.
122 virtual void OnModemStateChanged(
123 uint32 old_state, uint32 new_state, uint32 reason);
124 virtual void OnModemEnableCallback(const Error &error,
125 AsyncCallHandler *call_handler);
126 virtual void OnGetModemInfoCallback(const ModemHardwareInfo &info,
127 const Error &error,
128 AsyncCallHandler *call_handler);
129
130 // Method and signal callbacks inherited from ModemSimpleProxyDelegate.
131 virtual void OnGetModemStatusCallback(const DBusPropertiesMap &props,
132 const Error &error,
133 AsyncCallHandler *call_handler);
134 virtual void OnConnectCallback(const Error &error,
135 AsyncCallHandler *call_handler);
136 virtual void OnDisconnectCallback(const Error &error,
137 AsyncCallHandler *call_handler);
138
139 protected:
140 class MultiStepAsyncCallHandler : public AsyncCallHandler {
141 public:
142 explicit MultiStepAsyncCallHandler(EventDispatcher *dispatcher);
143 virtual ~MultiStepAsyncCallHandler();
144
145 // Override the non-error case
146 virtual bool CompleteOperation();
147
148 void AddTask(Task *task);
149 void PostNextTask();
150
151 private:
152 EventDispatcher *dispatcher_;
153 ScopedVector<Task> tasks_;
154
155 DISALLOW_COPY_AND_ASSIGN(MultiStepAsyncCallHandler);
156 };
157
158 static void CompleteOperation(AsyncCallHandler *reply_handler);
159 static void CompleteOperation(AsyncCallHandler *reply_handler,
160 const Error &error);
161 // Generic synthetic callback by which a Capability class can indicate
162 // that a requested operation is not supported.
163 void static OnUnsupportedOperation(const char *operation,
164 AsyncCallHandler *call_handler);
165
166 // Properties
167 bool allow_roaming_;
168 std::string carrier_;
169 std::string meid_;
170 std::string imei_;
171 std::string imsi_;
172 std::string esn_;
173 std::string mdn_;
174 std::string min_;
175 std::string model_id_;
176 std::string manufacturer_;
177 std::string firmware_revision_;
178 std::string hardware_revision_;
179
Darin Petkovdaf43862011-10-27 11:37:28 +0200180 private:
Darin Petkov721ac932011-11-16 15:43:09 +0100181 friend class CellularTest;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500182 friend class CellularCapabilityTest;
Darin Petkov31332412012-01-28 01:50:02 +0100183 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500184 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
185 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
186 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
187 FRIEND_TEST(CellularServiceTest, FriendlyName);
188 FRIEND_TEST(CellularTest, StartCDMARegister);
189 FRIEND_TEST(CellularTest, StartConnected);
190 FRIEND_TEST(CellularTest, StartGSMRegister);
191 FRIEND_TEST(CellularTest, StartLinked);
192 FRIEND_TEST(CellularTest, Connect);
193 FRIEND_TEST(CellularTest, DisconnectModem);
Darin Petkov721ac932011-11-16 15:43:09 +0100194
Darin Petkovdaf43862011-10-27 11:37:28 +0200195 Cellular *cellular_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500196
197 // Store cached copies of singletons for speed/ease of testing.
Darin Petkovdaf43862011-10-27 11:37:28 +0200198 ProxyFactory *proxy_factory_;
199
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500200 scoped_ptr<ModemProxyInterface> proxy_;
201 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
202
Darin Petkovdaf43862011-10-27 11:37:28 +0200203 DISALLOW_COPY_AND_ASSIGN(CellularCapability);
204};
205
206} // namespace shill
207
208#endif // SHILL_CELLULAR_CAPABILITY_