blob: a0c3c599180e4043b81c2cadedb99870f05bcd92 [file] [log] [blame]
Paul Stewartac802ac2013-04-02 15:45:24 -07001// Copyright (c) 2013 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_EAP_LISTENER_H_
6#define SHILL_EAP_LISTENER_H_
7
Paul Stewartac802ac2013-04-02 15:45:24 -07008#include <base/callback.h>
Ben Chancc67c522014-09-03 07:19:18 -07009#include <base/macros.h>
Paul Stewartac802ac2013-04-02 15:45:24 -070010#include <base/memory/scoped_ptr.h>
11
12namespace shill {
13
14class EventDispatcher;
15class IOHandler;
16class ScopedSocketCloser;
17class Sockets;
18
19// Listens for EAP packets on |interface_index| and invokes a
20// callback when a request frame arrives.
21class EapListener {
22 public:
23 typedef base::Callback<void()> EapRequestReceivedCallback;
24
25 explicit EapListener(EventDispatcher *event_dispatcher,
26 int interface_index);
27 virtual ~EapListener();
28
29 // Create a socket for tranmission and reception. Returns true
30 // if successful, false otherwise.
31 virtual bool Start();
32
33 // Destroy the client socket.
34 virtual void Stop();
35
36 // Setter for |request_received_callback_|.
37 virtual void set_request_received_callback(
38 const EapRequestReceivedCallback &callback) {
39 request_received_callback_ = callback;
40 }
41
42 private:
43 friend class EapListenerTest;
44
45 // The largest EAP packet we expect to receive.
46 static const size_t kMaxEapPacketLength;
47
48 // Creates |socket_|. Returns true on succes, false on failure.
49 bool CreateSocket();
50
51 // Retrieves an EAP packet from |socket_|. This is the callback method
52 // configured on |receive_request_handler_|.
53 void ReceiveRequest(int fd);
54
55 // Event dispatcher to use for creating an input handler.
56 EventDispatcher *dispatcher_;
57
58 // The interface index fo the device to monitor.
59 const int interface_index_;
60
61 // Callback handle to invoke when an EAP request is received.
62 EapRequestReceivedCallback request_received_callback_;
63
64 // Sockets instance to perform socket calls on.
65 scoped_ptr<Sockets> sockets_;
66
67 // Receive socket configured to receive PAE (Port Access Entity) packets.
68 int socket_;
69
70 // Scoped socket closer for the receive |socket_|.
71 scoped_ptr<ScopedSocketCloser> socket_closer_;
72
73 // Input handler for |socket_|. Calls ReceiveRequest().
74 scoped_ptr<IOHandler> receive_request_handler_;
75
76 DISALLOW_COPY_AND_ASSIGN(EapListener);
77};
78
79} // namespace shill
80
81#endif // SHILL_EAP_LISTENER_H_