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 | |
mukesh agrawal | 5d851b1 | 2013-07-11 14:09:41 -0700 | [diff] [blame] | 366 | void Cellular::DropConnection() { |
| 367 | if (ppp_device_) { |
| 368 | // For PPP dongles, IP configuration is handled on the |ppp_device_|, |
| 369 | // rather than the netdev plumbed into |this|. |
| 370 | ppp_device_->DropConnection(); |
| 371 | } else { |
| 372 | Device::DropConnection(); |
| 373 | } |
| 374 | } |
| 375 | |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 376 | void Cellular::OnNoNetworkRouting() { |
| 377 | SLOG(Cellular, 2) << __func__; |
| 378 | Device::OnNoNetworkRouting(); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 379 | |
| 380 | SLOG(Cellular, 2) << "Requesting active probe for out-of-credit detection."; |
| 381 | RequestConnectionHealthCheck(); |
| 382 | } |
| 383 | |
| 384 | void Cellular::OnConnectionHealthCheckerResult( |
| 385 | ConnectionHealthChecker::Result result) { |
Prathmesh Prabhu | 5489b7a | 2013-04-10 13:33:59 -0700 | [diff] [blame] | 386 | SLOG(Cellular, 2) << __func__ << "(Result = " |
| 387 | << ConnectionHealthChecker::ResultToString(result) << ")"; |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 388 | |
Prathmesh Prabhu | 3fd54bd | 2013-05-08 16:36:57 -0700 | [diff] [blame] | 389 | if (result == ConnectionHealthChecker::kResultCongestedTxQueue) { |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 390 | SLOG(Cellular, 2) << "Active probe determined possible out-of-credits " |
| 391 | << "scenario."; |
| 392 | if (service().get()) { |
Thieu Le | 91fccf6 | 2013-04-22 15:23:16 -0700 | [diff] [blame] | 393 | Metrics::CellularOutOfCreditsReason reason = |
| 394 | (result == ConnectionHealthChecker::kResultCongestedTxQueue) ? |
| 395 | Metrics::kCellularOutOfCreditsReasonTxCongested : |
| 396 | Metrics::kCellularOutOfCreditsReasonElongatedTimeWait; |
| 397 | metrics()->NotifyCellularOutOfCredits(reason); |
| 398 | |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 399 | service()->SetOutOfCredits(true); |
| 400 | SLOG(Cellular, 2) << "Disconnecting due to out-of-credit scenario."; |
| 401 | Error error; |
| 402 | service()->Disconnect(&error); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | void Cellular::PortalDetectorCallback(const PortalDetector::Result &result) { |
| 408 | Device::PortalDetectorCallback(result); |
| 409 | if (result.status != PortalDetector::kStatusSuccess && |
| 410 | capability_->ShouldDetectOutOfCredit()) { |
| 411 | SLOG(Cellular, 2) << "Portal detection failed. Launching active probe for " |
| 412 | << "out-of-credit detection."; |
| 413 | RequestConnectionHealthCheck(); |
| 414 | } |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 417 | void Cellular::Scan(ScanType scan_type, Error *error) { |
| 418 | // |scan_type| is ignored because Cellular only does a full scan. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 419 | // TODO(ers): for now report immediate success or failure. |
| 420 | capability_->Scan(error, ResultCallback()); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 423 | void Cellular::HandleNewRegistrationState() { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 424 | SLOG(Cellular, 2) << __func__ |
| 425 | << ": (new state " << GetStateString(state_) << ")"; |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 426 | if (capability_->IsServiceActivationRequired()) { |
| 427 | if (state_ == kStateEnabled && !service_.get()) { |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 428 | SLOG(Cellular, 2) << "Service activation required. Creating dummy " |
| 429 | << "service."; |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 430 | CreateService(); |
| 431 | } |
| 432 | return; |
| 433 | } |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 434 | if (!capability_->IsRegistered()) { |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 435 | if (!explicit_disconnect_ && |
| 436 | (state_ == kStateLinked || state_ == kStateConnected) && |
| 437 | service_.get()) |
| 438 | metrics()->NotifyCellularDeviceDrop( |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 439 | interface_index(), |
| 440 | capability_->GetNetworkTechnologyString(), |
| 441 | service_->strength()); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 442 | DestroyService(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 443 | if (state_ == kStateLinked || |
| 444 | state_ == kStateConnected || |
| 445 | state_ == kStateRegistered) { |
| 446 | SetState(kStateEnabled); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 447 | } |
| 448 | return; |
| 449 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 450 | // In Disabled state, defer creating a service until fully |
| 451 | // enabled. UI will ignore the appearance of a new service |
| 452 | // on a disabled device. |
| 453 | if (state_ == kStateDisabled) { |
| 454 | return; |
| 455 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 456 | if (state_ == kStateEnabled) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 457 | SetState(kStateRegistered); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 458 | } |
| 459 | if (!service_.get()) { |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 460 | metrics()->NotifyDeviceScanFinished(interface_index()); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 461 | CreateService(); |
| 462 | } |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 463 | capability_->GetSignalQuality(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 464 | if (state_ == kStateRegistered && modem_state_ == kModemStateConnected) |
| 465 | OnConnected(); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 466 | service_->SetNetworkTechnology(capability_->GetNetworkTechnologyString()); |
| 467 | service_->SetRoamingState(capability_->GetRoamingStateString()); |
Christopher Wiley | 9169d25 | 2012-11-30 15:13:39 -0800 | [diff] [blame] | 468 | manager()->UpdateService(service_); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 471 | void Cellular::HandleNewSignalQuality(uint32 strength) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 472 | SLOG(Cellular, 2) << "Signal strength: " << strength; |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 473 | if (service_) { |
| 474 | service_->SetStrength(strength); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | void Cellular::CreateService() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 479 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 480 | CHECK(!service_.get()); |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 481 | service_ = new CellularService(modem_info_, this); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 482 | capability_->OnServiceCreated(); |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 483 | manager()->RegisterService(service_); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 486 | void Cellular::DestroyService() { |
mukesh agrawal | 6813e76 | 2013-07-10 19:05:08 -0700 | [diff] [blame] | 487 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0f5dfa0 | 2012-11-14 16:35:32 +0100 | [diff] [blame] | 488 | DropConnection(); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 489 | if (service_) { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 490 | LOG(INFO) << "Deregistering cellular service " << service_->unique_name() |
Darin Petkov | 0f5dfa0 | 2012-11-14 16:35:32 +0100 | [diff] [blame] | 491 | << " for device " << link_name(); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 492 | manager()->DeregisterService(service_); |
| 493 | service_ = NULL; |
| 494 | } |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 497 | void Cellular::Connect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 498 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 499 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 500 | Error::PopulateAndLog(error, Error::kAlreadyConnected, |
| 501 | "Already connected; connection request ignored."); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 502 | return; |
Thieu Le | c7d8cd1 | 2013-02-13 11:38:14 -0800 | [diff] [blame] | 503 | } else if (state_ != kStateRegistered) { |
| 504 | Error::PopulateAndLog(error, Error::kNotRegistered, |
| 505 | "Modem not registered; connection request ignored."); |
| 506 | return; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 507 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 508 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 509 | if (!capability_->AllowRoaming() && |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 510 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 511 | Error::PopulateAndLog(error, Error::kNotOnHomeNetwork, |
| 512 | "Roaming disallowed; connection request ignored."); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 516 | DBusPropertiesMap properties; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 517 | capability_->SetupConnectProperties(&properties); |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 518 | ResultCallback cb = Bind(&Cellular::OnConnectReply, |
| 519 | weak_ptr_factory_.GetWeakPtr()); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 520 | OnConnecting(); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 521 | capability_->Connect(properties, error, cb); |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 522 | if (!error->IsSuccess()) |
| 523 | return; |
| 524 | |
| 525 | bool is_auto_connecting = service_.get() && service_->is_auto_connecting(); |
| 526 | metrics()->NotifyDeviceConnectStarted(interface_index(), is_auto_connecting); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | // Note that there's no ResultCallback argument to this, |
| 530 | // since Connect() isn't yet passed one. |
| 531 | void Cellular::OnConnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 532 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 533 | if (error.IsSuccess()) { |
| 534 | metrics()->NotifyDeviceConnectFinished(interface_index()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 535 | OnConnected(); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 536 | } else { |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 537 | metrics()->NotifyCellularDeviceFailure(error); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 538 | OnConnectFailed(error); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 539 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 542 | void Cellular::OnConnecting() { |
| 543 | if (service_) |
| 544 | service_->SetState(Service::kStateAssociating); |
| 545 | } |
| 546 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 547 | void Cellular::OnConnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 548 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 549 | if (state_ == kStateConnected || state_ == kStateLinked) { |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 550 | SLOG(Cellular, 2) << "Already connected"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 551 | return; |
| 552 | } |
Darin Petkov | 1c01bef | 2012-09-13 15:27:17 +0200 | [diff] [blame] | 553 | Closure start_cb = Bind(&Cellular::StartTermination, |
| 554 | weak_ptr_factory_.GetWeakPtr()); |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 555 | manager()->AddTerminationAction(FriendlyName(), start_cb); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 556 | SetState(kStateConnected); |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 557 | if (!service_) { |
| 558 | LOG(INFO) << "Disconnecting due to no cellular service."; |
| 559 | Disconnect(NULL); |
| 560 | } else if (!capability_->AllowRoaming() && |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 561 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 562 | LOG(INFO) << "Disconnecting due to roaming."; |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 563 | Disconnect(NULL); |
| 564 | } else { |
| 565 | EstablishLink(); |
| 566 | } |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 569 | void Cellular::OnConnectFailed(const Error &error) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 570 | if (service_) |
| 571 | service_->SetFailure(Service::kFailureUnknown); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 572 | } |
| 573 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 574 | void Cellular::Disconnect(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 575 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 576 | if (state_ != kStateConnected && state_ != kStateLinked) { |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 577 | Error::PopulateAndLog( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 578 | error, Error::kNotConnected, "Not connected; request ignored."); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 579 | return; |
| 580 | } |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 581 | explicit_disconnect_ = true; |
Thieu Le | 64b0fe5 | 2012-08-08 14:57:36 -0700 | [diff] [blame] | 582 | ResultCallback cb = Bind(&Cellular::OnDisconnectReply, |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 583 | weak_ptr_factory_.GetWeakPtr()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 584 | capability_->Disconnect(error, cb); |
| 585 | } |
| 586 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 587 | void Cellular::OnDisconnectReply(const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 588 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 589 | explicit_disconnect_ = false; |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 590 | if (error.IsSuccess()) { |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 591 | OnDisconnected(); |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 592 | } else { |
| 593 | metrics()->NotifyCellularDeviceFailure(error); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 594 | OnDisconnectFailed(); |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 595 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 596 | manager()->TerminationActionComplete(FriendlyName()); |
| 597 | manager()->RemoveTerminationAction(FriendlyName()); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 600 | void Cellular::OnDisconnected() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 601 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 602 | if (!DisconnectCleanup()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 603 | LOG(WARNING) << "Disconnect occurred while in state " |
| 604 | << GetStateString(state_); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 605 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | void Cellular::OnDisconnectFailed() { |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 609 | SLOG(Cellular, 2) << __func__; |
| 610 | // If the modem is in the disconnecting state, then |
| 611 | // the disconnect should eventually succeed, so do |
| 612 | // nothing. |
| 613 | if (modem_state_ == kModemStateDisconnecting) { |
| 614 | LOG(WARNING) << "Ignoring failed disconnect while modem is disconnecting."; |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | // OnDisconnectFailed got called because no bearers |
| 619 | // to disconnect were found. Which means that we shouldn't |
| 620 | // really remain in the connected/linked state if we |
| 621 | // are in one of those. |
| 622 | if (!DisconnectCleanup()) { |
| 623 | // otherwise, no-op |
| 624 | LOG(WARNING) << "Ignoring failed disconnect while in state " |
| 625 | << GetStateString(state_); |
| 626 | } |
| 627 | |
| 628 | // TODO(armansito): In either case, shill ends up thinking |
| 629 | // that it's disconnected, while for some reason the underlying |
| 630 | // modem might still actually be connected. In that case the UI |
| 631 | // would be reflecting an incorrect state and a further connection |
| 632 | // request would fail. We should perhaps tear down the modem and |
| 633 | // restart it here. |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 634 | } |
| 635 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 636 | void Cellular::EstablishLink() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 637 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 638 | CHECK_EQ(kStateConnected, state_); |
| 639 | unsigned int flags = 0; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 640 | if (manager()->device_info()->GetFlags(interface_index(), &flags) && |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 641 | (flags & IFF_UP) != 0) { |
| 642 | LinkEvent(flags, IFF_UP); |
| 643 | return; |
| 644 | } |
| 645 | // TODO(petkov): Provide a timeout for a failed link-up request. |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 646 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 647 | |
| 648 | // Set state to associating. |
| 649 | OnConnecting(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void Cellular::LinkEvent(unsigned int flags, unsigned int change) { |
| 653 | Device::LinkEvent(flags, change); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 654 | if (ppp_task_) { |
| 655 | LOG(INFO) << "Ignoring LinkEvent on device with PPP interface."; |
| 656 | return; |
| 657 | } |
| 658 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 659 | if ((flags & IFF_UP) != 0 && state_ == kStateConnected) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 660 | LOG(INFO) << link_name() << " is up."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 661 | SetState(kStateLinked); |
Paul Stewart | 2bf1d35 | 2011-12-06 15:02:55 -0800 | [diff] [blame] | 662 | if (AcquireIPConfig()) { |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 663 | SelectService(service_); |
| 664 | SetServiceState(Service::kStateConfiguring); |
| 665 | } else { |
| 666 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 667 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 668 | } else if ((flags & IFF_UP) == 0 && state_ == kStateLinked) { |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 669 | LOG(INFO) << link_name() << " is down."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 670 | SetState(kStateConnected); |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 671 | DropConnection(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 672 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 675 | void Cellular::OnDBusPropertiesChanged( |
| 676 | const string &interface, |
| 677 | const DBusPropertiesMap &changed_properties, |
| 678 | const vector<string> &invalidated_properties) { |
| 679 | capability_->OnDBusPropertiesChanged(interface, |
| 680 | changed_properties, |
| 681 | invalidated_properties); |
| 682 | } |
| 683 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 684 | void Cellular::set_home_provider(const Operator &oper) { |
| 685 | home_provider_.CopyFrom(oper); |
| 686 | } |
| 687 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 688 | string Cellular::CreateFriendlyServiceName() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 689 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 690 | return capability_.get() ? capability_->CreateFriendlyServiceName() : ""; |
| 691 | } |
| 692 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 693 | void Cellular::OnModemStateChanged(ModemState old_state, |
| 694 | ModemState new_state, |
| 695 | uint32 /*reason*/) { |
| 696 | if (old_state == new_state) { |
| 697 | return; |
| 698 | } |
| 699 | set_modem_state(new_state); |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 700 | if (old_state >= kModemStateRegistered && |
| 701 | new_state < kModemStateRegistered) { |
| 702 | capability_->SetUnregistered(new_state == kModemStateSearching); |
| 703 | HandleNewRegistrationState(); |
| 704 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 705 | switch (new_state) { |
| 706 | case kModemStateDisabled: |
| 707 | SetEnabled(false); |
| 708 | break; |
| 709 | case kModemStateEnabled: |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 710 | // Transition from Disabled to Enabled is handled in the |
| 711 | // DBusPropertiesChanged handler. |
| 712 | SLOG(Cellular, 2) << __func__ << ": Ignoring state change to Enabled"; |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 713 | // Intentionally falls through. |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 714 | case kModemStateSearching: |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 715 | case kModemStateRegistered: |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 716 | // If the modem state changes from Connecting/Connected/Disconnecting |
| 717 | // to Registered/Enabled/Searching, then it's an indication that the |
| 718 | // modem has been disconnected or got disconnected by the network. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 719 | if (old_state == kModemStateConnected || |
| 720 | old_state == kModemStateConnecting || |
| 721 | old_state == kModemStateDisconnecting) |
| 722 | OnDisconnected(); |
| 723 | break; |
| 724 | case kModemStateConnecting: |
| 725 | OnConnecting(); |
| 726 | break; |
| 727 | case kModemStateConnected: |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 728 | if (old_state == kModemStateConnecting) |
| 729 | OnConnected(); |
| 730 | else |
| 731 | SLOG(Cellular, 2) << __func__ << ": Ignoring state change to Connected"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 732 | break; |
| 733 | default: |
| 734 | break; |
| 735 | } |
| 736 | } |
| 737 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 738 | bool Cellular::IsActivating() const { |
| 739 | return capability_->IsActivating(); |
| 740 | } |
| 741 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 742 | bool Cellular::SetAllowRoaming(const bool &value, Error */*error*/) { |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 743 | SLOG(Cellular, 2) << __func__ |
| 744 | << "(" << allow_roaming_ << "->" << value << ")"; |
| 745 | if (allow_roaming_ == value) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 746 | return false; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 747 | } |
| 748 | allow_roaming_ = value; |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 749 | manager()->UpdateDevice(this); |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 750 | |
| 751 | // Use AllowRoaming() instead of allow_roaming_ in order to |
| 752 | // incorporate provider preferences when evaluating if a disconnect |
| 753 | // is required. |
| 754 | if (!capability_->AllowRoaming() && |
| 755 | capability_->GetRoamingStateString() == flimflam::kRoamingStateRoaming) { |
| 756 | Error error; |
| 757 | Disconnect(&error); |
| 758 | } |
| 759 | adaptor()->EmitBoolChanged(flimflam::kCellularAllowRoamingProperty, value); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 760 | return true; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 763 | void Cellular::StartTermination() { |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 764 | LOG(INFO) << __func__; |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 765 | Error error; |
| 766 | Disconnect(&error); |
| 767 | } |
| 768 | |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 769 | bool Cellular::DisconnectCleanup() { |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 770 | bool succeeded = false; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 771 | if (state_ == kStateConnected || state_ == kStateLinked) { |
| 772 | SetState(kStateRegistered); |
| 773 | SetServiceFailureSilent(Service::kFailureUnknown); |
| 774 | DestroyIPConfig(); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 775 | succeeded = true; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 776 | } |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 777 | capability_->DisconnectCleanup(); |
| 778 | return succeeded; |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 779 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 780 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 781 | void Cellular::StartPPP(const string &serial_device) { |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 782 | // Some PPP dongles also expose an Ethernet-like network device, |
| 783 | // using either cdc_ether, or cdc_ncm. dhcpcd may be running on that |
| 784 | // interface. If so, it will eventually time out, and cause us |
| 785 | // terminate the cellular connection. Avoid terminating the connection, |
| 786 | // by cancelling any such DHCP process. |
| 787 | DestroyIPConfig(); |
| 788 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 789 | base::Callback<void(pid_t, int)> death_callback( |
| 790 | Bind(&Cellular::OnPPPDied, weak_ptr_factory_.GetWeakPtr())); |
| 791 | vector<string> args; |
| 792 | map<string, string> environment; |
| 793 | Error error; |
| 794 | if (SLOG_IS_ON(PPP, 5)) { |
| 795 | args.push_back("debug"); |
| 796 | } |
| 797 | args.push_back("nodetach"); |
| 798 | args.push_back("nodefaultroute"); // Don't let pppd muck with routing table. |
| 799 | args.push_back("usepeerdns"); // Request DNS servers. |
| 800 | args.push_back("plugin"); // Goes with next arg. |
| 801 | args.push_back(PPPDevice::kPluginPath); |
| 802 | args.push_back(serial_device); |
| 803 | scoped_ptr<ExternalTask> new_ppp_task( |
| 804 | new ExternalTask(modem_info_->control_interface(), |
| 805 | modem_info_->glib(), |
| 806 | weak_ptr_factory_.GetWeakPtr(), |
| 807 | death_callback)); |
| 808 | if (new_ppp_task->Start( |
| 809 | FilePath(PPPDevice::kDaemonPath), args, environment, &error)) { |
| 810 | LOG(INFO) << "Forked pppd process."; |
| 811 | ppp_task_ = new_ppp_task.Pass(); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | // called by |ppp_task_| |
| 816 | void Cellular::GetLogin(string *user, string *password) { |
| 817 | LOG(INFO) << __func__; |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 818 | if (!service()) { |
| 819 | LOG(ERROR) << __func__ << " with no service "; |
| 820 | return; |
| 821 | } |
| 822 | CHECK(user); |
| 823 | CHECK(password); |
| 824 | *user = service()->ppp_username(); |
| 825 | *password = service()->ppp_password(); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | // Called by |ppp_task_|. |
| 829 | void Cellular::Notify(const string &reason, |
| 830 | const map<string, string> &dict) { |
| 831 | LOG(INFO) << __func__ << " " << reason << " on " << link_name(); |
| 832 | |
| 833 | if (reason != kPPPReasonConnect) { |
| 834 | DCHECK_EQ(kPPPReasonDisconnect, reason); |
| 835 | // DestroyLater, rather than while on stack. |
| 836 | ppp_task_.release()->DestroyLater(modem_info_->dispatcher()); |
| 837 | // For now, assume PPP failures are due to authentication issues. |
| 838 | SetServiceFailure(Service::kFailurePPPAuth); |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | string interface_name = PPPDevice::GetInterfaceName(dict); |
| 843 | DeviceInfo *device_info = modem_info_->manager()->device_info(); |
| 844 | int interface_index = device_info->GetIndex(interface_name); |
| 845 | if (interface_index < 0) { |
| 846 | // TODO(quiche): Consider handling the race when the RTNL notification about |
| 847 | // the new PPP device has not been received yet. crbug.com/246832. |
| 848 | NOTIMPLEMENTED() << ": No device info for " << interface_name << "."; |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | if (!ppp_device_ || ppp_device_->interface_index() != interface_index) { |
| 853 | ppp_device_ = new PPPDevice(modem_info_->control_interface(), |
| 854 | modem_info_->dispatcher(), |
| 855 | modem_info_->metrics(), |
| 856 | modem_info_->manager(), |
| 857 | interface_name, |
| 858 | interface_index); |
| 859 | device_info->RegisterDevice(ppp_device_); |
| 860 | } |
| 861 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 862 | CHECK(service_); |
mukesh agrawal | 5d851b1 | 2013-07-11 14:09:41 -0700 | [diff] [blame] | 863 | // For PPP, we only SelectService on the |ppp_device_|. |
| 864 | CHECK(!selected_service()); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 865 | const bool kBlackholeIPv6 = false; |
| 866 | ppp_device_->SetEnabled(true); |
| 867 | ppp_device_->SelectService(service_); |
| 868 | ppp_device_->UpdateIPConfigFromPPP(dict, kBlackholeIPv6); |
| 869 | } |
| 870 | |
| 871 | void Cellular::OnPPPDied(pid_t pid, int exit) { |
| 872 | LOG(INFO) << __func__ << " on " << link_name(); |
| 873 | Error error; |
| 874 | Disconnect(&error); |
| 875 | } |
| 876 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 877 | } // namespace shill |