[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / net / eapol.c
blob507c8ce2b172947569f7b32e1d8b676676b5e797
1 /*
2 * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER );
21 /** @file
23 * 802.1X Extensible Authentication Protocol over LANs demultiplexer
27 #include <gpxe/netdevice.h>
28 #include <gpxe/iobuf.h>
29 #include <gpxe/if_ether.h>
30 #include <gpxe/eapol.h>
31 #include <errno.h>
32 #include <byteswap.h>
34 /**
35 * Receive EAPOL network-layer packet
37 * @v iob I/O buffer
38 * @v netdev Network device
39 * @v ll_source Link-layer source address
41 * This function takes ownership of the I/O buffer passed to it.
43 static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
44 const void *ll_source )
46 struct eapol_frame *eapol = iob->data;
47 struct eapol_handler *handler;
49 if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
50 free_iob ( iob );
51 return -EINVAL;
54 for_each_table_entry ( handler, EAPOL_HANDLERS ) {
55 if ( handler->type == eapol->type ) {
56 iob_pull ( iob, EAPOL_HDR_LEN );
57 return handler->rx ( iob, netdev, ll_source );
61 free_iob ( iob );
62 return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
65 /**
66 * Transcribe EAPOL network-layer address
68 * @v net_addr Network-layer address
69 * @ret str String representation of network-layer address
71 * EAPOL doesn't have network-layer addresses, so we just return the
72 * string @c "<EAPOL>".
74 static const char * eapol_ntoa ( const void *net_addr __unused )
76 return "<EAPOL>";
79 /** EAPOL network protocol */
80 struct net_protocol eapol_protocol __net_protocol = {
81 .name = "EAPOL",
82 .rx = eapol_rx,
83 .ntoa = eapol_ntoa,
84 .net_proto = htons ( ETH_P_EAPOL ),