Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [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.h" |
| 6 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 7 | #include <netinet/in.h> |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 8 | #include <linux/if.h> // Needs definitions from netinet/in.h |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 9 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 10 | #include <string> |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 11 | #include <utility> |
| 12 | #include <vector> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 14 | #include <base/bind.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | #include <base/logging.h> |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 16 | #include <base/stringprintf.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 18 | #include <mobile_provider.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 19 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 20 | #include "shill/adaptor_interfaces.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 21 | #include "shill/cellular_capability_cdma.h" |
| 22 | #include "shill/cellular_capability_gsm.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 23 | #include "shill/cellular_capability_universal.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 24 | #include "shill/cellular_service.h" |
| 25 | #include "shill/control_interface.h" |
| 26 | #include "shill/device.h" |
| 27 | #include "shill/device_info.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 28 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 29 | #include "shill/event_dispatcher.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 30 | #include "shill/manager.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | #include "shill/profile.h" |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 32 | #include "shill/property_accessor.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 33 | #include "shill/proxy_factory.h" |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 34 | #include "shill/rtnl_handler.h" |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 35 | #include "shill/scope_logger.h" |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 36 | #include "shill/store_interface.h" |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 37 | #include "shill/technology.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 38 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 39 | using base::Bind; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 40 | using std::string; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 41 | using std::vector; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 42 | |
| 43 | namespace shill { |
| 44 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 45 | // static |
| 46 | const char Cellular::kAllowRoaming[] = "AllowRoaming"; |
| 47 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 48 | Cellular::Operator::Operator() { |
| 49 | SetName(""); |
| 50 | SetCode(""); |
| 51 | SetCountry(""); |
| 52 | } |
| 53 | |
| 54 | Cellular::Operator::~Operator() {} |
| 55 | |
| 56 | void Cellular::Operator::CopyFrom(const Operator &oper) { |
| 57 | dict_ = oper.dict_; |
| 58 | } |
| 59 | |
| 60 | const string &Cellular::Operator::GetName() const { |
| 61 | return dict_.find(flimflam::kOperatorNameKey)->second; |
| 62 | } |
| 63 | |
| 64 | void Cellular::Operator::SetName(const string &name) { |
| 65 | dict_[flimflam::kOperatorNameKey] = name; |
| 66 | } |
| 67 | |
| 68 | const string &Cellular::Operator::GetCode() const { |
| 69 | return dict_.find(flimflam::kOperatorCodeKey)->second; |
| 70 | } |
| 71 | |
| 72 | void Cellular::Operator::SetCode(const string &code) { |
| 73 | dict_[flimflam::kOperatorCodeKey] = code; |
| 74 | } |
| 75 | |
| 76 | const string &Cellular::Operator::GetCountry() const { |
| 77 | return dict_.find(flimflam::kOperatorCountryKey)->second; |
| 78 | } |
| 79 | |
| 80 | void Cellular::Operator::SetCountry(const string &country) { |
| 81 | dict_[flimflam::kOperatorCountryKey] = country; |
| 82 | } |
| 83 | |
| 84 | const Stringmap &Cellular::Operator::ToDict() const { |
| 85 | return dict_; |
| 86 | } |
| 87 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 88 | Cellular::Cellular(ControlInterface *control_interface, |
| 89 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 90 | Metrics *metrics, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 91 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 92 | const string &link_name, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 93 | const string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 94 | int interface_index, |
| 95 | Type type, |
| 96 | const string &owner, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 97 | const string &path, |
| 98 | mobile_provider_db *provider_db) |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 99 | : Device(control_interface, |
| 100 | dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 101 | metrics, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 102 | manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 103 | link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 104 | address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 105 | interface_index, |
| 106 | Technology::kCellular), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 107 | state_(kStateDisabled), |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 108 | modem_state_(kModemStateUnknown), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 109 | dbus_owner_(owner), |
| 110 | dbus_path_(path), |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 111 | provider_db_(provider_db), |
| 112 | allow_roaming_(false) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 113 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 114 | store->RegisterConstString(flimflam::kDBusConnectionProperty, &dbus_owner_); |
| 115 | store->RegisterConstString(flimflam::kDBusObjectProperty, &dbus_path_); |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 116 | HelpRegisterDerivedString(flimflam::kTechnologyFamilyProperty, |
| 117 | &Cellular::GetTechnologyFamily, |
| 118 | NULL); |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 119 | HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty, |
| 120 | &Cellular::GetAllowRoaming, |
| 121 | &Cellular::SetAllowRoaming); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 122 | store->RegisterConstStringmap(flimflam::kHomeProviderProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 123 | &home_provider_.ToDict()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 124 | // For now, only a single capability is supported. |
| 125 | InitCapability(type, ProxyFactory::GetInstance()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 126 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 127 | SLOG(Cellular, 2) << "Cellular device " << this->link_name() |
| 128 | << " initialized."; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 131 | Cellular::~Cellular() { |
| 132 | } |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 133 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 134 | bool Cellular::Load(StoreInterface *storage) { |
| 135 | const string id = GetStorageIdentifier(); |
| 136 | if (!storage->ContainsGroup(id)) { |
| 137 | LOG(WARNING) << "Device is not available in the persistent store: " << id; |
| 138 | return false; |
| 139 | } |
| 140 | storage->GetBool(id, kAllowRoaming, &allow_roaming_); |
| 141 | return Device::Load(storage); |
| 142 | } |
| 143 | |
| 144 | bool Cellular::Save(StoreInterface *storage) { |
| 145 | const string id = GetStorageIdentifier(); |
| 146 | storage->SetBool(id, kAllowRoaming, allow_roaming_); |
| 147 | return Device::Save(storage); |
| 148 | } |
| 149 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 150 | // static |
| 151 | string Cellular::GetStateString(State state) { |
| 152 | switch (state) { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 153 | case kStateDisabled: return "CellularStateDisabled"; |
| 154 | case kStateEnabled: return "CellularStateEnabled"; |
| 155 | case kStateRegistered: return "CellularStateRegistered"; |
| 156 | case kStateConnected: return "CellularStateConnected"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 157 | case kStateLinked: return "CellularStateLinked"; |
| 158 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 159 | } |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 160 | return StringPrintf("CellularStateUnknown-%d", state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 163 | string Cellular::GetTechnologyFamily(Error *error) { |
| 164 | return capability_->GetTypeString(); |
| 165 | } |
| 166 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 167 | void Cellular::SetState(State state) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 168 | SLOG(Cellular, 2) << GetStateString(state_) << " -> " |
| 169 | << GetStateString(state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 170 | state_ = state; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 173 | void Cellular::HelpRegisterDerivedBool( |
| 174 | const string &name, |
| 175 | bool(Cellular::*get)(Error *error), |
| 176 | void(Cellular::*set)(const bool &value, Error *error)) { |
| 177 | mutable_store()->RegisterDerivedBool( |
| 178 | name, |
| 179 | BoolAccessor( |
| 180 | new CustomAccessor<Cellular, bool>(this, get, set))); |
| 181 | } |
| 182 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 183 | void Cellular::HelpRegisterDerivedString( |
| 184 | const string &name, |
| 185 | string(Cellular::*get)(Error *), |
| 186 | void(Cellular::*set)(const string&, Error *)) { |
| 187 | mutable_store()->RegisterDerivedString( |
| 188 | name, |
| 189 | StringAccessor(new CustomAccessor<Cellular, string>(this, get, set))); |
| 190 | } |
| 191 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 192 | void Cellular::Start(Error *error, |
| 193 | const EnabledStateChangedCallback &callback) { |
Jason Glasgow | 4a49079 | 2012-04-10 15:02:05 -0400 | [diff] [blame] | 194 | DCHECK(error); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 195 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 196 | if (state_ != kStateDisabled) { |
| 197 | return; |
| 198 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 199 | capability_->StartModem(error, |
| 200 | Bind(&Cellular::OnModemStarted, this, callback)); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 203 | void Cellular::Stop(Error *error, |
| 204 | const EnabledStateChangedCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 205 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 206 | if (service_) { |
| 207 | // TODO(ers): See whether we can/should do DestroyService() here. |
| 208 | manager()->DeregisterService(service_); |
| 209 | service_ = NULL; |
| 210 | } |
| 211 | capability_->StopModem(error, |
| 212 | Bind(&Cellular::OnModemStopped, this, callback)); |
| 213 | } |
| 214 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 215 | bool Cellular::IsUnderlyingDeviceEnabled() const { |
| 216 | return IsEnabledModemState(modem_state_); |
| 217 | } |
| 218 | |
| 219 | // static |
| 220 | bool Cellular::IsEnabledModemState(ModemState state) { |
| 221 | switch (state) { |
| 222 | case kModemStateUnknown: |
| 223 | case kModemStateDisabled: |
| 224 | case kModemStateInitializing: |
| 225 | case kModemStateLocked: |
| 226 | case kModemStateDisabling: |
| 227 | case kModemStateEnabling: |
| 228 | return false; |
| 229 | case kModemStateEnabled: |
| 230 | case kModemStateSearching: |
| 231 | case kModemStateRegistered: |
| 232 | case kModemStateDisconnecting: |
| 233 | case kModemStateConnecting: |
| 234 | case kModemStateConnected: |
| 235 | return true; |
| 236 | } |
| 237 | return false; |
| 238 | } |
| 239 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 240 | void Cellular::OnModemStarted(const EnabledStateChangedCallback &callback, |
| 241 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 242 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 243 | if (error.IsSuccess() && (state_ == kStateDisabled)) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 244 | SetState(kStateEnabled); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 245 | // Registration state updates may have been ignored while the |
| 246 | // modem was not yet marked enabled. |
| 247 | HandleNewRegistrationState(); |
| 248 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 249 | callback.Run(error); |
| 250 | } |
| 251 | |
| 252 | void Cellular::OnModemStopped(const EnabledStateChangedCallback &callback, |
| 253 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 254 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 255 | if (state_ != kStateDisabled) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 256 | SetState(kStateDisabled); |
| 257 | callback.Run(error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 260 | void Cellular::InitCapability(Type type, ProxyFactory *proxy_factory) { |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 261 | // TODO(petkov): Consider moving capability construction into a factory that's |
| 262 | // external to the Cellular class. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 263 | SLOG(Cellular, 2) << __func__ << "(" << type << ")"; |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 264 | switch (type) { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 265 | case kTypeGSM: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 266 | capability_.reset(new CellularCapabilityGSM(this, proxy_factory)); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 267 | break; |
| 268 | case kTypeCDMA: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 269 | capability_.reset(new CellularCapabilityCDMA(this, proxy_factory)); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 270 | break; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 271 | case kTypeUniversal: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 272 | capability_.reset(new CellularCapabilityUniversal(this, proxy_factory)); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 273 | break; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 274 | default: NOTREACHED(); |
| 275 | } |
| 276 | } |
| 277 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 278 | void Cellular::Activate(const string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 279 | Error *error, const ResultCallback &callback) { |
| 280 | capability_->Activate(carrier, error, callback); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 283 | void Cellular::RegisterOnNetwork(const string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 284 | Error *error, |
| 285 | const ResultCallback &callback) { |
| 286 | capability_->RegisterOnNetwork(network_id, error, callback); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 289 | void Cellular::RequirePIN(const string &pin, bool require, |
| 290 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 291 | SLOG(Cellular, 2) << __func__ << "(" << require << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 292 | capability_->RequirePIN(pin, require, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 295 | void Cellular::EnterPIN(const string &pin, |
| 296 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 297 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 298 | capability_->EnterPIN(pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 301 | void Cellular::UnblockPIN(const string &unblock_code, |
| 302 | const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 303 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 304 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 305 | capability_->UnblockPIN(unblock_code, pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 308 | void Cellular::ChangePIN(const string &old_pin, const string &new_pin, |
| 309 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 310 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 311 | capability_->ChangePIN(old_pin, new_pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 314 | void Cellular::Scan(Error *error) { |
| 315 | // TODO(ers): for now report immediate success or failure. |
| 316 | capability_->Scan(error, ResultCallback()); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 319 | void Cellular::HandleNewRegistrationState() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 320 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 321 | if (!capability_->IsRegistered()) { |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 322 | DestroyService(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 323 | if (state_ == kStateLinked || |
| 324 | state_ == kStateConnected || |
| 325 | state_ == kStateRegistered) { |
| 326 | SetState(kStateEnabled); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 327 | } |
| 328 | return; |
| 329 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 330 | // In Disabled state, defer creating a service until fully |
| 331 | // enabled. UI will ignore the appearance of a new service |
| 332 | // on a disabled device. |
| 333 | if (state_ == kStateDisabled) { |
| 334 | return; |
| 335 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 336 | if (state_ == kStateEnabled) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 337 | SetState(kStateRegistered); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 338 | } |
| 339 | if (!service_.get()) { |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 340 | CreateService(); |
| 341 | } |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 342 | capability_->GetSignalQuality(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 343 | if (state_ == kStateRegistered && modem_state_ == kModemStateConnected) |
| 344 | OnConnected(); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 345 | service_->SetNetworkTechnology(capability_->GetNetworkTechnologyString()); |
| 346 | service_->SetRoamingState(capability_->GetRoamingStateString()); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 349 | void Cellular::HandleNewSignalQuality(uint32 strength) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 350 | SLOG(Cellular, 2) << "Signal strength: " << strength; |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 351 | if (service_) { |
| 352 | service_->SetStrength(strength); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | void Cellular::CreateService() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 357 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 358 | CHECK(!service_.get()); |
| 359 | service_ = |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 360 | new CellularService(control_interface(), dispatcher(), metrics(), |
| 361 | manager(), this); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 362 | capability_->OnServiceCreated(); |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 363 | manager()->RegisterService(service_); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 366 | void Cellular::DestroyService() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 367 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 368 | DestroyIPConfig(); |
| 369 | if (service_) { |
| 370 | manager()->DeregisterService(service_); |
| 371 | service_ = NULL; |
| 372 | } |
| 373 | SelectService(NULL); |
| 374 | } |
| 375 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 376 | bool Cellular::TechnologyIs(const Technology::Identifier type) const { |
| 377 | return type == Technology::kCellular; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 380 | void Cellular::Connect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 381 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 382 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 383 | Error::PopulateAndLog(error, Error::kAlreadyConnected, |
| 384 | "Already connected; connection request ignored."); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 385 | return; |
| 386 | } |
| 387 | CHECK_EQ(kStateRegistered, state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 388 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 389 | if (!capability_->AllowRoaming() && |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 390 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 391 | Error::PopulateAndLog(error, Error::kNotOnHomeNetwork, |
| 392 | "Roaming disallowed; connection request ignored."); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 396 | DBusPropertiesMap properties; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 397 | capability_->SetupConnectProperties(&properties); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 398 | // TODO(njw): Should a weak pointer be used here instead? |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 399 | // Would require something like a WeakPtrFactory on the class. |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 400 | ResultCallback cb = Bind(&Cellular::OnConnectReply, this); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 401 | OnConnecting(); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 402 | capability_->Connect(properties, error, cb); |
| 403 | } |
| 404 | |
| 405 | // Note that there's no ResultCallback argument to this, |
| 406 | // since Connect() isn't yet passed one. |
| 407 | void Cellular::OnConnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 408 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 409 | if (error.IsSuccess()) |
| 410 | OnConnected(); |
| 411 | else |
| 412 | OnConnectFailed(error); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 415 | void Cellular::OnConnecting() { |
| 416 | if (service_) |
| 417 | service_->SetState(Service::kStateAssociating); |
| 418 | } |
| 419 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 420 | void Cellular::OnConnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 421 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 422 | if (state_ == kStateConnected || state_ == kStateLinked) { |
| 423 | VLOG(2) << "Already connected"; |
| 424 | return; |
| 425 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 426 | SetState(kStateConnected); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 427 | if (!capability_->AllowRoaming() && |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 428 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
| 429 | Disconnect(NULL); |
| 430 | } else { |
| 431 | EstablishLink(); |
| 432 | } |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 435 | void Cellular::OnConnectFailed(const Error &error) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 436 | service_->SetFailure(Service::kFailureUnknown); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 439 | void Cellular::Disconnect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 440 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 441 | if (state_ != kStateConnected && state_ != kStateLinked) { |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 442 | Error::PopulateAndLog( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 443 | error, Error::kNotConnected, "Not connected; request ignored."); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 444 | return; |
| 445 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 446 | // TODO(njw): See Connect() about possible weak ptr for 'this'. |
| 447 | ResultCallback cb = Bind(&Cellular::OnDisconnectReply, this); |
| 448 | capability_->Disconnect(error, cb); |
| 449 | } |
| 450 | |
| 451 | // Note that there's no ResultCallback argument to this, |
| 452 | // since Disconnect() isn't yet passed one. |
| 453 | void Cellular::OnDisconnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 454 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 455 | if (error.IsSuccess()) |
| 456 | OnDisconnected(); |
| 457 | else |
| 458 | OnDisconnectFailed(); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 461 | void Cellular::OnDisconnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 462 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 463 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 464 | SetState(kStateRegistered); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 465 | SetServiceFailureSilent(Service::kFailureUnknown); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 466 | DestroyIPConfig(); |
| 467 | rtnl_handler()->SetInterfaceFlags(interface_index(), 0, IFF_UP); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 468 | } else { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 469 | LOG(WARNING) << "Disconnect occurred while in state " |
| 470 | << GetStateString(state_); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 471 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void Cellular::OnDisconnectFailed() { |
| 475 | // TODO(ers): Signal failure. |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 478 | void Cellular::EstablishLink() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 479 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 480 | CHECK_EQ(kStateConnected, state_); |
| 481 | unsigned int flags = 0; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 482 | if (manager()->device_info()->GetFlags(interface_index(), &flags) && |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 483 | (flags & IFF_UP) != 0) { |
| 484 | LinkEvent(flags, IFF_UP); |
| 485 | return; |
| 486 | } |
| 487 | // TODO(petkov): Provide a timeout for a failed link-up request. |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 488 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void Cellular::LinkEvent(unsigned int flags, unsigned int change) { |
| 492 | Device::LinkEvent(flags, change); |
| 493 | if ((flags & IFF_UP) != 0 && state_ == kStateConnected) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 494 | LOG(INFO) << link_name() << " is up."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 495 | SetState(kStateLinked); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 496 | if (AcquireIPConfig()) { |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 497 | SelectService(service_); |
| 498 | SetServiceState(Service::kStateConfiguring); |
| 499 | } else { |
| 500 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 501 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 502 | } else if ((flags & IFF_UP) == 0 && state_ == kStateLinked) { |
| 503 | SetState(kStateConnected); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 504 | DestroyService(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 505 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 508 | void Cellular::OnDBusPropertiesChanged( |
| 509 | const string &interface, |
| 510 | const DBusPropertiesMap &changed_properties, |
| 511 | const vector<string> &invalidated_properties) { |
| 512 | capability_->OnDBusPropertiesChanged(interface, |
| 513 | changed_properties, |
| 514 | invalidated_properties); |
| 515 | } |
| 516 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 517 | void Cellular::set_home_provider(const Operator &oper) { |
| 518 | home_provider_.CopyFrom(oper); |
| 519 | } |
| 520 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 521 | string Cellular::CreateFriendlyServiceName() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 522 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 523 | return capability_.get() ? capability_->CreateFriendlyServiceName() : ""; |
| 524 | } |
| 525 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 526 | void Cellular::OnModemStateChanged(ModemState old_state, |
| 527 | ModemState new_state, |
| 528 | uint32 /*reason*/) { |
| 529 | if (old_state == new_state) { |
| 530 | return; |
| 531 | } |
| 532 | set_modem_state(new_state); |
| 533 | switch (new_state) { |
| 534 | case kModemStateDisabled: |
| 535 | SetEnabled(false); |
| 536 | break; |
| 537 | case kModemStateEnabled: |
| 538 | case kModemStateSearching: |
| 539 | // Note: we only handle changes to Enabled from the Registered |
| 540 | // state here. Changes from Disabled to Enabled are handled in |
| 541 | // the DBusPropertiesChanged handler. |
| 542 | if (old_state == kModemStateRegistered) { |
| 543 | capability_->SetUnregistered(new_state == kModemStateSearching); |
| 544 | HandleNewRegistrationState(); |
| 545 | } |
| 546 | case kModemStateRegistered: |
| 547 | if (old_state == kModemStateConnected || |
| 548 | old_state == kModemStateConnecting || |
| 549 | old_state == kModemStateDisconnecting) |
| 550 | OnDisconnected(); |
| 551 | break; |
| 552 | case kModemStateConnecting: |
| 553 | OnConnecting(); |
| 554 | break; |
| 555 | case kModemStateConnected: |
| 556 | OnConnected(); |
| 557 | break; |
| 558 | default: |
| 559 | break; |
| 560 | } |
| 561 | } |
| 562 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 563 | void Cellular::SetAllowRoaming(const bool &value, Error */*error*/) { |
| 564 | SLOG(Cellular, 2) << __func__ |
| 565 | << "(" << allow_roaming_ << "->" << value << ")"; |
| 566 | if (allow_roaming_ == value) { |
| 567 | return; |
| 568 | } |
| 569 | allow_roaming_ = value; |
| 570 | manager()->SaveActiveProfile(); |
| 571 | |
| 572 | // Use AllowRoaming() instead of allow_roaming_ in order to |
| 573 | // incorporate provider preferences when evaluating if a disconnect |
| 574 | // is required. |
| 575 | if (!capability_->AllowRoaming() && |
| 576 | capability_->GetRoamingStateString() == flimflam::kRoamingStateRoaming) { |
| 577 | Error error; |
| 578 | Disconnect(&error); |
| 579 | } |
| 580 | adaptor()->EmitBoolChanged(flimflam::kCellularAllowRoamingProperty, value); |
| 581 | } |
| 582 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 583 | } // namespace shill |