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.14 2003/09/23 02:35:59 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.
32 #include <epan/packet.h>
33 #include "packet-ieee80211.h"
36 static int proto_eapol = -1;
37 static int hf_eapol_version = -1;
38 static int hf_eapol_type = -1;
39 static int hf_eapol_len = -1;
40 static int hf_eapol_keydes_type = -1;
41 static int hf_eapol_keydes_keylen = -1;
42 static int hf_eapol_keydes_replay_counter = -1;
43 static int hf_eapol_keydes_key_iv = -1;
44 static int hf_eapol_keydes_key_index_keytype = -1;
45 static int hf_eapol_keydes_key_index_indexnum = -1;
46 static int hf_eapol_keydes_key_signature = -1;
47 static int hf_eapol_keydes_key = -1;
49 static int hf_eapol_wpa_keydes_keyinfo = -1;
50 static int hf_eapol_wpa_keydes_nonce = -1;
51 static int hf_eapol_wpa_keydes_rsc = -1;
52 static int hf_eapol_wpa_keydes_id = -1;
53 static int hf_eapol_wpa_keydes_mic = -1;
54 static int hf_eapol_wpa_keydes_datalen = -1;
55 static int hf_eapol_wpa_keydes_data = -1;
57 static gint ett_eapol = -1;
58 static gint ett_eapol_keydes_data = -1;
59 static gint ett_eapol_key_index = -1;
61 static dissector_handle_t eap_handle;
62 static dissector_handle_t data_handle;
64 #define EAPOL_HDR_LEN 4
68 #define EAPOL_LOGOFF 2
70 #define EAPOL_ENCAP_ASF_ALERT 4
72 #define EAPOL_WPA_KEY 254
74 static const value_string eapol_type_vals[] = {
75 { EAP_PACKET, "EAP Packet" },
76 { EAPOL_START, "Start" },
77 { EAPOL_LOGOFF, "Logoff" },
79 { EAPOL_ENCAP_ASF_ALERT, "Encapsulated ASF Alert" },
83 static const value_string eapol_keydes_type_vals[] = {
84 { 1, "RC4 Descriptor" },
85 { EAPOL_WPA_KEY, "EAPOL WPA key" },
89 static const true_false_string keytype_tfs =
90 { "Unicast", "Broadcast" };
93 dissect_eapol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 guint16 eapol_key_len, eapol_data_len;
102 proto_tree *ti = NULL;
103 proto_tree *eapol_tree = NULL;
104 proto_tree *key_index_tree, *keydes_tree;
107 if (check_col(pinfo->cinfo, COL_PROTOCOL))
108 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EAPOL");
109 if (check_col(pinfo->cinfo, COL_INFO))
110 col_clear(pinfo->cinfo, COL_INFO);
113 ti = proto_tree_add_item(tree, proto_eapol, tvb, 0, -1, FALSE);
114 eapol_tree = proto_item_add_subtree(ti, ett_eapol);
116 proto_tree_add_item(eapol_tree, hf_eapol_version, tvb, offset, 1, FALSE);
120 eapol_type = tvb_get_guint8(tvb, offset);
122 proto_tree_add_uint(eapol_tree, hf_eapol_type, tvb, offset, 1, eapol_type);
123 if (check_col(pinfo->cinfo, COL_INFO))
124 col_add_str(pinfo->cinfo, COL_INFO,
125 val_to_str(eapol_type, eapol_type_vals, "Unknown type (0x%02X)"));
128 eapol_len = tvb_get_ntohs(tvb, offset);
129 len = EAPOL_HDR_LEN + eapol_len;
130 set_actual_length(tvb, len);
132 proto_item_set_len(ti, len);
133 proto_tree_add_uint(eapol_tree, hf_eapol_len, tvb, offset, 2, eapol_len);
137 switch (eapol_type) {
140 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
141 call_dissector(eap_handle, next_tvb, pinfo, eapol_tree);
146 keydesc_type = tvb_get_guint8(tvb, offset);
147 proto_tree_add_item(eapol_tree, hf_eapol_keydes_type, tvb, offset, 1, FALSE);
149 if (keydesc_type == EAPOL_WPA_KEY) {
150 proto_tree_add_uint(eapol_tree, hf_eapol_wpa_keydes_keyinfo, tvb,
151 offset, 2, tvb_get_ntohs(tvb, offset));
153 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_keylen, tvb, offset,
154 2, tvb_get_ntohs(tvb, offset));
156 proto_tree_add_item(eapol_tree, hf_eapol_keydes_replay_counter, tvb,
159 proto_tree_add_item(eapol_tree, hf_eapol_wpa_keydes_nonce, tvb, offset,
162 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_iv, tvb,
165 proto_tree_add_item(eapol_tree, hf_eapol_wpa_keydes_rsc, tvb, offset,
168 proto_tree_add_item(eapol_tree, hf_eapol_wpa_keydes_id, tvb, offset, 8,
171 proto_tree_add_item(eapol_tree, hf_eapol_wpa_keydes_mic, tvb, offset,
174 eapol_data_len = tvb_get_ntohs(tvb, offset);
175 proto_tree_add_uint(eapol_tree, hf_eapol_wpa_keydes_datalen, tvb,
176 offset, 2, eapol_data_len);
178 if (eapol_data_len != 0) {
179 ti = proto_tree_add_item(eapol_tree, hf_eapol_wpa_keydes_data,
180 tvb, offset, eapol_data_len, FALSE);
181 keydes_tree = proto_item_add_subtree(ti, ett_eapol_keydes_data);
182 ieee_80211_add_tagged_parameters(tvb, offset, keydes_tree,
187 eapol_key_len = tvb_get_ntohs(tvb, offset);
188 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_keylen, tvb, offset, 2, eapol_key_len);
190 proto_tree_add_item(eapol_tree, hf_eapol_keydes_replay_counter, tvb,
193 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_iv, tvb,
196 key_index = tvb_get_guint8(tvb, offset);
197 ti = proto_tree_add_text(eapol_tree, tvb, offset, 1,
198 "Key Index: %s, index %u",
199 (key_index & 0x80) ? "unicast" : "broadcast",
201 key_index_tree = proto_item_add_subtree(ti, ett_eapol_key_index);
202 proto_tree_add_boolean(eapol_tree, hf_eapol_keydes_key_index_keytype,
203 tvb, offset, 1, key_index);
204 proto_tree_add_uint(eapol_tree, hf_eapol_keydes_key_index_indexnum,
205 tvb, offset, 1, key_index);
207 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key_signature, tvb,
210 if (eapol_key_len != 0)
211 proto_tree_add_item(eapol_tree, hf_eapol_keydes_key, tvb, offset,
212 eapol_key_len, FALSE);
217 case EAPOL_ENCAP_ASF_ALERT: /* XXX - is this an SNMP trap? */
219 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
220 call_dissector(data_handle, next_tvb, pinfo, eapol_tree);
226 proto_register_eapol(void)
228 static hf_register_info hf[] = {
229 { &hf_eapol_version, {
230 "Version", "eapol.version", FT_UINT8, BASE_DEC,
231 NULL, 0x0, "", HFILL }},
233 "Type", "eapol.type", FT_UINT8, BASE_DEC,
234 VALS(eapol_type_vals), 0x0, "", HFILL }},
236 "Length", "eapol.len", FT_UINT16, BASE_DEC,
237 NULL, 0x0, "Length", HFILL }},
238 { &hf_eapol_keydes_type, {
239 "Descriptor Type", "eapol.keydes.type", FT_UINT8, BASE_DEC,
240 VALS(eapol_keydes_type_vals), 0x0, "Key Descriptor Type", HFILL }},
241 { &hf_eapol_keydes_keylen, {
242 "Key Length", "eapol.keydes.keylen", FT_UINT16, BASE_DEC,
243 NULL, 0x0, "Key Length", HFILL }},
244 { &hf_eapol_keydes_replay_counter, {
245 "Replay Counter", "eapol.keydes.replay_counter", FT_UINT64, BASE_DEC,
246 NULL, 0x0, "Replay Counter", HFILL }},
247 { &hf_eapol_keydes_key_iv, {
248 "Key IV", "eapol.keydes.key_iv", FT_BYTES, BASE_NONE,
249 NULL, 0x0, "Key Initialization Vector", HFILL }},
250 { &hf_eapol_keydes_key_index_keytype, {
251 "Key Type", "eapol.keydes.index.keytype", FT_BOOLEAN, 8,
252 TFS(&keytype_tfs), 0x80, "Key Type (unicast/broadcast)", HFILL }},
253 { &hf_eapol_keydes_key_index_indexnum, {
254 "Index Number", "eapol.keydes.index.indexnum", FT_UINT8, BASE_DEC,
255 NULL, 0x7F, "Key Index number", HFILL }},
256 { &hf_eapol_keydes_key_signature, {
257 "Key Signature", "eapol.keydes.key_signature", FT_BYTES, BASE_NONE,
258 NULL, 0x0, "Key Signature", HFILL }},
259 { &hf_eapol_keydes_key, {
260 "Key", "eapol.keydes.key", FT_BYTES, BASE_NONE,
261 NULL, 0x0, "Key", HFILL }},
263 { &hf_eapol_wpa_keydes_keyinfo, {
264 "Key Information", "eapol.keydes.key_info", FT_UINT16,
265 BASE_HEX, NULL, 0x0, "WPA key info", HFILL }},
266 { &hf_eapol_wpa_keydes_nonce, {
267 "Nonce", "eapol.keydes.nonce", FT_BYTES, BASE_NONE,
268 NULL, 0x0, "WPA Key Nonce", HFILL }},
269 { &hf_eapol_wpa_keydes_rsc, {
270 "WPA Key RSC", "eapol.keydes.rsc", FT_BYTES, BASE_NONE, NULL,
271 0x0, "WPA Key Receive Sequence Counter", HFILL }},
272 { &hf_eapol_wpa_keydes_id, {
273 "WPA Key ID", "eapol,keydes.id", FT_BYTES, BASE_NONE, NULL,
274 0x0, "WPA Key ID", HFILL }},
275 { &hf_eapol_wpa_keydes_mic, {
276 "WPA Key MIC", "eapol.keydes.mic", FT_BYTES, BASE_NONE, NULL,
277 0x0, "WPA Key Message Integrity Check", HFILL }},
278 { &hf_eapol_wpa_keydes_datalen, {
279 "WPA Key Length", "eapol.keydes.datalen", FT_UINT16, BASE_DEC,
280 NULL, 0x0, "WPA Key Data Length", HFILL }},
281 { &hf_eapol_wpa_keydes_data, {
282 "WPA Key", "eapol.keydes.data", FT_BYTES, BASE_NONE,
283 NULL, 0x0, "WPA Key Data", HFILL }},
285 static gint *ett[] = {
287 &ett_eapol_keydes_data,
291 proto_eapol = proto_register_protocol("802.1x Authentication", "EAPOL", "eapol");
292 proto_register_field_array(proto_eapol, hf, array_length(hf));
293 proto_register_subtree_array(ett, array_length(ett));
297 proto_reg_handoff_eapol(void)
299 dissector_handle_t eapol_handle;
302 * Get handles for the EAP and raw data dissectors.
304 eap_handle = find_dissector("eap");
305 data_handle = find_dissector("data");
307 eapol_handle = create_dissector_handle(dissect_eapol, proto_eapol);
308 dissector_add("ethertype", ETHERTYPE_EAPOL, eapol_handle);