blob: 8a59c36982e2ec85931e06c3550a935620286db8 [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
Darin Petkovc37a9c42012-09-06 15:28:22 +02005#ifndef SHILL_CELLULAR_CAPABILITY_H_
6#define SHILL_CELLULAR_CAPABILITY_H_
Darin Petkovdaf43862011-10-27 11:37:28 +02007
Darin Petkovb05315f2011-11-07 10:14:25 +01008#include <string>
Eric Shienbrood3e20a232012-02-16 11:35:56 -05009#include <vector>
Darin Petkovb05315f2011-11-07 10:14:25 +010010
Darin Petkovdaf43862011-10-27 11:37:28 +020011#include <base/basictypes.h>
Eric Shienbrood3e20a232012-02-16 11:35:56 -050012#include <base/callback.h>
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050013#include <base/memory/scoped_ptr.h>
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050014#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkovdaf43862011-10-27 11:37:28 +020015
Jason Glasgow82f9ab32012-04-04 14:27:19 -040016#include "shill/callbacks.h"
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040017#include "shill/cellular.h"
Darin Petkovae0c64e2011-11-15 15:50:27 +010018#include "shill/dbus_properties.h"
Thieu Lece4483e2013-01-23 15:12:03 -080019#include "shill/metrics.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050020
Darin Petkovdaf43862011-10-27 11:37:28 +020021namespace shill {
22
23class Cellular;
Darin Petkovb05315f2011-11-07 10:14:25 +010024class Error;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070025class ModemInfo;
Darin Petkovdaf43862011-10-27 11:37:28 +020026class ProxyFactory;
27
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050028// Cellular devices instantiate subclasses of CellularCapability that
29// handle the specific modem technologies and capabilities.
Jason Glasgow82f9ab32012-04-04 14:27:19 -040030//
31// The CellularCapability is directly subclassed by:
32// * CelllularCapabilityUniversal which handles all modems managed by
33// a modem manager using the the org.chromium.ModemManager1 DBUS
Arman Uguray72fab6a2013-01-10 19:32:42 -080034// interface.
Jason Glasgow82f9ab32012-04-04 14:27:19 -040035// * CellularCapabilityClassic which handles all modems managed by a
36// modem manager using the older org.chromium.ModemManager DBUS
37// interface. This class is further subclassed to represent CDMA
Arman Uguray72fab6a2013-01-10 19:32:42 -080038// and GSM modems.
Jason Glasgow82f9ab32012-04-04 14:27:19 -040039//
40// Pictorially:
41//
42// CellularCapability
43// |
44// |-- CellularCapabilityUniversal
Arman Uguray72fab6a2013-01-10 19:32:42 -080045// | |
46// | |-- CellularCapabilityUniversalCDMA
Jason Glasgow82f9ab32012-04-04 14:27:19 -040047// |
48// |-- CellularCapabilityClassic
49// |
50// |-- CellularCapabilityGSM
51// |
52// |-- CellularCapabilityCDMA
53//
Arman Uguray72fab6a2013-01-10 19:32:42 -080054// TODO(armansito): Currently, 3GPP logic is handled by
55// CellularCapabilityUniversal. Eventually CellularCapabilityUniversal will
56// only serve as the abstract base class for ModemManager1 3GPP and CDMA
57// capabilities.
Eric Shienbrood9a245532012-03-07 14:20:39 -050058class CellularCapability {
Darin Petkovdaf43862011-10-27 11:37:28 +020059 public:
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050060 static const int kTimeoutActivate;
61 static const int kTimeoutConnect;
62 static const int kTimeoutDefault;
Thieu Le049adb52012-11-12 17:14:51 -080063 static const int kTimeoutDisconnect;
Eric Shienbrood9a245532012-03-07 14:20:39 -050064 static const int kTimeoutEnable;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050065 static const int kTimeoutRegister;
Ben Chan5d0d32c2013-01-08 02:05:29 -080066 static const int kTimeoutReset;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050067 static const int kTimeoutScan;
68
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040069 static const char kModemPropertyIMSI[];
70 static const char kModemPropertyState[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050071
Darin Petkovdaf43862011-10-27 11:37:28 +020072 // |cellular| is the parent Cellular device.
Thieu Lece4483e2013-01-23 15:12:03 -080073 CellularCapability(Cellular *cellular,
74 ProxyFactory *proxy_factory,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070075 ModemInfo *modem_info);
Darin Petkovdaf43862011-10-27 11:37:28 +020076 virtual ~CellularCapability();
77
78 Cellular *cellular() const { return cellular_; }
79 ProxyFactory *proxy_factory() const { return proxy_factory_; }
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070080 ModemInfo *modem_info() const { return modem_info_; }
Darin Petkov5f316f62011-11-18 12:10:26 +010081
82 // Invoked by the parent Cellular device when a new service is created.
83 virtual void OnServiceCreated() = 0;
Darin Petkovdaf43862011-10-27 11:37:28 +020084
Darin Petkovae0c64e2011-11-15 15:50:27 +010085 virtual void SetupConnectProperties(DBusPropertiesMap *properties) = 0;
86
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050087 // StartModem attempts to put the modem in a state in which it is
88 // usable for creating services and establishing connections (if
89 // network conditions permit). It potentially consists of multiple
90 // non-blocking calls to the modem-manager server. After each call,
91 // control is passed back up to the main loop. Each time a reply to
92 // a non-blocking call is received, the operation advances to the next
93 // step, until either an error occurs in one of them, or all the steps
94 // have been completed, at which point StartModem() is finished.
Eric Shienbrood9a245532012-03-07 14:20:39 -050095 virtual void StartModem(Error *error,
96 const ResultCallback &callback) = 0;
Thieu Le923006b2012-04-05 16:32:58 -070097 // StopModem disconnects and disables a modem asynchronously.
98 // |callback| is invoked when this completes and the result is passed
99 // to the callback.
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400100 virtual void StopModem(Error *error, const ResultCallback &callback) = 0;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500101 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400102 const ResultCallback &callback) = 0;
103 virtual void Disconnect(Error *error, const ResultCallback &callback) = 0;
Christopher Wiley8a468902012-11-30 11:52:38 -0800104 // Called when a disconnect completes, successful or not.
105 virtual void DisconnectCleanup() = 0;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500106
107 // Activates the modem. Returns an Error on failure.
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500108 virtual void Activate(const std::string &carrier,
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400109 Error *error, const ResultCallback &callback) = 0;
Darin Petkova3d3be52011-11-14 21:34:16 +0100110
Arman Ugurayc7b15602013-02-16 00:56:18 -0800111 // Initiates the necessary to steps to verify that the cellular service has
112 // been activated. Once these steps have been completed, the service should
113 // be marked as activated.
114 //
115 // The default implementation fails by returning a kNotSupported error
116 // to the caller.
117 virtual void CompleteActivation(Error *error);
118
Ben Chan15786032012-11-04 21:28:02 -0800119 // Returns true if service activation is required. Returns false by default
120 // in this base class.
121 virtual bool IsServiceActivationRequired() const;
122
Darin Petkov184c54e2011-11-15 12:44:39 +0100123 // Network registration.
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500124 virtual void RegisterOnNetwork(const std::string &network_id,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500125 Error *error,
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400126 const ResultCallback &callback) = 0;
Darin Petkovb72cf402011-11-22 14:51:39 +0100127 virtual bool IsRegistered() = 0;
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400128 // If we are informed by means of something other than a signal indicating
129 // a registration state change that the modem has unregistered from the
130 // network, we need to update the network-type-specific capability object.
131 virtual void SetUnregistered(bool searching) = 0;
Darin Petkov184c54e2011-11-15 12:44:39 +0100132
Darin Petkovac635a82012-01-10 16:51:58 +0100133 virtual std::string CreateFriendlyServiceName() = 0;
134
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100135 // PIN management. The default implementation fails by returning an error.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500136 virtual void RequirePIN(const std::string &pin, bool require,
137 Error *error, const ResultCallback &callback);
138 virtual void EnterPIN(const std::string &pin,
139 Error *error, const ResultCallback &callback);
Darin Petkovb05315f2011-11-07 10:14:25 +0100140 virtual void UnblockPIN(const std::string &unblock_code,
141 const std::string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500142 Error *error, const ResultCallback &callback);
Darin Petkovb05315f2011-11-07 10:14:25 +0100143 virtual void ChangePIN(const std::string &old_pin,
144 const std::string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500145 Error *error, const ResultCallback &callback);
Darin Petkovb05315f2011-11-07 10:14:25 +0100146
Darin Petkovc37a9c42012-09-06 15:28:22 +0200147 // The default implementation fails by returning an error.
Ben Chan5d0d32c2013-01-08 02:05:29 -0800148 virtual void Reset(Error *error, const ResultCallback &callback);
Darin Petkovc37a9c42012-09-06 15:28:22 +0200149 virtual void SetCarrier(const std::string &carrier,
150 Error *error, const ResultCallback &callback);
151
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400152 // Asks the modem to scan for networks.
153 //
154 // The default implementation fails by filling error with
155 // kNotSupported.
156 //
157 // Subclasses should implement this by fetching scan results
158 // asynchronously. When the results are ready, update the
159 // flimflam::kFoundNetworksProperty and send a property change
160 // notification. Finally, callback must be invoked to inform the
161 // caller that the scan has completed.
162 //
163 // Errors are not generally reported, but on error the
164 // kFoundNetworksProperty should be cleared and a property change
165 // notification sent out.
166 //
167 // TODO(jglasgow): Refactor to reuse code by putting notification
168 // logic into Cellular or CellularCapability.
169 //
170 // TODO(jglasgow): Implement real error handling.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500171 virtual void Scan(Error *error, const ResultCallback &callback);
Darin Petkov1272a432011-11-10 15:53:37 +0100172
Darin Petkov20c13ec2011-11-09 15:07:15 +0100173 // Returns an empty string if the network technology is unknown.
174 virtual std::string GetNetworkTechnologyString() const = 0;
175
176 virtual std::string GetRoamingStateString() const = 0;
177
Eric Shienbrood9a245532012-03-07 14:20:39 -0500178 virtual void GetSignalQuality() = 0;
179
Eric Shienbrood0db6a9b2012-03-30 16:11:39 -0400180 virtual std::string GetTypeString() const = 0;
181
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400182 // Called when ModemManager has sent a property change notification
183 // signal over DBUS.
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400184 virtual void OnDBusPropertiesChanged(
185 const std::string &interface,
186 const DBusPropertiesMap &changed_properties,
187 const std::vector<std::string> &invalidated_properties) = 0;
Darin Petkovae0c64e2011-11-15 15:50:27 +0100188
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400189 // Should this device allow roaming?
190 // The decision to allow roaming or not is based on the home
191 // provider as well as on the user modifiable "allow_roaming"
192 // property.
193 virtual bool AllowRoaming() = 0;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500194
Christopher Wiley1582bdd2012-11-15 11:31:14 -0800195 virtual bool IsActivating() const;
196
Arman Ugurayd42d8ec2013-04-08 19:28:21 -0700197 // Returns true if the cellular device should initiate passive traffic
198 // monitoring to trigger active out-of-credit detection checks. This
199 // implementation returns false by default.
Arman Ugurayf84a4242013-04-09 20:01:07 -0700200 virtual bool ShouldDetectOutOfCredit() const;
Arman Ugurayd42d8ec2013-04-08 19:28:21 -0700201
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400202 protected:
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400203 // Releases all proxies held by the object. This is most useful
204 // during unit tests.
205 virtual void ReleaseProxies() = 0;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500206
Eric Shienbrood9a245532012-03-07 14:20:39 -0500207 static void OnUnsupportedOperation(const char *operation, Error *error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500208
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400209 // accessor for subclasses to read the allow roaming property
Jason Glasgow7b461df2012-05-01 16:38:45 -0400210 bool allow_roaming_property() const {
211 return cellular_->allow_roaming_property();
212 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500213
Darin Petkovdaf43862011-10-27 11:37:28 +0200214 private:
Thieu Le923006b2012-04-05 16:32:58 -0700215 friend class CellularCapabilityGSMTest;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500216 friend class CellularCapabilityTest;
Jason Glasgowef965562012-04-10 16:12:35 -0400217 friend class CellularCapabilityUniversalTest;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800218 friend class CellularCapabilityUniversalCDMATest;
Thieu Le923006b2012-04-05 16:32:58 -0700219 friend class CellularTest;
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100220 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500221 FRIEND_TEST(CellularTest, Connect);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400222 FRIEND_TEST(CellularTest, TearDown);
Darin Petkov721ac932011-11-16 15:43:09 +0100223
Darin Petkovdaf43862011-10-27 11:37:28 +0200224 Cellular *cellular_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500225
Darin Petkovdaf43862011-10-27 11:37:28 +0200226 ProxyFactory *proxy_factory_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700227 ModemInfo *modem_info_;
Darin Petkovdaf43862011-10-27 11:37:28 +0200228
Darin Petkovdaf43862011-10-27 11:37:28 +0200229 DISALLOW_COPY_AND_ASSIGN(CellularCapability);
230};
231
232} // namespace shill
233
Darin Petkovc37a9c42012-09-06 15:28:22 +0200234#endif // SHILL_CELLULAR_CAPABILITY_H_