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