blob: a88cb0936af568df2e47569b39cd2b796b5780da [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"
Chris Masone2b105542011-06-22 10:58:09 -070014#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015#include "shill/shill_event.h"
16
17namespace shill {
18
Darin Petkovbec79a22011-08-01 14:47:17 -070019class ModemCDMAProxyInterface;
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
Chris Masone3bd3c8c2011-06-13 08:20:26 -070023class Cellular : public Device {
24 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070025 enum Type {
26 kTypeGSM,
27 kTypeCDMA
28 };
29
30 enum State {
31 kStateDisabled,
32 kStateEnabled,
33 kStateRegistered,
34 kStateConnected,
35 };
36
Chris Masone889666b2011-07-03 12:58:50 -070037 class Network {
38 public:
39 Network();
Darin Petkove9d12e02011-07-27 15:09:37 -070040 ~Network();
Chris Masone889666b2011-07-03 12:58:50 -070041
42 const std::string &GetStatus() const;
43 void SetStatus(const std::string &status);
44
45 const std::string &GetId() const;
46 void SetId(const std::string &id);
47
48 const std::string &GetShortName() const;
49 void SetShortName(const std::string &name);
50
51 const std::string &GetLongName() const;
52 void SetLongName(const std::string &name);
53
54 const std::string &GetTechnology() const;
55 void SetTechnology(const std::string &technology);
56
57 const Stringmap &ToDict() const;
58
59 private:
60 Stringmap dict_;
Darin Petkove9d12e02011-07-27 15:09:37 -070061
Chris Masone889666b2011-07-03 12:58:50 -070062 DISALLOW_COPY_AND_ASSIGN(Network);
63 };
64
Darin Petkovbec79a22011-08-01 14:47:17 -070065 struct CDMA {
66 CDMA();
67
68 uint32 registration_state_evdo;
69 uint32 registration_state_1x;
70 uint32 activation_state;
71 };
72
Chris Masone889666b2011-07-03 12:58:50 -070073 struct SimLockStatus {
74 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070075 SimLockStatus() : retries_left(0) {}
76
Chris Masone889666b2011-07-03 12:58:50 -070077 std::string lock_type;
78 uint32 retries_left;
79 };
80
Darin Petkove9d12e02011-07-27 15:09:37 -070081 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
82 // the ModemManager.Modem DBus object path (e.g.,
83 // "/org/chromium/ModemManager/Gobi/0").
Chris Masone3bd3c8c2011-06-13 08:20:26 -070084 Cellular(ControlInterface *control_interface,
85 EventDispatcher *dispatcher,
86 Manager *manager,
Darin Petkove9d12e02011-07-27 15:09:37 -070087 const std::string &link_name,
88 int interface_index,
89 Type type,
90 const std::string &owner,
91 const std::string &path);
92 virtual ~Cellular();
93
94 // Inherited from Device.
95 virtual void Start();
96 virtual void Stop();
97 virtual bool TechnologyIs(Technology type);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070098
99 private:
Darin Petkovbec79a22011-08-01 14:47:17 -0700100 FRIEND_TEST(CellularTest, GetCDMARegistrationState);
Darin Petkovceb68172011-07-29 14:47:48 -0700101 FRIEND_TEST(CellularTest, GetModemInfo);
102 FRIEND_TEST(CellularTest, GetModemStatus);
Darin Petkove9d12e02011-07-27 15:09:37 -0700103 FRIEND_TEST(CellularTest, GetStateString);
104 FRIEND_TEST(CellularTest, GetTypeString);
Darin Petkovbec79a22011-08-01 14:47:17 -0700105 FRIEND_TEST(CellularTest, InitProxiesCDMA);
106 FRIEND_TEST(CellularTest, InitProxiesGSM);
Darin Petkove9d12e02011-07-27 15:09:37 -0700107 FRIEND_TEST(CellularTest, Start);
108
Chris Masone889666b2011-07-03 12:58:50 -0700109 Stringmaps EnumerateNetworks();
110 StrIntPair SimLockStatusToProperty();
111 void HelpRegisterDerivedStringmaps(const std::string &name,
112 Stringmaps(Cellular::*get)(void),
113 bool(Cellular::*set)(const Stringmaps&));
114 void HelpRegisterDerivedStrIntPair(const std::string &name,
115 StrIntPair(Cellular::*get)(void),
116 bool(Cellular::*set)(const StrIntPair&));
117
Darin Petkovbec79a22011-08-01 14:47:17 -0700118 void InitProxies();
119
Darin Petkove9d12e02011-07-27 15:09:37 -0700120 std::string GetTypeString();
121 std::string GetStateString();
122
Darin Petkovf5f61e02011-07-29 11:35:40 -0700123 void EnableModem();
124 void GetModemStatus();
Darin Petkovceb68172011-07-29 14:47:48 -0700125 void GetGSMProperties();
126 void RegisterGSMModem();
Darin Petkovceb68172011-07-29 14:47:48 -0700127 void ReportEnabled();
128
129 // Obtains the modem identifiers: MEID for CDMA; IMEI, IMSI, SPN and MSISDN
130 // for GSM.
131 void GetModemIdentifiers();
132
133 // Obtain modem's manufacturer, model ID, and hardware revision.
134 void GetModemInfo();
Darin Petkovf5f61e02011-07-29 11:35:40 -0700135
Darin Petkovbec79a22011-08-01 14:47:17 -0700136 void GetModemRegistrationState();
137 void GetCDMARegistrationState();
138 void GetGSMRegistrationState();
139
Darin Petkove9d12e02011-07-27 15:09:37 -0700140 Type type_;
141 State state_;
142
143 const std::string dbus_owner_; // ModemManager.Modem
144 const std::string dbus_path_; // ModemManager.Modem
145 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkove604f702011-07-28 15:51:17 -0700146 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
Darin Petkovbec79a22011-08-01 14:47:17 -0700147 scoped_ptr<ModemCDMAProxyInterface> cdma_proxy_;
148
149 CDMA cdma_;
Darin Petkove9d12e02011-07-27 15:09:37 -0700150
Chris Masone853b81b2011-06-24 14:11:41 -0700151 ServiceRefPtr service_;
152 bool service_registered_;
153
Chris Masoneb925cc82011-06-22 15:39:57 -0700154 // Properties
155 bool allow_roaming_;
156 std::string carrier_;
157 std::string meid_;
158 std::string imei_;
159 std::string imsi_;
160 std::string esn_;
161 std::string mdn_;
162 std::string min_;
163 std::string model_id_;
164 std::string manufacturer_;
165 std::string firmware_revision_;
166 std::string hardware_revision_;
Darin Petkovceb68172011-07-29 14:47:48 -0700167 uint16 prl_version_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700168 bool scanning_;
169 uint16 scan_interval_;
Chris Masone889666b2011-07-03 12:58:50 -0700170 std::vector<Network> found_networks_;
171 SimLockStatus sim_lock_status_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700172
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700173 DISALLOW_COPY_AND_ASSIGN(Cellular);
174};
175
176} // namespace shill
177
178#endif // SHILL_CELLULAR_