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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_ETHERNET_H_ |
| 6 | #define SHILL_ETHERNET_H_ |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 7 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 8 | #include <map> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 11 | #include <base/cancelable_callback.h> |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 12 | #include <base/memory/scoped_ptr.h> |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 13 | #include <base/memory/weak_ptr.h> |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 14 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 15 | #include "shill/certificate_file.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 16 | #include "shill/device.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 17 | #include "shill/event_dispatcher.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 19 | #include "shill/supplicant_eap_state_handler.h" |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 20 | #include "shill/supplicant_event_delegate_interface.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 21 | |
| 22 | namespace shill { |
| 23 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 24 | class CertificateFile; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 25 | class EapListener; |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 26 | class EthernetEapProvider; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 27 | class ProxyFactory; |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 28 | class Sockets; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 29 | class SupplicantEAPStateHandler; |
| 30 | class SupplicantInterfaceProxyInterface; |
| 31 | class SupplicantProcessProxyInterface; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 32 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 33 | class Ethernet : public Device, public SupplicantEventDelegateInterface { |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 34 | public: |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 35 | Ethernet(ControlInterface *control_interface, |
| 36 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 37 | Metrics *metrics, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 38 | Manager *manager, |
| 39 | const std::string& link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 40 | const std::string &address, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 41 | int interface_index); |
Ben Chan | 5ea763b | 2014-08-13 11:07:54 -0700 | [diff] [blame] | 42 | ~Ethernet() override; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 43 | |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 44 | virtual void Start(Error *error, const EnabledStateChangedCallback &callback); |
| 45 | virtual void Stop(Error *error, const EnabledStateChangedCallback &callback); |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 46 | virtual void LinkEvent(unsigned int flags, unsigned int change); |
Christopher Wiley | 2f1bbf0 | 2012-10-25 15:31:13 -0700 | [diff] [blame] | 47 | virtual void ConnectTo(EthernetService *service); |
| 48 | virtual void DisconnectFrom(EthernetService *service); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 49 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 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 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 70 | private: |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 71 | friend class EthernetTest; |
| 72 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 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 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 80 | // Invoked by |eap_listener_| when an EAP authenticator is detected. |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 81 | void OnEapDetected(); |
| 82 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 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. |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 94 | void CertificationTask(const std::string &subject, uint32_t depth); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 95 | void EAPEventTask(const std::string &status, const std::string ¶meter); |
| 96 | void SupplicantStateChangedTask(const std::string &state); |
| 97 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 98 | // Callback task run as a result of TryEapAuthentication(). |
| 99 | void TryEapAuthenticationTask(); |
| 100 | |
Paul Stewart | 8e9e41c | 2014-08-07 14:55:47 -0700 | [diff] [blame] | 101 | void SetupWakeOnLan(); |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 102 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 103 | EthernetServiceRefPtr service_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 104 | bool link_up_; |
| 105 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 106 | // Track whether we have completed EAP authentication successfully. |
| 107 | bool is_eap_authenticated_; |
| 108 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 109 | // Track whether an EAP authenticator has been detected on this link. |
| 110 | bool is_eap_detected_; |
| 111 | scoped_ptr<EapListener> eap_listener_; |
| 112 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 113 | // Track the progress of EAP authentication. |
| 114 | SupplicantEAPStateHandler eap_state_handler_; |
| 115 | |
| 116 | // Proxy instances used to talk to wpa_supplicant. |
| 117 | scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; |
| 118 | scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_; |
| 119 | std::string supplicant_interface_path_; |
| 120 | std::string supplicant_network_path_; |
| 121 | |
Paul Stewart | c350e68 | 2014-06-19 15:44:30 -0700 | [diff] [blame] | 122 | // Certificate file instance to generate public key data for remote |
| 123 | // authentication. |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 124 | CertificateFile certificate_file_; |
| 125 | |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 126 | // Make sure TryEapAuthenticationTask is only queued for execution once |
| 127 | // at a time. |
| 128 | base::CancelableClosure try_eap_authentication_callback_; |
| 129 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 130 | // Store cached copy of proxy factory singleton for speed/ease of testing. |
| 131 | ProxyFactory *proxy_factory_; |
| 132 | |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 133 | scoped_ptr<Sockets> sockets_; |
| 134 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 135 | base::WeakPtrFactory<Ethernet> weak_ptr_factory_; |
| 136 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 137 | DISALLOW_COPY_AND_ASSIGN(Ethernet); |
| 138 | }; |
| 139 | |
| 140 | } // namespace shill |
| 141 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 142 | #endif // SHILL_ETHERNET_H_ |