blob: e27de1dd71fe3791f2b2d5c6b25ef35c8f66f7ca [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,
mukesh agrawal51a7e932011-07-27 16:18:26 -0700100 this)),
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700101 service_registered_(false) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700102 store_.RegisterConstString(flimflam::kCarrierProperty, &carrier_);
Chris Masone4d42df82011-07-02 17:09:39 -0700103 store_.RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700104 store_.RegisterConstString(flimflam::kEsnProperty, &esn_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700105 store_.RegisterConstString(flimflam::kFirmwareRevisionProperty,
106 &firmware_revision_);
107 store_.RegisterConstString(flimflam::kHardwareRevisionProperty,
108 &hardware_revision_);
Chris Masone4d42df82011-07-02 17:09:39 -0700109 store_.RegisterConstString(flimflam::kImeiProperty, &imei_);
110 store_.RegisterConstString(flimflam::kImsiProperty, &imsi_);
111 store_.RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_);
112 store_.RegisterConstString(flimflam::kMdnProperty, &mdn_);
113 store_.RegisterConstString(flimflam::kMeidProperty, &meid_);
114 store_.RegisterConstString(flimflam::kMinProperty, &min_);
115 store_.RegisterConstString(flimflam::kModelIDProperty, &model_id_);
Chris Masone27c4aa52011-07-02 13:10:14 -0700116 store_.RegisterConstInt16(flimflam::kPRLVersionProperty, &prl_version_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700117
Chris Masone889666b2011-07-03 12:58:50 -0700118 HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty,
119 &Cellular::SimLockStatusToProperty,
120 NULL);
121 HelpRegisterDerivedStringmaps(flimflam::kFoundNetworksProperty,
122 &Cellular::EnumerateNetworks,
123 NULL);
Chris Masoneb925cc82011-06-22 15:39:57 -0700124
Chris Masone4d42df82011-07-02 17:09:39 -0700125 store_.RegisterConstBool(flimflam::kScanningProperty, &scanning_);
126 store_.RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_);
127
Chris Masone7df0c672011-07-15 10:24:54 -0700128 VLOG(2) << "Cellular device " << link_name_ << " initialized.";
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700129}
130
131Cellular::~Cellular() {
132 Stop();
133}
134
135void Cellular::Start() {
136 Device::Start();
137}
138
139void Cellular::Stop() {
Chris Masone2b105542011-06-22 10:58:09 -0700140 manager_->DeregisterService(service_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700141 Device::Stop();
142}
143
144bool Cellular::TechnologyIs(const Device::Technology type) {
145 return type == Device::kCellular;
146}
147
Chris Masone889666b2011-07-03 12:58:50 -0700148Stringmaps Cellular::EnumerateNetworks() {
149 Stringmaps to_return;
150 for (vector<Network>::const_iterator it = found_networks_.begin();
151 it != found_networks_.end();
152 ++it) {
153 to_return.push_back(it->ToDict());
154 }
155 return to_return;
156}
157
158StrIntPair Cellular::SimLockStatusToProperty() {
159 return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty,
160 sim_lock_status_.lock_type),
161 make_pair(flimflam::kSIMLockRetriesLeftProperty,
162 sim_lock_status_.retries_left));
163}
164
165void Cellular::HelpRegisterDerivedStringmaps(
166 const string &name,
167 Stringmaps(Cellular::*get)(void),
168 bool(Cellular::*set)(const Stringmaps&)) {
169 store_.RegisterDerivedStringmaps(
170 name,
171 StringmapsAccessor(
172 new CustomAccessor<Cellular, Stringmaps>(this, get, set)));
173}
174
175void Cellular::HelpRegisterDerivedStrIntPair(
176 const string &name,
177 StrIntPair(Cellular::*get)(void),
178 bool(Cellular::*set)(const StrIntPair&)) {
179 store_.RegisterDerivedStrIntPair(
180 name,
181 StrIntPairAccessor(
182 new CustomAccessor<Cellular, StrIntPair>(this, get, set)));
183}
184
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700185} // namespace shill