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.5 2007-10-04 16:41:33 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_TLS 13 /* RFC 2716 */
93 #define EAP_TYPE_SIM 18 /* RFC 4186 */
94 #define EAP_TYPE_TTLS 21 /* draft-funk-eap-ttls-v0-01.txt */
95 #define EAP_TYPE_AKA 23 /* RFC 4187 */
96 #define EAP_TYPE_FAST 43 /* RFC 4851 */
97 #define EAP_TYPE_EXPANDED_TYPES 254
98 #define EAP_TYPE_EXPERIMENTAL 255
100 static const struct tok eap_type_values
[] = {
101 { EAP_TYPE_NO_PROPOSED
, "No proposed" },
102 { EAP_TYPE_IDENTITY
, "Identity" },
103 { EAP_TYPE_NOTIFICATION
, "Notification" },
104 { EAP_TYPE_NAK
, "Nak" },
105 { EAP_TYPE_MD5_CHALLENGE
, "MD5-challenge" },
106 { EAP_TYPE_OTP
, "OTP" },
107 { EAP_TYPE_GTC
, "GTC" },
108 { EAP_TYPE_TLS
, "TLS" },
109 { EAP_TYPE_SIM
, "SIM" },
110 { EAP_TYPE_TTLS
, "TTLS" },
111 { EAP_TYPE_AKA
, "AKA" },
112 { EAP_TYPE_FAST
, "FAST" },
113 { EAP_TYPE_EXPANDED_TYPES
, "Expanded types" },
114 { EAP_TYPE_EXPERIMENTAL
, "Experimental" },
118 #define EAP_TLS_EXTRACT_BIT_L(x) (((x)&0x80)>>7)
120 /* RFC 2716 - EAP TLS bits */
121 #define EAP_TLS_FLAGS_LEN_INCLUDED (1 << 7)
122 #define EAP_TLS_FLAGS_MORE_FRAGMENTS (1 << 6)
123 #define EAP_TLS_FLAGS_START (1 << 5)
125 static const struct tok eap_tls_flags_values
[] = {
126 { EAP_TLS_FLAGS_LEN_INCLUDED
, "L bit" },
127 { EAP_TLS_FLAGS_MORE_FRAGMENTS
, "More fragments bit"},
128 { EAP_TLS_FLAGS_START
, "Start bit"},
132 #define EAP_TTLS_VERSION(x) ((x)&0x07)
134 /* EAP-AKA and EAP-SIM - RFC 4187 */
135 #define EAP_AKA_CHALLENGE 1
136 #define EAP_AKA_AUTH_REJECT 2
137 #define EAP_AKA_SYNC_FAILURE 4
138 #define EAP_AKA_IDENTITY 5
139 #define EAP_SIM_START 10
140 #define EAP_SIM_CHALLENGE 11
141 #define EAP_AKA_NOTIFICATION 12
142 #define EAP_AKA_REAUTH 13
143 #define EAP_AKA_CLIENT_ERROR 14
145 static const struct tok eap_aka_subtype_values
[] = {
146 { EAP_AKA_CHALLENGE
, "Challenge" },
147 { EAP_AKA_AUTH_REJECT
, "Auth reject" },
148 { EAP_AKA_SYNC_FAILURE
, "Sync failure" },
149 { EAP_AKA_IDENTITY
, "Identity" },
150 { EAP_SIM_START
, "Start" },
151 { EAP_SIM_CHALLENGE
, "Challenge" },
152 { EAP_AKA_NOTIFICATION
, "Notification" },
153 { EAP_AKA_REAUTH
, "Reauth" },
154 { EAP_AKA_CLIENT_ERROR
, "Client error" },
159 * Print EAP requests / responses
162 eap_print(netdissect_options
*ndo _U_
,
163 register const u_char
*cp
,
166 const struct eap_frame_t
*eap
;
168 u_int tlen
, type
, subtype
;
173 eap
= (const struct eap_frame_t
*)cp
;
176 /* in non-verbose mode just lets print the basic info */
178 printf("%s (%u) v%u, len %u",
179 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
182 EXTRACT_16BITS(eap
->length
));
186 printf("%s (%u) v%u, len %u",
187 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
190 EXTRACT_16BITS(eap
->length
));
192 tptr
+= sizeof(const struct eap_frame_t
);
193 tlen
-= sizeof(const struct eap_frame_t
);
196 case EAP_FRAME_TYPE_PACKET
:
198 len
= EXTRACT_16BITS(tptr
+2);
199 printf(", %s (%u), id %u, len %u",
200 tok2str(eap_code_values
, "unknown", type
),
205 if (!TTEST2(*tptr
, len
))
208 if (type
<= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
210 printf("\n\t\t Type %s (%u)",
211 tok2str(eap_type_values
, "unknown", *(tptr
+4)),
215 case EAP_TYPE_IDENTITY
:
217 printf(", Identity: ");
218 safeputs((const char *)tptr
+5, len
-5);
222 case EAP_TYPE_NOTIFICATION
:
224 printf(", Notification: ");
225 safeputs((const char *)tptr
+5, len
-5);
233 * one or more octets indicating
234 * the desired authentication
235 * type one octet per type
237 while (count
< len
) {
239 tok2str(eap_type_values
, "unknown", *(tptr
+count
)),
247 EAP_TTLS_VERSION(*(tptr
+5))); /* fall through */
249 printf(" flags [%s] 0x%02x,",
250 bittok2str(eap_tls_flags_values
, "none", *(tptr
+5)),
253 if (EAP_TLS_EXTRACT_BIT_L(*(tptr
+5))) {
254 printf(" len %u", EXTRACT_32BITS(tptr
+6));
260 EAP_TTLS_VERSION(*(tptr
+5)));
261 printf(" flags [%s] 0x%02x,",
262 bittok2str(eap_tls_flags_values
, "none", *(tptr
+5)),
265 if (EAP_TLS_EXTRACT_BIT_L(*(tptr
+5))) {
266 printf(" len %u", EXTRACT_32BITS(tptr
+6));
269 /* FIXME - TLV attributes follow */
274 printf(" subtype [%s] 0x%02x,",
275 tok2str(eap_aka_subtype_values
, "unknown", *(tptr
+5)),
278 /* FIXME - TLV attributes follow */
281 case EAP_TYPE_MD5_CHALLENGE
:
284 case EAP_TYPE_EXPANDED_TYPES
:
285 case EAP_TYPE_EXPERIMENTAL
:
292 case EAP_FRAME_TYPE_LOGOFF
:
293 case EAP_FRAME_TYPE_ENCAP_ASF_ALERT
:
300 printf("\n\t[|EAP]");