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