blob: 7ed4e661e89a2486ff50351de2149f159fc6f666 [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewartb50f0b92011-05-16 16:31:42 -07002// 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 Masone46eaaf52011-05-24 13:08:30 -07008#include <string>
9
Paul Stewart35eff132013-04-12 12:08:40 -070010#include <base/cancelable_callback.h>
Paul Stewartced3ad72013-04-03 13:39:25 -070011#include <base/memory/scoped_ptr.h>
Paul Stewart9413bcc2013-04-04 16:12:43 -070012#include <base/memory/weak_ptr.h>
Paul Stewartced3ad72013-04-03 13:39:25 -070013
Paul Stewart9413bcc2013-04-04 16:12:43 -070014#include "shill/certificate_file.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070015#include "shill/device.h"
Paul Stewart9413bcc2013-04-04 16:12:43 -070016#include "shill/supplicant_eap_state_handler.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070017#include "shill/event_dispatcher.h"
Chris Masone2b105542011-06-22 10:58:09 -070018#include "shill/refptr_types.h"
Paul Stewart9413bcc2013-04-04 16:12:43 -070019#include "shill/supplicant_event_delegate_interface.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070020
21namespace shill {
22
Paul Stewart9413bcc2013-04-04 16:12:43 -070023class CertificateFile;
Paul Stewartced3ad72013-04-03 13:39:25 -070024class EapListener;
Paul Stewart35eff132013-04-12 12:08:40 -070025class EthernetEapProvider;
Paul Stewart9413bcc2013-04-04 16:12:43 -070026class NSS;
27class ProxyFactory;
28class SupplicantEAPStateHandler;
29class SupplicantInterfaceProxyInterface;
30class SupplicantProcessProxyInterface;
Paul Stewartced3ad72013-04-03 13:39:25 -070031
Paul Stewart9413bcc2013-04-04 16:12:43 -070032class Ethernet : public Device, public SupplicantEventDelegateInterface {
Paul Stewartb50f0b92011-05-16 16:31:42 -070033 public:
Darin Petkovafa6fc42011-06-21 16:21:08 -070034 Ethernet(ControlInterface *control_interface,
35 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080036 Metrics *metrics,
Darin Petkovafa6fc42011-06-21 16:21:08 -070037 Manager *manager,
38 const std::string& link_name,
Chris Masone626719f2011-08-18 16:58:48 -070039 const std::string &address,
Darin Petkovafa6fc42011-06-21 16:21:08 -070040 int interface_index);
mukesh agrawal93a29ed2012-04-17 16:13:01 -070041 virtual ~Ethernet();
Darin Petkovafa6fc42011-06-21 16:21:08 -070042
mukesh agrawal93a29ed2012-04-17 16:13:01 -070043 virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
44 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
mukesh agrawal93a29ed2012-04-17 16:13:01 -070045 virtual void LinkEvent(unsigned int flags, unsigned int change);
Christopher Wiley2f1bbf02012-10-25 15:31:13 -070046 virtual void ConnectTo(EthernetService *service);
47 virtual void DisconnectFrom(EthernetService *service);
Paul Stewartf1ce5d22011-05-19 13:10:20 -070048
Paul Stewart9413bcc2013-04-04 16:12:43 -070049 // 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 &parameter);
65 virtual void PropertiesChanged(
66 const std::map<std::string, ::DBus::Variant> &properties);
67 virtual void ScanDone();
68
Paul Stewartb50f0b92011-05-16 16:31:42 -070069 private:
Paul Stewartced3ad72013-04-03 13:39:25 -070070 friend class EthernetTest;
71
Paul Stewart35eff132013-04-12 12:08:40 -070072 // 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 Stewart9413bcc2013-04-04 16:12:43 -070079 // Invoked by |eap_listener_| when an EAP authenticator is detected.
Paul Stewartced3ad72013-04-03 13:39:25 -070080 void OnEapDetected();
81
Paul Stewart9413bcc2013-04-04 16:12:43 -070082 // 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 &parameter);
95 void SupplicantStateChangedTask(const std::string &state);
96
Paul Stewart35eff132013-04-12 12:08:40 -070097 // Callback task run as a result of TryEapAuthentication().
98 void TryEapAuthenticationTask();
99
Paul Stewart9413bcc2013-04-04 16:12:43 -0700100 EthernetServiceRefPtr service_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700101 bool link_up_;
102
Paul Stewart9413bcc2013-04-04 16:12:43 -0700103 // Track whether we have completed EAP authentication successfully.
104 bool is_eap_authenticated_;
105
Paul Stewartced3ad72013-04-03 13:39:25 -0700106 // Track whether an EAP authenticator has been detected on this link.
107 bool is_eap_detected_;
108 scoped_ptr<EapListener> eap_listener_;
109
Paul Stewart9413bcc2013-04-04 16:12:43 -0700110 // 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 Stewart35eff132013-04-12 12:08:40 -0700124 // Make sure TryEapAuthenticationTask is only queued for execution once
125 // at a time.
126 base::CancelableClosure try_eap_authentication_callback_;
127
Paul Stewart9413bcc2013-04-04 16:12:43 -0700128 // 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 Stewartb50f0b92011-05-16 16:31:42 -0700133 DISALLOW_COPY_AND_ASSIGN(Ethernet);
134};
135
136} // namespace shill
137
138#endif // SHILL_ETHERNET_