1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | #include <stdio.h> |
---|
27 | #include "libpacketdump.h" |
---|
28 | |
---|
29 | #define POPBYTE(x) \ |
---|
30 | do { \ |
---|
31 | if (len<1) return; \ |
---|
32 | x=*(packet++); \ |
---|
33 | } while(0) |
---|
34 | |
---|
35 | #define POPWORD(x) \ |
---|
36 | do { \ |
---|
37 | if (len<2) return; \ |
---|
38 | x=htons(*(uint16_t*)packet); \ |
---|
39 | packet+=2; \ |
---|
40 | } while(0) |
---|
41 | |
---|
42 | static void decode_eap_request(const char *packet, unsigned len) |
---|
43 | { |
---|
44 | int v; |
---|
45 | POPBYTE(v); |
---|
46 | printf(" 802.1x: EAP: Identifier: %u\n",v); |
---|
47 | POPWORD(v); |
---|
48 | printf(" 802.1x: EAP: Length: %u\n",v); |
---|
49 | POPBYTE(v); |
---|
50 | printf(" 802.1x: EAP: Type: "); |
---|
51 | switch(v) { |
---|
52 | case 1: printf(" Identity (1)\n"); break; |
---|
53 | case 2: printf(" Notification (2)\n"); break; |
---|
54 | case 3: printf(" NAK (3)\n"); break; |
---|
55 | case 4: printf(" MD5-Challenge (4)\n"); break; |
---|
56 | case 5: printf(" One-Time Password (5)\n"); break; |
---|
57 | case 6: printf(" Generic Token Card (6)\n"); break; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | static void decode_eap(const char *packet, unsigned len) |
---|
62 | { |
---|
63 | int v; |
---|
64 | POPWORD(v); |
---|
65 | printf(" 802.1x: Length: %d\n",v); |
---|
66 | POPBYTE(v); |
---|
67 | printf(" 802.1x: EAP: "); |
---|
68 | switch(v) { |
---|
69 | case 1: |
---|
70 | printf("Request (1)\n"); |
---|
71 | decode_eap_request(packet,len); |
---|
72 | break; |
---|
73 | case 2: printf("Response (2)\n"); break; |
---|
74 | case 3: printf("Success (3)\n"); break; |
---|
75 | case 4: printf("Failure (4)\n"); break; |
---|
76 | default: printf("#0x%02x\n",v); break; |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | static void decode_eapol_start(const char *packet, unsigned len) |
---|
82 | { |
---|
83 | int v; |
---|
84 | POPWORD(v); |
---|
85 | printf(" 802.1x: Length: %d\n",v); |
---|
86 | } |
---|
87 | |
---|
88 | static void decode_eapol_logoff(const char *packet, unsigned len) |
---|
89 | { |
---|
90 | int v; |
---|
91 | POPWORD(v); |
---|
92 | printf(" 802.1x: Length: %d\n",v); |
---|
93 | } |
---|
94 | |
---|
95 | struct key_descriptor { |
---|
96 | uint8_t descriptor_type; |
---|
97 | uint16_t key_length; |
---|
98 | uint64_t replay_counter; |
---|
99 | uint8_t key_iv[27-12]; |
---|
100 | uint8_t kevy_index; |
---|
101 | uint8_t key_signature[44-29]; |
---|
102 | }; |
---|
103 | |
---|
104 | static void decode_eapol_key(const char *packet, unsigned len) |
---|
105 | { |
---|
106 | int v; |
---|
107 | POPWORD(v); |
---|
108 | printf(" 802.1x: Length: %d\n",v); |
---|
109 | } |
---|
110 | |
---|
111 | static void decode_eapol_encapsulated_asf_alert(const char *packet, unsigned len) |
---|
112 | { |
---|
113 | int v; |
---|
114 | POPWORD(v); |
---|
115 | printf(" 802.1x: Length: %d\n",v); |
---|
116 | } |
---|
117 | |
---|
118 | DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) |
---|
119 | { |
---|
120 | int v; |
---|
121 | int type; |
---|
122 | POPBYTE(v); |
---|
123 | printf(" 802.1x: Version: %u\n",v); |
---|
124 | POPBYTE(type); |
---|
125 | printf(" 802.1x: Type: "); |
---|
126 | switch (type) { |
---|
127 | case 0: |
---|
128 | printf(" EAP-Packet (0)\n"); |
---|
129 | decode_eap(packet,len); |
---|
130 | break; |
---|
131 | case 1: printf(" EAPOL-Start (1)\n"); |
---|
132 | decode_eapol_start(packet,len); |
---|
133 | break; |
---|
134 | case 2: |
---|
135 | printf(" EAPOL-Logoff (2)\n"); |
---|
136 | decode_eapol_logoff(packet,len); |
---|
137 | break; |
---|
138 | case 3: |
---|
139 | printf(" EAPOL-Key (3)\n"); |
---|
140 | decode_eapol_key(packet,len); |
---|
141 | break; |
---|
142 | case 4: |
---|
143 | printf(" EAPOL-Encasulated-ASF-Alert (4)\n"); |
---|
144 | decode_eapol_encapsulated_asf_alert(packet,len); |
---|
145 | break; |
---|
146 | default: |
---|
147 | printf(" Unknown #0x%02x\n",v); |
---|
148 | decode_next(packet,len,"eapol",type); |
---|
149 | break; |
---|
150 | } |
---|
151 | |
---|
152 | return; |
---|
153 | } |
---|