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.
28 #include <tcpdump-stdinc.h>
30 #include "interface.h"
33 #define EAP_FRAME_TYPE_PACKET 0
34 #define EAP_FRAME_TYPE_START 1
35 #define EAP_FRAME_TYPE_LOGOFF 2
36 #define EAP_FRAME_TYPE_KEY 3
37 #define EAP_FRAME_TYPE_ENCAP_ASF_ALERT 4
40 unsigned char version
;
42 unsigned char length
[2];
45 static const struct tok eap_frame_type_values
[] = {
46 { EAP_FRAME_TYPE_PACKET
, "EAP packet" },
47 { EAP_FRAME_TYPE_START
, "EAPOL start" },
48 { EAP_FRAME_TYPE_LOGOFF
, "EAPOL logoff" },
49 { EAP_FRAME_TYPE_KEY
, "EAPOL key" },
50 { EAP_FRAME_TYPE_ENCAP_ASF_ALERT
, "Encapsulated ASF alert" },
58 unsigned char length
[2];
62 #define EAP_RESPONSE 2
66 static const struct tok eap_code_values
[] = {
67 { EAP_REQUEST
, "Request" },
68 { EAP_RESPONSE
, "Response" },
69 { EAP_SUCCESS
, "Success" },
70 { EAP_FAILURE
, "Failure" },
74 #define EAP_TYPE_NO_PROPOSED 0
75 #define EAP_TYPE_IDENTITY 1
76 #define EAP_TYPE_NOTIFICATION 2
77 #define EAP_TYPE_NAK 3
78 #define EAP_TYPE_MD5_CHALLENGE 4
79 #define EAP_TYPE_OTP 5
80 #define EAP_TYPE_GTC 6
81 #define EAP_TYPE_TLS 13 /* RFC 2716 */
82 #define EAP_TYPE_SIM 18 /* RFC 4186 */
83 #define EAP_TYPE_TTLS 21 /* draft-funk-eap-ttls-v0-01.txt */
84 #define EAP_TYPE_AKA 23 /* RFC 4187 */
85 #define EAP_TYPE_FAST 43 /* RFC 4851 */
86 #define EAP_TYPE_EXPANDED_TYPES 254
87 #define EAP_TYPE_EXPERIMENTAL 255
89 static const struct tok eap_type_values
[] = {
90 { EAP_TYPE_NO_PROPOSED
, "No proposed" },
91 { EAP_TYPE_IDENTITY
, "Identity" },
92 { EAP_TYPE_NOTIFICATION
, "Notification" },
93 { EAP_TYPE_NAK
, "Nak" },
94 { EAP_TYPE_MD5_CHALLENGE
, "MD5-challenge" },
95 { EAP_TYPE_OTP
, "OTP" },
96 { EAP_TYPE_GTC
, "GTC" },
97 { EAP_TYPE_TLS
, "TLS" },
98 { EAP_TYPE_SIM
, "SIM" },
99 { EAP_TYPE_TTLS
, "TTLS" },
100 { EAP_TYPE_AKA
, "AKA" },
101 { EAP_TYPE_FAST
, "FAST" },
102 { EAP_TYPE_EXPANDED_TYPES
, "Expanded types" },
103 { EAP_TYPE_EXPERIMENTAL
, "Experimental" },
107 #define EAP_TLS_EXTRACT_BIT_L(x) (((x)&0x80)>>7)
109 /* RFC 2716 - EAP TLS bits */
110 #define EAP_TLS_FLAGS_LEN_INCLUDED (1 << 7)
111 #define EAP_TLS_FLAGS_MORE_FRAGMENTS (1 << 6)
112 #define EAP_TLS_FLAGS_START (1 << 5)
114 static const struct tok eap_tls_flags_values
[] = {
115 { EAP_TLS_FLAGS_LEN_INCLUDED
, "L bit" },
116 { EAP_TLS_FLAGS_MORE_FRAGMENTS
, "More fragments bit"},
117 { EAP_TLS_FLAGS_START
, "Start bit"},
121 #define EAP_TTLS_VERSION(x) ((x)&0x07)
123 /* EAP-AKA and EAP-SIM - RFC 4187 */
124 #define EAP_AKA_CHALLENGE 1
125 #define EAP_AKA_AUTH_REJECT 2
126 #define EAP_AKA_SYNC_FAILURE 4
127 #define EAP_AKA_IDENTITY 5
128 #define EAP_SIM_START 10
129 #define EAP_SIM_CHALLENGE 11
130 #define EAP_AKA_NOTIFICATION 12
131 #define EAP_AKA_REAUTH 13
132 #define EAP_AKA_CLIENT_ERROR 14
134 static const struct tok eap_aka_subtype_values
[] = {
135 { EAP_AKA_CHALLENGE
, "Challenge" },
136 { EAP_AKA_AUTH_REJECT
, "Auth reject" },
137 { EAP_AKA_SYNC_FAILURE
, "Sync failure" },
138 { EAP_AKA_IDENTITY
, "Identity" },
139 { EAP_SIM_START
, "Start" },
140 { EAP_SIM_CHALLENGE
, "Challenge" },
141 { EAP_AKA_NOTIFICATION
, "Notification" },
142 { EAP_AKA_REAUTH
, "Reauth" },
143 { EAP_AKA_CLIENT_ERROR
, "Client error" },
148 * Print EAP requests / responses
151 eap_print(netdissect_options
*ndo
,
152 register const u_char
*cp
,
155 const struct eap_frame_t
*eap
;
157 u_int tlen
, type
, subtype
;
162 eap
= (const struct eap_frame_t
*)cp
;
165 /* in non-verbose mode just lets print the basic info */
166 if (ndo
->ndo_vflag
< 1) {
167 ND_PRINT((ndo
, "%s (%u) v%u, len %u",
168 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
171 EXTRACT_16BITS(eap
->length
)));
175 ND_PRINT((ndo
, "%s (%u) v%u, len %u",
176 tok2str(eap_frame_type_values
, "unknown", eap
->type
),
179 EXTRACT_16BITS(eap
->length
)));
181 tptr
+= sizeof(const struct eap_frame_t
);
182 tlen
-= sizeof(const struct eap_frame_t
);
185 case EAP_FRAME_TYPE_PACKET
:
187 len
= EXTRACT_16BITS(tptr
+2);
188 ND_PRINT((ndo
, ", %s (%u), id %u, len %u",
189 tok2str(eap_code_values
, "unknown", type
),
194 ND_TCHECK2(*tptr
, len
);
196 if (type
<= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
198 ND_PRINT((ndo
, "\n\t\t Type %s (%u)",
199 tok2str(eap_type_values
, "unknown", *(tptr
+4)),
203 case EAP_TYPE_IDENTITY
:
205 ND_PRINT((ndo
, ", Identity: "));
206 safeputs(ndo
, tptr
+ 5, len
- 5);
210 case EAP_TYPE_NOTIFICATION
:
212 ND_PRINT((ndo
, ", Notification: "));
213 safeputs(ndo
, tptr
+ 5, len
- 5);
221 * one or more octets indicating
222 * the desired authentication
223 * type one octet per type
225 while (count
< len
) {
226 ND_PRINT((ndo
, " %s (%u),",
227 tok2str(eap_type_values
, "unknown", *(tptr
+count
)),
234 ND_PRINT((ndo
, " TTLSv%u",
235 EAP_TTLS_VERSION(*(tptr
+ 5)))); /* fall through */
237 ND_PRINT((ndo
, " flags [%s] 0x%02x,",
238 bittok2str(eap_tls_flags_values
, "none", *(tptr
+5)),
241 if (EAP_TLS_EXTRACT_BIT_L(*(tptr
+5))) {
242 ND_PRINT((ndo
, " len %u", EXTRACT_32BITS(tptr
+ 6)));
247 ND_PRINT((ndo
, " FASTv%u",
248 EAP_TTLS_VERSION(*(tptr
+ 5))));
249 ND_PRINT((ndo
, " flags [%s] 0x%02x,",
250 bittok2str(eap_tls_flags_values
, "none", *(tptr
+5)),
253 if (EAP_TLS_EXTRACT_BIT_L(*(tptr
+5))) {
254 ND_PRINT((ndo
, " len %u", EXTRACT_32BITS(tptr
+ 6)));
257 /* FIXME - TLV attributes follow */
262 ND_PRINT((ndo
, " subtype [%s] 0x%02x,",
263 tok2str(eap_aka_subtype_values
, "unknown", *(tptr
+5)),
266 /* FIXME - TLV attributes follow */
269 case EAP_TYPE_MD5_CHALLENGE
:
272 case EAP_TYPE_EXPANDED_TYPES
:
273 case EAP_TYPE_EXPERIMENTAL
:
280 case EAP_FRAME_TYPE_LOGOFF
:
281 case EAP_FRAME_TYPE_ENCAP_ASF_ALERT
:
288 ND_PRINT((ndo
, "\n\t[|EAP]"));