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.12 2002/08/28 21:00:13 jmayer 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.
32 #include <epan/packet.h>
33 #include "packet-ieee8023.h"
34 #include "packet-ipx.h"
35 #include "packet-llc.h"
38 static int proto_eapol = -1;
39 static int hf_eapol_version = -1;
40 static int hf_eapol_type = -1;
41 static int hf_eapol_len = -1;
42 static int hf_eapol_keydes_type = -1;
43 static int hf_eapol_keydes_keylen = -1;
44 static int hf_eapol_keydes_replay_counter = -1;
45 static int hf_eapol_keydes_key_iv = -1;
46 static int hf_eapol_keydes_key_index_keytype = -1;
47 static int hf_eapol_keydes_key_index_indexnum = -1;
48 static int hf_eapol_keydes_key_signature = -1;
49 static int hf_eapol_keydes_key = -1;
51 static gint ett_eapol = -1;
52 static gint ett_eapol_key_index = -1;
54 static dissector_handle_t eap_handle;
55 static dissector_handle_t data_handle;
57 #define EAPOL_HDR_LEN 4
61 #define EAPOL_LOGOFF 2
63 #define EAPOL_ENCAP_ASF_ALERT 4
65 static const value_string eapol_type_vals[] = {
66 { EAP_PACKET, "EAP Packet" },
67 { EAPOL_START, "Start" },
68 { EAPOL_LOGOFF, "Logoff" },
70 { EAPOL_ENCAP_ASF_ALERT, "Encapsulated ASF Alert" },
74 static const value_string eapol_keydes_type_vals[] = {
75 { 1, "RC4 Descriptor" },
79 static const true_false_string keytype_tfs =
80 { "Unicast", "Broadcast" };
83 dissect_eapol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
89 guint16 eapol_key_len;
91 proto_tree *ti = NULL;
92 proto_tree *eapol_tree = NULL;
93 proto_tree *key_index_tree;
96 if (check_col(pinfo->cinfo, COL_PROTOCOL))
97 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EAPOL");
98 if (check_col(pinfo->cinfo, COL_INFO))
99 col_clear(pinfo->cinfo, COL_INFO);
102 ti = proto_tree_add_item(tree, proto_eapol, tvb, 0, -1, FALSE);
103 eapol_tree = proto_item_add_subtree(ti, ett_eapol);
105 proto_tree_add_item(eapol_tree, hf_eapol_version, tvb, offset, 1, FALSE);
109 eapol_type = tvb_get_guint8(tvb, offset);
111 proto_tree_add_uint(eapol_tree, hf_eapol_type, tvb, offset, 1, eapol_type);
112 if (check_col(pinfo->cinfo, COL_INFO))
113 col_add_str(pinfo->cinfo, COL_INFO,
114 val_to_str(eapol_type, eapol_type_vals, "Unknown type (0x%02X)"));
117 eapol_len = tvb_get_ntohs(tvb, offset);
118 len = EAPOL_HDR_LEN + eapol_len;
119 set_actual_length(tvb, len);
121 proto_item_set_len(ti, len);
122 proto_tree_add_uint(eapol_tree, hf_eapol_len, tvb, offset, 2, eapol_len);
126 switch (eapol_type) {
129 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
130 call_dissector(eap_handle, next_tvb, pinfo, eapol_tree);
135 proto_tree_add_item(eapol_tree, hf_eapol_keydes_type, tvb, offset, 1, FALSE);
137 eapol_key_len = tvb_get_ntohs(tvb, offset);
138 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_keylen, tvb, offset, 2, eapol_key_len);
140 proto_tree_add_item(eapol_tree, hf_eapol_keydes_replay_counter, tvb,
143 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_iv, tvb,
146 key_index = tvb_get_guint8(tvb, offset);
147 ti = proto_tree_add_text(eapol_tree, tvb, offset, 1,
148 "Key Index: %s, index %u",
149 (key_index & 0x80) ? "unicast" : "broadcast",
151 key_index_tree = proto_item_add_subtree(ti, ett_eapol_key_index);
152 proto_tree_add_boolean(eapol_tree, hf_eapol_keydes_key_index_keytype,
153 tvb, offset, 1, key_index);
154 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_key_index_indexnum,
155 tvb, offset, 1, key_index);
157 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_signature, tvb,
160 if (eapol_key_len != 0)
161 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key, tvb, offset,
162 eapol_key_len, FALSE);
166 case EAPOL_ENCAP_ASF_ALERT: /* XXX - is this an SNMP trap? */
168 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
169 call_dissector(data_handle, next_tvb, pinfo, eapol_tree);
175 proto_register_eapol(void)
177 static hf_register_info hf[] = {
178 { &hf_eapol_version, {
179 "Version", "eapol.version", FT_UINT8, BASE_DEC,
180 NULL, 0x0, "", HFILL }},
182 "Type", "eapol.type", FT_UINT8, BASE_DEC,
183 VALS(eapol_type_vals), 0x0, "", HFILL }},
185 "Length", "eapol.len", FT_UINT16, BASE_DEC,
186 NULL, 0x0, "Length", HFILL }},
187 { &hf_eapol_keydes_type, {
188 "Descriptor Type", "eapol.keydes.type", FT_UINT8, BASE_DEC,
189 VALS(eapol_keydes_type_vals), 0x0, "Key Descriptor Type", HFILL }},
190 { &hf_eapol_keydes_keylen, {
191 "Key Length", "eapol.keydes.keylen", FT_UINT16, BASE_DEC,
192 NULL, 0x0, "Key Length", HFILL }},
193 { &hf_eapol_keydes_replay_counter, {
194 "Replay Counter", "eapol.keydes.replay_counter", FT_UINT64, BASE_DEC,
195 NULL, 0x0, "Replay Counter", HFILL }},
196 { &hf_eapol_keydes_key_iv, {
197 "Key IV", "eapol.keydes.key_iv", FT_BYTES, BASE_NONE,
198 NULL, 0x0, "Key Initialization Vector", HFILL }},
199 { &hf_eapol_keydes_key_index_keytype, {
200 "Key Type", "eapol.keydes.index.keytype", FT_BOOLEAN, 8,
201 TFS(&keytype_tfs), 0x80, "Key Type (unicast/broadcast)", HFILL }},
202 { &hf_eapol_keydes_key_index_indexnum, {
203 "Index Number", "eapol.keydes.index.indexnum", FT_UINT8, BASE_DEC,
204 NULL, 0x7F, "Key Index number", HFILL }},
205 { &hf_eapol_keydes_key_signature, {
206 "Key Signature", "eapol.keydes.key_signature", FT_BYTES, BASE_NONE,
207 NULL, 0x0, "Key Signature", HFILL }},
208 { &hf_eapol_keydes_key, {
209 "Key", "eapol.keydes.key", FT_BYTES, BASE_NONE,
210 NULL, 0x0, "Key", HFILL }},
212 static gint *ett[] = {
217 proto_eapol = proto_register_protocol("802.1x Authentication", "EAPOL", "eapol");
218 proto_register_field_array(proto_eapol, hf, array_length(hf));
219 proto_register_subtree_array(ett, array_length(ett));
223 proto_reg_handoff_eapol(void)
225 dissector_handle_t eapol_handle;
228 * Get handles for the EAP and raw data dissectors.
230 eap_handle = find_dissector("eap");
231 data_handle = find_dissector("data");
233 eapol_handle = create_dissector_handle(dissect_eapol, proto_eapol);
234 dissector_add("ethertype", ETHERTYPE_EAPOL, eapol_handle);