]> The Tcpdump Group git mirrors - tcpdump/blob - print-eap.c
from Carles Kishimoto <[email protected]>: make the EAP printer more verbose
[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 #ifndef lint
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 $";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "netdissect.h"
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h"
42 #include "ether.h"
43
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
49
50 struct eap_frame_t {
51 unsigned char version;
52 unsigned char type;
53 unsigned char length[2];
54 };
55
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" },
62 { 0, NULL}
63 };
64
65 /* RFC 3748 */
66 struct eap_packet_t {
67 unsigned char code;
68 unsigned char id;
69 unsigned char length[2];
70 };
71
72 #define EAP_REQUEST 1
73 #define EAP_RESPONSE 2
74 #define EAP_SUCCESS 3
75 #define EAP_FAILURE 4
76
77 static const struct tok eap_code_values[] = {
78 { EAP_REQUEST, "Request" },
79 { EAP_RESPONSE, "Response" },
80 { EAP_SUCCESS, "Success" },
81 { EAP_FAILURE, "Failure" },
82 { 0, NULL}
83 };
84
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
94
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" },
105 { 0, NULL}
106 };
107
108 /*
109 * Print EAP requests / responses
110 */
111 void
112 eap_print(netdissect_options *ndo _U_,
113 register const u_char *cp,
114 u_int length _U_)
115 {
116 const struct eap_frame_t *eap;
117 const u_char *tptr;
118 u_int tlen, type, subtype;
119 int count=0, len;
120
121 tptr = cp;
122 tlen = length;
123 eap = (const struct eap_frame_t *)cp;
124 TCHECK(*eap);
125
126 /* in non-verbose mode just lets print the basic info */
127 if (vflag < 1) {
128 printf("%s (%u) v%u, len %u",
129 tok2str(eap_frame_type_values, "unknown", eap->type),
130 eap->type,
131 eap->version,
132 EXTRACT_16BITS(eap->length));
133 return;
134 }
135
136 printf("%s (%u) v%u, len %u",
137 tok2str(eap_frame_type_values, "unknown", eap->type),
138 eap->type,
139 eap->version,
140 EXTRACT_16BITS(eap->length));
141
142 tptr += sizeof(const struct eap_frame_t);
143 tlen -= sizeof(const struct eap_frame_t);
144
145 switch (eap->type) {
146 case EAP_FRAME_TYPE_PACKET:
147 type = *(tptr);
148 len = EXTRACT_16BITS(tptr+2);
149 printf(", %s (%u), id %u, len %u",
150 tok2str(eap_code_values, "unknown", type),
151 type,
152 *(tptr+1),
153 len);
154
155 if (!TTEST2(*tptr, len))
156 goto trunc;
157
158 if (type <= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
159 subtype = *(tptr+4);
160 printf("\n\t\t Type %s (%u)",
161 tok2str(eap_type_values, "unknown", *(tptr+4)),
162 *(tptr+4));
163
164 switch (subtype) {
165 case EAP_TYPE_IDENTITY:
166 if (len - 5 > 0) {
167 printf(", Identity: ");
168 safeputs((const char *)tptr+5, len-5);
169 }
170 break;
171
172 case EAP_TYPE_NOTIFICATION:
173 if (len - 5 > 0) {
174 printf(", Notification: ");
175 safeputs((const char *)tptr+5, len-5);
176 }
177 break;
178
179 case EAP_TYPE_NAK:
180 count = 5;
181
182 /*
183 * one or more octets indicating
184 * the desired authentication
185 * type one octet per type
186 */
187 while (count < len) {
188 printf(" %s (%u),",
189 tok2str(eap_type_values, "unknown", *(tptr+count)),
190 *(tptr+count));
191 count++;
192 }
193 break;
194
195 case EAP_TYPE_MD5_CHALLENGE:
196 case EAP_TYPE_OTP:
197 case EAP_TYPE_GTC:
198 case EAP_TYPE_EXPANDED_TYPES:
199 case EAP_TYPE_EXPERIMENTAL:
200 default:
201 break;
202 }
203 }
204 break;
205
206 case EAP_FRAME_TYPE_LOGOFF:
207 case EAP_FRAME_TYPE_ENCAP_ASF_ALERT:
208 default:
209 break;
210 }
211 return;
212
213 trunc:
214 printf("\n\t[|EAP]");
215 }
216
217 /*
218 * Local Variables:
219 * c-basic-offset: 4
220 * End:
221 */