Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 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_capability.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
| 9 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 10 | #include "shill/cellular.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 11 | #include "shill/error.h" |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 12 | #include "shill/property_accessor.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 13 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 14 | using base::Closure; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 15 | using std::string; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 16 | |
| 17 | namespace shill { |
| 18 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 19 | const char CellularCapability::kPropertyIMSI[] = "imsi"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 20 | // All timeout values are in milliseconds |
| 21 | const int CellularCapability::kTimeoutActivate = 120000; |
| 22 | const int CellularCapability::kTimeoutConnect = 45000; |
| 23 | const int CellularCapability::kTimeoutDefault = 5000; |
| 24 | const int CellularCapability::kTimeoutEnable = 15000; |
| 25 | const int CellularCapability::kTimeoutRegister = 90000; |
| 26 | const int CellularCapability::kTimeoutScan = 120000; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 27 | |
| 28 | CellularCapability::CellularCapability(Cellular *cellular, |
| 29 | ProxyFactory *proxy_factory) |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 30 | : cellular_(cellular), |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 31 | proxy_factory_(proxy_factory), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 32 | allow_roaming_(false) { |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 33 | HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty, |
| 34 | &CellularCapability::GetAllowRoaming, |
| 35 | &CellularCapability::SetAllowRoaming); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 36 | } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 37 | |
| 38 | CellularCapability::~CellularCapability() {} |
| 39 | |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 40 | void 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 | |
| 50 | void 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 Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 56 | // 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 Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 61 | Error error; |
| 62 | cellular()->Disconnect(&error); |
| 63 | } |
| 64 | cellular()->adaptor()->EmitBoolChanged( |
| 65 | flimflam::kCellularAllowRoamingProperty, value); |
| 66 | } |
| 67 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 68 | void 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 Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 76 | void CellularCapability::StepCompletedCallback( |
| 77 | const ResultCallback &callback, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 78 | bool ignore_error, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 79 | CellularTaskList *tasks, |
| 80 | const Error &error) { |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 81 | if ((ignore_error || error.IsSuccess()) && !tasks->empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 82 | RunNextStep(tasks); |
| 83 | return; |
| 84 | } |
| 85 | delete tasks; |
| 86 | callback.Run(error); |
| 87 | } |
| 88 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 89 | void CellularCapability::OnUnsupportedOperation( |
| 90 | const char *operation, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 91 | Error *error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 92 | string message("The "); |
| 93 | message.append(operation).append(" operation is not supported."); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 94 | Error::PopulateAndLog(error, Error::kNotSupported, message); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 97 | void CellularCapability::RegisterOnNetwork( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 98 | const string &/*network_id*/, |
| 99 | Error *error, const ResultCallback &/*callback*/) { |
| 100 | OnUnsupportedOperation(__func__, error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 103 | void CellularCapability::RequirePIN(const std::string &/*pin*/, |
| 104 | bool /*require*/, |
| 105 | Error *error, |
| 106 | const ResultCallback &/*callback*/) { |
| 107 | OnUnsupportedOperation(__func__, error); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 110 | void CellularCapability::EnterPIN(const string &/*pin*/, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 111 | Error *error, |
| 112 | const ResultCallback &/*callback*/) { |
| 113 | OnUnsupportedOperation(__func__, error); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void CellularCapability::UnblockPIN(const string &/*unblock_code*/, |
| 117 | const string &/*pin*/, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | Error *error, |
| 119 | const ResultCallback &/*callback*/) { |
| 120 | OnUnsupportedOperation(__func__, error); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void CellularCapability::ChangePIN(const string &/*old_pin*/, |
| 124 | const string &/*new_pin*/, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 125 | Error *error, |
| 126 | const ResultCallback &/*callback*/) { |
| 127 | OnUnsupportedOperation(__func__, error); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 130 | void CellularCapability::Scan(Error *error, |
| 131 | const ResultCallback &callback) { |
| 132 | OnUnsupportedOperation(__func__, error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 133 | } |
| 134 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 135 | } // namespace shill |