blob: ea7ea366a982320139752b990fbc29d1ecdd84f5 [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
Chris Masone34af2182011-08-22 11:59:36 -070020// static
21const char CellularService::kServiceType[] = "cellular";
22
Darin Petkov381928f2012-02-02 23:00:12 +010023// TODO(petkov): Add these to system_api/dbus/service_constants.h
24namespace {
25const char kKeyOLPURL[] = "url";
26const char kKeyOLPMethod[] = "method";
27const char kKeyOLPPostData[] = "postdata";
28} // namespace {}
29
30CellularService::OLP::OLP() {
31 SetURL("");
32 SetMethod("");
33 SetPostData("");
34}
35
36CellularService::OLP::~OLP() {}
37
38void CellularService::OLP::CopyFrom(const OLP &olp) {
39 dict_ = olp.dict_;
40}
41
42bool CellularService::OLP::Equals(const OLP &olp) const {
43 return dict_ == olp.dict_;
44}
45
46const string &CellularService::OLP::GetURL() const {
47 return dict_.find(kKeyOLPURL)->second;
48}
49
50void CellularService::OLP::SetURL(const string &url) {
51 dict_[kKeyOLPURL] = url;
52}
53
54const string &CellularService::OLP::GetMethod() const {
55 return dict_.find(kKeyOLPMethod)->second;
56}
57
58void CellularService::OLP::SetMethod(const string &method) {
59 dict_[kKeyOLPMethod] = method;
60}
61
62const string &CellularService::OLP::GetPostData() const {
63 return dict_.find(kKeyOLPPostData)->second;
64}
65
66void CellularService::OLP::SetPostData(const string &post_data) {
67 dict_[kKeyOLPPostData] = post_data;
68}
69
70const Stringmap &CellularService::OLP::ToDict() const {
71 return dict_;
72}
73
Chris Masone3bd3c8c2011-06-13 08:20:26 -070074CellularService::CellularService(ControlInterface *control_interface,
75 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080076 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070077 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070078 const CellularRefPtr &device)
Thieu Le3426c8f2012-01-11 17:35:11 -080079 : Service(control_interface, dispatcher, metrics, manager,
80 Technology::kCellular),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070081 cellular_(device) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070082 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070083 store->RegisterConstString(flimflam::kActivationStateProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070084 &activation_state_);
Paul Stewartac4ac002011-08-26 12:04:26 -070085 store->RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
86 store->RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070087 &last_good_apn_info_);
Paul Stewartac4ac002011-08-26 12:04:26 -070088 store->RegisterConstString(flimflam::kNetworkTechnologyProperty,
Darin Petkovb72cf402011-11-22 14:51:39 +010089 &network_technology_);
Darin Petkov381928f2012-02-02 23:00:12 +010090 store->RegisterConstStringmap(flimflam::kPaymentPortalProperty,
91 &olp_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070092 store->RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
93 store->RegisterConstStringmap(flimflam::kServingOperatorProperty,
Darin Petkov3335b372011-08-22 11:05:32 -070094 &serving_operator_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070095 store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_);
Darin Petkovac635a82012-01-10 16:51:58 +010096
97 set_friendly_name(device->CreateFriendlyServiceName());
Darin Petkov31332412012-01-28 01:50:02 +010098 SetStorageIdentifier("cellular_" + device->address() + "_" + friendly_name());
Chris Masone3bd3c8c2011-06-13 08:20:26 -070099}
100
101CellularService::~CellularService() { }
102
Darin Petkov4d6d9412011-08-24 13:19:54 -0700103void CellularService::Connect(Error *error) {
mukesh agrawaladb68482012-01-17 16:31:51 -0800104 Service::Connect(error);
Darin Petkov4d6d9412011-08-24 13:19:54 -0700105 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -0700106}
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700107
Darin Petkovfb0625e2012-01-16 13:05:56 +0100108void CellularService::Disconnect(Error *error) {
109 Service::Disconnect(error);
110 cellular_->Disconnect(error);
111}
112
Darin Petkovb100ae72011-08-24 16:19:45 -0700113void CellularService::ActivateCellularModem(const string &carrier,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500114 ReturnerInterface *returner) {
115 cellular_->Activate(carrier, returner);
Darin Petkovc408e692011-08-17 13:47:15 -0700116}
117
Paul Stewart22aa71b2011-09-16 12:15:11 -0700118bool CellularService::TechnologyIs(const Technology::Identifier type) const {
119 return cellular_->TechnologyIs(type);
120}
121
Darin Petkov31332412012-01-28 01:50:02 +0100122void CellularService::SetStorageIdentifier(const string &identifier) {
123 storage_identifier_ = identifier;
124 std::replace_if(storage_identifier_.begin(),
125 storage_identifier_.end(),
126 &Service::IllegalChar, '_');
127}
128
Chris Masone6515aab2011-10-12 16:19:09 -0700129string CellularService::GetStorageIdentifier() const {
Darin Petkov31332412012-01-28 01:50:02 +0100130 return storage_identifier_;
Chris Masone34af2182011-08-22 11:59:36 -0700131}
132
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800133string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -0700134 return cellular_->GetRpcIdentifier();
135}
136
Darin Petkovb9c99332012-01-12 13:13:00 +0100137void CellularService::SetActivationState(const string &state) {
138 if (state == activation_state_) {
139 return;
140 }
141 activation_state_ = state;
142 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
143}
144
Darin Petkov381928f2012-02-02 23:00:12 +0100145void CellularService::SetOLP(const OLP &olp) {
146 if (olp_.Equals(olp)) {
147 return;
148 }
149 olp_.CopyFrom(olp);
150 adaptor()->EmitStringmapChanged(flimflam::kPaymentPortalProperty,
151 olp.ToDict());
152}
153
154void CellularService::SetUsageURL(const std::string &url) {
155 if (url == usage_url_) {
156 return;
157 }
158 usage_url_ = url;
159 adaptor()->EmitStringChanged(flimflam::kUsageURLProperty, url);
160}
161
Darin Petkovb72cf402011-11-22 14:51:39 +0100162void CellularService::SetNetworkTechnology(const string &technology) {
163 if (technology == network_technology_) {
164 return;
165 }
166 network_technology_ = technology;
167 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
168 technology);
169}
170
171void CellularService::SetRoamingState(const string &state) {
172 if (state == roaming_state_) {
173 return;
174 }
175 roaming_state_ = state;
176 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
177}
178
Darin Petkov3335b372011-08-22 11:05:32 -0700179const Cellular::Operator &CellularService::serving_operator() const {
180 return serving_operator_;
181}
182
Darin Petkov9cb02682012-01-28 00:17:38 +0100183void CellularService::SetServingOperator(const Cellular::Operator &oper) {
184 if (serving_operator_.Equals(oper)) {
185 return;
186 }
Darin Petkov3335b372011-08-22 11:05:32 -0700187 serving_operator_.CopyFrom(oper);
Darin Petkov9cb02682012-01-28 00:17:38 +0100188 adaptor()->EmitStringmapChanged(flimflam::kServingOperatorProperty,
189 oper.ToDict());
Darin Petkov3335b372011-08-22 11:05:32 -0700190}
191
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700192} // namespace shill