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