blob: 4f8efbfa3b077b77155ab350917ec1f757a37c67 [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 Petkove9d12e02011-07-27 15:09:37 -070011#include <gtest/gtest_prod.h> // for FRIEND_TEST
Chris Masone3bd3c8c2011-06-13 08:20:26 -070012
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013#include "shill/device.h"
Darin Petkovd9661952011-08-03 16:25:42 -070014#include "shill/modem_cdma_proxy_interface.h"
Chris Masone2b105542011-06-22 10:58:09 -070015#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070016#include "shill/shill_event.h"
17
18namespace shill {
19
Darin Petkove9d12e02011-07-27 15:09:37 -070020class ModemProxyInterface;
Darin Petkove604f702011-07-28 15:51:17 -070021class ModemSimpleProxyInterface;
Darin Petkove9d12e02011-07-27 15:09:37 -070022
Darin Petkovd9661952011-08-03 16:25:42 -070023class Cellular : public Device,
24 public ModemCDMAProxyListener {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070025 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070026 enum Type {
27 kTypeGSM,
28 kTypeCDMA
29 };
30
31 enum State {
32 kStateDisabled,
33 kStateEnabled,
34 kStateRegistered,
35 kStateConnected,
36 };
37
Chris Masone889666b2011-07-03 12:58:50 -070038 class Network {
39 public:
40 Network();
Darin Petkove9d12e02011-07-27 15:09:37 -070041 ~Network();
Chris Masone889666b2011-07-03 12:58:50 -070042
43 const std::string &GetStatus() const;
44 void SetStatus(const std::string &status);
45
46 const std::string &GetId() const;
47 void SetId(const std::string &id);
48
49 const std::string &GetShortName() const;
50 void SetShortName(const std::string &name);
51
52 const std::string &GetLongName() const;
53 void SetLongName(const std::string &name);
54
55 const std::string &GetTechnology() const;
56 void SetTechnology(const std::string &technology);
57
58 const Stringmap &ToDict() const;
59
60 private:
61 Stringmap dict_;
Darin Petkove9d12e02011-07-27 15:09:37 -070062
Chris Masone889666b2011-07-03 12:58:50 -070063 DISALLOW_COPY_AND_ASSIGN(Network);
64 };
65
Darin Petkovbec79a22011-08-01 14:47:17 -070066 struct CDMA {
67 CDMA();
68
69 uint32 registration_state_evdo;
70 uint32 registration_state_1x;
71 uint32 activation_state;
72 };
73
Chris Masone889666b2011-07-03 12:58:50 -070074 struct SimLockStatus {
75 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070076 SimLockStatus() : retries_left(0) {}
77
Chris Masone889666b2011-07-03 12:58:50 -070078 std::string lock_type;
79 uint32 retries_left;
80 };
81
Darin Petkove9d12e02011-07-27 15:09:37 -070082 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
83 // the ModemManager.Modem DBus object path (e.g.,
84 // "/org/chromium/ModemManager/Gobi/0").
Chris Masone3bd3c8c2011-06-13 08:20:26 -070085 Cellular(ControlInterface *control_interface,
86 EventDispatcher *dispatcher,
87 Manager *manager,
Darin Petkove9d12e02011-07-27 15:09:37 -070088 const std::string &link_name,
89 int interface_index,
90 Type type,
91 const std::string &owner,
92 const std::string &path);
93 virtual ~Cellular();
94
95 // Inherited from Device.
96 virtual void Start();
97 virtual void Stop();
98 virtual bool TechnologyIs(Technology type);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070099
100 private:
Darin Petkovbec79a22011-08-01 14:47:17 -0700101 FRIEND_TEST(CellularTest, GetCDMARegistrationState);
Darin Petkovd9661952011-08-03 16:25:42 -0700102 FRIEND_TEST(CellularTest, GetCDMASignalQuality);
Darin Petkovceb68172011-07-29 14:47:48 -0700103 FRIEND_TEST(CellularTest, GetModemInfo);
104 FRIEND_TEST(CellularTest, GetModemStatus);
Darin Petkove9d12e02011-07-27 15:09:37 -0700105 FRIEND_TEST(CellularTest, GetStateString);
106 FRIEND_TEST(CellularTest, GetTypeString);
Darin Petkovbec79a22011-08-01 14:47:17 -0700107 FRIEND_TEST(CellularTest, InitProxiesCDMA);
108 FRIEND_TEST(CellularTest, InitProxiesGSM);
Darin Petkove9d12e02011-07-27 15:09:37 -0700109 FRIEND_TEST(CellularTest, Start);
110
Chris Masone889666b2011-07-03 12:58:50 -0700111 Stringmaps EnumerateNetworks();
112 StrIntPair SimLockStatusToProperty();
113 void HelpRegisterDerivedStringmaps(const std::string &name,
114 Stringmaps(Cellular::*get)(void),
115 bool(Cellular::*set)(const Stringmaps&));
116 void HelpRegisterDerivedStrIntPair(const std::string &name,
117 StrIntPair(Cellular::*get)(void),
118 bool(Cellular::*set)(const StrIntPair&));
119
Darin Petkovbec79a22011-08-01 14:47:17 -0700120 void InitProxies();
121
Darin Petkove9d12e02011-07-27 15:09:37 -0700122 std::string GetTypeString();
123 std::string GetStateString();
124
Darin Petkovf5f61e02011-07-29 11:35:40 -0700125 void EnableModem();
126 void GetModemStatus();
Darin Petkovceb68172011-07-29 14:47:48 -0700127 void GetGSMProperties();
128 void RegisterGSMModem();
Darin Petkovceb68172011-07-29 14:47:48 -0700129
130 // Obtains the modem identifiers: MEID for CDMA; IMEI, IMSI, SPN and MSISDN
131 // for GSM.
132 void GetModemIdentifiers();
133
Darin Petkovd9661952011-08-03 16:25:42 -0700134 // Obtains modem's manufacturer, model ID, and hardware revision.
Darin Petkovceb68172011-07-29 14:47:48 -0700135 void GetModemInfo();
Darin Petkovf5f61e02011-07-29 11:35:40 -0700136
Darin Petkovbec79a22011-08-01 14:47:17 -0700137 void GetModemRegistrationState();
138 void GetCDMARegistrationState();
139 void GetGSMRegistrationState();
140
Darin Petkovd9661952011-08-03 16:25:42 -0700141 // Processes a change in the modem registration state, possibly creating,
142 // destroying or updating the CellularService.
143 void HandleNewRegistrationState();
144
145 void CreateService();
146
147 void GetModemSignalQuality();
148 uint32 GetCDMASignalQuality();
149 uint32 GetGSMSignalQuality();
150
151 void HandleNewSignalQuality(uint32 strength);
152
153 // Returns true if the modem is registered. Note that this method looks at the
154 // latest CDMA/GSM registration info obtained from the modem rather than the
155 // device |state_|.
156 bool IsModemRegistered();
157
158 // Signal callbacks from ModemCDMAProxyListener.
159 virtual void OnCDMARegistrationStateChanged(uint32 state_1x,
160 uint32 state_evdo);
161 virtual void OnCDMASignalQualityChanged(uint32 strength);
162
Darin Petkove9d12e02011-07-27 15:09:37 -0700163 Type type_;
164 State state_;
165
166 const std::string dbus_owner_; // ModemManager.Modem
167 const std::string dbus_path_; // ModemManager.Modem
168 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkove604f702011-07-28 15:51:17 -0700169 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
Darin Petkovbec79a22011-08-01 14:47:17 -0700170 scoped_ptr<ModemCDMAProxyInterface> cdma_proxy_;
171
172 CDMA cdma_;
Darin Petkove9d12e02011-07-27 15:09:37 -0700173
Darin Petkovd9661952011-08-03 16:25:42 -0700174 CellularServiceRefPtr service_;
Chris Masone853b81b2011-06-24 14:11:41 -0700175 bool service_registered_;
176
Chris Masoneb925cc82011-06-22 15:39:57 -0700177 // Properties
178 bool allow_roaming_;
179 std::string carrier_;
180 std::string meid_;
181 std::string imei_;
182 std::string imsi_;
183 std::string esn_;
184 std::string mdn_;
185 std::string min_;
186 std::string model_id_;
187 std::string manufacturer_;
188 std::string firmware_revision_;
189 std::string hardware_revision_;
Darin Petkovceb68172011-07-29 14:47:48 -0700190 uint16 prl_version_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700191 bool scanning_;
192 uint16 scan_interval_;
Chris Masone889666b2011-07-03 12:58:50 -0700193 std::vector<Network> found_networks_;
194 SimLockStatus sim_lock_status_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700195
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700196 DISALLOW_COPY_AND_ASSIGN(Cellular);
197};
198
199} // namespace shill
200
201#endif // SHILL_CELLULAR_