Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -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 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 5 | #include "shill/ethernet.h" |
| 6 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 7 | #include <netinet/ether.h> |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 8 | #include <linux/if.h> // Needs definitions from netinet/ether.h |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 9 | #include <stdio.h> |
| 10 | #include <string.h> |
| 11 | #include <time.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 12 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 13 | #include <map> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 14 | #include <string> |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 15 | #include <vector> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 16 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 17 | #include <base/bind.h> |
| 18 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 19 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 20 | #include "shill/control_interface.h" |
| 21 | #include "shill/device.h" |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 22 | #include "shill/device_info.h" |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 23 | #include "shill/eap_credentials.h" |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 24 | #include "shill/eap_listener.h" |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 25 | #include "shill/ethernet_eap_provider.h" |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 26 | #include "shill/ethernet_service.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 27 | #include "shill/event_dispatcher.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 28 | #include "shill/logging.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 29 | #include "shill/manager.h" |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 30 | #include "shill/nss.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | #include "shill/profile.h" |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 32 | #include "shill/proxy_factory.h" |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 33 | #include "shill/rtnl_handler.h" |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 34 | #include "shill/supplicant_interface_proxy_interface.h" |
| 35 | #include "shill/supplicant_process_proxy_interface.h" |
| 36 | #include "shill/wpa_supplicant.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 37 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 38 | using std::map; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 39 | using std::string; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 40 | using std::vector; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 41 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 42 | namespace shill { |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 43 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 44 | Ethernet::Ethernet(ControlInterface *control_interface, |
| 45 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 46 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 47 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 48 | const string &link_name, |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 49 | const string &address, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 50 | int interface_index) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 51 | : Device(control_interface, |
| 52 | dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 53 | metrics, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 54 | manager, |
| 55 | link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 56 | address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 57 | interface_index, |
| 58 | Technology::kEthernet), |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 59 | link_up_(false), |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 60 | is_eap_authenticated_(false), |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 61 | is_eap_detected_(false), |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 62 | eap_listener_(new EapListener(dispatcher, interface_index)), |
| 63 | nss_(NSS::GetInstance()), |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 64 | proxy_factory_(ProxyFactory::GetInstance()), |
| 65 | weak_ptr_factory_(this) { |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 66 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 67 | store->RegisterConstBool(kEapAuthenticationCompletedProperty, |
| 68 | &is_eap_authenticated_); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 69 | store->RegisterConstBool(kEapAuthenticatorDetectedProperty, |
| 70 | &is_eap_detected_); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 71 | eap_listener_->set_request_received_callback( |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 72 | base::Bind(&Ethernet::OnEapDetected, weak_ptr_factory_.GetWeakPtr())); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 73 | SLOG(Ethernet, 2) << "Ethernet device " << link_name << " initialized."; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | Ethernet::~Ethernet() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 77 | Stop(NULL, EnabledStateChangedCallback()); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 80 | void Ethernet::Start(Error *error, |
mukesh agrawal | 6813e76 | 2013-07-10 19:05:08 -0700 | [diff] [blame] | 81 | const EnabledStateChangedCallback &/*callback*/) { |
Paul Stewart | 2713d6c | 2011-08-25 15:38:15 -0700 | [diff] [blame] | 82 | service_ = new EthernetService(control_interface(), |
| 83 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 84 | metrics(), |
Paul Stewart | 2713d6c | 2011-08-25 15:38:15 -0700 | [diff] [blame] | 85 | manager(), |
| 86 | this); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 87 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 88 | OnEnabledStateChanged(EnabledStateChangedCallback(), Error()); |
| 89 | if (error) |
| 90 | error->Reset(); // indicate immediate completion |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 91 | } |
| 92 | |
mukesh agrawal | 6813e76 | 2013-07-10 19:05:08 -0700 | [diff] [blame] | 93 | void Ethernet::Stop(Error *error, |
| 94 | const EnabledStateChangedCallback &/*callback*/) { |
Paul Stewart | f2792e8 | 2011-12-12 10:23:11 -0800 | [diff] [blame] | 95 | if (service_) { |
| 96 | manager()->DeregisterService(service_); |
| 97 | service_ = NULL; |
| 98 | } |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 99 | StopSupplicant(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 100 | OnEnabledStateChanged(EnabledStateChangedCallback(), Error()); |
| 101 | if (error) |
| 102 | error->Reset(); // indicate immediate completion |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 105 | void Ethernet::LinkEvent(unsigned int flags, unsigned int change) { |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 106 | Device::LinkEvent(flags, change); |
| 107 | if ((flags & IFF_LOWER_UP) != 0 && !link_up_) { |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 108 | link_up_ = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 109 | if (service_) { |
Christopher Wiley | 2f1bbf0 | 2012-10-25 15:31:13 -0700 | [diff] [blame] | 110 | LOG(INFO) << "Registering " << link_name() << " with manager."; |
| 111 | // Manager will bring up L3 for us. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 112 | manager()->RegisterService(service_); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 113 | } |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 114 | eap_listener_->Start(); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 115 | } else if ((flags & IFF_LOWER_UP) == 0 && link_up_) { |
| 116 | link_up_ = false; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 117 | is_eap_detected_ = false; |
Paul Stewart | 63c9393 | 2012-01-06 11:24:12 -0800 | [diff] [blame] | 118 | DestroyIPConfig(); |
Thieu Le | 9c49707 | 2012-10-31 14:06:20 -0700 | [diff] [blame] | 119 | if (service_) |
| 120 | manager()->DeregisterService(service_); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 121 | SelectService(NULL); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 122 | GetEapProvider()->ClearCredentialChangeCallback(this); |
| 123 | SetIsEapAuthenticated(false); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 124 | StopSupplicant(); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 125 | eap_listener_->Stop(); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Christopher Wiley | 2f1bbf0 | 2012-10-25 15:31:13 -0700 | [diff] [blame] | 129 | void Ethernet::ConnectTo(EthernetService *service) { |
| 130 | CHECK(service == service_.get()) << "Ethernet was asked to connect the " |
| 131 | << "wrong service?"; |
| 132 | if (AcquireIPConfigWithLeaseName(service->GetStorageIdentifier())) { |
| 133 | SelectService(service); |
| 134 | SetServiceState(Service::kStateConfiguring); |
| 135 | } else { |
| 136 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 137 | SetServiceState(Service::kStateFailure); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 138 | DestroyIPConfig(); |
Christopher Wiley | 2f1bbf0 | 2012-10-25 15:31:13 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | void Ethernet::DisconnectFrom(EthernetService *service) { |
| 143 | CHECK(service == service_.get()) << "Ethernet was asked to disconnect the " |
| 144 | << "wrong service?"; |
| 145 | DropConnection(); |
| 146 | } |
| 147 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 148 | void Ethernet::TryEapAuthentication() { |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 149 | try_eap_authentication_callback_.Reset( |
| 150 | Bind(&Ethernet::TryEapAuthenticationTask, |
| 151 | weak_ptr_factory_.GetWeakPtr())); |
| 152 | dispatcher()->PostTask(try_eap_authentication_callback_.callback()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 155 | void Ethernet::BSSAdded(const ::DBus::Path &path, |
| 156 | const map<string, ::DBus::Variant> &properties) { |
| 157 | NOTREACHED() << __func__ << " is not implemented for Ethernet"; |
| 158 | } |
| 159 | |
| 160 | void Ethernet::BSSRemoved(const ::DBus::Path &path) { |
| 161 | NOTREACHED() << __func__ << " is not implemented for Ethernet"; |
| 162 | } |
| 163 | |
| 164 | void Ethernet::Certification(const map<string, ::DBus::Variant> &properties) { |
| 165 | string subject; |
| 166 | uint32 depth; |
| 167 | if (WPASupplicant::ExtractRemoteCertification(properties, &subject, &depth)) { |
| 168 | dispatcher()->PostTask(Bind(&Ethernet::CertificationTask, |
| 169 | weak_ptr_factory_.GetWeakPtr(), |
| 170 | subject, depth)); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void Ethernet::EAPEvent(const string &status, const string ¶meter) { |
| 175 | dispatcher()->PostTask(Bind(&Ethernet::EAPEventTask, |
| 176 | weak_ptr_factory_.GetWeakPtr(), |
| 177 | status, |
| 178 | parameter)); |
| 179 | } |
| 180 | |
| 181 | void Ethernet::PropertiesChanged( |
| 182 | const map<string, ::DBus::Variant> &properties) { |
| 183 | const map<string, ::DBus::Variant>::const_iterator properties_it = |
| 184 | properties.find(WPASupplicant::kInterfacePropertyState); |
| 185 | if (properties_it == properties.end()) { |
| 186 | return; |
| 187 | } |
| 188 | dispatcher()->PostTask(Bind(&Ethernet::SupplicantStateChangedTask, |
| 189 | weak_ptr_factory_.GetWeakPtr(), |
| 190 | properties_it->second.reader().get_string())); |
| 191 | } |
| 192 | |
| 193 | void Ethernet::ScanDone() { |
| 194 | NOTREACHED() << __func__ << " is not implented for Ethernet"; |
| 195 | } |
| 196 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 197 | EthernetEapProvider *Ethernet::GetEapProvider() { |
| 198 | EthernetEapProvider *eap_provider = manager()->ethernet_eap_provider(); |
| 199 | CHECK(eap_provider); |
| 200 | return eap_provider; |
| 201 | } |
| 202 | |
| 203 | ServiceConstRefPtr Ethernet::GetEapService() { |
| 204 | ServiceConstRefPtr eap_service = GetEapProvider()->service(); |
| 205 | CHECK(eap_service); |
| 206 | return eap_service; |
| 207 | } |
| 208 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 209 | void Ethernet::OnEapDetected() { |
| 210 | is_eap_detected_ = true; |
| 211 | eap_listener_->Stop(); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 212 | GetEapProvider()->SetCredentialChangeCallback( |
| 213 | this, |
| 214 | base::Bind(&Ethernet::TryEapAuthentication, |
| 215 | weak_ptr_factory_.GetWeakPtr())); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 216 | TryEapAuthentication(); |
| 217 | } |
| 218 | |
| 219 | bool Ethernet::StartSupplicant() { |
| 220 | if (supplicant_process_proxy_.get()) { |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | supplicant_process_proxy_.reset( |
| 225 | proxy_factory_->CreateSupplicantProcessProxy( |
| 226 | WPASupplicant::kDBusPath, WPASupplicant::kDBusAddr)); |
| 227 | ::DBus::Path interface_path; |
| 228 | try { |
| 229 | map<string, DBus::Variant> create_interface_args; |
| 230 | create_interface_args[WPASupplicant::kInterfacePropertyName].writer(). |
| 231 | append_string(link_name().c_str()); |
| 232 | create_interface_args[WPASupplicant::kInterfacePropertyDriver].writer(). |
| 233 | append_string(WPASupplicant::kDriverWired); |
| 234 | create_interface_args[ |
| 235 | WPASupplicant::kInterfacePropertyConfigFile].writer(). |
| 236 | append_string(WPASupplicant::kSupplicantConfPath); |
| 237 | interface_path = |
| 238 | supplicant_process_proxy_->CreateInterface(create_interface_args); |
| 239 | } catch (const DBus::Error &e) { // NOLINT |
| 240 | if (!strcmp(e.name(), WPASupplicant::kErrorInterfaceExists)) { |
| 241 | interface_path = supplicant_process_proxy_->GetInterface(link_name()); |
| 242 | } else { |
| 243 | LOG(ERROR) << __func__ << ": Failed to create interface with supplicant."; |
| 244 | StopSupplicant(); |
| 245 | return false; |
| 246 | } |
| 247 | } |
| 248 | supplicant_interface_proxy_.reset( |
| 249 | proxy_factory_->CreateSupplicantInterfaceProxy( |
| 250 | this, interface_path, WPASupplicant::kDBusAddr)); |
| 251 | supplicant_interface_path_ = interface_path; |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | bool Ethernet::StartEapAuthentication() { |
| 256 | map<string, DBus::Variant> params; |
| 257 | vector<char> nss_identifier(link_name().begin(), link_name().end()); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 258 | GetEapService()->eap()->PopulateSupplicantProperties( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 259 | &certificate_file_, nss_, nss_identifier, ¶ms); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 260 | params[WPASupplicant::kNetworkPropertyEapKeyManagement].writer(). |
| 261 | append_string(WPASupplicant::kKeyManagementIeee8021X); |
| 262 | params[WPASupplicant::kNetworkPropertyEapolFlags].writer(). |
| 263 | append_uint32(0); |
| 264 | params[WPASupplicant::kNetworkPropertyScanSSID].writer(). |
| 265 | append_uint32(0); |
| 266 | service_->ClearEAPCertification(); |
| 267 | eap_state_handler_.Reset(); |
| 268 | |
| 269 | try { |
| 270 | if (!supplicant_network_path_.empty()) { |
| 271 | supplicant_interface_proxy_->RemoveNetwork(supplicant_network_path_); |
| 272 | } |
| 273 | supplicant_network_path_ = supplicant_interface_proxy_->AddNetwork(params); |
| 274 | CHECK(!supplicant_network_path_.empty()); |
| 275 | } catch (const DBus::Error &e) { // NOLINT |
| 276 | LOG(ERROR) << "exception while adding network: " << e.what(); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | supplicant_interface_proxy_->SelectNetwork(supplicant_network_path_); |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 281 | supplicant_interface_proxy_->EAPLogon(); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 282 | return true; |
| 283 | } |
| 284 | |
| 285 | void Ethernet::StopSupplicant() { |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 286 | if (supplicant_interface_proxy_.get()) { |
| 287 | supplicant_interface_proxy_->EAPLogoff(); |
| 288 | } |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 289 | supplicant_interface_proxy_.reset(); |
| 290 | if (!supplicant_interface_path_.empty() && supplicant_process_proxy_.get()) { |
| 291 | try { |
| 292 | supplicant_process_proxy_->RemoveInterface( |
| 293 | ::DBus::Path(supplicant_interface_path_)); |
| 294 | } catch (const DBus::Error &e) { // NOLINT |
| 295 | LOG(ERROR) << __func__ << ": Failed to remove interface from supplicant."; |
| 296 | } |
| 297 | } |
| 298 | supplicant_network_path_ = ""; |
| 299 | supplicant_interface_path_ = ""; |
| 300 | supplicant_process_proxy_.reset(); |
| 301 | SetIsEapAuthenticated(false); |
| 302 | } |
| 303 | |
| 304 | void Ethernet::SetIsEapAuthenticated(bool is_eap_authenticated) { |
| 305 | if (is_eap_authenticated == is_eap_authenticated_) { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | // If our EAP authentication state changes, we have now joined a different |
| 310 | // network. Restart the DHCP process and any other connection state. |
| 311 | DisconnectFrom(service_); |
| 312 | if (service_ && link_up_) { |
| 313 | ConnectTo(service_); |
| 314 | } |
| 315 | is_eap_authenticated_ = is_eap_authenticated; |
| 316 | adaptor()->EmitBoolChanged(kEapAuthenticationCompletedProperty, |
| 317 | is_eap_authenticated_); |
| 318 | } |
| 319 | |
| 320 | void Ethernet::CertificationTask(const string &subject, uint32 depth) { |
| 321 | if (!service_) { |
| 322 | LOG(ERROR) << "Ethernet " << link_name() << " " << __func__ |
| 323 | << " with no service."; |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | service_->AddEAPCertification(subject, depth); |
| 328 | } |
| 329 | |
| 330 | void Ethernet::EAPEventTask(const string &status, const string ¶meter) { |
| 331 | LOG(INFO) << "In " << __func__ << " with status " << status |
| 332 | << ", parameter " << parameter; |
| 333 | Service::ConnectFailure failure = Service::kFailureUnknown; |
| 334 | if (eap_state_handler_.ParseStatus(status, parameter, &failure)) { |
| 335 | LOG(INFO) << "EAP authentication succeeded!"; |
| 336 | SetIsEapAuthenticated(true); |
| 337 | } else if (failure != Service::Service::kFailureUnknown) { |
| 338 | LOG(INFO) << "EAP authentication failed!"; |
| 339 | SetIsEapAuthenticated(false); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | void Ethernet::SupplicantStateChangedTask(const string &state) { |
| 344 | LOG(INFO) << "Supplicant state changed to " << state; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 347 | void Ethernet::TryEapAuthenticationTask() { |
| 348 | if (!service_) { |
| 349 | LOG(INFO) << "Service is missing; not doing EAP authentication."; |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | if (!GetEapService()->Is8021xConnectable()) { |
| 354 | if (is_eap_authenticated_) { |
| 355 | LOG(INFO) << "EAP Service lost 802.1X credentials; " |
| 356 | << "terminating EAP authentication."; |
| 357 | } else { |
| 358 | LOG(INFO) << "EAP Service lacks 802.1X credentials; " |
| 359 | << "not doing EAP authentication."; |
| 360 | } |
| 361 | StopSupplicant(); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | if (!is_eap_detected_) { |
| 366 | LOG(WARNING) << "EAP authenticator not detected; " |
| 367 | << "not doing EAP authentication."; |
| 368 | return; |
| 369 | } |
| 370 | if (!StartSupplicant()) { |
| 371 | LOG(ERROR) << "Failed to start supplicant."; |
| 372 | return; |
| 373 | } |
| 374 | StartEapAuthentication(); |
| 375 | } |
| 376 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 377 | } // namespace shill |