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> |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 16 | #include <base/file_path.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" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 25 | #include "shill/cellular_capability_universal_cdma.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | #include "shill/cellular_service.h" |
| 27 | #include "shill/control_interface.h" |
| 28 | #include "shill/device.h" |
| 29 | #include "shill/device_info.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 30 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 31 | #include "shill/event_dispatcher.h" |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 32 | #include "shill/external_task.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 33 | #include "shill/logging.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 34 | #include "shill/manager.h" |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 35 | #include "shill/ppp_device.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 36 | #include "shill/profile.h" |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 37 | #include "shill/property_accessor.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 38 | #include "shill/proxy_factory.h" |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 39 | #include "shill/rtnl_handler.h" |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 40 | #include "shill/store_interface.h" |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 41 | #include "shill/technology.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 42 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 43 | using base::Bind; |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 44 | using base::Closure; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 45 | using base::FilePath; |
| 46 | using std::map; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 47 | using std::string; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 48 | using std::vector; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 49 | |
| 50 | namespace shill { |
| 51 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 52 | // static |
| 53 | const char Cellular::kAllowRoaming[] = "AllowRoaming"; |
| 54 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 55 | Cellular::Operator::Operator() { |
| 56 | SetName(""); |
| 57 | SetCode(""); |
| 58 | SetCountry(""); |
| 59 | } |
| 60 | |
| 61 | Cellular::Operator::~Operator() {} |
| 62 | |
| 63 | void Cellular::Operator::CopyFrom(const Operator &oper) { |
| 64 | dict_ = oper.dict_; |
| 65 | } |
| 66 | |
| 67 | const string &Cellular::Operator::GetName() const { |
| 68 | return dict_.find(flimflam::kOperatorNameKey)->second; |
| 69 | } |
| 70 | |
| 71 | void Cellular::Operator::SetName(const string &name) { |
| 72 | dict_[flimflam::kOperatorNameKey] = name; |
| 73 | } |
| 74 | |
| 75 | const string &Cellular::Operator::GetCode() const { |
| 76 | return dict_.find(flimflam::kOperatorCodeKey)->second; |
| 77 | } |
| 78 | |
| 79 | void Cellular::Operator::SetCode(const string &code) { |
| 80 | dict_[flimflam::kOperatorCodeKey] = code; |
| 81 | } |
| 82 | |
| 83 | const string &Cellular::Operator::GetCountry() const { |
| 84 | return dict_.find(flimflam::kOperatorCountryKey)->second; |
| 85 | } |
| 86 | |
| 87 | void Cellular::Operator::SetCountry(const string &country) { |
| 88 | dict_[flimflam::kOperatorCountryKey] = country; |
| 89 | } |
| 90 | |
| 91 | const Stringmap &Cellular::Operator::ToDict() const { |
| 92 | return dict_; |
| 93 | } |
| 94 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 95 | Cellular::Cellular(ModemInfo *modem_info, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 96 | const string &link_name, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 97 | const string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 98 | int interface_index, |
| 99 | Type type, |
| 100 | const string &owner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 101 | const string &service, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 102 | const string &path, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 103 | ProxyFactory *proxy_factory) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 104 | : Device(modem_info->control_interface(), |
| 105 | modem_info->dispatcher(), |
| 106 | modem_info->metrics(), |
| 107 | modem_info->manager(), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 108 | link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 109 | address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 110 | interface_index, |
| 111 | Technology::kCellular), |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 112 | weak_ptr_factory_(this), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 113 | state_(kStateDisabled), |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 114 | modem_state_(kModemStateUnknown), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 115 | dbus_owner_(owner), |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 116 | dbus_service_(service), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 117 | dbus_path_(path), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 118 | modem_info_(modem_info), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 119 | proxy_factory_(proxy_factory), |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 120 | allow_roaming_(false), |
| 121 | explicit_disconnect_(false) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 122 | PropertyStore *store = this->mutable_store(); |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 123 | // TODO(jglasgow): kDBusConnectionProperty is deprecated. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 124 | store->RegisterConstString(flimflam::kDBusConnectionProperty, &dbus_owner_); |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 125 | store->RegisterConstString(flimflam::kDBusServiceProperty, &dbus_service_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 126 | store->RegisterConstString(flimflam::kDBusObjectProperty, &dbus_path_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 127 | HelpRegisterConstDerivedString(flimflam::kTechnologyFamilyProperty, |
| 128 | &Cellular::GetTechnologyFamily); |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 129 | HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty, |
| 130 | &Cellular::GetAllowRoaming, |
| 131 | &Cellular::SetAllowRoaming); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 132 | store->RegisterConstStringmap(flimflam::kHomeProviderProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 133 | &home_provider_.ToDict()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 134 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 135 | // For now, only a single capability is supported. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 136 | InitCapability(type); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 137 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 138 | SLOG(Cellular, 2) << "Cellular device " << this->link_name() |
| 139 | << " initialized."; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 142 | Cellular::~Cellular() { |
| 143 | } |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 144 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 145 | bool Cellular::Load(StoreInterface *storage) { |
| 146 | const string id = GetStorageIdentifier(); |
| 147 | if (!storage->ContainsGroup(id)) { |
| 148 | LOG(WARNING) << "Device is not available in the persistent store: " << id; |
| 149 | return false; |
| 150 | } |
| 151 | storage->GetBool(id, kAllowRoaming, &allow_roaming_); |
| 152 | return Device::Load(storage); |
| 153 | } |
| 154 | |
| 155 | bool Cellular::Save(StoreInterface *storage) { |
| 156 | const string id = GetStorageIdentifier(); |
| 157 | storage->SetBool(id, kAllowRoaming, allow_roaming_); |
| 158 | return Device::Save(storage); |
| 159 | } |
| 160 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 161 | // static |
| 162 | string Cellular::GetStateString(State state) { |
| 163 | switch (state) { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 164 | case kStateDisabled: return "CellularStateDisabled"; |
| 165 | case kStateEnabled: return "CellularStateEnabled"; |
| 166 | case kStateRegistered: return "CellularStateRegistered"; |
| 167 | case kStateConnected: return "CellularStateConnected"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 168 | case kStateLinked: return "CellularStateLinked"; |
| 169 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 170 | } |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 171 | return StringPrintf("CellularStateUnknown-%d", state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 174 | string Cellular::GetTechnologyFamily(Error *error) { |
| 175 | return capability_->GetTypeString(); |
| 176 | } |
| 177 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 178 | void Cellular::SetState(State state) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 179 | SLOG(Cellular, 2) << GetStateString(state_) << " -> " |
| 180 | << GetStateString(state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 181 | state_ = state; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 184 | void Cellular::HelpRegisterDerivedBool( |
| 185 | const string &name, |
| 186 | bool(Cellular::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 187 | bool(Cellular::*set)(const bool &value, Error *error)) { |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 188 | mutable_store()->RegisterDerivedBool( |
| 189 | name, |
| 190 | BoolAccessor( |
| 191 | new CustomAccessor<Cellular, bool>(this, get, set))); |
| 192 | } |
| 193 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 194 | void Cellular::HelpRegisterConstDerivedString( |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 195 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 196 | string(Cellular::*get)(Error *)) { |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 197 | mutable_store()->RegisterDerivedString( |
| 198 | name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 199 | StringAccessor(new CustomAccessor<Cellular, string>(this, get, NULL))); |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 202 | void Cellular::Start(Error *error, |
| 203 | const EnabledStateChangedCallback &callback) { |
Jason Glasgow | 4a49079 | 2012-04-10 15:02:05 -0400 | [diff] [blame] | 204 | DCHECK(error); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 205 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 206 | if (state_ != kStateDisabled) { |
| 207 | return; |
| 208 | } |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 209 | ResultCallback cb = Bind(&Cellular::StartModemCallback, |
| 210 | weak_ptr_factory_.GetWeakPtr(), |
| 211 | callback); |
| 212 | capability_->StartModem(error, cb); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 215 | void Cellular::Stop(Error *error, |
| 216 | const EnabledStateChangedCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 217 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 218 | explicit_disconnect_ = true; |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 219 | ResultCallback cb = Bind(&Cellular::StopModemCallback, |
| 220 | weak_ptr_factory_.GetWeakPtr(), |
| 221 | callback); |
| 222 | capability_->StopModem(error, cb); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 225 | bool Cellular::IsUnderlyingDeviceEnabled() const { |
| 226 | return IsEnabledModemState(modem_state_); |
| 227 | } |
| 228 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 229 | bool Cellular::IsModemRegistered() const { |
| 230 | return (modem_state_ == Cellular::kModemStateRegistered || |
| 231 | modem_state_ == Cellular::kModemStateConnecting || |
| 232 | modem_state_ == Cellular::kModemStateConnected); |
| 233 | } |
| 234 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 235 | // static |
| 236 | bool Cellular::IsEnabledModemState(ModemState state) { |
| 237 | switch (state) { |
| 238 | case kModemStateUnknown: |
| 239 | case kModemStateDisabled: |
| 240 | case kModemStateInitializing: |
| 241 | case kModemStateLocked: |
| 242 | case kModemStateDisabling: |
| 243 | case kModemStateEnabling: |
| 244 | return false; |
| 245 | case kModemStateEnabled: |
| 246 | case kModemStateSearching: |
| 247 | case kModemStateRegistered: |
| 248 | case kModemStateDisconnecting: |
| 249 | case kModemStateConnecting: |
| 250 | case kModemStateConnected: |
| 251 | return true; |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 256 | void Cellular::StartModemCallback(const EnabledStateChangedCallback &callback, |
| 257 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 258 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 259 | if (error.IsSuccess() && (state_ == kStateDisabled)) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 260 | SetState(kStateEnabled); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 261 | // Registration state updates may have been ignored while the |
| 262 | // modem was not yet marked enabled. |
| 263 | HandleNewRegistrationState(); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 264 | if (capability_->ShouldDetectOutOfCredit()) |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 265 | set_traffic_monitor_enabled(true); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 266 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 267 | callback.Run(error); |
| 268 | } |
| 269 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 270 | void Cellular::StopModemCallback(const EnabledStateChangedCallback &callback, |
| 271 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 272 | SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_); |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 273 | explicit_disconnect_ = false; |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 274 | // Destroy the cellular service regardless of any errors that occur during |
| 275 | // the stop process since we do not know the state of the modem at this |
| 276 | // point. |
| 277 | DestroyService(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 278 | if (state_ != kStateDisabled) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 279 | SetState(kStateDisabled); |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 280 | set_traffic_monitor_enabled(false); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 281 | callback.Run(error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 284 | void Cellular::InitCapability(Type type) { |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 285 | // TODO(petkov): Consider moving capability construction into a factory that's |
| 286 | // external to the Cellular class. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 287 | SLOG(Cellular, 2) << __func__ << "(" << type << ")"; |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 288 | switch (type) { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 289 | case kTypeGSM: |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 290 | capability_.reset(new CellularCapabilityGSM(this, |
| 291 | proxy_factory_, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 292 | modem_info_)); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 293 | break; |
| 294 | case kTypeCDMA: |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 295 | capability_.reset(new CellularCapabilityCDMA(this, |
| 296 | proxy_factory_, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 297 | modem_info_)); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 298 | break; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 299 | case kTypeUniversal: |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 300 | capability_.reset(new CellularCapabilityUniversal( |
| 301 | this, |
| 302 | proxy_factory_, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 303 | modem_info_)); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 304 | break; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 305 | case kTypeUniversalCDMA: |
| 306 | capability_.reset(new CellularCapabilityUniversalCDMA( |
| 307 | this, |
| 308 | proxy_factory_, |
| 309 | modem_info_)); |
| 310 | break; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 311 | default: NOTREACHED(); |
| 312 | } |
| 313 | } |
| 314 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 315 | void Cellular::Activate(const string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 316 | Error *error, const ResultCallback &callback) { |
| 317 | capability_->Activate(carrier, error, callback); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 320 | void Cellular::CompleteActivation(Error *error) { |
| 321 | capability_->CompleteActivation(error); |
| 322 | } |
| 323 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 324 | void Cellular::RegisterOnNetwork(const string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 325 | Error *error, |
| 326 | const ResultCallback &callback) { |
| 327 | capability_->RegisterOnNetwork(network_id, error, callback); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 328 | } |
| 329 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 330 | void Cellular::RequirePIN(const string &pin, bool require, |
| 331 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 332 | SLOG(Cellular, 2) << __func__ << "(" << require << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 333 | capability_->RequirePIN(pin, require, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 336 | void Cellular::EnterPIN(const string &pin, |
| 337 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 338 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 339 | capability_->EnterPIN(pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 342 | void Cellular::UnblockPIN(const string &unblock_code, |
| 343 | const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 344 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 345 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 346 | capability_->UnblockPIN(unblock_code, pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 349 | void Cellular::ChangePIN(const string &old_pin, const string &new_pin, |
| 350 | Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 351 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 352 | capability_->ChangePIN(old_pin, new_pin, error, callback); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 355 | void Cellular::Reset(Error *error, const ResultCallback &callback) { |
| 356 | SLOG(Cellular, 2) << __func__; |
| 357 | capability_->Reset(error, callback); |
| 358 | } |
| 359 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 360 | void Cellular::SetCarrier(const string &carrier, |
| 361 | Error *error, const ResultCallback &callback) { |
| 362 | SLOG(Cellular, 2) << __func__ << "(" << carrier << ")"; |
| 363 | capability_->SetCarrier(carrier, error, callback); |
| 364 | } |
| 365 | |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 366 | void Cellular::OnNoNetworkRouting() { |
| 367 | SLOG(Cellular, 2) << __func__; |
| 368 | Device::OnNoNetworkRouting(); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 369 | |
| 370 | SLOG(Cellular, 2) << "Requesting active probe for out-of-credit detection."; |
| 371 | RequestConnectionHealthCheck(); |
| 372 | } |
| 373 | |
| 374 | void Cellular::OnConnectionHealthCheckerResult( |
| 375 | ConnectionHealthChecker::Result result) { |
Prathmesh Prabhu | 5489b7a | 2013-04-10 13:33:59 -0700 | [diff] [blame] | 376 | SLOG(Cellular, 2) << __func__ << "(Result = " |
| 377 | << ConnectionHealthChecker::ResultToString(result) << ")"; |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 378 | |
Prathmesh Prabhu | 3fd54bd | 2013-05-08 16:36:57 -0700 | [diff] [blame] | 379 | if (result == ConnectionHealthChecker::kResultCongestedTxQueue) { |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 380 | SLOG(Cellular, 2) << "Active probe determined possible out-of-credits " |
| 381 | << "scenario."; |
| 382 | if (service().get()) { |
Thieu Le | 91fccf6 | 2013-04-22 15:23:16 -0700 | [diff] [blame] | 383 | Metrics::CellularOutOfCreditsReason reason = |
| 384 | (result == ConnectionHealthChecker::kResultCongestedTxQueue) ? |
| 385 | Metrics::kCellularOutOfCreditsReasonTxCongested : |
| 386 | Metrics::kCellularOutOfCreditsReasonElongatedTimeWait; |
| 387 | metrics()->NotifyCellularOutOfCredits(reason); |
| 388 | |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 389 | service()->SetOutOfCredits(true); |
| 390 | SLOG(Cellular, 2) << "Disconnecting due to out-of-credit scenario."; |
| 391 | Error error; |
| 392 | service()->Disconnect(&error); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | void Cellular::PortalDetectorCallback(const PortalDetector::Result &result) { |
| 398 | Device::PortalDetectorCallback(result); |
| 399 | if (result.status != PortalDetector::kStatusSuccess && |
| 400 | capability_->ShouldDetectOutOfCredit()) { |
| 401 | SLOG(Cellular, 2) << "Portal detection failed. Launching active probe for " |
| 402 | << "out-of-credit detection."; |
| 403 | RequestConnectionHealthCheck(); |
| 404 | } |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 407 | void Cellular::Scan(ScanType scan_type, Error *error) { |
| 408 | // |scan_type| is ignored because Cellular only does a full scan. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 409 | // TODO(ers): for now report immediate success or failure. |
| 410 | capability_->Scan(error, ResultCallback()); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 413 | void Cellular::HandleNewRegistrationState() { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 414 | SLOG(Cellular, 2) << __func__ |
| 415 | << ": (new state " << GetStateString(state_) << ")"; |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 416 | if (capability_->IsServiceActivationRequired()) { |
| 417 | if (state_ == kStateEnabled && !service_.get()) { |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 418 | SLOG(Cellular, 2) << "Service activation required. Creating dummy " |
| 419 | << "service."; |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 420 | CreateService(); |
| 421 | } |
| 422 | return; |
| 423 | } |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 424 | if (!capability_->IsRegistered()) { |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 425 | if (!explicit_disconnect_ && |
| 426 | (state_ == kStateLinked || state_ == kStateConnected) && |
| 427 | service_.get()) |
| 428 | metrics()->NotifyCellularDeviceDrop( |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 429 | interface_index(), |
| 430 | capability_->GetNetworkTechnologyString(), |
| 431 | service_->strength()); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 432 | DestroyService(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 433 | if (state_ == kStateLinked || |
| 434 | state_ == kStateConnected || |
| 435 | state_ == kStateRegistered) { |
| 436 | SetState(kStateEnabled); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 437 | } |
| 438 | return; |
| 439 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 440 | // In Disabled state, defer creating a service until fully |
| 441 | // enabled. UI will ignore the appearance of a new service |
| 442 | // on a disabled device. |
| 443 | if (state_ == kStateDisabled) { |
| 444 | return; |
| 445 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 446 | if (state_ == kStateEnabled) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 447 | SetState(kStateRegistered); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 448 | } |
| 449 | if (!service_.get()) { |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 450 | metrics()->NotifyDeviceScanFinished(interface_index()); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 451 | CreateService(); |
| 452 | } |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 453 | capability_->GetSignalQuality(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 454 | if (state_ == kStateRegistered && modem_state_ == kModemStateConnected) |
| 455 | OnConnected(); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 456 | service_->SetNetworkTechnology(capability_->GetNetworkTechnologyString()); |
| 457 | service_->SetRoamingState(capability_->GetRoamingStateString()); |
Christopher Wiley | 9169d25 | 2012-11-30 15:13:39 -0800 | [diff] [blame] | 458 | manager()->UpdateService(service_); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 461 | void Cellular::HandleNewSignalQuality(uint32 strength) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 462 | SLOG(Cellular, 2) << "Signal strength: " << strength; |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 463 | if (service_) { |
| 464 | service_->SetStrength(strength); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
| 468 | void Cellular::CreateService() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 469 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 470 | CHECK(!service_.get()); |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 471 | service_ = new CellularService(modem_info_, this); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 472 | capability_->OnServiceCreated(); |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 473 | manager()->RegisterService(service_); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 476 | void Cellular::DestroyService() { |
Darin Petkov | 0f5dfa0 | 2012-11-14 16:35:32 +0100 | [diff] [blame] | 477 | DropConnection(); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 478 | if (service_) { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 479 | LOG(INFO) << "Deregistering cellular service " << service_->unique_name() |
Darin Petkov | 0f5dfa0 | 2012-11-14 16:35:32 +0100 | [diff] [blame] | 480 | << " for device " << link_name(); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 481 | manager()->DeregisterService(service_); |
| 482 | service_ = NULL; |
| 483 | } |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 486 | void Cellular::Connect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 487 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 488 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 489 | Error::PopulateAndLog(error, Error::kAlreadyConnected, |
| 490 | "Already connected; connection request ignored."); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 491 | return; |
Thieu Le | c7d8cd1 | 2013-02-13 11:38:14 -0800 | [diff] [blame] | 492 | } else if (state_ != kStateRegistered) { |
| 493 | Error::PopulateAndLog(error, Error::kNotRegistered, |
| 494 | "Modem not registered; connection request ignored."); |
| 495 | return; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 496 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 497 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 498 | if (!capability_->AllowRoaming() && |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 499 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 500 | Error::PopulateAndLog(error, Error::kNotOnHomeNetwork, |
| 501 | "Roaming disallowed; connection request ignored."); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 502 | return; |
| 503 | } |
| 504 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 505 | DBusPropertiesMap properties; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 506 | capability_->SetupConnectProperties(&properties); |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 507 | ResultCallback cb = Bind(&Cellular::OnConnectReply, |
| 508 | weak_ptr_factory_.GetWeakPtr()); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 509 | OnConnecting(); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 510 | capability_->Connect(properties, error, cb); |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 511 | if (!error->IsSuccess()) |
| 512 | return; |
| 513 | |
| 514 | bool is_auto_connecting = service_.get() && service_->is_auto_connecting(); |
| 515 | metrics()->NotifyDeviceConnectStarted(interface_index(), is_auto_connecting); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // Note that there's no ResultCallback argument to this, |
| 519 | // since Connect() isn't yet passed one. |
| 520 | void Cellular::OnConnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 521 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 522 | if (error.IsSuccess()) { |
| 523 | metrics()->NotifyDeviceConnectFinished(interface_index()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 524 | OnConnected(); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 525 | } else { |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 526 | metrics()->NotifyCellularDeviceFailure(error); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 527 | OnConnectFailed(error); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 528 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 531 | void Cellular::OnConnecting() { |
| 532 | if (service_) |
| 533 | service_->SetState(Service::kStateAssociating); |
| 534 | } |
| 535 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 536 | void Cellular::OnConnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 537 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 538 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 539 | SLOG(Cellular, 2) << "Already connected"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 540 | return; |
| 541 | } |
Darin Petkov | 1c01bef | 2012-09-13 15:27:17 +0200 | [diff] [blame] | 542 | Closure start_cb = Bind(&Cellular::StartTermination, |
| 543 | weak_ptr_factory_.GetWeakPtr()); |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 544 | manager()->AddTerminationAction(FriendlyName(), start_cb); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 545 | SetState(kStateConnected); |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 546 | if (!service_) { |
| 547 | LOG(INFO) << "Disconnecting due to no cellular service."; |
| 548 | Disconnect(NULL); |
| 549 | } else if (!capability_->AllowRoaming() && |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 550 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 551 | LOG(INFO) << "Disconnecting due to roaming."; |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 552 | Disconnect(NULL); |
| 553 | } else { |
| 554 | EstablishLink(); |
| 555 | } |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 558 | void Cellular::OnConnectFailed(const Error &error) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 559 | if (service_) |
| 560 | service_->SetFailure(Service::kFailureUnknown); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 561 | } |
| 562 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 563 | void Cellular::Disconnect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 564 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 565 | if (state_ != kStateConnected && state_ != kStateLinked) { |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 566 | Error::PopulateAndLog( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 567 | error, Error::kNotConnected, "Not connected; request ignored."); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 568 | return; |
| 569 | } |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 570 | explicit_disconnect_ = true; |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 571 | ResultCallback cb = Bind(&Cellular::OnDisconnectReply, |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 572 | weak_ptr_factory_.GetWeakPtr()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 573 | capability_->Disconnect(error, cb); |
| 574 | } |
| 575 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 576 | void Cellular::OnDisconnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 577 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 578 | explicit_disconnect_ = false; |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 579 | if (error.IsSuccess()) { |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 580 | OnDisconnected(); |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 581 | } else { |
| 582 | metrics()->NotifyCellularDeviceFailure(error); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 583 | OnDisconnectFailed(); |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 584 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 585 | manager()->TerminationActionComplete(FriendlyName()); |
| 586 | manager()->RemoveTerminationAction(FriendlyName()); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 589 | void Cellular::OnDisconnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 590 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 591 | if (!DisconnectCleanup()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 592 | LOG(WARNING) << "Disconnect occurred while in state " |
| 593 | << GetStateString(state_); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 594 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void Cellular::OnDisconnectFailed() { |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 598 | SLOG(Cellular, 2) << __func__; |
| 599 | // If the modem is in the disconnecting state, then |
| 600 | // the disconnect should eventually succeed, so do |
| 601 | // nothing. |
| 602 | if (modem_state_ == kModemStateDisconnecting) { |
| 603 | LOG(WARNING) << "Ignoring failed disconnect while modem is disconnecting."; |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | // OnDisconnectFailed got called because no bearers |
| 608 | // to disconnect were found. Which means that we shouldn't |
| 609 | // really remain in the connected/linked state if we |
| 610 | // are in one of those. |
| 611 | if (!DisconnectCleanup()) { |
| 612 | // otherwise, no-op |
| 613 | LOG(WARNING) << "Ignoring failed disconnect while in state " |
| 614 | << GetStateString(state_); |
| 615 | } |
| 616 | |
| 617 | // TODO(armansito): In either case, shill ends up thinking |
| 618 | // that it's disconnected, while for some reason the underlying |
| 619 | // modem might still actually be connected. In that case the UI |
| 620 | // would be reflecting an incorrect state and a further connection |
| 621 | // request would fail. We should perhaps tear down the modem and |
| 622 | // restart it here. |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 623 | } |
| 624 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 625 | void Cellular::EstablishLink() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 626 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 627 | CHECK_EQ(kStateConnected, state_); |
| 628 | unsigned int flags = 0; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 629 | if (manager()->device_info()->GetFlags(interface_index(), &flags) && |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 630 | (flags & IFF_UP) != 0) { |
| 631 | LinkEvent(flags, IFF_UP); |
| 632 | return; |
| 633 | } |
| 634 | // TODO(petkov): Provide a timeout for a failed link-up request. |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 635 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 636 | |
| 637 | // Set state to associating. |
| 638 | OnConnecting(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void Cellular::LinkEvent(unsigned int flags, unsigned int change) { |
| 642 | Device::LinkEvent(flags, change); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 643 | if (ppp_task_) { |
| 644 | LOG(INFO) << "Ignoring LinkEvent on device with PPP interface."; |
| 645 | return; |
| 646 | } |
| 647 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 648 | if ((flags & IFF_UP) != 0 && state_ == kStateConnected) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 649 | LOG(INFO) << link_name() << " is up."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 650 | SetState(kStateLinked); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 651 | if (AcquireIPConfig()) { |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 652 | SelectService(service_); |
| 653 | SetServiceState(Service::kStateConfiguring); |
| 654 | } else { |
| 655 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 656 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 657 | } else if ((flags & IFF_UP) == 0 && state_ == kStateLinked) { |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 658 | LOG(INFO) << link_name() << " is down."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 659 | SetState(kStateConnected); |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 660 | DropConnection(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 661 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 664 | void Cellular::OnDBusPropertiesChanged( |
| 665 | const string &interface, |
| 666 | const DBusPropertiesMap &changed_properties, |
| 667 | const vector<string> &invalidated_properties) { |
| 668 | capability_->OnDBusPropertiesChanged(interface, |
| 669 | changed_properties, |
| 670 | invalidated_properties); |
| 671 | } |
| 672 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 673 | void Cellular::set_home_provider(const Operator &oper) { |
| 674 | home_provider_.CopyFrom(oper); |
| 675 | } |
| 676 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 677 | string Cellular::CreateFriendlyServiceName() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 678 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 679 | return capability_.get() ? capability_->CreateFriendlyServiceName() : ""; |
| 680 | } |
| 681 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 682 | void Cellular::OnModemStateChanged(ModemState old_state, |
| 683 | ModemState new_state, |
| 684 | uint32 /*reason*/) { |
| 685 | if (old_state == new_state) { |
| 686 | return; |
| 687 | } |
| 688 | set_modem_state(new_state); |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 689 | if (old_state >= kModemStateRegistered && |
| 690 | new_state < kModemStateRegistered) { |
| 691 | capability_->SetUnregistered(new_state == kModemStateSearching); |
| 692 | HandleNewRegistrationState(); |
| 693 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 694 | switch (new_state) { |
| 695 | case kModemStateDisabled: |
| 696 | SetEnabled(false); |
| 697 | break; |
| 698 | case kModemStateEnabled: |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 699 | // Transition from Disabled to Enabled is handled in the |
| 700 | // DBusPropertiesChanged handler. |
| 701 | SLOG(Cellular, 2) << __func__ << ": Ignoring state change to Enabled"; |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 702 | // Intentionally falls through. |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 703 | case kModemStateSearching: |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 704 | case kModemStateRegistered: |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 705 | // If the modem state changes from Connecting/Connected/Disconnecting |
| 706 | // to Registered/Enabled/Searching, then it's an indication that the |
| 707 | // modem has been disconnected or got disconnected by the network. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 708 | if (old_state == kModemStateConnected || |
| 709 | old_state == kModemStateConnecting || |
| 710 | old_state == kModemStateDisconnecting) |
| 711 | OnDisconnected(); |
| 712 | break; |
| 713 | case kModemStateConnecting: |
| 714 | OnConnecting(); |
| 715 | break; |
| 716 | case kModemStateConnected: |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 717 | if (old_state == kModemStateConnecting) |
| 718 | OnConnected(); |
| 719 | else |
| 720 | SLOG(Cellular, 2) << __func__ << ": Ignoring state change to Connected"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 721 | break; |
| 722 | default: |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 727 | bool Cellular::IsActivating() const { |
| 728 | return capability_->IsActivating(); |
| 729 | } |
| 730 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 731 | bool Cellular::SetAllowRoaming(const bool &value, Error */*error*/) { |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 732 | SLOG(Cellular, 2) << __func__ |
| 733 | << "(" << allow_roaming_ << "->" << value << ")"; |
| 734 | if (allow_roaming_ == value) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 735 | return false; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 736 | } |
| 737 | allow_roaming_ = value; |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 738 | manager()->UpdateDevice(this); |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 739 | |
| 740 | // Use AllowRoaming() instead of allow_roaming_ in order to |
| 741 | // incorporate provider preferences when evaluating if a disconnect |
| 742 | // is required. |
| 743 | if (!capability_->AllowRoaming() && |
| 744 | capability_->GetRoamingStateString() == flimflam::kRoamingStateRoaming) { |
| 745 | Error error; |
| 746 | Disconnect(&error); |
| 747 | } |
| 748 | adaptor()->EmitBoolChanged(flimflam::kCellularAllowRoamingProperty, value); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 749 | return true; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 750 | } |
| 751 | |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 752 | void Cellular::StartTermination() { |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 753 | LOG(INFO) << __func__; |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 754 | Error error; |
| 755 | Disconnect(&error); |
| 756 | } |
| 757 | |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 758 | bool Cellular::DisconnectCleanup() { |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 759 | bool succeeded = false; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 760 | if (state_ == kStateConnected || state_ == kStateLinked) { |
| 761 | SetState(kStateRegistered); |
| 762 | SetServiceFailureSilent(Service::kFailureUnknown); |
| 763 | DestroyIPConfig(); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 764 | succeeded = true; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 765 | } |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 766 | capability_->DisconnectCleanup(); |
| 767 | return succeeded; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 768 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 769 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 770 | void Cellular::StartPPP(const string &serial_device) { |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 771 | // Some PPP dongles also expose an Ethernet-like network device, |
| 772 | // using either cdc_ether, or cdc_ncm. dhcpcd may be running on that |
| 773 | // interface. If so, it will eventually time out, and cause us |
| 774 | // terminate the cellular connection. Avoid terminating the connection, |
| 775 | // by cancelling any such DHCP process. |
| 776 | DestroyIPConfig(); |
| 777 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 778 | base::Callback<void(pid_t, int)> death_callback( |
| 779 | Bind(&Cellular::OnPPPDied, weak_ptr_factory_.GetWeakPtr())); |
| 780 | vector<string> args; |
| 781 | map<string, string> environment; |
| 782 | Error error; |
| 783 | if (SLOG_IS_ON(PPP, 5)) { |
| 784 | args.push_back("debug"); |
| 785 | } |
| 786 | args.push_back("nodetach"); |
| 787 | args.push_back("nodefaultroute"); // Don't let pppd muck with routing table. |
| 788 | args.push_back("usepeerdns"); // Request DNS servers. |
| 789 | args.push_back("plugin"); // Goes with next arg. |
| 790 | args.push_back(PPPDevice::kPluginPath); |
| 791 | args.push_back(serial_device); |
| 792 | scoped_ptr<ExternalTask> new_ppp_task( |
| 793 | new ExternalTask(modem_info_->control_interface(), |
| 794 | modem_info_->glib(), |
| 795 | weak_ptr_factory_.GetWeakPtr(), |
| 796 | death_callback)); |
| 797 | if (new_ppp_task->Start( |
| 798 | FilePath(PPPDevice::kDaemonPath), args, environment, &error)) { |
| 799 | LOG(INFO) << "Forked pppd process."; |
| 800 | ppp_task_ = new_ppp_task.Pass(); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | // called by |ppp_task_| |
| 805 | void Cellular::GetLogin(string *user, string *password) { |
| 806 | LOG(INFO) << __func__; |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 807 | if (!service()) { |
| 808 | LOG(ERROR) << __func__ << " with no service "; |
| 809 | return; |
| 810 | } |
| 811 | CHECK(user); |
| 812 | CHECK(password); |
| 813 | *user = service()->ppp_username(); |
| 814 | *password = service()->ppp_password(); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // Called by |ppp_task_|. |
| 818 | void Cellular::Notify(const string &reason, |
| 819 | const map<string, string> &dict) { |
| 820 | LOG(INFO) << __func__ << " " << reason << " on " << link_name(); |
| 821 | |
| 822 | if (reason != kPPPReasonConnect) { |
| 823 | DCHECK_EQ(kPPPReasonDisconnect, reason); |
| 824 | // DestroyLater, rather than while on stack. |
| 825 | ppp_task_.release()->DestroyLater(modem_info_->dispatcher()); |
| 826 | // For now, assume PPP failures are due to authentication issues. |
| 827 | SetServiceFailure(Service::kFailurePPPAuth); |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | string interface_name = PPPDevice::GetInterfaceName(dict); |
| 832 | DeviceInfo *device_info = modem_info_->manager()->device_info(); |
| 833 | int interface_index = device_info->GetIndex(interface_name); |
| 834 | if (interface_index < 0) { |
| 835 | // TODO(quiche): Consider handling the race when the RTNL notification about |
| 836 | // the new PPP device has not been received yet. crbug.com/246832. |
| 837 | NOTIMPLEMENTED() << ": No device info for " << interface_name << "."; |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | if (!ppp_device_ || ppp_device_->interface_index() != interface_index) { |
| 842 | ppp_device_ = new PPPDevice(modem_info_->control_interface(), |
| 843 | modem_info_->dispatcher(), |
| 844 | modem_info_->metrics(), |
| 845 | modem_info_->manager(), |
| 846 | interface_name, |
| 847 | interface_index); |
| 848 | device_info->RegisterDevice(ppp_device_); |
| 849 | } |
| 850 | |
| 851 | // TODO(quiche): Consider if we should have a separate Service for the |
| 852 | // PPPDevice. (crbug.com/246456) |
| 853 | CHECK(service_); |
| 854 | const bool kBlackholeIPv6 = false; |
| 855 | ppp_device_->SetEnabled(true); |
| 856 | ppp_device_->SelectService(service_); |
| 857 | ppp_device_->UpdateIPConfigFromPPP(dict, kBlackholeIPv6); |
| 858 | } |
| 859 | |
| 860 | void Cellular::OnPPPDied(pid_t pid, int exit) { |
| 861 | LOG(INFO) << __func__ << " on " << link_name(); |
| 862 | Error error; |
| 863 | Disconnect(&error); |
| 864 | } |
| 865 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 866 | } // namespace shill |