blob: 3259f93cbe06246c60d7bddb2301d71ad1667144 [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"
Darin Petkovb05315f2011-11-07 10:14:25 +010013
Eric Shienbrood3e20a232012-02-16 11:35:56 -050014using base::Closure;
Darin Petkovb05315f2011-11-07 10:14:25 +010015using std::string;
Darin Petkovdaf43862011-10-27 11:37:28 +020016
17namespace shill {
18
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050019const char CellularCapability::kPropertyIMSI[] = "imsi";
Eric Shienbrood9a245532012-03-07 14:20:39 -050020// All timeout values are in milliseconds
21const int CellularCapability::kTimeoutActivate = 120000;
22const int CellularCapability::kTimeoutConnect = 45000;
23const int CellularCapability::kTimeoutDefault = 5000;
24const int CellularCapability::kTimeoutEnable = 15000;
25const int CellularCapability::kTimeoutRegister = 90000;
26const int CellularCapability::kTimeoutScan = 120000;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050027
28CellularCapability::CellularCapability(Cellular *cellular,
29 ProxyFactory *proxy_factory)
Jason Glasgow82f9ab32012-04-04 14:27:19 -040030 : cellular_(cellular),
Eric Shienbrood9a245532012-03-07 14:20:39 -050031 proxy_factory_(proxy_factory),
Jason Glasgow82f9ab32012-04-04 14:27:19 -040032 allow_roaming_(false) {
Darin Petkov9c1dcef2012-02-07 15:58:26 +010033 HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty,
34 &CellularCapability::GetAllowRoaming,
35 &CellularCapability::SetAllowRoaming);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050036}
Darin Petkovdaf43862011-10-27 11:37:28 +020037
38CellularCapability::~CellularCapability() {}
39
Darin Petkov9c1dcef2012-02-07 15:58:26 +010040void CellularCapability::HelpRegisterDerivedBool(
41 const string &name,
42 bool(CellularCapability::*get)(Error *error),
43 void(CellularCapability::*set)(const bool &value, Error *error)) {
44 cellular()->mutable_store()->RegisterDerivedBool(
45 name,
46 BoolAccessor(
47 new CustomAccessor<CellularCapability, bool>(this, get, set)));
48}
49
50void CellularCapability::SetAllowRoaming(const bool &value, Error */*error*/) {
51 VLOG(2) << __func__ << "(" << allow_roaming_ << "->" << value << ")";
52 if (allow_roaming_ == value) {
53 return;
54 }
55 allow_roaming_ = value;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040056 // Use AllowRoaming() instead of allow_roaming_ in order to
57 // incorporate provider preferences when evaluating if a disconnect
58 // is required.
59 if (!AllowRoaming() &&
60 GetRoamingStateString() == flimflam::kRoamingStateRoaming) {
Darin Petkov9c1dcef2012-02-07 15:58:26 +010061 Error error;
62 cellular()->Disconnect(&error);
63 }
64 cellular()->adaptor()->EmitBoolChanged(
65 flimflam::kCellularAllowRoamingProperty, value);
66}
67
Eric Shienbrood9a245532012-03-07 14:20:39 -050068void CellularCapability::RunNextStep(CellularTaskList *tasks) {
69 CHECK(!tasks->empty());
70 VLOG(2) << __func__ << ": " << tasks->size() << " remaining tasks";
71 Closure task = (*tasks)[0];
72 tasks->erase(tasks->begin());
73 cellular()->dispatcher()->PostTask(task);
Darin Petkovb05315f2011-11-07 10:14:25 +010074}
75
Eric Shienbrood9a245532012-03-07 14:20:39 -050076void CellularCapability::StepCompletedCallback(
77 const ResultCallback &callback,
Thieu Le923006b2012-04-05 16:32:58 -070078 bool ignore_error,
Eric Shienbrood9a245532012-03-07 14:20:39 -050079 CellularTaskList *tasks,
80 const Error &error) {
Thieu Le923006b2012-04-05 16:32:58 -070081 if ((ignore_error || error.IsSuccess()) && !tasks->empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 RunNextStep(tasks);
83 return;
84 }
85 delete tasks;
86 callback.Run(error);
87}
88
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050089void CellularCapability::OnUnsupportedOperation(
90 const char *operation,
Eric Shienbrood9a245532012-03-07 14:20:39 -050091 Error *error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050092 string message("The ");
93 message.append(operation).append(" operation is not supported.");
Eric Shienbrood9a245532012-03-07 14:20:39 -050094 Error::PopulateAndLog(error, Error::kNotSupported, message);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050095}
96
Darin Petkov184c54e2011-11-15 12:44:39 +010097void CellularCapability::RegisterOnNetwork(
Eric Shienbrood9a245532012-03-07 14:20:39 -050098 const string &/*network_id*/,
99 Error *error, const ResultCallback &/*callback*/) {
100 OnUnsupportedOperation(__func__, error);
Darin Petkov184c54e2011-11-15 12:44:39 +0100101}
102
Eric Shienbrood9a245532012-03-07 14:20:39 -0500103void CellularCapability::RequirePIN(const std::string &/*pin*/,
104 bool /*require*/,
105 Error *error,
106 const ResultCallback &/*callback*/) {
107 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100108}
109
Darin Petkove5bc2cb2011-12-07 14:47:32 +0100110void CellularCapability::EnterPIN(const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500111 Error *error,
112 const ResultCallback &/*callback*/) {
113 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100114}
115
116void CellularCapability::UnblockPIN(const string &/*unblock_code*/,
117 const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500118 Error *error,
119 const ResultCallback &/*callback*/) {
120 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100121}
122
123void CellularCapability::ChangePIN(const string &/*old_pin*/,
124 const string &/*new_pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500125 Error *error,
126 const ResultCallback &/*callback*/) {
127 OnUnsupportedOperation(__func__, error);
Darin Petkovb05315f2011-11-07 10:14:25 +0100128}
129
Eric Shienbrood9a245532012-03-07 14:20:39 -0500130void CellularCapability::Scan(Error *error,
131 const ResultCallback &callback) {
132 OnUnsupportedOperation(__func__, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500133}
134
Darin Petkovdaf43862011-10-27 11:37:28 +0200135} // namespace shill