blob: d13306c7d4ed83421c29475a967a243efca6d7ba [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_ETHERNET_H_
6#define SHILL_ETHERNET_H_
Paul Stewartb50f0b92011-05-16 16:31:42 -07007
Alex Vakulenko8a532292014-06-16 17:18:44 -07008#include <map>
Chris Masone46eaaf52011-05-24 13:08:30 -07009#include <string>
10
Paul Stewart35eff132013-04-12 12:08:40 -070011#include <base/cancelable_callback.h>
Paul Stewartced3ad72013-04-03 13:39:25 -070012#include <base/memory/scoped_ptr.h>
Paul Stewart9413bcc2013-04-04 16:12:43 -070013#include <base/memory/weak_ptr.h>
Paul Stewartced3ad72013-04-03 13:39:25 -070014
Paul Stewart9413bcc2013-04-04 16:12:43 -070015#include "shill/certificate_file.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070016#include "shill/device.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"
Alex Vakulenkoa41ab512014-07-23 14:24:23 -070019#include "shill/supplicant_eap_state_handler.h"
Paul Stewart9413bcc2013-04-04 16:12:43 -070020#include "shill/supplicant_event_delegate_interface.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070021
22namespace shill {
23
Paul Stewart9413bcc2013-04-04 16:12:43 -070024class CertificateFile;
Paul Stewartced3ad72013-04-03 13:39:25 -070025class EapListener;
Paul Stewart35eff132013-04-12 12:08:40 -070026class EthernetEapProvider;
Paul Stewart9413bcc2013-04-04 16:12:43 -070027class ProxyFactory;
mukesh agrawal8bda7962014-04-01 17:09:35 -070028class Sockets;
Paul Stewart9413bcc2013-04-04 16:12:43 -070029class SupplicantEAPStateHandler;
30class SupplicantInterfaceProxyInterface;
31class SupplicantProcessProxyInterface;
Paul Stewartced3ad72013-04-03 13:39:25 -070032
Paul Stewart9413bcc2013-04-04 16:12:43 -070033class Ethernet : public Device, public SupplicantEventDelegateInterface {
Paul Stewartb50f0b92011-05-16 16:31:42 -070034 public:
Darin Petkovafa6fc42011-06-21 16:21:08 -070035 Ethernet(ControlInterface *control_interface,
36 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080037 Metrics *metrics,
Darin Petkovafa6fc42011-06-21 16:21:08 -070038 Manager *manager,
39 const std::string& link_name,
Chris Masone626719f2011-08-18 16:58:48 -070040 const std::string &address,
Darin Petkovafa6fc42011-06-21 16:21:08 -070041 int interface_index);
Ben Chan5ea763b2014-08-13 11:07:54 -070042 ~Ethernet() override;
Darin Petkovafa6fc42011-06-21 16:21:08 -070043
mukesh agrawal93a29ed2012-04-17 16:13:01 -070044 virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
45 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
mukesh agrawal93a29ed2012-04-17 16:13:01 -070046 virtual void LinkEvent(unsigned int flags, unsigned int change);
Christopher Wiley2f1bbf02012-10-25 15:31:13 -070047 virtual void ConnectTo(EthernetService *service);
48 virtual void DisconnectFrom(EthernetService *service);
Paul Stewartf1ce5d22011-05-19 13:10:20 -070049
Paul Stewart9413bcc2013-04-04 16:12:43 -070050 // 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 &parameter);
66 virtual void PropertiesChanged(
67 const std::map<std::string, ::DBus::Variant> &properties);
68 virtual void ScanDone();
69
Paul Stewartb50f0b92011-05-16 16:31:42 -070070 private:
Paul Stewartced3ad72013-04-03 13:39:25 -070071 friend class EthernetTest;
72
Paul Stewart35eff132013-04-12 12:08:40 -070073 // 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 Stewart9413bcc2013-04-04 16:12:43 -070080 // Invoked by |eap_listener_| when an EAP authenticator is detected.
Paul Stewartced3ad72013-04-03 13:39:25 -070081 void OnEapDetected();
82
Paul Stewart9413bcc2013-04-04 16:12:43 -070083 // 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 Chan7fab8972014-08-10 17:14:46 -070094 void CertificationTask(const std::string &subject, uint32_t depth);
Paul Stewart9413bcc2013-04-04 16:12:43 -070095 void EAPEventTask(const std::string &status, const std::string &parameter);
96 void SupplicantStateChangedTask(const std::string &state);
97
Paul Stewart35eff132013-04-12 12:08:40 -070098 // Callback task run as a result of TryEapAuthentication().
99 void TryEapAuthenticationTask();
100
Paul Stewart8e9e41c2014-08-07 14:55:47 -0700101 void SetupWakeOnLan();
mukesh agrawal8bda7962014-04-01 17:09:35 -0700102
Paul Stewart9413bcc2013-04-04 16:12:43 -0700103 EthernetServiceRefPtr service_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700104 bool link_up_;
105
Paul Stewart9413bcc2013-04-04 16:12:43 -0700106 // Track whether we have completed EAP authentication successfully.
107 bool is_eap_authenticated_;
108
Paul Stewartced3ad72013-04-03 13:39:25 -0700109 // Track whether an EAP authenticator has been detected on this link.
110 bool is_eap_detected_;
111 scoped_ptr<EapListener> eap_listener_;
112
Paul Stewart9413bcc2013-04-04 16:12:43 -0700113 // 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 Stewartc350e682014-06-19 15:44:30 -0700122 // Certificate file instance to generate public key data for remote
123 // authentication.
Paul Stewart9413bcc2013-04-04 16:12:43 -0700124 CertificateFile certificate_file_;
125
Paul Stewart35eff132013-04-12 12:08:40 -0700126 // Make sure TryEapAuthenticationTask is only queued for execution once
127 // at a time.
128 base::CancelableClosure try_eap_authentication_callback_;
129
Paul Stewart9413bcc2013-04-04 16:12:43 -0700130 // Store cached copy of proxy factory singleton for speed/ease of testing.
131 ProxyFactory *proxy_factory_;
132
mukesh agrawal8bda7962014-04-01 17:09:35 -0700133 scoped_ptr<Sockets> sockets_;
134
Paul Stewart9413bcc2013-04-04 16:12:43 -0700135 base::WeakPtrFactory<Ethernet> weak_ptr_factory_;
136
Paul Stewartb50f0b92011-05-16 16:31:42 -0700137 DISALLOW_COPY_AND_ASSIGN(Ethernet);
138};
139
140} // namespace shill
141
Ben Chanc45688b2014-07-02 23:50:45 -0700142#endif // SHILL_ETHERNET_H_