blob: 4e62020015183121c3c1bcd7cf6fe42c59cfd733 [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:
91 // The following five methods are only ever called as
92 // callbacks (from the main loop), which is why they
93 // don't take an Error * argument.
94 virtual void EnableModem(const ResultCallback &callback);
95 virtual void DisableModem(const ResultCallback &callback);
96 virtual void GetModemStatus(const ResultCallback &callback);
97 virtual void GetModemInfo(const ResultCallback &callback);
98 virtual void GetProperties(const ResultCallback &callback) = 0;
99
100 void FinishEnable(const ResultCallback &callback);
101 void FinishDisable(const ResultCallback &callback);
102 virtual void InitProxies();
103 virtual void ReleaseProxies();
104
105 static void OnUnsupportedOperation(const char *operation, Error *error);
106
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400107 // Properties
108 bool scanning_supported_;
109 std::string meid_;
110 std::string imsi_;
111 std::string imei_;
112 std::string esn_;
113 std::string mdn_;
114 std::string min_;
115 std::string model_id_;
116 std::string manufacturer_;
117 std::string firmware_revision_;
118 std::string hardware_revision_;
119 std::string carrier_;
120
Nathan Williamsb54974f2012-04-19 11:16:30 -0400121 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
122
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400123 private:
124 friend class CellularTest;
125 friend class CellularCapabilityTest;
126 friend class CellularCapabilityGSMTest;
127 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
128 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
129 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
130 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
131 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
132 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
133 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
134 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
135 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
136 FRIEND_TEST(CellularCapabilityTest, TryApns);
137 FRIEND_TEST(CellularServiceTest, FriendlyName);
138 FRIEND_TEST(CellularTest, StartCDMARegister);
139 FRIEND_TEST(CellularTest, StartConnected);
140 FRIEND_TEST(CellularTest, StartGSMRegister);
141 FRIEND_TEST(CellularTest, StartLinked);
142 FRIEND_TEST(CellularTest, Connect);
143 FRIEND_TEST(CellularTest, ConnectFailure);
144 FRIEND_TEST(CellularTest, Disconnect);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400145 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
146 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400147
148 void HelpRegisterDerivedBool(
149 const std::string &name,
150 bool(CellularCapability::*get)(Error *error),
151 void(CellularCapability::*set)(const bool &value, Error *error));
152
153 // Method reply and signal callbacks from Modem interface
Nathan Williams3022be52012-04-19 17:40:49 -0400154 void OnModemStateChangedSignal(
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400155 uint32 old_state, uint32 new_state, uint32 reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400156 void OnGetModemInfoReply(const ResultCallback &callback,
157 const ModemHardwareInfo &info,
158 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400159
160 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400161 void OnGetModemStatusReply(const ResultCallback &callback,
162 const DBusPropertiesMap &props,
163 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400164
165 Cellular *cellular_;
166 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
167
168 scoped_ptr<ModemProxyInterface> proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400169
170 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
171};
172
173} // namespace shill
174
175#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_