ethernet.h revision fc5236388674c3ae04255d98f5a3e93b789be185
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 20#if !defined(DISABLE_WIRED_8021X) 21#include "shill/key_value_store.h" 22#include "shill/supplicant/supplicant_eap_state_handler.h" 23#include "shill/supplicant/supplicant_event_delegate_interface.h" 24#endif // DISABLE_WIRED_8021X 25 26namespace shill { 27 28class ProxyFactory; 29class Sockets; 30class StoreInterface; 31 32#if !defined(DISABLE_WIRED_8021X) 33class CertificateFile; 34class EapListener; 35class EthernetEapProvider; 36class SupplicantEAPStateHandler; 37class SupplicantInterfaceProxyInterface; 38class SupplicantProcessProxyInterface; 39#endif // DISABLE_WIRED_8021X 40 41class Ethernet 42#if !defined(DISABLE_WIRED_8021X) 43 : public Device, public SupplicantEventDelegateInterface { 44#else 45 : public Device { 46#endif // DISABLE_WIRED_8021X 47 public: 48 Ethernet(ControlInterface* control_interface, 49 EventDispatcher* dispatcher, 50 Metrics* metrics, 51 Manager* manager, 52 const std::string& link_name, 53 const std::string& address, 54 int interface_index); 55 ~Ethernet() override; 56 57 void Start(Error* error, 58 const EnabledStateChangedCallback& callback) override; 59 void Stop(Error* error, const EnabledStateChangedCallback& callback) override; 60 void LinkEvent(unsigned int flags, unsigned int change) override; 61 bool Load(StoreInterface* storage) override; 62 bool Save(StoreInterface* storage) override; 63 64 virtual void ConnectTo(EthernetService* service); 65 virtual void DisconnectFrom(EthernetService* service); 66 67#if !defined(DISABLE_WIRED_8021X) 68 // Test to see if conditions are correct for EAP authentication (both 69 // credentials and a remote EAP authenticator is present) and initiate 70 // an authentication if possible. 71 virtual void TryEapAuthentication(); 72 73 // Implementation of SupplicantEventDelegateInterface. These methods 74 // are called by SupplicantInterfaceProxy, in response to events from 75 // wpa_supplicant. 76 void BSSAdded( 77 const std::string& BSS, 78 const KeyValueStore& properties) override; 79 void BSSRemoved(const std::string& BSS) override; 80 void Certification(const KeyValueStore& properties) override; 81 void EAPEvent(const std::string& status, 82 const std::string& parameter) override; 83 void PropertiesChanged(const KeyValueStore& properties) override; 84 void ScanDone(const bool& /*success*/) override; 85 void TDLSDiscoverResponse(const std::string& peer_address) override; 86#endif // DISABLE_WIRED_8021X 87 88 virtual bool link_up() const { return link_up_; } 89 90 private: 91 friend class EthernetTest; 92 friend class EthernetServiceTest; // For weak_ptr_factory_. 93 friend class PPPoEServiceTest; // For weak_ptr_factory_. 94 95#if !defined(DISABLE_WIRED_8021X) 96 // Return a pointer to the EAP provider for Ethernet devices. 97 EthernetEapProvider* GetEapProvider(); 98 99 // Return a reference to the shared service that contains EAP credentials 100 // for Ethernet. 101 ServiceConstRefPtr GetEapService(); 102 103 // Invoked by |eap_listener_| when an EAP authenticator is detected. 104 void OnEapDetected(); 105 106 // Start and stop a supplicant instance on this link. 107 bool StartSupplicant(); 108 void StopSupplicant(); 109 110 // Start the EAP authentication process. 111 bool StartEapAuthentication(); 112 113 // Change our EAP authentication state. 114 void SetIsEapAuthenticated(bool is_eap_authenticated); 115 116 // Callback tasks run as a result of event delegate methods. 117 void CertificationTask(const std::string& subject, uint32_t depth); 118 void EAPEventTask(const std::string& status, const std::string& parameter); 119 void SupplicantStateChangedTask(const std::string& state); 120 121 // Callback task run as a result of TryEapAuthentication(). 122 void TryEapAuthenticationTask(); 123#endif // DISABLE_WIRED_8021X 124 125 // Accessors for the PPoE property. 126 bool GetPPPoEMode(Error* error); 127 bool ConfigurePPPoEMode(const bool& mode, Error* error); 128 void ClearPPPoEMode(Error* error); 129 130 // Helpers for creating services with |this| as their device. 131 EthernetServiceRefPtr CreateEthernetService(); 132 EthernetServiceRefPtr CreatePPPoEService(); 133 134 void SetupWakeOnLan(); 135 136 ControlInterface* control_interface_; 137 138 EthernetServiceRefPtr service_; 139 bool link_up_; 140 141#if !defined(DISABLE_WIRED_8021X) 142 // Track whether we have completed EAP authentication successfully. 143 bool is_eap_authenticated_; 144 145 // Track whether an EAP authenticator has been detected on this link. 146 bool is_eap_detected_; 147 std::unique_ptr<EapListener> eap_listener_; 148 149 // Track the progress of EAP authentication. 150 SupplicantEAPStateHandler eap_state_handler_; 151 152 // Proxy instances used to talk to wpa_supplicant. 153 std::unique_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; 154 std::unique_ptr<SupplicantInterfaceProxyInterface> 155 supplicant_interface_proxy_; 156 std::string supplicant_interface_path_; 157 std::string supplicant_network_path_; 158 159 // Certificate file instance to generate public key data for remote 160 // authentication. 161 CertificateFile certificate_file_; 162 163 // Make sure TryEapAuthenticationTask is only queued for execution once 164 // at a time. 165 base::CancelableClosure try_eap_authentication_callback_; 166#endif // DISABLE_WIRED_8021X 167 168 // Store cached copy of proxy factory singleton for speed/ease of testing. 169 ProxyFactory* proxy_factory_; 170 171 std::unique_ptr<Sockets> sockets_; 172 173 base::WeakPtrFactory<Ethernet> weak_ptr_factory_; 174 175 DISALLOW_COPY_AND_ASSIGN(Ethernet); 176}; 177 178} // namespace shill 179 180#endif // SHILL_ETHERNET_ETHERNET_H_ 181