blob: 49c1f2415855e2cff674e8acbbb109ab15685691 [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
Jason Glasgow14521872012-05-07 19:12:15 -04005#ifndef SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_
6#define SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_
Jason Glasgow82f9ab32012-04-04 14:27:19 -04007
8#include <deque>
Jason Glasgowaf583282012-04-18 15:18:22 -04009#include <map>
Jason Glasgow82f9ab32012-04-04 14:27:19 -040010#include <string>
11#include <vector>
12
13#include <base/memory/scoped_ptr.h>
14#include <base/memory/weak_ptr.h>
15#include <gtest/gtest_prod.h> // for FRIEND_TEST
Ben Chanf6120e92012-06-28 18:56:17 -070016#include <ModemManager/ModemManager-enums.h>
Jason Glasgow82f9ab32012-04-04 14:27:19 -040017
18#include "shill/accessor_interface.h"
19#include "shill/cellular.h"
20#include "shill/cellular_capability.h"
21#include "shill/mm1_modem_modem3gpp_proxy_interface.h"
22#include "shill/mm1_modem_modemcdma_proxy_interface.h"
23#include "shill/mm1_modem_proxy_interface.h"
24#include "shill/mm1_modem_simple_proxy_interface.h"
25#include "shill/mm1_sim_proxy_interface.h"
26
27
28struct mobile_provider;
29
30namespace shill {
31
32// CellularCapabilityUniversal handles modems using the
33// org.chromium.ModemManager1 DBUS interface. This class is used for
34// all types of modems, i.e. CDMA, GSM, and LTE modems.
35class CellularCapabilityUniversal : public CellularCapability {
36 public:
37 typedef std::vector<DBusPropertiesMap> ScanResults;
38 typedef DBusPropertiesMap ScanResult;
Jason Glasgowaf583282012-04-18 15:18:22 -040039 typedef std::map< uint32_t, uint32_t > LockRetryData;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040040
Jason Glasgow14521872012-05-07 19:12:15 -040041 // Constants used in connect method call. Make available to test matchers.
42 // TODO(jglasgow): Generate from modem manager into
43 // ModemManager-names.h.
44 // See http://crosbug.com/30551.
45 static const char kConnectPin[];
46 static const char kConnectOperatorId[];
47 static const char kConnectBands[];
48 static const char kConnectAllowedModes[];
49 static const char kConnectPreferredMode[];
50 static const char kConnectApn[];
51 static const char kConnectIPType[];
52 static const char kConnectUser[];
53 static const char kConnectPassword[];
54 static const char kConnectNumber[];
55 static const char kConnectAllowRoaming[];
56 static const char kConnectRMProtocol[];
57
Jason Glasgow82f9ab32012-04-04 14:27:19 -040058 CellularCapabilityUniversal(Cellular *cellular, ProxyFactory *proxy_factory);
59
60 // Inherited from CellularCapability.
Gary Moraine285a842012-08-15 08:23:57 -070061 // Checks the modem state. If the state is kModemStateDisabled, then the
62 // modem is enabled. Otherwise, the enable command is buffered until the
63 // modem becomes disabled. ModemManager rejects the enable command if the
64 // modem is not disabled, for exmaple, if it is initializing insted.
Jason Glasgow82f9ab32012-04-04 14:27:19 -040065 virtual void StartModem(Error *error, const ResultCallback &callback);
66 virtual void StopModem(Error *error, const ResultCallback &callback);
67 virtual void Connect(const DBusPropertiesMap &properties, Error *error,
68 const ResultCallback &callback);
69 virtual void Disconnect(Error *error, const ResultCallback &callback);
70 virtual void Activate(const std::string &carrier,
71 Error *error, const ResultCallback &callback);
72
73 virtual void OnServiceCreated();
Jason Glasgow82f9ab32012-04-04 14:27:19 -040074 virtual void SetupConnectProperties(DBusPropertiesMap *properties);
Jason Glasgowef965562012-04-10 16:12:35 -040075 virtual void GetProperties();
Jason Glasgow82f9ab32012-04-04 14:27:19 -040076 virtual void Register(const ResultCallback &callback);
77
78 virtual void RegisterOnNetwork(const std::string &network_id,
79 Error *error,
80 const ResultCallback &callback);
81 virtual bool IsRegistered();
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040082 virtual void SetUnregistered(bool searching);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040083 virtual std::string CreateFriendlyServiceName();
84 virtual void RequirePIN(const std::string &pin, bool require,
85 Error *error, const ResultCallback &callback);
86 virtual void EnterPIN(const std::string &pin,
87 Error *error, const ResultCallback &callback);
88 virtual void UnblockPIN(const std::string &unblock_code,
89 const std::string &pin,
90 Error *error, const ResultCallback &callback);
91 virtual void ChangePIN(const std::string &old_pin,
92 const std::string &new_pin,
93 Error *error, const ResultCallback &callback);
94
95 virtual void Scan(Error *error, const ResultCallback &callback);
96 virtual std::string GetNetworkTechnologyString() const;
97 virtual std::string GetRoamingStateString() const;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040098 virtual void GetSignalQuality();
Jason Glasgow9f09aef2012-05-08 16:26:55 -040099 virtual std::string GetTypeString() const;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400100 virtual void OnDBusPropertiesChanged(
101 const std::string &interface,
102 const DBusPropertiesMap &changed_properties,
103 const std::vector<std::string> &invalidated_properties);
Jason Glasgowaf583282012-04-18 15:18:22 -0400104 virtual bool AllowRoaming();
Jason Glasgow14521872012-05-07 19:12:15 -0400105
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400106 protected:
107 virtual void InitProxies();
108 virtual void ReleaseProxies();
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400109
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400110 private:
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400111 // Constants used in scan results. Make available to unit tests.
112 // TODO(jglasgow): Generate from modem manager into ModemManager-names.h.
113 // See http://crosbug.com/30551.
114 static const char kStatusProperty[];
115 static const char kOperatorLongProperty[];
116 static const char kOperatorShortProperty[];
117 static const char kOperatorCodeProperty[];
118 static const char kOperatorAccessTechnologyProperty[];
119
Jason Glasgow14521872012-05-07 19:12:15 -0400120 // Modem Model ID strings. From modem firmware via modemmanager.
121 static const char kE362ModelId[];
122
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400123 friend class CellularTest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400124 friend class CellularCapabilityTest;
Thieu Le3d275392012-07-20 15:32:58 -0700125 friend class CellularCapabilityUniversalTest;
126 FRIEND_TEST(CellularCapabilityUniversalTest, Connect);
127 FRIEND_TEST(CellularCapabilityUniversalTest, ConnectApns);
Darin Petkova4ca3c32012-08-17 16:05:24 +0200128 FRIEND_TEST(CellularCapabilityUniversalTest, CreateFriendlyServiceName);
Thieu Le3d275392012-07-20 15:32:58 -0700129 FRIEND_TEST(CellularCapabilityUniversalTest, DisconnectNoProxy);
130 FRIEND_TEST(CellularCapabilityUniversalTest, GetTypeString);
131 FRIEND_TEST(CellularCapabilityUniversalTest, PropertiesChanged);
132 FRIEND_TEST(CellularCapabilityUniversalTest, Scan);
133 FRIEND_TEST(CellularCapabilityUniversalTest, ScanFailure);
Darin Petkovb4fccd22012-08-10 11:59:26 +0200134 FRIEND_TEST(CellularCapabilityUniversalTest, SetHomeProvider);
Thieu Le3d275392012-07-20 15:32:58 -0700135 FRIEND_TEST(CellularCapabilityUniversalTest, SimPropertiesChanged);
Jason Glasgowaf583282012-04-18 15:18:22 -0400136 FRIEND_TEST(CellularCapabilityUniversalTest, StartModem);
Jason Glasgow02401cc2012-05-16 10:35:37 -0400137 FRIEND_TEST(CellularCapabilityUniversalTest, StopModem);
138 FRIEND_TEST(CellularCapabilityUniversalTest, StopModemConnected);
Darin Petkova4ca3c32012-08-17 16:05:24 +0200139 FRIEND_TEST(CellularCapabilityUniversalTest, UpdateOperatorInfo);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400140
Jason Glasgowef965562012-04-10 16:12:35 -0400141 // Methods used in starting a modem
Gary Moraine285a842012-08-15 08:23:57 -0700142 void EnableModem(Error *error, const ResultCallback &callback);
Jason Glasgowef965562012-04-10 16:12:35 -0400143 void Start_EnableModemCompleted(const ResultCallback &callback,
144 const Error &error);
Jason Glasgowef965562012-04-10 16:12:35 -0400145
146 // Methods used in stopping a modem
147 void Stop_DisconnectCompleted(const ResultCallback &callback,
148 const Error &error);
149 void Stop_Disable(const ResultCallback &callback);
150 void Stop_DisableCompleted(const ResultCallback &callback,
151 const Error &error);
152
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400153 // Sets the upper level information about the home cellular provider from the
154 // modem's IMSI and SPN.
155 void SetHomeProvider();
156
157 // Updates the Universal operator name and country based on a newly
158 // obtained network id.
159 void UpdateOperatorInfo();
160
161 // Updates the serving operator on the active service.
162 void UpdateServingOperator();
163
164 // Initializes the |apn_list_| property based on the current |home_provider_|.
165 void InitAPNList();
166
167 Stringmap ParseScanResult(const ScanResult &result);
168
169 KeyValueStore SimLockStatusToProperty(Error *error);
170
171 void SetupApnTryList();
172 void FillConnectPropertyMap(DBusPropertiesMap *properties);
173
174 void HelpRegisterDerivedKeyValueStore(
175 const std::string &name,
176 KeyValueStore(CellularCapabilityUniversal::*get)(Error *error),
177 void(CellularCapabilityUniversal::*set)(
178 const KeyValueStore &value, Error *error));
179
Jason Glasgow14521872012-05-07 19:12:15 -0400180 // Returns true if a connect error should be retried. This function
181 // abstracts modem specific behavior for modems which do a lousy job
182 // of returning specific errors on connect failures.
183 bool RetriableConnectError(const Error &error) const;
184
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400185 // Signal callbacks
Nathan Williams3022be52012-04-19 17:40:49 -0400186 void OnNetworkModeSignal(uint32 mode);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400187 void OnModemStateChangedSignal(int32 old_state,
188 int32 new_state,
189 uint32 reason);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400190
191 // Property Change notification handlers
Nathan Williams3022be52012-04-19 17:40:49 -0400192 void OnModemPropertiesChanged(
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400193 const DBusPropertiesMap &properties,
194 const std::vector<std::string> &invalidated_properties);
195
Nathan Williams3022be52012-04-19 17:40:49 -0400196 void OnSignalQualityChanged(uint32 quality);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400197
Jason Glasgowef965562012-04-10 16:12:35 -0400198 // Updates the sim_path_ variable and creates a new proxy to the
199 // DBUS ModemManager1.Sim interface
Nathan Williams3022be52012-04-19 17:40:49 -0400200 void OnSimPathChanged(const std::string &sim_path);
Jason Glasgowaf583282012-04-18 15:18:22 -0400201 void OnModemCapabilitesChanged(uint32 capabilities);
202 void OnModemCurrentCapabilitiesChanged(uint32 current_capabilities);
203 void OnMdnChanged(const std::string &mdn);
204 void OnModemManufacturerChanged(const std::string &manufacturer);
205 void OnModemModelChanged(const std::string &model);
206 void OnModemRevisionChanged(const std::string &revision);
207 void OnModemStateChanged(Cellular::ModemState state);
208 void OnAccessTechnologiesChanged(uint32 access_technologies);
209 void OnSupportedModesChanged(uint32 supported_modes);
210 void OnAllowedModesChanged(uint32 allowed_modes);
211 void OnPreferredModeChanged(MMModemMode preferred_mode);
212 void OnLockRetriesChanged(MMModemLock unlock_required,
213 const LockRetryData &lock_retries);
214 void OnSimLockStatusChanged();
215
216 // 3GPP property change handlers
217 virtual void OnModem3GPPPropertiesChanged(
218 const DBusPropertiesMap &properties,
219 const std::vector<std::string> &invalidated_properties);
220 void OnImeiChanged(const std::string &imei);
221 void On3GPPRegistrationChanged(MMModem3gppRegistrationState state,
222 const std::string &operator_code,
223 const std::string &operator_name);
224 void OnFacilityLocksChanged(uint32 locks);
225
226 // SIM property change handlers
227 void OnSimPropertiesChanged(
228 const DBusPropertiesMap &props,
229 const std::vector<std::string> &invalidated_properties);
230 void OnImsiChanged(const std::string &imsi);
231 void OnSimIdentifierChanged(const std::string &id);
232 void OnOperatorIdChanged(const std::string &operator_id);
233 void OnOperatorNameChanged(const std::string &operator_name);
Jason Glasgowef965562012-04-10 16:12:35 -0400234
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400235 // Method callbacks
Nathan Williams3022be52012-04-19 17:40:49 -0400236 void OnRegisterReply(const ResultCallback &callback,
237 const Error &error);
238 void OnScanReply(const ResultCallback &callback,
239 const ScanResults &results,
240 const Error &error);
Nathan Williamsb54974f2012-04-19 11:16:30 -0400241 void OnConnectReply(const ResultCallback &callback,
242 const DBus::Path &bearer,
243 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400244
245 scoped_ptr<mm1::ModemModem3gppProxyInterface> modem_3gpp_proxy_;
246 scoped_ptr<mm1::ModemModemCdmaProxyInterface> modem_cdma_proxy_;
247 scoped_ptr<mm1::ModemProxyInterface> modem_proxy_;
248 scoped_ptr<mm1::ModemSimpleProxyInterface> modem_simple_proxy_;
249 scoped_ptr<mm1::SimProxyInterface> sim_proxy_;
250
251 base::WeakPtrFactory<CellularCapabilityUniversal> weak_ptr_factory_;
252
253 MMModem3gppRegistrationState registration_state_;
254 MMModemCdmaRegistrationState cdma_registration_state_;
Jason Glasgowaf583282012-04-18 15:18:22 -0400255
256 // Bits based on MMModemCapabilities
Jason Glasgow14521872012-05-07 19:12:15 -0400257 uint32 capabilities_; // technologies supported, may require reload
258 uint32 current_capabilities_; // technologies supportsed without a reload
259 uint32 access_technologies_; // Bits based on MMModemAccessTechnology
260 uint32 supported_modes_; // Bits based on MMModemMode
261 uint32 allowed_modes_; // Bits based on MMModemMode
262 MMModemMode preferred_mode_; // A single MMModemMode bit
Jason Glasgowaf583282012-04-18 15:18:22 -0400263
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400264 Cellular::Operator serving_operator_;
265 std::string spn_;
Jason Glasgowaf583282012-04-18 15:18:22 -0400266 std::string sim_identifier_;
267 std::string operator_id_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400268 mobile_provider *home_provider_;
269 std::string desired_network_;
270
271 // Properties.
272 std::string carrier_;
273 std::string esn_;
274 std::string firmware_revision_;
275 std::string hardware_revision_;
276 std::string imei_;
277 std::string imsi_;
278 std::string manufacturer_;
279 std::string mdn_;
280 std::string meid_;
281 std::string min_;
282 std::string model_id_;
283 std::string selected_network_;
284 Stringmaps found_networks_;
285 std::deque<Stringmap> apn_try_list_;
286 bool scanning_supported_;
287 bool scanning_;
288 uint16 scan_interval_;
289 SimLockStatus sim_lock_status_;
290 Stringmaps apn_list_;
Jason Glasgowef965562012-04-10 16:12:35 -0400291 std::string sim_path_;
Nathan Williamsb54974f2012-04-19 11:16:30 -0400292 DBus::Path bearer_path_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400293
Gary Moraine285a842012-08-15 08:23:57 -0700294 // If the modem is not in a state to be enabled when StartModem is called,
295 // enabling is deferred using this callback.
296 base::Closure deferred_enable_modem_callback_;
297
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400298 static unsigned int friendly_service_name_id_;
299
300 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityUniversal);
301};
302
303} // namespace shill
304
Jason Glasgow14521872012-05-07 19:12:15 -0400305#endif // SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_