2 * Copyright (c) 2004 - Michael Richardson <mcr@xelerance.com>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code distributions
6 * retain the above copyright notice and this paragraph in its entirety, (2)
7 * distributions including binary code include the above copyright notice and
8 * this paragraph in its entirety in the documentation or other materials
9 * provided with the distribution, and (3) all advertising materials mentioning
10 * features or use of this software display the following acknowledgement:
11 * ``This product includes software developed by the University of California,
12 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 * the University nor the names of its contributors may be used to endorse
14 * or promote products derived from this software without specific prior
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * Format and print EAP packets.
25 static const char rcsid
[] _U_
=
26 "@(#) $Header: /tcpdump/master/tcpdump/print-eap.c,v 1.4 2007-10-04 08:34:28 hannes Exp $";
33 #include <tcpdump-stdinc.h>
38 #include "netdissect.h"
39 #include "interface.h"
40 #include "addrtoname.h"
44 #define EAP_FRAME_TYPE_PACKET 0
45 #define EAP_FRAME_TYPE_START 1
46 #define EAP_FRAME_TYPE_LOGOFF 2
47 #define EAP_FRAME_TYPE_KEY 3
48 #define EAP_FRAME_TYPE_ENCAP_ASF_ALERT 4
51 unsigned char version
;
53 unsigned char length
[2];
56 static const struct tok eap_frame_type_values
[] = {
57 { EAP_FRAME_TYPE_PACKET
, "EAP packet" },
58 { EAP_FRAME_TYPE_START
, "EAPOL start" },
59 { EAP_FRAME_TYPE_LOGOFF
, "EAPOL logoff" },
60 { EAP_FRAME_TYPE_KEY
, "EAPOL key" },
61 { EAP_FRAME_TYPE_ENCAP_ASF_ALERT
, "Encapsulated ASF alert" },
69 unsigned char length
[2];
73 #define EAP_RESPONSE 2
77 static const struct tok eap_code_values
[] = {
78 { EAP_REQUEST
, "Request" },
79 { EAP_RESPONSE
, "Response" },
80 { EAP_SUCCESS
, "Success" },
81 { EAP_FAILURE
, "Failure" },
85 #define EAP_TYPE_NO_PROPOSED 0
86 #define EAP_TYPE_IDENTITY 1
87 #define EAP_TYPE_NOTIFICATION 2
88 #define EAP_TYPE_NAK 3
89 #define EAP_TYPE_MD5_CHALLENGE 4
90 #define EAP_TYPE_OTP 5
91 #define EAP_TYPE_GTC 6
92 #define EAP_TYPE_EXPANDED_TYPES 254
93 #define EAP_TYPE_EXPERIMENTAL 255
95 static const struct tok eap_type_values
[] = {
96 { EAP_TYPE_NO_PROPOSED
, "No proposed" },
97 { EAP_TYPE_IDENTITY
, "Identity" },
98 { EAP_TYPE_NOTIFICATION
, "Notification" },
99 { EAP_TYPE_NAK
, "Nak" },
100 { EAP_TYPE_MD5_CHALLENGE
, "MD5-challenge" },
101 { EAP_TYPE_OTP
, "OTP" },
102 { EAP_TYPE_GTC
, "GTC" },
103 { EAP_TYPE_EXPANDED_TYPES
, "Expanded types" },
104 { EAP_TYPE_EXPERIMENTAL
, "Experimental" },
109 * Print EAP requests / responses
112 eap_print(netdissect_options
*ndo _U_
,
113 register const u_char
*cp
,
116 const struct eap_frame_t
*eap
;
118 u_int tlen
, type
, subtype
;
123 eap
= (const struct eap_frame_t
*)cp
;
126 /* in non-verbose mode just lets print the basic info */
128 printf("%s (%u) v%u, len %u",
129 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
132 EXTRACT_16BITS(eap
->length
));
136 printf("%s (%u) v%u, len %u",
137 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
140 EXTRACT_16BITS(eap
->length
));
142 tptr
+= sizeof(const struct eap_frame_t
);
143 tlen
-= sizeof(const struct eap_frame_t
);
146 case EAP_FRAME_TYPE_PACKET
:
148 len
= EXTRACT_16BITS(tptr
+2);
149 printf(", %s (%u), id %u, len %u",
150 tok2str(eap_code_values
, "unknown", type
),
155 if (!TTEST2(*tptr
, len
))
158 if (type
<= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
160 printf("\n\t\t Type %s (%u)",
161 tok2str(eap_type_values
, "unknown", *(tptr
+4)),
165 case EAP_TYPE_IDENTITY
:
167 printf(", Identity: ");
168 safeputs((const char *)tptr
+5, len
-5);
172 case EAP_TYPE_NOTIFICATION
:
174 printf(", Notification: ");
175 safeputs((const char *)tptr
+5, len
-5);
183 * one or more octets indicating
184 * the desired authentication
185 * type one octet per type
187 while (count
< len
) {
189 tok2str(eap_type_values
, "unknown", *(tptr
+count
)),
195 case EAP_TYPE_MD5_CHALLENGE
:
198 case EAP_TYPE_EXPANDED_TYPES
:
199 case EAP_TYPE_EXPERIMENTAL
:
206 case EAP_FRAME_TYPE_LOGOFF
:
207 case EAP_FRAME_TYPE_ENCAP_ASF_ALERT
:
214 printf("\n\t[|EAP]");