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