blob: 4b2d26d4a3598a664be609f88e1fb0ad03e5c7de [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
17#include "shill/cellular_capability.h"
18#include "shill/dbus_properties.h"
19#include "shill/modem_proxy_interface.h"
20#include "shill/modem_simple_proxy_interface.h"
21
22namespace shill {
23
24class Cellular;
25class Error;
26class EventDispatcher;
27class ProxyFactory;
28
29// CellularCapabilityClassic handles modems using the
30// org.chromium.ModemManager DBUS interface.
31class CellularCapabilityClassic : public CellularCapability {
32 public:
33 static const char kConnectPropertyApn[];
34 static const char kConnectPropertyApnUsername[];
35 static const char kConnectPropertyApnPassword[];
36 static const char kConnectPropertyHomeOnly[];
37 static const char kConnectPropertyPhoneNumber[];
38
39 // |cellular| is the parent Cellular device.
40 CellularCapabilityClassic(Cellular *cellular, ProxyFactory *proxy_factory);
41 virtual ~CellularCapabilityClassic();
42
43 virtual void StopModem(Error *error, const ResultCallback &callback);
44 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
45 const ResultCallback &callback);
46 virtual void Disconnect(Error *error, const ResultCallback &callback);
47
48 virtual void Activate(const std::string &carrier,
49 Error *error, const ResultCallback &callback);
50
51 // Network registration.
52 virtual void RegisterOnNetwork(const std::string &network_id,
53 Error *error,
54 const ResultCallback &callback);
55
56 // PIN management. The default implementation fails by returning an error.
57 virtual void RequirePIN(const std::string &pin, bool require,
58 Error *error, const ResultCallback &callback);
59 virtual void EnterPIN(const std::string &pin,
60 Error *error, const ResultCallback &callback);
61 virtual void UnblockPIN(const std::string &unblock_code,
62 const std::string &pin,
63 Error *error, const ResultCallback &callback);
64 virtual void ChangePIN(const std::string &old_pin,
65 const std::string &new_pin,
66 Error *error, const ResultCallback &callback);
67
68 virtual void Scan(Error *error, const ResultCallback &callback);
69
Jason Glasgow82f9ab32012-04-04 14:27:19 -040070 protected:
71 // The following five methods are only ever called as
72 // callbacks (from the main loop), which is why they
73 // don't take an Error * argument.
74 virtual void EnableModem(const ResultCallback &callback);
75 virtual void DisableModem(const ResultCallback &callback);
76 virtual void GetModemStatus(const ResultCallback &callback);
77 virtual void GetModemInfo(const ResultCallback &callback);
78 virtual void GetProperties(const ResultCallback &callback) = 0;
79
80 void FinishEnable(const ResultCallback &callback);
81 void FinishDisable(const ResultCallback &callback);
82 virtual void InitProxies();
83 virtual void ReleaseProxies();
84
85 static void OnUnsupportedOperation(const char *operation, Error *error);
86
87 virtual void OnConnectReply(const ResultCallback &callback,
88 const Error &error);
89
90 // Properties
91 bool scanning_supported_;
92 std::string meid_;
93 std::string imsi_;
94 std::string imei_;
95 std::string esn_;
96 std::string mdn_;
97 std::string min_;
98 std::string model_id_;
99 std::string manufacturer_;
100 std::string firmware_revision_;
101 std::string hardware_revision_;
102 std::string carrier_;
103
104 private:
105 friend class CellularTest;
106 friend class CellularCapabilityTest;
107 friend class CellularCapabilityGSMTest;
108 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
109 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
110 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
111 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
112 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
113 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
114 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
115 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
116 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
117 FRIEND_TEST(CellularCapabilityTest, TryApns);
118 FRIEND_TEST(CellularServiceTest, FriendlyName);
119 FRIEND_TEST(CellularTest, StartCDMARegister);
120 FRIEND_TEST(CellularTest, StartConnected);
121 FRIEND_TEST(CellularTest, StartGSMRegister);
122 FRIEND_TEST(CellularTest, StartLinked);
123 FRIEND_TEST(CellularTest, Connect);
124 FRIEND_TEST(CellularTest, ConnectFailure);
125 FRIEND_TEST(CellularTest, Disconnect);
126
127 void HelpRegisterDerivedBool(
128 const std::string &name,
129 bool(CellularCapability::*get)(Error *error),
130 void(CellularCapability::*set)(const bool &value, Error *error));
131
132 // Method reply and signal callbacks from Modem interface
133 virtual void OnModemStateChangedSignal(
134 uint32 old_state, uint32 new_state, uint32 reason);
135 virtual void OnGetModemInfoReply(const ResultCallback &callback,
136 const ModemHardwareInfo &info,
137 const Error &error);
138
139 // Method reply callbacks from Modem.Simple interface
140 virtual void OnGetModemStatusReply(const ResultCallback &callback,
141 const DBusPropertiesMap &props,
142 const Error &error);
143 virtual void OnDisconnectReply(const ResultCallback &callback,
144 const Error &error);
145
146 Cellular *cellular_;
147 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
148
149 scoped_ptr<ModemProxyInterface> proxy_;
150 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
151
152 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
153};
154
155} // namespace shill
156
157#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_