ethernet.h revision 87602518c59af2f9e8288d81a1f877dd80f24433
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#ifndef SHILL_ETHERNET_ETHERNET_H_ 6#define SHILL_ETHERNET_ETHERNET_H_ 7 8#include <map> 9#include <memory> 10#include <string> 11 12#include <base/cancelable_callback.h> 13#include <base/memory/weak_ptr.h> 14 15#include "shill/certificate_file.h" 16#include "shill/device.h" 17#include "shill/event_dispatcher.h" 18#include "shill/refptr_types.h" 19#include "shill/supplicant_eap_state_handler.h" 20#include "shill/supplicant_event_delegate_interface.h" 21 22namespace shill { 23 24class CertificateFile; 25class EapListener; 26class EthernetEapProvider; 27class ProxyFactory; 28class Sockets; 29class SupplicantEAPStateHandler; 30class SupplicantInterfaceProxyInterface; 31class SupplicantProcessProxyInterface; 32 33class Ethernet : public Device, public SupplicantEventDelegateInterface { 34 public: 35 Ethernet(ControlInterface *control_interface, 36 EventDispatcher *dispatcher, 37 Metrics *metrics, 38 Manager *manager, 39 const std::string& link_name, 40 const std::string &address, 41 int interface_index); 42 ~Ethernet() override; 43 44 virtual void Start(Error *error, const EnabledStateChangedCallback &callback); 45 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback); 46 virtual void LinkEvent(unsigned int flags, unsigned int change); 47 virtual void ConnectTo(EthernetService *service); 48 virtual void DisconnectFrom(EthernetService *service); 49 50 // Test to see if conditions are correct for EAP authentication (both 51 // credentials and a remote EAP authenticator is present) and initiate 52 // an authentication if possible. 53 virtual void TryEapAuthentication(); 54 55 // Implementation of SupplicantEventDelegateInterface. These methods 56 // are called by SupplicantInterfaceProxy, in response to events from 57 // wpa_supplicant. 58 virtual void BSSAdded( 59 const ::DBus::Path &BSS, 60 const std::map<std::string, ::DBus::Variant> &properties); 61 virtual void BSSRemoved(const ::DBus::Path &BSS); 62 virtual void Certification( 63 const std::map<std::string, ::DBus::Variant> &properties); 64 virtual void EAPEvent( 65 const std::string &status, const std::string ¶meter); 66 virtual void PropertiesChanged( 67 const std::map<std::string, ::DBus::Variant> &properties); 68 virtual void ScanDone(); 69 70 private: 71 friend class EthernetTest; 72 73 // Return a pointer to the EAP provider for Ethernet devices. 74 EthernetEapProvider *GetEapProvider(); 75 76 // Return a reference to the shared service that contains EAP credentials 77 // for Ethernet. 78 ServiceConstRefPtr GetEapService(); 79 80 // Invoked by |eap_listener_| when an EAP authenticator is detected. 81 void OnEapDetected(); 82 83 // Start and stop a supplicant instance on this link. 84 bool StartSupplicant(); 85 void StopSupplicant(); 86 87 // Start the EAP authentication process. 88 bool StartEapAuthentication(); 89 90 // Change our EAP authentication state. 91 void SetIsEapAuthenticated(bool is_eap_authenticated); 92 93 // Callback tasks run as a result of event delegate methods. 94 void CertificationTask(const std::string &subject, uint32_t depth); 95 void EAPEventTask(const std::string &status, const std::string ¶meter); 96 void SupplicantStateChangedTask(const std::string &state); 97 98 // Callback task run as a result of TryEapAuthentication(). 99 void TryEapAuthenticationTask(); 100 101 void SetupWakeOnLan(); 102 103 EthernetServiceRefPtr service_; 104 bool link_up_; 105 106 // Track whether we have completed EAP authentication successfully. 107 bool is_eap_authenticated_; 108 109 // Track whether an EAP authenticator has been detected on this link. 110 bool is_eap_detected_; 111 std::unique_ptr<EapListener> eap_listener_; 112 113 // Track the progress of EAP authentication. 114 SupplicantEAPStateHandler eap_state_handler_; 115 116 // Proxy instances used to talk to wpa_supplicant. 117 std::unique_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; 118 std::unique_ptr<SupplicantInterfaceProxyInterface> 119 supplicant_interface_proxy_; 120 std::string supplicant_interface_path_; 121 std::string supplicant_network_path_; 122 123 // Certificate file instance to generate public key data for remote 124 // authentication. 125 CertificateFile certificate_file_; 126 127 // Make sure TryEapAuthenticationTask is only queued for execution once 128 // at a time. 129 base::CancelableClosure try_eap_authentication_callback_; 130 131 // Store cached copy of proxy factory singleton for speed/ease of testing. 132 ProxyFactory *proxy_factory_; 133 134 std::unique_ptr<Sockets> sockets_; 135 136 base::WeakPtrFactory<Ethernet> weak_ptr_factory_; 137 138 DISALLOW_COPY_AND_ASSIGN(Ethernet); 139}; 140 141} // namespace shill 142 143#endif // SHILL_ETHERNET_ETHERNET_H_ 144