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