blob: da450bc9aafe3d4101f4a6aad076d2c6dd87e13f [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_UNIVERSAL_
6#define SHILL_CELLULAR_CAPABILITY_UNIVERSAL_
7
8#include <deque>
9#include <string>
10#include <vector>
11
12#include <base/memory/scoped_ptr.h>
13#include <base/memory/weak_ptr.h>
14#include <gtest/gtest_prod.h> // for FRIEND_TEST
15#include <mm/ModemManager-enums.h>
16
17#include "shill/accessor_interface.h"
18#include "shill/cellular.h"
19#include "shill/cellular_capability.h"
20#include "shill/mm1_modem_modem3gpp_proxy_interface.h"
21#include "shill/mm1_modem_modemcdma_proxy_interface.h"
22#include "shill/mm1_modem_proxy_interface.h"
23#include "shill/mm1_modem_simple_proxy_interface.h"
24#include "shill/mm1_sim_proxy_interface.h"
25
26
27struct mobile_provider;
28
29namespace shill {
30
31// CellularCapabilityUniversal handles modems using the
32// org.chromium.ModemManager1 DBUS interface. This class is used for
33// all types of modems, i.e. CDMA, GSM, and LTE modems.
34class CellularCapabilityUniversal : public CellularCapability {
35 public:
36 typedef std::vector<DBusPropertiesMap> ScanResults;
37 typedef DBusPropertiesMap ScanResult;
38
39 CellularCapabilityUniversal(Cellular *cellular, ProxyFactory *proxy_factory);
40
41 // Inherited from CellularCapability.
42 virtual void StartModem(Error *error, const ResultCallback &callback);
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 virtual void Activate(const std::string &carrier,
48 Error *error, const ResultCallback &callback);
49
50 virtual void OnServiceCreated();
51 virtual void UpdateStatus(const DBusPropertiesMap &properties);
52 virtual void SetupConnectProperties(DBusPropertiesMap *properties);
53 virtual void GetRegistrationState();
Jason Glasgowef965562012-04-10 16:12:35 -040054 virtual void GetProperties();
Jason Glasgow82f9ab32012-04-04 14:27:19 -040055 virtual void Register(const ResultCallback &callback);
56
57 virtual void RegisterOnNetwork(const std::string &network_id,
58 Error *error,
59 const ResultCallback &callback);
60 virtual bool IsRegistered();
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040061 virtual void SetUnregistered(bool searching);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040062 virtual std::string CreateFriendlyServiceName();
63 virtual void RequirePIN(const std::string &pin, bool require,
64 Error *error, const ResultCallback &callback);
65 virtual void EnterPIN(const std::string &pin,
66 Error *error, const ResultCallback &callback);
67 virtual void UnblockPIN(const std::string &unblock_code,
68 const std::string &pin,
69 Error *error, const ResultCallback &callback);
70 virtual void ChangePIN(const std::string &old_pin,
71 const std::string &new_pin,
72 Error *error, const ResultCallback &callback);
73
74 virtual void Scan(Error *error, const ResultCallback &callback);
75 virtual std::string GetNetworkTechnologyString() const;
76 virtual std::string GetRoamingStateString() const;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040077 virtual void GetSignalQuality();
Jason Glasgow4c0724a2012-04-17 15:47:40 -040078 virtual std::string GetTypeString() const { return "Universal"; }
Jason Glasgow82f9ab32012-04-04 14:27:19 -040079 virtual void OnDBusPropertiesChanged(
80 const std::string &interface,
81 const DBusPropertiesMap &changed_properties,
82 const std::vector<std::string> &invalidated_properties);
83 virtual void OnModem3GPPPropertiesChanged(
84 const DBusPropertiesMap &properties);
85
86 protected:
87 virtual void InitProxies();
88 virtual void ReleaseProxies();
Jason Glasgow82f9ab32012-04-04 14:27:19 -040089
90 virtual bool AllowRoaming();
91
92 private:
93 friend class CellularTest;
94 friend class CellularCapabilityUniversalTest;
95 friend class CellularCapabilityTest;
96 FRIEND_TEST(CellularCapabilityUniversalTest, CreateDeviceFromProperties);
97 FRIEND_TEST(CellularCapabilityUniversalTest, CreateFriendlyServiceName);
98 FRIEND_TEST(CellularCapabilityUniversalTest, GetIMEI);
99 FRIEND_TEST(CellularCapabilityUniversalTest, GetIMSI);
100 FRIEND_TEST(CellularCapabilityUniversalTest, GetMSISDN);
101 FRIEND_TEST(CellularCapabilityUniversalTest, GetSPN);
102 FRIEND_TEST(CellularCapabilityUniversalTest, RequirePIN);
103 FRIEND_TEST(CellularCapabilityUniversalTest, EnterPIN);
104 FRIEND_TEST(CellularCapabilityUniversalTest, UnblockPIN);
105 FRIEND_TEST(CellularCapabilityUniversalTest, ChangePIN);
106 FRIEND_TEST(CellularCapabilityUniversalTest, InitAPNList);
107 FRIEND_TEST(CellularCapabilityUniversalTest, ParseScanResult);
108 FRIEND_TEST(CellularCapabilityUniversalTest, ParseScanResultProviderLookup);
109 FRIEND_TEST(CellularCapabilityUniversalTest, RegisterOnNetwork);
110 FRIEND_TEST(CellularCapabilityUniversalTest, Scan);
111 FRIEND_TEST(CellularCapabilityUniversalTest, SetAccessTechnologies);
112 FRIEND_TEST(CellularCapabilityUniversalTest, SetHomeProvider);
113 FRIEND_TEST(CellularCapabilityUniversalTest, UpdateOperatorInfo);
114 FRIEND_TEST(CellularCapabilityUniversalTest, GetRegistrationState);
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400115 FRIEND_TEST(CellularCapabilityUniversalTest, OnDBusPropertiesChanged);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400116 FRIEND_TEST(CellularCapabilityUniversalTest, SetupApnTryList);
117 FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
118 FRIEND_TEST(CellularCapabilityTest, TryApns);
119 FRIEND_TEST(CellularTest, StartUniversalRegister);
120 FRIEND_TEST(ModemTest, CreateDeviceFromProperties);
121
Jason Glasgowef965562012-04-10 16:12:35 -0400122 // Methods used in starting a modem
123 void Start_EnableModemCompleted(const ResultCallback &callback,
124 const Error &error);
125 void Start_RegisterCompleted(const ResultCallback &callback,
126 const Error &error);
127
128 // Methods used in stopping a modem
129 void Stop_DisconnectCompleted(const ResultCallback &callback,
130 const Error &error);
131 void Stop_Disable(const ResultCallback &callback);
132 void Stop_DisableCompleted(const ResultCallback &callback,
133 const Error &error);
134
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400135 // TOOD(jglasgow): document what this does!!!!!
136 void SetAccessTechnologies(uint32 access_technologies);
137
138 // Sets the upper level information about the home cellular provider from the
139 // modem's IMSI and SPN.
140 void SetHomeProvider();
141
142 // Updates the Universal operator name and country based on a newly
143 // obtained network id.
144 void UpdateOperatorInfo();
145
146 // Updates the serving operator on the active service.
147 void UpdateServingOperator();
148
149 // Initializes the |apn_list_| property based on the current |home_provider_|.
150 void InitAPNList();
151
152 Stringmap ParseScanResult(const ScanResult &result);
153
154 KeyValueStore SimLockStatusToProperty(Error *error);
155
156 void SetupApnTryList();
157 void FillConnectPropertyMap(DBusPropertiesMap *properties);
158
159 void HelpRegisterDerivedKeyValueStore(
160 const std::string &name,
161 KeyValueStore(CellularCapabilityUniversal::*get)(Error *error),
162 void(CellularCapabilityUniversal::*set)(
163 const KeyValueStore &value, Error *error));
164
165 // Signal callbacks
Nathan Williams3022be52012-04-19 17:40:49 -0400166 void OnNetworkModeSignal(uint32 mode);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400167 void OnModemStateChangedSignal(int32 old_state,
168 int32 new_state,
169 uint32 reason);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400170
171 // Property Change notification handlers
Nathan Williams3022be52012-04-19 17:40:49 -0400172 void OnModemPropertiesChanged(
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400173 const DBusPropertiesMap &properties,
174 const std::vector<std::string> &invalidated_properties);
175
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400176 // TODO(jglasgow): install generic property change notification handler
Nathan Williams3022be52012-04-19 17:40:49 -0400177 void On3GPPRegistrationChanged(MMModem3gppRegistrationState state,
178 const std::string &operator_code,
179 const std::string &operator_name);
180 void OnSignalQualityChanged(uint32 quality);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400181
Jason Glasgowef965562012-04-10 16:12:35 -0400182 // Updates the sim_path_ variable and creates a new proxy to the
183 // DBUS ModemManager1.Sim interface
Nathan Williams3022be52012-04-19 17:40:49 -0400184 void OnSimPathChanged(const std::string &sim_path);
Jason Glasgowef965562012-04-10 16:12:35 -0400185
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400186 // Method callbacks
Nathan Williams3022be52012-04-19 17:40:49 -0400187 void OnRegisterReply(const ResultCallback &callback,
188 const Error &error);
189 void OnScanReply(const ResultCallback &callback,
190 const ScanResults &results,
191 const Error &error);
Nathan Williamsb54974f2012-04-19 11:16:30 -0400192 void OnConnectReply(const ResultCallback &callback,
193 const DBus::Path &bearer,
194 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400195
196 scoped_ptr<mm1::ModemModem3gppProxyInterface> modem_3gpp_proxy_;
197 scoped_ptr<mm1::ModemModemCdmaProxyInterface> modem_cdma_proxy_;
198 scoped_ptr<mm1::ModemProxyInterface> modem_proxy_;
199 scoped_ptr<mm1::ModemSimpleProxyInterface> modem_simple_proxy_;
200 scoped_ptr<mm1::SimProxyInterface> sim_proxy_;
201
202 base::WeakPtrFactory<CellularCapabilityUniversal> weak_ptr_factory_;
203
204 MMModem3gppRegistrationState registration_state_;
205 MMModemCdmaRegistrationState cdma_registration_state_;
206 uint32 access_technologies_; // Bits based on MMModemAccessTechnology
207 Cellular::Operator serving_operator_;
208 std::string spn_;
209 mobile_provider *home_provider_;
210 std::string desired_network_;
211
212 // Properties.
213 std::string carrier_;
214 std::string esn_;
215 std::string firmware_revision_;
216 std::string hardware_revision_;
217 std::string imei_;
218 std::string imsi_;
219 std::string manufacturer_;
220 std::string mdn_;
221 std::string meid_;
222 std::string min_;
223 std::string model_id_;
224 std::string selected_network_;
225 Stringmaps found_networks_;
226 std::deque<Stringmap> apn_try_list_;
227 bool scanning_supported_;
228 bool scanning_;
229 uint16 scan_interval_;
230 SimLockStatus sim_lock_status_;
231 Stringmaps apn_list_;
Jason Glasgowef965562012-04-10 16:12:35 -0400232 std::string sim_path_;
Nathan Williamsb54974f2012-04-19 11:16:30 -0400233 DBus::Path bearer_path_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400234
235 static unsigned int friendly_service_name_id_;
236
237 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityUniversal);
238};
239
240} // namespace shill
241
242#endif // SHILL_CELLULAR_CAPABILITY_UNIVERSAL_