Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 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/wimax.h" |
| 6 | |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 7 | #include <base/bind.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 8 | #include <base/strings/string_util.h> |
| 9 | #include <base/strings/stringprintf.h> |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 10 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame] | 11 | #include "shill/key_value_store.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 12 | #include "shill/logging.h" |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 13 | #include "shill/manager.h" |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 14 | #include "shill/proxy_factory.h" |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 15 | #include "shill/wimax_device_proxy_interface.h" |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 16 | #include "shill/wimax_service.h" |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 17 | |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 18 | using base::Bind; |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 19 | using std::set; |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 20 | using std::string; |
| 21 | |
| 22 | namespace shill { |
| 23 | |
Ben Chan | 92ca56c | 2013-08-16 17:01:11 -0700 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | const char *DeviceStatusToString(wimax_manager::DeviceStatus status) { |
| 27 | switch (status) { |
| 28 | case wimax_manager::kDeviceStatusUninitialized: |
| 29 | return "Uninitialized"; |
| 30 | case wimax_manager::kDeviceStatusDisabled: |
| 31 | return "Disabled"; |
| 32 | case wimax_manager::kDeviceStatusReady: |
| 33 | return "Ready"; |
| 34 | case wimax_manager::kDeviceStatusScanning: |
| 35 | return "Scanning"; |
| 36 | case wimax_manager::kDeviceStatusConnecting: |
| 37 | return "Connecting"; |
| 38 | case wimax_manager::kDeviceStatusConnected: |
| 39 | return "Connected"; |
| 40 | default: |
| 41 | return "Unknown"; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } // namespace |
| 46 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 47 | const int WiMax::kDefaultConnectTimeoutSeconds = 60; |
| 48 | const int WiMax::kDefaultRPCTimeoutSeconds = 30; |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 49 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 50 | WiMax::WiMax(ControlInterface *control, |
| 51 | EventDispatcher *dispatcher, |
| 52 | Metrics *metrics, |
| 53 | Manager *manager, |
| 54 | const string &link_name, |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 55 | const string &address, |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 56 | int interface_index, |
| 57 | const RpcIdentifier &path) |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 58 | : Device(control, dispatcher, metrics, manager, link_name, address, |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 59 | interface_index, Technology::kWiMax), |
| 60 | path_(path), |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 61 | weak_ptr_factory_(this), |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 62 | scanning_(false), |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 63 | status_(wimax_manager::kDeviceStatusUninitialized), |
| 64 | proxy_factory_(ProxyFactory::GetInstance()), |
| 65 | connect_timeout_seconds_(kDefaultConnectTimeoutSeconds) { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 66 | LOG(INFO) << "WiMAX device created: " << link_name << " @ " << path; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 67 | PropertyStore *store = mutable_store(); |
Ben Chan | 4276cca | 2013-09-20 10:07:04 -0700 | [diff] [blame] | 68 | store->RegisterConstBool(kScanningProperty, &scanning_); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 69 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 70 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 71 | WiMax::~WiMax() { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 72 | LOG(INFO) << "WiMAX device destroyed: " << link_name(); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 73 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 74 | |
| 75 | void WiMax::Start(Error *error, const EnabledStateChangedCallback &callback) { |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 76 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 77 | scanning_ = false; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 78 | proxy_.reset(proxy_factory_->CreateWiMaxDeviceProxy(path_)); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 79 | proxy_->set_networks_changed_callback( |
| 80 | Bind(&WiMax::OnNetworksChanged, Unretained(this))); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 81 | proxy_->set_status_changed_callback( |
| 82 | Bind(&WiMax::OnStatusChanged, Unretained(this))); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 83 | proxy_->Enable( |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 84 | error, Bind(&WiMax::OnEnableComplete, this, callback), |
| 85 | kDefaultRPCTimeoutSeconds * 1000); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void WiMax::Stop(Error *error, const EnabledStateChangedCallback &callback) { |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 89 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 90 | StopConnectTimeout(); |
| 91 | if (pending_service_) { |
| 92 | pending_service_->SetState(Service::kStateIdle); |
| 93 | pending_service_ = NULL; |
| 94 | } |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 95 | if (selected_service()) { |
| 96 | Error error; |
| 97 | DisconnectFrom(selected_service(), &error); |
| 98 | } |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 99 | scanning_ = false; |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 100 | networks_.clear(); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 101 | manager()->wimax_provider()->OnNetworksChanged(); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 102 | if (proxy_.get()) { |
| 103 | proxy_->Disable( |
| 104 | error, Bind(&WiMax::OnDisableComplete, this, callback), |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 105 | kDefaultRPCTimeoutSeconds * 1000); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 106 | } else { |
| 107 | OnDisableComplete(callback, Error()); |
| 108 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Wade Guthrie | 4823f4f | 2013-07-25 10:03:03 -0700 | [diff] [blame] | 111 | void WiMax::Scan(ScanType /*scan_type*/, Error *error, |
| 112 | const string &/*reason*/) { |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 113 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 114 | if (scanning_) { |
| 115 | Error::PopulateAndLog( |
| 116 | error, Error::kInProgress, "Scan already in progress."); |
| 117 | return; |
| 118 | } |
| 119 | scanning_ = true; |
| 120 | proxy_->ScanNetworks( |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 121 | error, Bind(&WiMax::OnScanNetworksComplete, this), |
| 122 | kDefaultRPCTimeoutSeconds * 1000); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 123 | if (error->IsFailure()) { |
| 124 | OnScanNetworksComplete(*error); |
| 125 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 128 | void WiMax::ConnectTo(const WiMaxServiceRefPtr &service, Error *error) { |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 129 | SLOG(WiMax, 2) << __func__ << "(" << service->GetStorageIdentifier() << ")"; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 130 | if (pending_service_) { |
| 131 | Error::PopulateAndLog( |
| 132 | error, Error::kInProgress, |
| 133 | base::StringPrintf( |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 134 | "Pending connect to service %s, ignoring connect request to %s.", |
| 135 | pending_service_->unique_name().c_str(), |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 136 | service->GetStorageIdentifier().c_str())); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | service->SetState(Service::kStateAssociating); |
| 140 | pending_service_ = service; |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 141 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 142 | // We use the RPC device status to determine the outcome of the connect |
| 143 | // operation by listening for status updates in OnStatusChanged. A transition |
| 144 | // to Connected means success. A transition to Connecting and then to a status |
| 145 | // different than Connected means failure. Also, schedule a connect timeout to |
| 146 | // guard against the RPC device never transitioning to a Connecting or a |
| 147 | // Connected state. |
| 148 | status_ = wimax_manager::kDeviceStatusUninitialized; |
| 149 | StartConnectTimeout(); |
| 150 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame] | 151 | KeyValueStore parameters; |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 152 | service->GetConnectParameters(¶meters); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 153 | proxy_->Connect( |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 154 | service->GetNetworkObjectPath(), parameters, |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 155 | error, Bind(&WiMax::OnConnectComplete, this), |
| 156 | kDefaultRPCTimeoutSeconds * 1000); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 157 | if (error->IsFailure()) { |
| 158 | OnConnectComplete(*error); |
| 159 | } |
| 160 | } |
| 161 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 162 | void WiMax::DisconnectFrom(const ServiceRefPtr &service, Error *error) { |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 163 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 164 | if (pending_service_) { |
| 165 | Error::PopulateAndLog( |
| 166 | error, Error::kInProgress, |
| 167 | base::StringPrintf( |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 168 | "Pending connect to service %s, " |
| 169 | "ignoring disconnect request from %s.", |
| 170 | pending_service_->unique_name().c_str(), |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 171 | service->GetStorageIdentifier().c_str())); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | if (selected_service() && service != selected_service()) { |
| 175 | Error::PopulateAndLog( |
| 176 | error, Error::kNotConnected, |
| 177 | base::StringPrintf( |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 178 | "Current service is %s, ignoring disconnect request from %s.", |
| 179 | selected_service()->unique_name().c_str(), |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 180 | service->GetStorageIdentifier().c_str())); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 181 | return; |
| 182 | } |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 183 | DropConnection(); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 184 | proxy_->Disconnect( |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 185 | error, Bind(&WiMax::OnDisconnectComplete, this), |
| 186 | kDefaultRPCTimeoutSeconds * 1000); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 187 | if (error->IsFailure()) { |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 188 | OnDisconnectComplete(*error); |
| 189 | } |
| 190 | } |
| 191 | |
Darin Petkov | 6b9b2e1 | 2012-07-10 15:51:42 +0200 | [diff] [blame] | 192 | bool WiMax::IsIdle() const { |
| 193 | return !pending_service_ && !selected_service(); |
| 194 | } |
| 195 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 196 | void WiMax::OnServiceStopped(const WiMaxServiceRefPtr &service) { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 197 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 198 | if (service == selected_service()) { |
| 199 | DropConnection(); |
| 200 | } |
Darin Petkov | c1e5273 | 2012-05-25 15:23:45 +0200 | [diff] [blame] | 201 | if (service == pending_service_) { |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 202 | pending_service_ = NULL; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 206 | void WiMax::OnDeviceVanished() { |
| 207 | LOG(INFO) << "WiMAX device vanished: " << link_name(); |
| 208 | proxy_.reset(); |
| 209 | DropService(Service::kStateIdle); |
| 210 | // Disable the device. This will also clear any relevant properties such as |
| 211 | // the live network set. |
| 212 | SetEnabled(false); |
| 213 | } |
| 214 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 215 | void WiMax::OnScanNetworksComplete(const Error &/*error*/) { |
| 216 | SLOG(WiMax, 2) << __func__; |
| 217 | scanning_ = false; |
| 218 | // The networks are updated when the NetworksChanged signal is received. |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void WiMax::OnConnectComplete(const Error &error) { |
| 222 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 223 | if (error.IsSuccess()) { |
| 224 | // Nothing to do -- the connection process is resumed on the StatusChanged |
| 225 | // signal. |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 226 | return; |
| 227 | } |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 228 | DropService(Service::kStateFailure); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 231 | void WiMax::OnDisconnectComplete(const Error &/*error*/) { |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 232 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void WiMax::OnEnableComplete(const EnabledStateChangedCallback &callback, |
| 236 | const Error &error) { |
| 237 | SLOG(WiMax, 2) << __func__; |
| 238 | if (error.IsFailure()) { |
| 239 | proxy_.reset(); |
| 240 | } else { |
Darin Petkov | 59f2d69 | 2012-06-07 15:57:46 +0200 | [diff] [blame] | 241 | LOG(INFO) << "WiMAX device " << link_name() << " enabled."; |
| 242 | // Updates the live networks based on the current WiMaxManager.Device |
| 243 | // networks. The RPC device will signal when the network set changes. |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 244 | Error e; |
Darin Petkov | 59f2d69 | 2012-06-07 15:57:46 +0200 | [diff] [blame] | 245 | OnNetworksChanged(proxy_->Networks(&e)); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 246 | } |
| 247 | callback.Run(error); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void WiMax::OnDisableComplete(const EnabledStateChangedCallback &callback, |
| 251 | const Error &error) { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 252 | LOG(INFO) << "WiMAX device " << link_name() << " disabled."; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 253 | proxy_.reset(); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 254 | callback.Run(error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 257 | void WiMax::OnNetworksChanged(const RpcIdentifiers &networks) { |
| 258 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 259 | networks_.clear(); |
| 260 | networks_.insert(networks.begin(), networks.end()); |
| 261 | manager()->wimax_provider()->OnNetworksChanged(); |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 264 | void WiMax::OnStatusChanged(wimax_manager::DeviceStatus status) { |
Ben Chan | 92ca56c | 2013-08-16 17:01:11 -0700 | [diff] [blame] | 265 | SLOG(WiMax, 2) << "WiMAX device " << link_name() |
| 266 | << " status: " << DeviceStatusToString(status); |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 267 | wimax_manager::DeviceStatus old_status = status_; |
| 268 | status_ = status; |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 269 | switch (status) { |
| 270 | case wimax_manager::kDeviceStatusConnected: |
| 271 | if (!pending_service_) { |
| 272 | LOG(WARNING) << "Unexpected status change; ignored."; |
| 273 | return; |
| 274 | } |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 275 | // Stops the connect timeout -- the DHCP provider has a separate timeout. |
| 276 | StopConnectTimeout(); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 277 | if (AcquireIPConfig()) { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 278 | LOG(INFO) << "WiMAX device " << link_name() << " connected to " |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 279 | << pending_service_->GetStorageIdentifier(); |
| 280 | SelectService(pending_service_); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 281 | pending_service_ = NULL; |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 282 | SetServiceState(Service::kStateConfiguring); |
| 283 | } else { |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 284 | DropService(Service::kStateFailure); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 285 | } |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 286 | break; |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 287 | case wimax_manager::kDeviceStatusConnecting: |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 288 | LOG(INFO) << "WiMAX device " << link_name() << " connecting..."; |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 289 | // Nothing to do. |
| 290 | break; |
| 291 | default: |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 292 | // We may receive a queued up status update (e.g., to Scanning) before |
| 293 | // receiving the status update to Connecting, so be careful to fail the |
| 294 | // service only on the right status transition. |
| 295 | if (old_status == wimax_manager::kDeviceStatusConnecting || |
| 296 | old_status == wimax_manager::kDeviceStatusConnected) { |
| 297 | LOG(INFO) << "WiMAX device " << link_name() |
Ben Chan | 92ca56c | 2013-08-16 17:01:11 -0700 | [diff] [blame] | 298 | << " status: " << DeviceStatusToString(old_status) |
| 299 | << " -> " << DeviceStatusToString(status); |
Ben Chan | e494e31 | 2013-08-23 12:56:05 -0700 | [diff] [blame] | 300 | // TODO(benchan): Investigate a method to determine if the connection |
| 301 | // failure is due to incorrect EAP credentials and indicate that via |
| 302 | // Service::kFailureBadPassphrase (crosbug.com/p/16324). |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 303 | DropService(Service::kStateFailure); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 304 | } |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 309 | void WiMax::DropService(Service::ConnectState state) { |
| 310 | SLOG(WiMax, 2) << __func__ |
| 311 | << "(" << Service::ConnectStateToString(state) << ")"; |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 312 | StopConnectTimeout(); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 313 | if (pending_service_) { |
| 314 | LOG(WARNING) << "Unable to initiate connection to: " |
| 315 | << pending_service_->GetStorageIdentifier(); |
| 316 | pending_service_->SetState(state); |
| 317 | pending_service_ = NULL; |
| 318 | } |
| 319 | if (selected_service()) { |
| 320 | LOG(WARNING) << "Service disconnected: " |
| 321 | << selected_service()->GetStorageIdentifier(); |
| 322 | selected_service()->SetState(state); |
| 323 | DropConnection(); |
| 324 | } |
| 325 | } |
| 326 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 327 | void WiMax::StartConnectTimeout() { |
| 328 | SLOG(WiMax, 2) << __func__; |
| 329 | if (IsConnectTimeoutStarted()) { |
| 330 | return; |
| 331 | } |
| 332 | connect_timeout_callback_.Reset( |
| 333 | Bind(&WiMax::OnConnectTimeout, weak_ptr_factory_.GetWeakPtr())); |
| 334 | dispatcher()->PostDelayedTask( |
| 335 | connect_timeout_callback_.callback(), connect_timeout_seconds_ * 1000); |
| 336 | } |
| 337 | |
| 338 | void WiMax::StopConnectTimeout() { |
| 339 | SLOG(WiMax, 2) << __func__; |
| 340 | connect_timeout_callback_.Cancel(); |
| 341 | } |
| 342 | |
| 343 | bool WiMax::IsConnectTimeoutStarted() const { |
| 344 | return !connect_timeout_callback_.IsCancelled(); |
| 345 | } |
| 346 | |
| 347 | void WiMax::OnConnectTimeout() { |
| 348 | LOG(ERROR) << "WiMAX device " << link_name() << ": connect timeout."; |
| 349 | StopConnectTimeout(); |
| 350 | DropService(Service::kStateFailure); |
| 351 | } |
| 352 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 353 | } // namespace shill |