blob: 22eb749dcbeff8d2396d1d132d6368155265ae2c [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovdaf43862011-10-27 11:37:28 +02002// 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_capability.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05008#include <chromeos/dbus/service_constants.h>
9
Darin Petkovdaf43862011-10-27 11:37:28 +020010#include "shill/cellular.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010011#include "shill/error.h"
Darin Petkov9c1dcef2012-02-07 15:58:26 +010012#include "shill/property_accessor.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070013#include "shill/scope_logger.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010014
Eric Shienbrood3e20a232012-02-16 11:35:56 -050015using base::Closure;
Darin Petkovb05315f2011-11-07 10:14:25 +010016using std::string;
Darin Petkovdaf43862011-10-27 11:37:28 +020017
18namespace shill {
19
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040020const char CellularCapability::kModemPropertyIMSI[] = "imsi";
21const char CellularCapability::kModemPropertyState[] = "State";
Eric Shienbrood9a245532012-03-07 14:20:39 -050022// All timeout values are in milliseconds
23const int CellularCapability::kTimeoutActivate = 120000;
24const int CellularCapability::kTimeoutConnect = 45000;
25const int CellularCapability::kTimeoutDefault = 5000;
26const int CellularCapability::kTimeoutEnable = 15000;
27const int CellularCapability::kTimeoutRegister = 90000;
28const int CellularCapability::kTimeoutScan = 120000;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050029
30CellularCapability::CellularCapability(Cellular *cellular,
31 ProxyFactory *proxy_factory)
Jason Glasgow82f9ab32012-04-04 14:27:19 -040032 : cellular_(cellular),
Eric Shienbrood9a245532012-03-07 14:20:39 -050033 proxy_factory_(proxy_factory),
Jason Glasgow82f9ab32012-04-04 14:27:19 -040034 allow_roaming_(false) {
Darin Petkov9c1dcef2012-02-07 15:58:26 +010035 HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty,
36 &CellularCapability::GetAllowRoaming,
37 &CellularCapability::SetAllowRoaming);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050038}
Darin Petkovdaf43862011-10-27 11:37:28 +020039
40CellularCapability::~CellularCapability() {}
41
Darin Petkov9c1dcef2012-02-07 15:58:26 +010042void CellularCapability::HelpRegisterDerivedBool(
43 const string &name,
44 bool(CellularCapability::*get)(Error *error),
45 void(CellularCapability::*set)(const bool &value, Error *error)) {
46 cellular()->mutable_store()->RegisterDerivedBool(
47 name,
48 BoolAccessor(
49 new CustomAccessor<CellularCapability, bool>(this, get, set)));
50}
51
52void CellularCapability::SetAllowRoaming(const bool &value, Error */*error*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070053 SLOG(Cellular, 2) << __func__
54 << "(" << allow_roaming_ << "->" << value << ")";
Darin Petkov9c1dcef2012-02-07 15:58:26 +010055 if (allow_roaming_ == value) {
56 return;
57 }
58 allow_roaming_ = value;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040059 // Use AllowRoaming() instead of allow_roaming_ in order to
60 // incorporate provider preferences when evaluating if a disconnect
61 // is required.
62 if (!AllowRoaming() &&
63 GetRoamingStateString() == flimflam::kRoamingStateRoaming) {
Darin Petkov9c1dcef2012-02-07 15:58:26 +010064 Error error;
65 cellular()->Disconnect(&error);
66 }
67 cellular()->adaptor()->EmitBoolChanged(
68 flimflam::kCellularAllowRoamingProperty, value);
69}
70
Eric Shienbrood9a245532012-03-07 14:20:39 -050071void CellularCapability::RunNextStep(CellularTaskList *tasks) {
72 CHECK(!tasks->empty());
Ben Chanfad4a0b2012-04-18 15:49:59 -070073 SLOG(Cellular, 2) << __func__ << ": " << tasks->size() << " remaining tasks";
Eric Shienbrood9a245532012-03-07 14:20:39 -050074 Closure task = (*tasks)[0];
75 tasks->erase(tasks->begin());
76 cellular()->dispatcher()->PostTask(task);
Darin Petkovb05315f2011-11-07 10:14:25 +010077}
78
Eric Shienbrood9a245532012-03-07 14:20:39 -050079void CellularCapability::StepCompletedCallback(
80 const ResultCallback &callback,
Thieu Le923006b2012-04-05 16:32:58 -070081 bool ignore_error,
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 CellularTaskList *tasks,
83 const Error &error) {
Thieu Le923006b2012-04-05 16:32:58 -070084 if ((ignore_error || error.IsSuccess()) && !tasks->empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050085 RunNextStep(tasks);
86 return;
87 }
88 delete tasks;
89 callback.Run(error);
90}
91
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050092void CellularCapability::OnUnsupportedOperation(
93 const char *operation,
Eric Shienbrood9a245532012-03-07 14:20:39 -050094 Error *error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050095 string message("The ");
96 message.append(operation).append(" operation is not supported.");
Eric Shienbrood9a245532012-03-07 14:20:39 -050097 Error::PopulateAndLog(error, Error::kNotSupported, message);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050098}
99
Darin Petkov184c54e2011-11-15 12:44:39 +0100100void CellularCapability::RegisterOnNetwork(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500101 const string &/*network_id*/,
102 Error *error, const ResultCallback &/*callback*/) {
103 OnUnsupportedOperation(__func__, error);
Darin Petkov184c54e2011-11-15 12:44:39 +0100104}
105
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106void CellularCapability::RequirePIN(const std::string &/*pin*/,
107 bool /*require*/,
108 Error *error,
109 const ResultCallback &/*callback*/) {
110 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100111}
112
Darin Petkove5bc2cb2011-12-07 14:47:32 +0100113void CellularCapability::EnterPIN(const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500114 Error *error,
115 const ResultCallback &/*callback*/) {
116 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100117}
118
119void CellularCapability::UnblockPIN(const string &/*unblock_code*/,
120 const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121 Error *error,
122 const ResultCallback &/*callback*/) {
123 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100124}
125
126void CellularCapability::ChangePIN(const string &/*old_pin*/,
127 const string &/*new_pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 Error *error,
129 const ResultCallback &/*callback*/) {
130 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100131}
132
Eric Shienbrood9a245532012-03-07 14:20:39 -0500133void CellularCapability::Scan(Error *error,
134 const ResultCallback &callback) {
135 OnUnsupportedOperation(__func__, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500136}
137
Darin Petkovdaf43862011-10-27 11:37:28 +0200138} // namespace shill