2 * Routines for EAPOL 802.1X authentication header disassembly
3 * (From IEEE Draft P802.1X/D11; is there a later draft, or a
4 * final standard? If so, check it.)
6 * $Id: packet-eapol.c,v 1.9 2002/03/11 08:47:46 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
40 #include <epan/packet.h>
41 #include "packet-ieee8023.h"
42 #include "packet-ipx.h"
43 #include "packet-llc.h"
46 static int proto_eapol = -1;
47 static int hf_eapol_version = -1;
48 static int hf_eapol_type = -1;
49 static int hf_eapol_len = -1;
50 static int hf_eapol_keydes_type = -1;
51 static int hf_eapol_keydes_keylen = -1;
52 static int hf_eapol_keydes_replay_counter = -1;
53 static int hf_eapol_keydes_key_iv = -1;
54 static int hf_eapol_keydes_key_index_keytype = -1;
55 static int hf_eapol_keydes_key_index_indexnum = -1;
56 static int hf_eapol_keydes_key_signature = -1;
57 static int hf_eapol_keydes_key = -1;
59 static gint ett_eapol = -1;
60 static gint ett_eapol_key_index = -1;
62 static dissector_handle_t eap_handle;
63 static dissector_handle_t data_handle;
65 #define EAPOL_HDR_LEN 4
69 #define EAPOL_LOGOFF 2
71 #define EAPOL_ENCAP_ASF_ALERT 4
73 static const value_string eapol_type_vals[] = {
74 { EAP_PACKET, "EAP Packet" },
75 { EAPOL_START, "Start" },
76 { EAPOL_LOGOFF, "Logoff" },
78 { EAPOL_ENCAP_ASF_ALERT, "Encapsulated ASF Alert" },
82 static const value_string eapol_keydes_type_vals[] = {
83 { 1, "RC4 Descriptor" },
87 static const true_false_string keytype_tfs =
88 { "Unicast", "Broadcast" };
91 dissect_eapol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
98 guint16 eapol_key_len;
100 proto_tree *ti = NULL;
101 proto_tree *eapol_tree = NULL;
102 proto_tree *key_index_tree;
105 if (check_col(pinfo->cinfo, COL_PROTOCOL))
106 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EAPOL");
107 if (check_col(pinfo->cinfo, COL_INFO))
108 col_clear(pinfo->cinfo, COL_INFO);
111 ti = proto_tree_add_item(tree, proto_eapol, tvb, 0, -1, FALSE);
112 eapol_tree = proto_item_add_subtree(ti, ett_eapol);
114 proto_tree_add_item(eapol_tree, hf_eapol_version, tvb, offset, 1, FALSE);
118 eapol_type = tvb_get_guint8(tvb, offset);
120 proto_tree_add_uint(eapol_tree, hf_eapol_type, tvb, offset, 1, eapol_type);
121 if (check_col(pinfo->cinfo, COL_INFO))
122 col_add_str(pinfo->cinfo, COL_INFO,
123 val_to_str(eapol_type, eapol_type_vals, "Unknown type (0x%02X)"));
126 eapol_len = tvb_get_ntohs(tvb, offset);
127 len = EAPOL_HDR_LEN + eapol_len;
128 set_actual_length(tvb, len);
130 proto_item_set_len(ti, len);
131 proto_tree_add_uint(eapol_tree, hf_eapol_len, tvb, offset, 2, eapol_len);
135 switch (eapol_type) {
138 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
139 call_dissector(eap_handle, next_tvb, pinfo, eapol_tree);
144 proto_tree_add_item(eapol_tree, hf_eapol_keydes_type, tvb, offset, 1, FALSE);
146 eapol_key_len = tvb_get_ntohs(tvb, offset);
147 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_keylen, tvb, offset, 2, eapol_key_len);
149 proto_tree_add_item(eapol_tree, hf_eapol_keydes_replay_counter, tvb,
152 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_iv, tvb,
155 key_index = tvb_get_guint8(tvb, offset);
156 ti = proto_tree_add_text(eapol_tree, tvb, offset, 1,
157 "Key Index: %s, index %u",
158 (key_index & 0x80) ? "unicast" : "broadcast",
160 key_index_tree = proto_item_add_subtree(ti, ett_eapol_key_index);
161 proto_tree_add_boolean(eapol_tree, hf_eapol_keydes_key_index_keytype,
162 tvb, offset, 1, key_index);
163 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_key_index_indexnum,
164 tvb, offset, 1, key_index);
166 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_signature, tvb,
169 if (eapol_key_len != 0)
170 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key, tvb, offset,
171 eapol_key_len, FALSE);
175 case EAPOL_ENCAP_ASF_ALERT: /* XXX - is this an SNMP trap? */
177 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
178 call_dissector(data_handle, next_tvb, pinfo, eapol_tree);
184 proto_register_eapol(void)
186 static hf_register_info hf[] = {
187 { &hf_eapol_version, {
188 "Version", "eapol.version", FT_UINT8, BASE_DEC,
189 NULL, 0x0, "", HFILL }},
191 "Type", "eapol.type", FT_UINT8, BASE_DEC,
192 VALS(eapol_type_vals), 0x0, "", HFILL }},
194 "Length", "eapol.len", FT_UINT16, BASE_DEC,
195 NULL, 0x0, "Length", HFILL }},
196 { &hf_eapol_keydes_type, {
197 "Descriptor Type", "eapol.keydes.type", FT_UINT8, BASE_DEC,
198 VALS(eapol_keydes_type_vals), 0x0, "Key Descriptor Type", HFILL }},
199 { &hf_eapol_keydes_keylen, {
200 "Key Length", "eapol.keydes.keylen", FT_UINT16, BASE_DEC,
201 NULL, 0x0, "Key Length", HFILL }},
202 { &hf_eapol_keydes_replay_counter, {
203 "Replay Counter", "eapol.keydes.replay_counter", FT_UINT64, BASE_DEC,
204 NULL, 0x0, "Replay Counter", HFILL }},
205 { &hf_eapol_keydes_key_iv, {
206 "Key IV", "eapol.keydes.key_iv", FT_BYTES, BASE_NONE,
207 NULL, 0x0, "Key Initialization Vector", HFILL }},
208 { &hf_eapol_keydes_key_index_keytype, {
209 "Key Type", "eapol.keydes.index.keytype", FT_BOOLEAN, 8,
210 TFS(&keytype_tfs), 0x80, "Key Type (unicast/broadcast)", HFILL }},
211 { &hf_eapol_keydes_key_index_indexnum, {
212 "Index Number", "eapol.keydes.index.indexnum", FT_UINT8, BASE_DEC,
213 NULL, 0x7F, "Key Index number", HFILL }},
214 { &hf_eapol_keydes_key_signature, {
215 "Key Signature", "eapol.keydes.key_signature", FT_BYTES, BASE_NONE,
216 NULL, 0x0, "Key Signature", HFILL }},
217 { &hf_eapol_keydes_key, {
218 "Key", "eapol.keydes.key", FT_BYTES, BASE_NONE,
219 NULL, 0x0, "Key", HFILL }},
221 static gint *ett[] = {
226 proto_eapol = proto_register_protocol("802.1x Authentication", "EAPOL", "eapol");
227 proto_register_field_array(proto_eapol, hf, array_length(hf));
228 proto_register_subtree_array(ett, array_length(ett));
232 proto_reg_handoff_eapol(void)
234 dissector_handle_t eapol_handle;
237 * Get handles for the EAP and raw data dissectors.
239 eap_handle = find_dissector("eap");
240 data_handle = find_dissector("data");
242 eapol_handle = create_dissector_handle(dissect_eapol, proto_eapol);
243 dissector_add("ethertype", ETHERTYPE_EAPOL, eapol_handle);