blob: 4c39a3e7f969cdebcf9598b5b87462033a972702 [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masone3bd3c8c2011-06-13 08:20:26 -07002// 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_service.h"
6
7#include <string>
8
9#include <base/logging.h>
Chris Masone34af2182011-08-22 11:59:36 -070010#include <base/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070011#include <chromeos/dbus/service_constants.h>
12
Darin Petkovb72cf402011-11-22 14:51:39 +010013#include "shill/adaptor_interfaces.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070014#include "shill/cellular.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015
16using std::string;
17
18namespace shill {
Darin Petkovc5f56562011-08-06 16:40:05 -070019
Darin Petkov381928f2012-02-02 23:00:12 +010020// TODO(petkov): Add these to system_api/dbus/service_constants.h
21namespace {
22const char kKeyOLPURL[] = "url";
23const char kKeyOLPMethod[] = "method";
24const char kKeyOLPPostData[] = "postdata";
25} // namespace {}
26
27CellularService::OLP::OLP() {
28 SetURL("");
29 SetMethod("");
30 SetPostData("");
31}
32
33CellularService::OLP::~OLP() {}
34
35void CellularService::OLP::CopyFrom(const OLP &olp) {
36 dict_ = olp.dict_;
37}
38
39bool CellularService::OLP::Equals(const OLP &olp) const {
40 return dict_ == olp.dict_;
41}
42
43const string &CellularService::OLP::GetURL() const {
44 return dict_.find(kKeyOLPURL)->second;
45}
46
47void CellularService::OLP::SetURL(const string &url) {
48 dict_[kKeyOLPURL] = url;
49}
50
51const string &CellularService::OLP::GetMethod() const {
52 return dict_.find(kKeyOLPMethod)->second;
53}
54
55void CellularService::OLP::SetMethod(const string &method) {
56 dict_[kKeyOLPMethod] = method;
57}
58
59const string &CellularService::OLP::GetPostData() const {
60 return dict_.find(kKeyOLPPostData)->second;
61}
62
63void CellularService::OLP::SetPostData(const string &post_data) {
64 dict_[kKeyOLPPostData] = post_data;
65}
66
67const Stringmap &CellularService::OLP::ToDict() const {
68 return dict_;
69}
70
Chris Masone3bd3c8c2011-06-13 08:20:26 -070071CellularService::CellularService(ControlInterface *control_interface,
72 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080073 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070074 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070075 const CellularRefPtr &device)
Thieu Le3426c8f2012-01-11 17:35:11 -080076 : Service(control_interface, dispatcher, metrics, manager,
77 Technology::kCellular),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070078 cellular_(device) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070079 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070080 store->RegisterConstString(flimflam::kActivationStateProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070081 &activation_state_);
Paul Stewartac4ac002011-08-26 12:04:26 -070082 store->RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
83 store->RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070084 &last_good_apn_info_);
Paul Stewartac4ac002011-08-26 12:04:26 -070085 store->RegisterConstString(flimflam::kNetworkTechnologyProperty,
Darin Petkovb72cf402011-11-22 14:51:39 +010086 &network_technology_);
Darin Petkov381928f2012-02-02 23:00:12 +010087 store->RegisterConstStringmap(flimflam::kPaymentPortalProperty,
88 &olp_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070089 store->RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
90 store->RegisterConstStringmap(flimflam::kServingOperatorProperty,
Darin Petkov3335b372011-08-22 11:05:32 -070091 &serving_operator_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070092 store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_);
Darin Petkovac635a82012-01-10 16:51:58 +010093
94 set_friendly_name(device->CreateFriendlyServiceName());
Darin Petkovdd3e8662012-02-03 13:16:20 +010095 SetStorageIdentifier(string(flimflam::kTypeCellular) + "_" +
96 device->address() + "_" + friendly_name());
Chris Masone3bd3c8c2011-06-13 08:20:26 -070097}
98
99CellularService::~CellularService() { }
100
Darin Petkov4d6d9412011-08-24 13:19:54 -0700101void CellularService::Connect(Error *error) {
mukesh agrawaladb68482012-01-17 16:31:51 -0800102 Service::Connect(error);
Darin Petkov4d6d9412011-08-24 13:19:54 -0700103 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -0700104}
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700105
Darin Petkovfb0625e2012-01-16 13:05:56 +0100106void CellularService::Disconnect(Error *error) {
107 Service::Disconnect(error);
108 cellular_->Disconnect(error);
109}
110
Darin Petkovb100ae72011-08-24 16:19:45 -0700111void CellularService::ActivateCellularModem(const string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500112 Error *error,
113 const ResultCallback &callback) {
114 cellular_->Activate(carrier, error, callback);
Darin Petkovc408e692011-08-17 13:47:15 -0700115}
116
Paul Stewart22aa71b2011-09-16 12:15:11 -0700117bool CellularService::TechnologyIs(const Technology::Identifier type) const {
118 return cellular_->TechnologyIs(type);
119}
120
Darin Petkov31332412012-01-28 01:50:02 +0100121void CellularService::SetStorageIdentifier(const string &identifier) {
122 storage_identifier_ = identifier;
123 std::replace_if(storage_identifier_.begin(),
124 storage_identifier_.end(),
125 &Service::IllegalChar, '_');
126}
127
Chris Masone6515aab2011-10-12 16:19:09 -0700128string CellularService::GetStorageIdentifier() const {
Darin Petkov31332412012-01-28 01:50:02 +0100129 return storage_identifier_;
Chris Masone34af2182011-08-22 11:59:36 -0700130}
131
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800132string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -0700133 return cellular_->GetRpcIdentifier();
134}
135
Darin Petkovb9c99332012-01-12 13:13:00 +0100136void CellularService::SetActivationState(const string &state) {
137 if (state == activation_state_) {
138 return;
139 }
140 activation_state_ = state;
141 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
142}
143
Darin Petkov381928f2012-02-02 23:00:12 +0100144void CellularService::SetOLP(const OLP &olp) {
145 if (olp_.Equals(olp)) {
146 return;
147 }
148 olp_.CopyFrom(olp);
149 adaptor()->EmitStringmapChanged(flimflam::kPaymentPortalProperty,
150 olp.ToDict());
151}
152
153void CellularService::SetUsageURL(const std::string &url) {
154 if (url == usage_url_) {
155 return;
156 }
157 usage_url_ = url;
158 adaptor()->EmitStringChanged(flimflam::kUsageURLProperty, url);
159}
160
Darin Petkovb72cf402011-11-22 14:51:39 +0100161void CellularService::SetNetworkTechnology(const string &technology) {
162 if (technology == network_technology_) {
163 return;
164 }
165 network_technology_ = technology;
166 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
167 technology);
168}
169
170void CellularService::SetRoamingState(const string &state) {
171 if (state == roaming_state_) {
172 return;
173 }
174 roaming_state_ = state;
175 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
176}
177
Darin Petkov3335b372011-08-22 11:05:32 -0700178const Cellular::Operator &CellularService::serving_operator() const {
179 return serving_operator_;
180}
181
Darin Petkov9cb02682012-01-28 00:17:38 +0100182void CellularService::SetServingOperator(const Cellular::Operator &oper) {
183 if (serving_operator_.Equals(oper)) {
184 return;
185 }
Darin Petkov3335b372011-08-22 11:05:32 -0700186 serving_operator_.CopyFrom(oper);
Darin Petkov9cb02682012-01-28 00:17:38 +0100187 adaptor()->EmitStringmapChanged(flimflam::kServingOperatorProperty,
188 oper.ToDict());
Darin Petkov3335b372011-08-22 11:05:32 -0700189}
190
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700191} // namespace shill