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