blob: 00f1afc618b1af396ea9ff8197b260a83b9da4fe [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 Petkove9d12e02011-07-27 15:09:37 -070019class ModemProxyInterface;
Darin Petkove604f702011-07-28 15:51:17 -070020class ModemSimpleProxyInterface;
Darin Petkove9d12e02011-07-27 15:09:37 -070021
Chris Masone3bd3c8c2011-06-13 08:20:26 -070022class Cellular : public Device {
23 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070024 enum Type {
25 kTypeGSM,
26 kTypeCDMA
27 };
28
29 enum State {
30 kStateDisabled,
31 kStateEnabled,
32 kStateRegistered,
33 kStateConnected,
34 };
35
Chris Masone889666b2011-07-03 12:58:50 -070036 class Network {
37 public:
38 Network();
Darin Petkove9d12e02011-07-27 15:09:37 -070039 ~Network();
Chris Masone889666b2011-07-03 12:58:50 -070040
41 const std::string &GetStatus() const;
42 void SetStatus(const std::string &status);
43
44 const std::string &GetId() const;
45 void SetId(const std::string &id);
46
47 const std::string &GetShortName() const;
48 void SetShortName(const std::string &name);
49
50 const std::string &GetLongName() const;
51 void SetLongName(const std::string &name);
52
53 const std::string &GetTechnology() const;
54 void SetTechnology(const std::string &technology);
55
56 const Stringmap &ToDict() const;
57
58 private:
59 Stringmap dict_;
Darin Petkove9d12e02011-07-27 15:09:37 -070060
Chris Masone889666b2011-07-03 12:58:50 -070061 DISALLOW_COPY_AND_ASSIGN(Network);
62 };
63
64 struct SimLockStatus {
65 public:
Darin Petkove9d12e02011-07-27 15:09:37 -070066 SimLockStatus() : retries_left(0) {}
67
Chris Masone889666b2011-07-03 12:58:50 -070068 std::string lock_type;
69 uint32 retries_left;
70 };
71
Darin Petkove9d12e02011-07-27 15:09:37 -070072 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
73 // the ModemManager.Modem DBus object path (e.g.,
74 // "/org/chromium/ModemManager/Gobi/0").
Chris Masone3bd3c8c2011-06-13 08:20:26 -070075 Cellular(ControlInterface *control_interface,
76 EventDispatcher *dispatcher,
77 Manager *manager,
Darin Petkove9d12e02011-07-27 15:09:37 -070078 const std::string &link_name,
79 int interface_index,
80 Type type,
81 const std::string &owner,
82 const std::string &path);
83 virtual ~Cellular();
84
85 // Inherited from Device.
86 virtual void Start();
87 virtual void Stop();
88 virtual bool TechnologyIs(Technology type);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070089
90 private:
Darin Petkove9d12e02011-07-27 15:09:37 -070091 FRIEND_TEST(CellularTest, GetStateString);
92 FRIEND_TEST(CellularTest, GetTypeString);
93 FRIEND_TEST(CellularTest, Start);
94
Chris Masone889666b2011-07-03 12:58:50 -070095 Stringmaps EnumerateNetworks();
96 StrIntPair SimLockStatusToProperty();
97 void HelpRegisterDerivedStringmaps(const std::string &name,
98 Stringmaps(Cellular::*get)(void),
99 bool(Cellular::*set)(const Stringmaps&));
100 void HelpRegisterDerivedStrIntPair(const std::string &name,
101 StrIntPair(Cellular::*get)(void),
102 bool(Cellular::*set)(const StrIntPair&));
103
Darin Petkove9d12e02011-07-27 15:09:37 -0700104 std::string GetTypeString();
105 std::string GetStateString();
106
Darin Petkovf5f61e02011-07-29 11:35:40 -0700107 void EnableModem();
108 void GetModemStatus();
109
Darin Petkove9d12e02011-07-27 15:09:37 -0700110 Type type_;
111 State state_;
112
113 const std::string dbus_owner_; // ModemManager.Modem
114 const std::string dbus_path_; // ModemManager.Modem
115 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkove604f702011-07-28 15:51:17 -0700116 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
Darin Petkove9d12e02011-07-27 15:09:37 -0700117
Chris Masone853b81b2011-06-24 14:11:41 -0700118 ServiceRefPtr service_;
119 bool service_registered_;
120
Chris Masoneb925cc82011-06-22 15:39:57 -0700121 // Properties
122 bool allow_roaming_;
123 std::string carrier_;
124 std::string meid_;
125 std::string imei_;
126 std::string imsi_;
127 std::string esn_;
128 std::string mdn_;
129 std::string min_;
130 std::string model_id_;
131 std::string manufacturer_;
132 std::string firmware_revision_;
133 std::string hardware_revision_;
134 int16 prl_version_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700135 bool scanning_;
136 uint16 scan_interval_;
Chris Masone889666b2011-07-03 12:58:50 -0700137 std::vector<Network> found_networks_;
138 SimLockStatus sim_lock_status_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700139
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700140 DISALLOW_COPY_AND_ASSIGN(Cellular);
141};
142
143} // namespace shill
144
145#endif // SHILL_CELLULAR_