blob: 8e90222b4f5f6e37a4766f8e5873b4b3c8245ac9 [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 Masone7aa5f902011-07-11 11:13:35 -070019#include "shill/profile.h"
Chris Masone889666b2011-07-03 12:58:50 -070020#include "shill/property_accessor.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070021#include "shill/shill_event.h"
22
Chris Masone889666b2011-07-03 12:58:50 -070023using std::make_pair;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070024using std::string;
Chris Masone889666b2011-07-03 12:58:50 -070025using std::vector;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070026
27namespace shill {
28
Chris Masone889666b2011-07-03 12:58:50 -070029Cellular::Network::Network() {
30 dict_[flimflam::kStatusProperty] = "";
31 dict_[flimflam::kNetworkIdProperty] = "";
32 dict_[flimflam::kShortNameProperty] = "";
33 dict_[flimflam::kLongNameProperty] = "";
34 dict_[flimflam::kTechnologyProperty] = "";
35}
36
37Cellular::Network::~Network() {}
38
39const std::string &Cellular::Network::GetStatus() const {
40 return dict_.find(flimflam::kStatusProperty)->second;
41}
42
43void Cellular::Network::SetStatus(const std::string &status) {
44 dict_[flimflam::kStatusProperty] = status;
45}
46
47const std::string &Cellular::Network::GetId() const {
48 return dict_.find(flimflam::kNetworkIdProperty)->second;
49}
50
51void Cellular::Network::SetId(const std::string &id) {
52 dict_[flimflam::kNetworkIdProperty] = id;
53}
54
55const std::string &Cellular::Network::GetShortName() const {
56 return dict_.find(flimflam::kShortNameProperty)->second;
57}
58
59void Cellular::Network::SetShortName(const std::string &name) {
60 dict_[flimflam::kShortNameProperty] = name;
61}
62
63const std::string &Cellular::Network::GetLongName() const {
64 return dict_.find(flimflam::kLongNameProperty)->second;
65}
66
67void Cellular::Network::SetLongName(const std::string &name) {
68 dict_[flimflam::kLongNameProperty] = name;
69}
70
71const std::string &Cellular::Network::GetTechnology() const {
72 return dict_.find(flimflam::kTechnologyProperty)->second;
73}
74
75void Cellular::Network::SetTechnology(const std::string &technology) {
76 dict_[flimflam::kTechnologyProperty] = technology;
77}
78
79const Stringmap &Cellular::Network::ToDict() const {
80 return dict_;
81}
82
83Cellular::SimLockStatus::SimLockStatus() {}
84
85Cellular::SimLockStatus::~SimLockStatus() {}
86
Chris Masone3bd3c8c2011-06-13 08:20:26 -070087Cellular::Cellular(ControlInterface *control_interface,
88 EventDispatcher *dispatcher,
89 Manager *manager,
90 const string &link,
91 int interface_index)
92 : Device(control_interface,
93 dispatcher,
94 manager,
95 link,
96 interface_index),
97 service_(new CellularService(control_interface,
98 dispatcher,
Chris Masone6791a432011-07-12 13:23:19 -070099 manager,
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700100 this,
Chris Masone7aa5f902011-07-11 11:13:35 -0700101 "service-" + link_name())),
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700102 service_registered_(false) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700103 store_.RegisterConstString(flimflam::kCarrierProperty, &carrier_);
Chris Masone4d42df82011-07-02 17:09:39 -0700104 store_.RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700105 store_.RegisterConstString(flimflam::kEsnProperty, &esn_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700106 store_.RegisterConstString(flimflam::kFirmwareRevisionProperty,
107 &firmware_revision_);
108 store_.RegisterConstString(flimflam::kHardwareRevisionProperty,
109 &hardware_revision_);
Chris Masone4d42df82011-07-02 17:09:39 -0700110 store_.RegisterConstString(flimflam::kImeiProperty, &imei_);
111 store_.RegisterConstString(flimflam::kImsiProperty, &imsi_);
112 store_.RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_);
113 store_.RegisterConstString(flimflam::kMdnProperty, &mdn_);
114 store_.RegisterConstString(flimflam::kMeidProperty, &meid_);
115 store_.RegisterConstString(flimflam::kMinProperty, &min_);
116 store_.RegisterConstString(flimflam::kModelIDProperty, &model_id_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700117 store_.RegisterConstInt16(flimflam::kPRLVersionProperty, &prl_version_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700118
Chris Masone889666b2011-07-03 12:58:50 -0700119 HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty,
120 &Cellular::SimLockStatusToProperty,
121 NULL);
122 HelpRegisterDerivedStringmaps(flimflam::kFoundNetworksProperty,
123 &Cellular::EnumerateNetworks,
124 NULL);
Chris Masoneb925cc82011-06-22 15:39:57 -0700125
Chris Masone4d42df82011-07-02 17:09:39 -0700126 store_.RegisterConstBool(flimflam::kScanningProperty, &scanning_);
127 store_.RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_);
128
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700129 VLOG(2) << "Cellular device " << link_name() << " initialized.";
130}
131
132Cellular::~Cellular() {
133 Stop();
134}
135
136void Cellular::Start() {
137 Device::Start();
138}
139
140void Cellular::Stop() {
Chris Masone2b105542011-06-22 10:58:09 -0700141 manager_->DeregisterService(service_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700142 Device::Stop();
143}
144
145bool Cellular::TechnologyIs(const Device::Technology type) {
146 return type == Device::kCellular;
147}
148
Chris Masone889666b2011-07-03 12:58:50 -0700149Stringmaps Cellular::EnumerateNetworks() {
150 Stringmaps to_return;
151 for (vector<Network>::const_iterator it = found_networks_.begin();
152 it != found_networks_.end();
153 ++it) {
154 to_return.push_back(it->ToDict());
155 }
156 return to_return;
157}
158
159StrIntPair Cellular::SimLockStatusToProperty() {
160 return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty,
161 sim_lock_status_.lock_type),
162 make_pair(flimflam::kSIMLockRetriesLeftProperty,
163 sim_lock_status_.retries_left));
164}
165
166void Cellular::HelpRegisterDerivedStringmaps(
167 const string &name,
168 Stringmaps(Cellular::*get)(void),
169 bool(Cellular::*set)(const Stringmaps&)) {
170 store_.RegisterDerivedStringmaps(
171 name,
172 StringmapsAccessor(
173 new CustomAccessor<Cellular, Stringmaps>(this, get, set)));
174}
175
176void Cellular::HelpRegisterDerivedStrIntPair(
177 const string &name,
178 StrIntPair(Cellular::*get)(void),
179 bool(Cellular::*set)(const StrIntPair&)) {
180 store_.RegisterDerivedStrIntPair(
181 name,
182 StrIntPairAccessor(
183 new CustomAccessor<Cellular, StrIntPair>(this, get, set)));
184}
185
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700186} // namespace shill