2 * Routines for EAPOL 802.1X authentication header disassembly
4 * $Id: packet-eapol.c,v 1.6 2002/02/17 00:51:19 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
33 #ifdef HAVE_NETINET_IN_H
34 # include <netinet/in.h>
38 #include <epan/packet.h>
39 #include "packet-ieee8023.h"
40 #include "packet-ipx.h"
41 #include "packet-llc.h"
44 static int proto_eapol = -1;
45 static int hf_eapol_version = -1;
46 static int hf_eapol_type = -1;
47 static int hf_eapol_len = -1;
49 static gint ett_eapol = -1;
51 static dissector_handle_t data_handle;
53 typedef struct _e_eapol
60 static const char *eapol_type_name[] = {
65 "Encapsulated ASF Alert"
67 #define EAPOL_TYPE_COUNT (sizeof(eapol_type_name)/sizeof(eapol_type_name[0]))
69 extern void dissect_eap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
72 dissect_eapol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
77 proto_tree *volatile eapol_tree;
80 if (check_col(pinfo->cinfo, COL_PROTOCOL))
81 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EAPOL");
82 if (check_col(pinfo->cinfo, COL_INFO))
83 col_clear(pinfo->cinfo, COL_INFO);
85 tvb_memcpy(tvb, (guint8 *)&eapolh, 0, sizeof(eapolh));
86 eapolh.eapol_len = ntohs(eapolh.eapol_len);
88 len = sizeof(eapolh) + eapolh.eapol_len;
90 set_actual_length(tvb, len);
95 ti = proto_tree_add_item(tree, proto_eapol, tvb, 0, len, FALSE);
96 eapol_tree = proto_item_add_subtree(ti, ett_eapol);
98 proto_tree_add_uint(eapol_tree, hf_eapol_version, tvb, 0, 1, eapolh.eapol_ver);
99 proto_tree_add_text(eapol_tree, tvb, 1, 1, "Type: %s (%u)",
100 eapolh.eapol_type > EAPOL_TYPE_COUNT?
101 "Unknown" : eapol_type_name[eapolh.eapol_type],
103 proto_tree_add_uint(eapol_tree, hf_eapol_len, tvb, 2, 2, eapolh.eapol_len);
106 next_tvb = tvb_new_subset(tvb, 4, -1, -1);
108 if (eapolh.eapol_type == 0 && next_tvb != NULL)
109 dissect_eap(next_tvb, pinfo, eapol_tree);
111 call_dissector(data_handle,tvb_new_subset(tvb, 4,-1,tvb_reported_length_remaining(tvb,4)), pinfo, tree);
115 proto_register_eapol(void)
117 static hf_register_info hf[] = {
118 { &hf_eapol_version, {
119 "Version", "eapol.version", FT_UINT8, BASE_DEC,
120 NULL, 0x0, "", HFILL }},
122 "Type", "eapol.type", FT_UINT8, BASE_DEC,
123 0, 0x0, "", HFILL }},
125 "Length", "eapol.len", FT_UINT16, BASE_DEC,
126 NULL, 0x0, "Length", HFILL }},
128 static gint *ett[] = {
132 proto_eapol = proto_register_protocol("802.1x Authentication", "EAPOL", "eapol");
133 proto_register_field_array(proto_eapol, hf, array_length(hf));
134 proto_register_subtree_array(ett, array_length(ett));
138 proto_reg_handoff_eapol(void)
140 dissector_handle_t eapol_handle;
142 data_handle = find_dissector("data");
143 eapol_handle = create_dissector_handle(dissect_eapol, proto_eapol);
144 dissector_add("ethertype", ETHERTYPE_EAPOL, eapol_handle);