blob: c19503fa5753b490d230db5cf5de87ba8e741965 [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
Jason Glasgow82f9ab32012-04-04 14:27:19 -040087 // Properties
88 bool scanning_supported_;
89 std::string meid_;
90 std::string imsi_;
91 std::string imei_;
92 std::string esn_;
93 std::string mdn_;
94 std::string min_;
95 std::string model_id_;
96 std::string manufacturer_;
97 std::string firmware_revision_;
98 std::string hardware_revision_;
99 std::string carrier_;
100
Nathan Williamsb54974f2012-04-19 11:16:30 -0400101 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
102
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400103 private:
104 friend class CellularTest;
105 friend class CellularCapabilityTest;
106 friend class CellularCapabilityGSMTest;
107 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
108 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
109 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
110 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
111 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
112 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
113 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
114 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
115 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
116 FRIEND_TEST(CellularCapabilityTest, TryApns);
117 FRIEND_TEST(CellularServiceTest, FriendlyName);
118 FRIEND_TEST(CellularTest, StartCDMARegister);
119 FRIEND_TEST(CellularTest, StartConnected);
120 FRIEND_TEST(CellularTest, StartGSMRegister);
121 FRIEND_TEST(CellularTest, StartLinked);
122 FRIEND_TEST(CellularTest, Connect);
123 FRIEND_TEST(CellularTest, ConnectFailure);
124 FRIEND_TEST(CellularTest, Disconnect);
125
126 void HelpRegisterDerivedBool(
127 const std::string &name,
128 bool(CellularCapability::*get)(Error *error),
129 void(CellularCapability::*set)(const bool &value, Error *error));
130
131 // Method reply and signal callbacks from Modem interface
132 virtual void OnModemStateChangedSignal(
133 uint32 old_state, uint32 new_state, uint32 reason);
134 virtual void OnGetModemInfoReply(const ResultCallback &callback,
135 const ModemHardwareInfo &info,
136 const Error &error);
137
138 // Method reply callbacks from Modem.Simple interface
139 virtual void OnGetModemStatusReply(const ResultCallback &callback,
140 const DBusPropertiesMap &props,
141 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400142
143 Cellular *cellular_;
144 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
145
146 scoped_ptr<ModemProxyInterface> proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400147
148 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
149};
150
151} // namespace shill
152
153#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_