]> The Tcpdump Group git mirrors - tcpdump/blob - print-eap.c
7b58851b5fc57ec9c7f1e43849fca79bbb134ef3
[tcpdump] / print-eap.c
1 /*
2 * Copyright (c) 2004 - Michael Richardson <mcr@xelerance.com>
3 *
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
15 * written permission.
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.
19 *
20 * Format and print EAP packets.
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <tcpdump-stdinc.h>
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "netdissect.h"
34 #include "interface.h"
35 #include "extract.h"
36 #include "ether.h"
37
38 #define EAP_FRAME_TYPE_PACKET 0
39 #define EAP_FRAME_TYPE_START 1
40 #define EAP_FRAME_TYPE_LOGOFF 2
41 #define EAP_FRAME_TYPE_KEY 3
42 #define EAP_FRAME_TYPE_ENCAP_ASF_ALERT 4
43
44 struct eap_frame_t {
45 unsigned char version;
46 unsigned char type;
47 unsigned char length[2];
48 };
49
50 static const struct tok eap_frame_type_values[] = {
51 { EAP_FRAME_TYPE_PACKET, "EAP packet" },
52 { EAP_FRAME_TYPE_START, "EAPOL start" },
53 { EAP_FRAME_TYPE_LOGOFF, "EAPOL logoff" },
54 { EAP_FRAME_TYPE_KEY, "EAPOL key" },
55 { EAP_FRAME_TYPE_ENCAP_ASF_ALERT, "Encapsulated ASF alert" },
56 { 0, NULL}
57 };
58
59 /* RFC 3748 */
60 struct eap_packet_t {
61 unsigned char code;
62 unsigned char id;
63 unsigned char length[2];
64 };
65
66 #define EAP_REQUEST 1
67 #define EAP_RESPONSE 2
68 #define EAP_SUCCESS 3
69 #define EAP_FAILURE 4
70
71 static const struct tok eap_code_values[] = {
72 { EAP_REQUEST, "Request" },
73 { EAP_RESPONSE, "Response" },
74 { EAP_SUCCESS, "Success" },
75 { EAP_FAILURE, "Failure" },
76 { 0, NULL}
77 };
78
79 #define EAP_TYPE_NO_PROPOSED 0
80 #define EAP_TYPE_IDENTITY 1
81 #define EAP_TYPE_NOTIFICATION 2
82 #define EAP_TYPE_NAK 3
83 #define EAP_TYPE_MD5_CHALLENGE 4
84 #define EAP_TYPE_OTP 5
85 #define EAP_TYPE_GTC 6
86 #define EAP_TYPE_TLS 13 /* RFC 2716 */
87 #define EAP_TYPE_SIM 18 /* RFC 4186 */
88 #define EAP_TYPE_TTLS 21 /* draft-funk-eap-ttls-v0-01.txt */
89 #define EAP_TYPE_AKA 23 /* RFC 4187 */
90 #define EAP_TYPE_FAST 43 /* RFC 4851 */
91 #define EAP_TYPE_EXPANDED_TYPES 254
92 #define EAP_TYPE_EXPERIMENTAL 255
93
94 static const struct tok eap_type_values[] = {
95 { EAP_TYPE_NO_PROPOSED, "No proposed" },
96 { EAP_TYPE_IDENTITY, "Identity" },
97 { EAP_TYPE_NOTIFICATION, "Notification" },
98 { EAP_TYPE_NAK, "Nak" },
99 { EAP_TYPE_MD5_CHALLENGE, "MD5-challenge" },
100 { EAP_TYPE_OTP, "OTP" },
101 { EAP_TYPE_GTC, "GTC" },
102 { EAP_TYPE_TLS, "TLS" },
103 { EAP_TYPE_SIM, "SIM" },
104 { EAP_TYPE_TTLS, "TTLS" },
105 { EAP_TYPE_AKA, "AKA" },
106 { EAP_TYPE_FAST, "FAST" },
107 { EAP_TYPE_EXPANDED_TYPES, "Expanded types" },
108 { EAP_TYPE_EXPERIMENTAL, "Experimental" },
109 { 0, NULL}
110 };
111
112 #define EAP_TLS_EXTRACT_BIT_L(x) (((x)&0x80)>>7)
113
114 /* RFC 2716 - EAP TLS bits */
115 #define EAP_TLS_FLAGS_LEN_INCLUDED (1 << 7)
116 #define EAP_TLS_FLAGS_MORE_FRAGMENTS (1 << 6)
117 #define EAP_TLS_FLAGS_START (1 << 5)
118
119 static const struct tok eap_tls_flags_values[] = {
120 { EAP_TLS_FLAGS_LEN_INCLUDED, "L bit" },
121 { EAP_TLS_FLAGS_MORE_FRAGMENTS, "More fragments bit"},
122 { EAP_TLS_FLAGS_START, "Start bit"},
123 { 0, NULL}
124 };
125
126 #define EAP_TTLS_VERSION(x) ((x)&0x07)
127
128 /* EAP-AKA and EAP-SIM - RFC 4187 */
129 #define EAP_AKA_CHALLENGE 1
130 #define EAP_AKA_AUTH_REJECT 2
131 #define EAP_AKA_SYNC_FAILURE 4
132 #define EAP_AKA_IDENTITY 5
133 #define EAP_SIM_START 10
134 #define EAP_SIM_CHALLENGE 11
135 #define EAP_AKA_NOTIFICATION 12
136 #define EAP_AKA_REAUTH 13
137 #define EAP_AKA_CLIENT_ERROR 14
138
139 static const struct tok eap_aka_subtype_values[] = {
140 { EAP_AKA_CHALLENGE, "Challenge" },
141 { EAP_AKA_AUTH_REJECT, "Auth reject" },
142 { EAP_AKA_SYNC_FAILURE, "Sync failure" },
143 { EAP_AKA_IDENTITY, "Identity" },
144 { EAP_SIM_START, "Start" },
145 { EAP_SIM_CHALLENGE, "Challenge" },
146 { EAP_AKA_NOTIFICATION, "Notification" },
147 { EAP_AKA_REAUTH, "Reauth" },
148 { EAP_AKA_CLIENT_ERROR, "Client error" },
149 { 0, NULL}
150 };
151
152 /*
153 * Print EAP requests / responses
154 */
155 void
156 eap_print(netdissect_options *ndo _U_,
157 register const u_char *cp,
158 u_int length _U_)
159 {
160 const struct eap_frame_t *eap;
161 const u_char *tptr;
162 u_int tlen, type, subtype;
163 int count=0, len;
164
165 tptr = cp;
166 tlen = length;
167 eap = (const struct eap_frame_t *)cp;
168 TCHECK(*eap);
169
170 /* in non-verbose mode just lets print the basic info */
171 if (vflag < 1) {
172 printf("%s (%u) v%u, len %u",
173 tok2str(eap_frame_type_values, "unknown", eap->type),
174 eap->type,
175 eap->version,
176 EXTRACT_16BITS(eap->length));
177 return;
178 }
179
180 printf("%s (%u) v%u, len %u",
181 tok2str(eap_frame_type_values, "unknown", eap->type),
182 eap->type,
183 eap->version,
184 EXTRACT_16BITS(eap->length));
185
186 tptr += sizeof(const struct eap_frame_t);
187 tlen -= sizeof(const struct eap_frame_t);
188
189 switch (eap->type) {
190 case EAP_FRAME_TYPE_PACKET:
191 type = *(tptr);
192 len = EXTRACT_16BITS(tptr+2);
193 printf(", %s (%u), id %u, len %u",
194 tok2str(eap_code_values, "unknown", type),
195 type,
196 *(tptr+1),
197 len);
198
199 if (!TTEST2(*tptr, len))
200 goto trunc;
201
202 if (type <= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
203 subtype = *(tptr+4);
204 printf("\n\t\t Type %s (%u)",
205 tok2str(eap_type_values, "unknown", *(tptr+4)),
206 *(tptr+4));
207
208 switch (subtype) {
209 case EAP_TYPE_IDENTITY:
210 if (len - 5 > 0) {
211 printf(", Identity: ");
212 safeputs((const char *)tptr+5, len-5);
213 }
214 break;
215
216 case EAP_TYPE_NOTIFICATION:
217 if (len - 5 > 0) {
218 printf(", Notification: ");
219 safeputs((const char *)tptr+5, len-5);
220 }
221 break;
222
223 case EAP_TYPE_NAK:
224 count = 5;
225
226 /*
227 * one or more octets indicating
228 * the desired authentication
229 * type one octet per type
230 */
231 while (count < len) {
232 printf(" %s (%u),",
233 tok2str(eap_type_values, "unknown", *(tptr+count)),
234 *(tptr+count));
235 count++;
236 }
237 break;
238
239 case EAP_TYPE_TTLS:
240 printf(" TTLSv%u",
241 EAP_TTLS_VERSION(*(tptr+5))); /* fall through */
242 case EAP_TYPE_TLS:
243 printf(" flags [%s] 0x%02x,",
244 bittok2str(eap_tls_flags_values, "none", *(tptr+5)),
245 *(tptr+5));
246
247 if (EAP_TLS_EXTRACT_BIT_L(*(tptr+5))) {
248 printf(" len %u", EXTRACT_32BITS(tptr+6));
249 }
250 break;
251
252 case EAP_TYPE_FAST:
253 printf(" FASTv%u",
254 EAP_TTLS_VERSION(*(tptr+5)));
255 printf(" flags [%s] 0x%02x,",
256 bittok2str(eap_tls_flags_values, "none", *(tptr+5)),
257 *(tptr+5));
258
259 if (EAP_TLS_EXTRACT_BIT_L(*(tptr+5))) {
260 printf(" len %u", EXTRACT_32BITS(tptr+6));
261 }
262
263 /* FIXME - TLV attributes follow */
264 break;
265
266 case EAP_TYPE_AKA:
267 case EAP_TYPE_SIM:
268 printf(" subtype [%s] 0x%02x,",
269 tok2str(eap_aka_subtype_values, "unknown", *(tptr+5)),
270 *(tptr+5));
271
272 /* FIXME - TLV attributes follow */
273 break;
274
275 case EAP_TYPE_MD5_CHALLENGE:
276 case EAP_TYPE_OTP:
277 case EAP_TYPE_GTC:
278 case EAP_TYPE_EXPANDED_TYPES:
279 case EAP_TYPE_EXPERIMENTAL:
280 default:
281 break;
282 }
283 }
284 break;
285
286 case EAP_FRAME_TYPE_LOGOFF:
287 case EAP_FRAME_TYPE_ENCAP_ASF_ALERT:
288 default:
289 break;
290 }
291 return;
292
293 trunc:
294 printf("\n\t[|EAP]");
295 }
296
297 /*
298 * Local Variables:
299 * c-basic-offset: 4
300 * End:
301 */