blob: 431c8e4a8577a0fb45faa5edb0d6a807adb1bde7 [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
Darin Petkovc37a9c42012-09-06 15:28:22 +02005#ifndef SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
6#define SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
Jason Glasgow82f9ab32012-04-04 14:27:19 -04007
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;
Darin Petkovc37a9c42012-09-06 15:28:22 +020028class ModemGobiProxyInterface;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070029class ModemInfo;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040030class ProxyFactory;
31
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040032enum ModemClassicState {
33 kModemClassicStateUnknown = 0,
34 kModemClassicStateDisabled = 10,
35 kModemClassicStateDisabling = 20,
36 kModemClassicStateEnabling = 30,
37 kModemClassicStateEnabled = 40,
38 kModemClassicStateSearching = 50,
39 kModemClassicStateRegistered = 60,
40 kModemClassicStateDisconnecting = 70,
41 kModemClassicStateConnecting = 80,
42 kModemClassicStateConnected = 90,
43};
44
Jason Glasgow82f9ab32012-04-04 14:27:19 -040045// CellularCapabilityClassic handles modems using the
46// org.chromium.ModemManager DBUS interface.
47class CellularCapabilityClassic : public CellularCapability {
48 public:
49 static const char kConnectPropertyApn[];
50 static const char kConnectPropertyApnUsername[];
51 static const char kConnectPropertyApnPassword[];
52 static const char kConnectPropertyHomeOnly[];
53 static const char kConnectPropertyPhoneNumber[];
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040054 static const char kModemPropertyEnabled[];
Darin Petkovc37a9c42012-09-06 15:28:22 +020055 static const int kTimeoutSetCarrierMilliseconds;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040056
57 // |cellular| is the parent Cellular device.
Thieu Lece4483e2013-01-23 15:12:03 -080058 CellularCapabilityClassic(Cellular *cellular,
59 ProxyFactory *proxy_factory,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070060 ModemInfo *modem_info);
Ben Chan5ea763b2014-08-13 11:07:54 -070061 ~CellularCapabilityClassic() override;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040062
Ben Chanf98f00e2014-02-05 14:48:43 -080063 // Inherited from CellularCapability.
Alex Vakulenko016fa0e2014-08-11 15:59:58 -070064 void OnDBusPropertiesChanged(
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040065 const std::string &interface,
Ben Chanf98f00e2014-02-05 14:48:43 -080066 const DBusPropertiesMap &changed_properties,
67 const std::vector<std::string> &invalidated_properties) override;
Alex Vakulenko016fa0e2014-08-11 15:59:58 -070068 void StopModem(Error *error, const ResultCallback &callback) override;
69 bool AreProxiesInitialized() const override;
70 void SetCarrier(const std::string &carrier,
71 Error *error,
72 const ResultCallback &callback) override;
73 void Connect(const DBusPropertiesMap &properties,
74 Error *error,
75 const ResultCallback &callback) override;
76 void Disconnect(Error *error,
77 const ResultCallback &callback) override;
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040078
Jason Glasgow82f9ab32012-04-04 14:27:19 -040079 protected:
Jason Glasgowa0caabf2012-05-04 11:31:41 -040080 typedef std::vector<base::Closure> CellularTaskList;
81
Jason Glasgow4380f0d2012-05-03 18:05:04 -040082 virtual void GetRegistrationState() = 0;
83
Jason Glasgow82f9ab32012-04-04 14:27:19 -040084 // The following five methods are only ever called as
85 // callbacks (from the main loop), which is why they
86 // don't take an Error * argument.
87 virtual void EnableModem(const ResultCallback &callback);
88 virtual void DisableModem(const ResultCallback &callback);
89 virtual void GetModemStatus(const ResultCallback &callback);
90 virtual void GetModemInfo(const ResultCallback &callback);
91 virtual void GetProperties(const ResultCallback &callback) = 0;
92
93 void FinishEnable(const ResultCallback &callback);
94 void FinishDisable(const ResultCallback &callback);
95 virtual void InitProxies();
96 virtual void ReleaseProxies();
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070097
98 // Default implementation is no-op.
99 virtual void UpdateStatus(const DBusPropertiesMap &properties);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400100
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400101 // Runs the next task in a list.
102 // Precondition: |tasks| is not empty.
103 void RunNextStep(CellularTaskList *tasks);
104 // StepCompletedCallback is called after a task completes.
105 // |callback| is the original callback that needs to be invoked when all of
106 // the tasks complete or if there is a failure. |ignore_error| will be set
107 // to true if the next task should be run regardless of the result of the
108 // just-completed task. |tasks| is the list of tasks remaining. |error| is
109 // the result of the just-completed task.
Ben Chanf98f00e2014-02-05 14:48:43 -0800110 void StepCompletedCallback(const ResultCallback &callback,
111 bool ignore_error,
112 CellularTaskList *tasks,
113 const Error &error);
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400114
Nathan Williamsb54974f2012-04-19 11:16:30 -0400115 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
116
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400117 private:
118 friend class CellularTest;
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800119 friend class CellularCapabilityCDMATest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400120 friend class CellularCapabilityTest;
121 friend class CellularCapabilityGSMTest;
122 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy);
123 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
124 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus);
125 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
126 FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
127 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
128 FRIEND_TEST(CellularCapabilityTest, FinishEnable);
129 FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
130 FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
131 FRIEND_TEST(CellularCapabilityTest, TryApns);
132 FRIEND_TEST(CellularServiceTest, FriendlyName);
133 FRIEND_TEST(CellularTest, StartCDMARegister);
134 FRIEND_TEST(CellularTest, StartConnected);
135 FRIEND_TEST(CellularTest, StartGSMRegister);
136 FRIEND_TEST(CellularTest, StartLinked);
137 FRIEND_TEST(CellularTest, Connect);
138 FRIEND_TEST(CellularTest, ConnectFailure);
Thieu Leb5954a22012-05-18 10:37:34 -0700139 FRIEND_TEST(CellularTest, ConnectFailureNoService);
Thieu Led4974cd2013-05-23 10:39:28 -0700140 FRIEND_TEST(CellularTest, ConnectSuccessNoService);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400141 FRIEND_TEST(CellularTest, Disconnect);
Arman Uguray539c4232012-09-11 10:00:22 -0700142 FRIEND_TEST(CellularTest, DisconnectFailure);
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800143 FRIEND_TEST(CellularTest, DisconnectWithCallback);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400144 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
145 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400146
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400147 // Method reply and signal callbacks from Modem interface
Ben Chan7fab8972014-08-10 17:14:46 -0700148 void OnModemStateChangedSignal(uint32_t old_state,
149 uint32_t new_state,
150 uint32_t reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400151 void OnGetModemInfoReply(const ResultCallback &callback,
152 const ModemHardwareInfo &info,
153 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400154
155 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400156 void OnGetModemStatusReply(const ResultCallback &callback,
157 const DBusPropertiesMap &props,
158 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400159
160 Cellular *cellular_;
161 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400162 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200163 scoped_ptr<ModemGobiProxyInterface> gobi_proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400164
165 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
166};
167
168} // namespace shill
169
Darin Petkovc37a9c42012-09-06 15:28:22 +0200170#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_