blob: dc9b00b3e2682735e8de34ecb64cc84d5a745385 [file] [log] [blame]
Chris Masone3bd3c8c2011-06-13 08:20:26 -07001// Copyright (c) 2011 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_
6#define SHILL_CELLULAR_
7
8#include <string>
9
10#include <base/basictypes.h>
Darin Petkovc5f56562011-08-06 16:40:05 -070011#include <base/task.h>
Darin Petkove9d12e02011-07-27 15:09:37 -070012#include <gtest/gtest_prod.h> // for FRIEND_TEST
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013
Darin Petkovc5f56562011-08-06 16:40:05 -070014#include "shill/dbus_properties.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015#include "shill/device.h"
Darin Petkovd9661952011-08-03 16:25:42 -070016#include "shill/modem_cdma_proxy_interface.h"
Darin Petkovc5f56562011-08-06 16:40:05 -070017#include "shill/modem_proxy_interface.h"
Chris Masone2b105542011-06-22 10:58:09 -070018#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070019#include "shill/shill_event.h"
20
21namespace shill {
22
Darin Petkove604f702011-07-28 15:51:17 -070023class ModemSimpleProxyInterface;
Darin Petkove9d12e02011-07-27 15:09:37 -070024
Darin Petkovd9661952011-08-03 16:25:42 -070025class Cellular : public Device,
Darin Petkovc5f56562011-08-06 16:40:05 -070026 public ModemCDMAProxyListener,
27 public ModemProxyListener {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070028 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070029 enum Type {
30 kTypeGSM,
31 kTypeCDMA
32 };
33
34 enum State {
35 kStateDisabled,
36 kStateEnabled,
37 kStateRegistered,
38 kStateConnected,
39 };
40
Chris Masone889666b2011-07-03 12:58:50 -070041 class Network {
42 public:
43 Network();
Darin Petkove9d12e02011-07-27 15:09:37 -070044 ~Network();
Chris Masone889666b2011-07-03 12:58:50 -070045
46 const std::string &GetStatus() const;
47 void SetStatus(const std::string &status);
48
49 const std::string &GetId() const;
50 void SetId(const std::string &id);
51
52 const std::string &GetShortName() const;
53 void SetShortName(const std::string &name);
54
55 const std::string &GetLongName() const;
56 void SetLongName(const std::string &name);
57
58 const std::string &GetTechnology() const;
59 void SetTechnology(const std::string &technology);
60
61 const Stringmap &ToDict() const;
62
63 private:
64 Stringmap dict_;
Darin Petkove9d12e02011-07-27 15:09:37 -070065
Chris Masone889666b2011-07-03 12:58:50 -070066 DISALLOW_COPY_AND_ASSIGN(Network);
67 };
68
Darin Petkovbec79a22011-08-01 14:47:17 -070069 struct CDMA {
70 CDMA();
71
72 uint32 registration_state_evdo;
73 uint32 registration_state_1x;
74 uint32 activation_state;
75 };
76
Chris Masone889666b2011-07-03 12:58:50 -070077 struct SimLockStatus {
78 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070079 SimLockStatus() : retries_left(0) {}
80
Chris Masone889666b2011-07-03 12:58:50 -070081 std::string lock_type;
82 uint32 retries_left;
83 };
84
Darin Petkovc5f56562011-08-06 16:40:05 -070085 static const char kConnectPropertyPhoneNumber[];
86
Darin Petkove9d12e02011-07-27 15:09:37 -070087 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
88 // the ModemManager.Modem DBus object path (e.g.,
89 // "/org/chromium/ModemManager/Gobi/0").
Chris Masone3bd3c8c2011-06-13 08:20:26 -070090 Cellular(ControlInterface *control_interface,
91 EventDispatcher *dispatcher,
92 Manager *manager,
Darin Petkove9d12e02011-07-27 15:09:37 -070093 const std::string &link_name,
94 int interface_index,
95 Type type,
96 const std::string &owner,
97 const std::string &path);
98 virtual ~Cellular();
99
Darin Petkovc5f56562011-08-06 16:40:05 -0700100 // Asynchronously connects the modem to the network.
101 void Connect();
102
Darin Petkove9d12e02011-07-27 15:09:37 -0700103 // Inherited from Device.
104 virtual void Start();
105 virtual void Stop();
106 virtual bool TechnologyIs(Technology type);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700107
108 private:
Darin Petkovc5f56562011-08-06 16:40:05 -0700109 static const char kPhoneNumberCDMA[];
110 static const char kPhoneNumberGSM[];
111
112 FRIEND_TEST(CellularTest, Connect);
Darin Petkovbec79a22011-08-01 14:47:17 -0700113 FRIEND_TEST(CellularTest, GetCDMARegistrationState);
Darin Petkovd9661952011-08-03 16:25:42 -0700114 FRIEND_TEST(CellularTest, GetCDMASignalQuality);
Darin Petkovceb68172011-07-29 14:47:48 -0700115 FRIEND_TEST(CellularTest, GetModemInfo);
116 FRIEND_TEST(CellularTest, GetModemStatus);
Darin Petkove9d12e02011-07-27 15:09:37 -0700117 FRIEND_TEST(CellularTest, GetStateString);
118 FRIEND_TEST(CellularTest, GetTypeString);
Darin Petkovbec79a22011-08-01 14:47:17 -0700119 FRIEND_TEST(CellularTest, InitProxiesCDMA);
120 FRIEND_TEST(CellularTest, InitProxiesGSM);
Darin Petkove9d12e02011-07-27 15:09:37 -0700121 FRIEND_TEST(CellularTest, Start);
122
Darin Petkovc5f56562011-08-06 16:40:05 -0700123 void ConnectTask(const DBusPropertiesMap &properties);
124
Chris Masone889666b2011-07-03 12:58:50 -0700125 Stringmaps EnumerateNetworks();
126 StrIntPair SimLockStatusToProperty();
127 void HelpRegisterDerivedStringmaps(const std::string &name,
128 Stringmaps(Cellular::*get)(void),
129 bool(Cellular::*set)(const Stringmaps&));
130 void HelpRegisterDerivedStrIntPair(const std::string &name,
131 StrIntPair(Cellular::*get)(void),
132 bool(Cellular::*set)(const StrIntPair&));
133
Darin Petkovbec79a22011-08-01 14:47:17 -0700134 void InitProxies();
135
Darin Petkove9d12e02011-07-27 15:09:37 -0700136 std::string GetTypeString();
137 std::string GetStateString();
138
Darin Petkovf5f61e02011-07-29 11:35:40 -0700139 void EnableModem();
140 void GetModemStatus();
Darin Petkovceb68172011-07-29 14:47:48 -0700141 void GetGSMProperties();
142 void RegisterGSMModem();
Darin Petkovceb68172011-07-29 14:47:48 -0700143
144 // Obtains the modem identifiers: MEID for CDMA; IMEI, IMSI, SPN and MSISDN
145 // for GSM.
146 void GetModemIdentifiers();
147
Darin Petkovd9661952011-08-03 16:25:42 -0700148 // Obtains modem's manufacturer, model ID, and hardware revision.
Darin Petkovceb68172011-07-29 14:47:48 -0700149 void GetModemInfo();
Darin Petkovf5f61e02011-07-29 11:35:40 -0700150
Darin Petkovbec79a22011-08-01 14:47:17 -0700151 void GetModemRegistrationState();
152 void GetCDMARegistrationState();
153 void GetGSMRegistrationState();
154
Darin Petkovd9661952011-08-03 16:25:42 -0700155 // Processes a change in the modem registration state, possibly creating,
156 // destroying or updating the CellularService.
157 void HandleNewRegistrationState();
158
159 void CreateService();
160
161 void GetModemSignalQuality();
162 uint32 GetCDMASignalQuality();
163 uint32 GetGSMSignalQuality();
164
165 void HandleNewSignalQuality(uint32 strength);
166
167 // Returns true if the modem is registered. Note that this method looks at the
168 // latest CDMA/GSM registration info obtained from the modem rather than the
169 // device |state_|.
170 bool IsModemRegistered();
171
Darin Petkovc5f56562011-08-06 16:40:05 -0700172 // Signal callbacks inherited from ModemCDMAProxyListener.
Darin Petkovd9661952011-08-03 16:25:42 -0700173 virtual void OnCDMARegistrationStateChanged(uint32 state_1x,
174 uint32 state_evdo);
175 virtual void OnCDMASignalQualityChanged(uint32 strength);
176
Darin Petkovc5f56562011-08-06 16:40:05 -0700177 // Signal callbacks inherited from ModemProxyListener.
178 virtual void OnModemStateChanged(uint32 old_state,
179 uint32 new_state,
180 uint32 reason);
181
Darin Petkove9d12e02011-07-27 15:09:37 -0700182 Type type_;
183 State state_;
184
185 const std::string dbus_owner_; // ModemManager.Modem
186 const std::string dbus_path_; // ModemManager.Modem
187 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkove604f702011-07-28 15:51:17 -0700188 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
Darin Petkovbec79a22011-08-01 14:47:17 -0700189 scoped_ptr<ModemCDMAProxyInterface> cdma_proxy_;
190
191 CDMA cdma_;
Darin Petkove9d12e02011-07-27 15:09:37 -0700192
Darin Petkovd9661952011-08-03 16:25:42 -0700193 CellularServiceRefPtr service_;
Chris Masone853b81b2011-06-24 14:11:41 -0700194 bool service_registered_;
195
Darin Petkovc5f56562011-08-06 16:40:05 -0700196 ScopedRunnableMethodFactory<Cellular> task_factory_;
197
Chris Masoneb925cc82011-06-22 15:39:57 -0700198 // Properties
199 bool allow_roaming_;
200 std::string carrier_;
201 std::string meid_;
202 std::string imei_;
203 std::string imsi_;
204 std::string esn_;
205 std::string mdn_;
206 std::string min_;
207 std::string model_id_;
208 std::string manufacturer_;
209 std::string firmware_revision_;
210 std::string hardware_revision_;
Darin Petkovceb68172011-07-29 14:47:48 -0700211 uint16 prl_version_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700212 bool scanning_;
213 uint16 scan_interval_;
Chris Masone889666b2011-07-03 12:58:50 -0700214 std::vector<Network> found_networks_;
215 SimLockStatus sim_lock_status_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700216
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700217 DISALLOW_COPY_AND_ASSIGN(Cellular);
218};
219
220} // namespace shill
221
222#endif // SHILL_CELLULAR_