blob: 251eaf4754f68233e4e3ee53c4415c781b60e93a [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#include "shill/cellular.h"
6
7#include <string>
Chris Masone889666b2011-07-03 12:58:50 -07008#include <utility>
9#include <vector>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070010
11#include <base/logging.h>
Chris Masoneb925cc82011-06-22 15:39:57 -070012#include <chromeos/dbus/service_constants.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013
14#include "shill/cellular_service.h"
15#include "shill/control_interface.h"
16#include "shill/device.h"
17#include "shill/device_info.h"
18#include "shill/manager.h"
Chris Masone889666b2011-07-03 12:58:50 -070019#include "shill/property_accessor.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070020#include "shill/shill_event.h"
21
Chris Masone889666b2011-07-03 12:58:50 -070022using std::make_pair;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070023using std::string;
Chris Masone889666b2011-07-03 12:58:50 -070024using std::vector;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070025
26namespace shill {
27
Chris Masone889666b2011-07-03 12:58:50 -070028Cellular::Network::Network() {
29 dict_[flimflam::kStatusProperty] = "";
30 dict_[flimflam::kNetworkIdProperty] = "";
31 dict_[flimflam::kShortNameProperty] = "";
32 dict_[flimflam::kLongNameProperty] = "";
33 dict_[flimflam::kTechnologyProperty] = "";
34}
35
36Cellular::Network::~Network() {}
37
38const std::string &Cellular::Network::GetStatus() const {
39 return dict_.find(flimflam::kStatusProperty)->second;
40}
41
42void Cellular::Network::SetStatus(const std::string &status) {
43 dict_[flimflam::kStatusProperty] = status;
44}
45
46const std::string &Cellular::Network::GetId() const {
47 return dict_.find(flimflam::kNetworkIdProperty)->second;
48}
49
50void Cellular::Network::SetId(const std::string &id) {
51 dict_[flimflam::kNetworkIdProperty] = id;
52}
53
54const std::string &Cellular::Network::GetShortName() const {
55 return dict_.find(flimflam::kShortNameProperty)->second;
56}
57
58void Cellular::Network::SetShortName(const std::string &name) {
59 dict_[flimflam::kShortNameProperty] = name;
60}
61
62const std::string &Cellular::Network::GetLongName() const {
63 return dict_.find(flimflam::kLongNameProperty)->second;
64}
65
66void Cellular::Network::SetLongName(const std::string &name) {
67 dict_[flimflam::kLongNameProperty] = name;
68}
69
70const std::string &Cellular::Network::GetTechnology() const {
71 return dict_.find(flimflam::kTechnologyProperty)->second;
72}
73
74void Cellular::Network::SetTechnology(const std::string &technology) {
75 dict_[flimflam::kTechnologyProperty] = technology;
76}
77
78const Stringmap &Cellular::Network::ToDict() const {
79 return dict_;
80}
81
82Cellular::SimLockStatus::SimLockStatus() {}
83
84Cellular::SimLockStatus::~SimLockStatus() {}
85
Chris Masone3bd3c8c2011-06-13 08:20:26 -070086Cellular::Cellular(ControlInterface *control_interface,
87 EventDispatcher *dispatcher,
88 Manager *manager,
89 const string &link,
90 int interface_index)
91 : Device(control_interface,
92 dispatcher,
93 manager,
94 link,
95 interface_index),
96 service_(new CellularService(control_interface,
97 dispatcher,
98 this,
99 "service-" + link)),
100 service_registered_(false) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700101 store_.RegisterConstString(flimflam::kCarrierProperty, &carrier_);
Chris Masone4d42df82011-07-02 17:09:39 -0700102 store_.RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700103 store_.RegisterConstString(flimflam::kEsnProperty, &esn_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700104 store_.RegisterConstString(flimflam::kFirmwareRevisionProperty,
105 &firmware_revision_);
106 store_.RegisterConstString(flimflam::kHardwareRevisionProperty,
107 &hardware_revision_);
Chris Masone4d42df82011-07-02 17:09:39 -0700108 store_.RegisterConstString(flimflam::kImeiProperty, &imei_);
109 store_.RegisterConstString(flimflam::kImsiProperty, &imsi_);
110 store_.RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_);
111 store_.RegisterConstString(flimflam::kMdnProperty, &mdn_);
112 store_.RegisterConstString(flimflam::kMeidProperty, &meid_);
113 store_.RegisterConstString(flimflam::kMinProperty, &min_);
114 store_.RegisterConstString(flimflam::kModelIDProperty, &model_id_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700115 store_.RegisterConstInt16(flimflam::kPRLVersionProperty, &prl_version_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700116
Chris Masone889666b2011-07-03 12:58:50 -0700117 HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty,
118 &Cellular::SimLockStatusToProperty,
119 NULL);
120 HelpRegisterDerivedStringmaps(flimflam::kFoundNetworksProperty,
121 &Cellular::EnumerateNetworks,
122 NULL);
Chris Masoneb925cc82011-06-22 15:39:57 -0700123
Chris Masone4d42df82011-07-02 17:09:39 -0700124 store_.RegisterConstBool(flimflam::kScanningProperty, &scanning_);
125 store_.RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_);
126
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700127 VLOG(2) << "Cellular device " << link_name() << " initialized.";
128}
129
130Cellular::~Cellular() {
131 Stop();
132}
133
134void Cellular::Start() {
135 Device::Start();
136}
137
138void Cellular::Stop() {
Chris Masone2b105542011-06-22 10:58:09 -0700139 manager_->DeregisterService(service_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700140 Device::Stop();
141}
142
143bool Cellular::TechnologyIs(const Device::Technology type) {
144 return type == Device::kCellular;
145}
146
Chris Masone889666b2011-07-03 12:58:50 -0700147Stringmaps Cellular::EnumerateNetworks() {
148 Stringmaps to_return;
149 for (vector<Network>::const_iterator it = found_networks_.begin();
150 it != found_networks_.end();
151 ++it) {
152 to_return.push_back(it->ToDict());
153 }
154 return to_return;
155}
156
157StrIntPair Cellular::SimLockStatusToProperty() {
158 return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty,
159 sim_lock_status_.lock_type),
160 make_pair(flimflam::kSIMLockRetriesLeftProperty,
161 sim_lock_status_.retries_left));
162}
163
164void Cellular::HelpRegisterDerivedStringmaps(
165 const string &name,
166 Stringmaps(Cellular::*get)(void),
167 bool(Cellular::*set)(const Stringmaps&)) {
168 store_.RegisterDerivedStringmaps(
169 name,
170 StringmapsAccessor(
171 new CustomAccessor<Cellular, Stringmaps>(this, get, set)));
172}
173
174void Cellular::HelpRegisterDerivedStrIntPair(
175 const string &name,
176 StrIntPair(Cellular::*get)(void),
177 bool(Cellular::*set)(const StrIntPair&)) {
178 store_.RegisterDerivedStrIntPair(
179 name,
180 StrIntPairAccessor(
181 new CustomAccessor<Cellular, StrIntPair>(this, get, set)));
182}
183
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700184} // namespace shill