1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 1998-2006 The TCPDUMP project |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that: (1) source code |
---|
8 | * distributions retain the above copyright notice and this paragraph |
---|
9 | * in its entirety, and (2) distributions including binary code include |
---|
10 | * the above copyright notice and this paragraph in its entirety in |
---|
11 | * the documentation or other materials provided with the distribution. |
---|
12 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
---|
13 | * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
---|
14 | * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
15 | * FOR A PARTICULAR PURPOSE. |
---|
16 | * |
---|
17 | * support for the IEEE MPCP protocol as per 802.3ah |
---|
18 | * |
---|
19 | * Original code by Hannes Gredler (hannes@juniper.net) |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef lint |
---|
23 | static const char rcsid[] _U_ = |
---|
24 | "@(#) $Header: /tcpdump/master/tcpdump/print-mpcp.c,v 1.2 2006-02-10 17:24:55 hannes Exp $"; |
---|
25 | #endif |
---|
26 | |
---|
27 | #ifdef HAVE_CONFIG_H |
---|
28 | #include "config.h" |
---|
29 | #endif |
---|
30 | |
---|
31 | #include <tcpdump-stdinc.h> |
---|
32 | |
---|
33 | #include <stdio.h> |
---|
34 | #include <stdlib.h> |
---|
35 | #include <string.h> |
---|
36 | |
---|
37 | #include "interface.h" |
---|
38 | #include "extract.h" |
---|
39 | #include "addrtoname.h" |
---|
40 | #include "ether.h" |
---|
41 | |
---|
42 | #define MPCP_TIMESTAMP_LEN 4 |
---|
43 | #define MPCP_TIMESTAMP_DURATION_LEN 2 |
---|
44 | |
---|
45 | struct mpcp_common_header_t { |
---|
46 | u_int8_t opcode[2]; |
---|
47 | u_int8_t timestamp[MPCP_TIMESTAMP_LEN]; |
---|
48 | }; |
---|
49 | |
---|
50 | #define MPCP_OPCODE_PAUSE 0x0001 |
---|
51 | #define MPCP_OPCODE_GATE 0x0002 |
---|
52 | #define MPCP_OPCODE_REPORT 0x0003 |
---|
53 | #define MPCP_OPCODE_REG_REQ 0x0004 |
---|
54 | #define MPCP_OPCODE_REG 0x0005 |
---|
55 | #define MPCP_OPCODE_REG_ACK 0x0006 |
---|
56 | |
---|
57 | static const struct tok mpcp_opcode_values[] = { |
---|
58 | { MPCP_OPCODE_PAUSE, "Pause" }, |
---|
59 | { MPCP_OPCODE_GATE, "Gate" }, |
---|
60 | { MPCP_OPCODE_REPORT, "Report" }, |
---|
61 | { MPCP_OPCODE_REG_REQ, "Register Request" }, |
---|
62 | { MPCP_OPCODE_REG, "Register" }, |
---|
63 | { MPCP_OPCODE_REG_ACK, "Register ACK" }, |
---|
64 | { 0, NULL} |
---|
65 | }; |
---|
66 | |
---|
67 | #define MPCP_GRANT_NUMBER_LEN 1 |
---|
68 | #define MPCP_GRANT_NUMBER_MASK 0x7 |
---|
69 | static const struct tok mpcp_grant_flag_values[] = { |
---|
70 | { 0x08, "Discovery" }, |
---|
71 | { 0x10, "Force Grant #1" }, |
---|
72 | { 0x20, "Force Grant #2" }, |
---|
73 | { 0x40, "Force Grant #3" }, |
---|
74 | { 0x80, "Force Grant #4" }, |
---|
75 | { 0, NULL} |
---|
76 | }; |
---|
77 | |
---|
78 | struct mpcp_grant_t { |
---|
79 | u_int8_t starttime[MPCP_TIMESTAMP_LEN]; |
---|
80 | u_int8_t duration[MPCP_TIMESTAMP_DURATION_LEN]; |
---|
81 | }; |
---|
82 | |
---|
83 | struct mpcp_reg_req_t { |
---|
84 | u_int8_t flags; |
---|
85 | u_int8_t pending_grants; |
---|
86 | }; |
---|
87 | |
---|
88 | |
---|
89 | static const struct tok mpcp_reg_req_flag_values[] = { |
---|
90 | { 1, "Register" }, |
---|
91 | { 3, "De-Register" }, |
---|
92 | { 0, NULL} |
---|
93 | }; |
---|
94 | |
---|
95 | struct mpcp_reg_t { |
---|
96 | u_int8_t assigned_port[2]; |
---|
97 | u_int8_t flags; |
---|
98 | u_int8_t sync_time[MPCP_TIMESTAMP_DURATION_LEN]; |
---|
99 | u_int8_t echoed_pending_grants; |
---|
100 | }; |
---|
101 | |
---|
102 | static const struct tok mpcp_reg_flag_values[] = { |
---|
103 | { 1, "Re-Register" }, |
---|
104 | { 2, "De-Register" }, |
---|
105 | { 3, "ACK" }, |
---|
106 | { 4, "NACK" }, |
---|
107 | { 0, NULL} |
---|
108 | }; |
---|
109 | |
---|
110 | #define MPCP_REPORT_QUEUESETS_LEN 1 |
---|
111 | #define MPCP_REPORT_REPORTBITMAP_LEN 1 |
---|
112 | static const struct tok mpcp_report_bitmap_values[] = { |
---|
113 | { 0x01, "Q0" }, |
---|
114 | { 0x02, "Q1" }, |
---|
115 | { 0x04, "Q2" }, |
---|
116 | { 0x08, "Q3" }, |
---|
117 | { 0x10, "Q4" }, |
---|
118 | { 0x20, "Q5" }, |
---|
119 | { 0x40, "Q6" }, |
---|
120 | { 0x80, "Q7" }, |
---|
121 | { 0, NULL} |
---|
122 | }; |
---|
123 | |
---|
124 | struct mpcp_reg_ack_t { |
---|
125 | u_int8_t flags; |
---|
126 | u_int8_t echoed_assigned_port[2]; |
---|
127 | u_int8_t echoed_sync_time[MPCP_TIMESTAMP_DURATION_LEN]; |
---|
128 | }; |
---|
129 | |
---|
130 | static const struct tok mpcp_reg_ack_flag_values[] = { |
---|
131 | { 0, "NACK" }, |
---|
132 | { 1, "ACK" }, |
---|
133 | { 0, NULL} |
---|
134 | }; |
---|
135 | |
---|
136 | void |
---|
137 | mpcp_print(register const u_char *pptr, register u_int length) { |
---|
138 | |
---|
139 | union { |
---|
140 | const struct mpcp_common_header_t *common_header; |
---|
141 | const struct mpcp_grant_t *grant; |
---|
142 | const struct mpcp_reg_req_t *reg_req; |
---|
143 | const struct mpcp_reg_t *reg; |
---|
144 | const struct mpcp_reg_ack_t *reg_ack; |
---|
145 | } mpcp; |
---|
146 | |
---|
147 | |
---|
148 | const u_char *tptr; |
---|
149 | u_int16_t opcode; |
---|
150 | u_int8_t grant_numbers, grant; |
---|
151 | u_int8_t queue_sets, queue_set, report_bitmap, report; |
---|
152 | |
---|
153 | tptr=pptr; |
---|
154 | mpcp.common_header = (const struct mpcp_common_header_t *)pptr; |
---|
155 | |
---|
156 | if (!TTEST2(*tptr, sizeof(const struct mpcp_common_header_t))) |
---|
157 | goto trunc; |
---|
158 | opcode = EXTRACT_16BITS(mpcp.common_header->opcode); |
---|
159 | printf("MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode)); |
---|
160 | if (opcode != MPCP_OPCODE_PAUSE) { |
---|
161 | printf(", Timestamp %u ticks", EXTRACT_32BITS(mpcp.common_header->timestamp)); |
---|
162 | } |
---|
163 | printf(", length %u", length); |
---|
164 | |
---|
165 | if (!vflag) |
---|
166 | return; |
---|
167 | |
---|
168 | tptr += sizeof(const struct mpcp_common_header_t); |
---|
169 | |
---|
170 | switch (opcode) { |
---|
171 | case MPCP_OPCODE_PAUSE: |
---|
172 | break; |
---|
173 | |
---|
174 | case MPCP_OPCODE_GATE: |
---|
175 | if (!TTEST2(*tptr, MPCP_GRANT_NUMBER_LEN)) |
---|
176 | goto trunc; |
---|
177 | grant_numbers = *tptr & MPCP_GRANT_NUMBER_MASK; |
---|
178 | printf("\n\tGrant Numbers %u, Flags [ %s ]", |
---|
179 | grant_numbers, |
---|
180 | bittok2str(mpcp_grant_flag_values, |
---|
181 | "?", |
---|
182 | *tptr &~ MPCP_GRANT_NUMBER_MASK)); |
---|
183 | tptr++; |
---|
184 | |
---|
185 | for (grant = 1; grant <= grant_numbers; grant++) { |
---|
186 | if (!TTEST2(*tptr, sizeof(const struct mpcp_grant_t))) |
---|
187 | goto trunc; |
---|
188 | mpcp.grant = (const struct mpcp_grant_t *)tptr; |
---|
189 | printf("\n\tGrant #%u, Start-Time %u ticks, duration %u ticks", |
---|
190 | grant, |
---|
191 | EXTRACT_32BITS(mpcp.grant->starttime), |
---|
192 | EXTRACT_16BITS(mpcp.grant->duration)); |
---|
193 | tptr += sizeof(const struct mpcp_grant_t); |
---|
194 | } |
---|
195 | |
---|
196 | if (!TTEST2(*tptr, MPCP_TIMESTAMP_DURATION_LEN)) |
---|
197 | goto trunc; |
---|
198 | printf("\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr)); |
---|
199 | break; |
---|
200 | |
---|
201 | |
---|
202 | case MPCP_OPCODE_REPORT: |
---|
203 | if (!TTEST2(*tptr, MPCP_REPORT_QUEUESETS_LEN)) |
---|
204 | goto trunc; |
---|
205 | queue_sets = *tptr; |
---|
206 | tptr+=MPCP_REPORT_QUEUESETS_LEN; |
---|
207 | printf("\n\tTotal Queue-Sets %u", queue_sets); |
---|
208 | |
---|
209 | for (queue_set = 1; queue_set < queue_sets; queue_set++) { |
---|
210 | if (!TTEST2(*tptr, MPCP_REPORT_REPORTBITMAP_LEN)) |
---|
211 | goto trunc; |
---|
212 | report_bitmap = *(tptr); |
---|
213 | printf("\n\t Queue-Set #%u, Report-Bitmap [ %s ]", |
---|
214 | queue_sets, |
---|
215 | bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap)); |
---|
216 | tptr++; |
---|
217 | |
---|
218 | report=1; |
---|
219 | while (report_bitmap != 0) { |
---|
220 | if (report_bitmap & 1) { |
---|
221 | if (!TTEST2(*tptr, MPCP_TIMESTAMP_DURATION_LEN)) |
---|
222 | goto trunc; |
---|
223 | printf("\n\t Q%u Report, Duration %u ticks", |
---|
224 | report, |
---|
225 | EXTRACT_16BITS(tptr)); |
---|
226 | tptr+=MPCP_TIMESTAMP_DURATION_LEN; |
---|
227 | } |
---|
228 | report++; |
---|
229 | report_bitmap = report_bitmap >> 1; |
---|
230 | } |
---|
231 | } |
---|
232 | break; |
---|
233 | |
---|
234 | case MPCP_OPCODE_REG_REQ: |
---|
235 | if (!TTEST2(*tptr, sizeof(const struct mpcp_reg_req_t))) |
---|
236 | goto trunc; |
---|
237 | mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr; |
---|
238 | printf("\n\tFlags [ %s ], Pending-Grants %u", |
---|
239 | bittok2str(mpcp_reg_req_flag_values, "Reserved", mpcp.reg_req->flags), |
---|
240 | mpcp.reg_req->pending_grants); |
---|
241 | break; |
---|
242 | |
---|
243 | case MPCP_OPCODE_REG: |
---|
244 | if (!TTEST2(*tptr, sizeof(const struct mpcp_reg_t))) |
---|
245 | goto trunc; |
---|
246 | mpcp.reg = (const struct mpcp_reg_t *)tptr; |
---|
247 | printf("\n\tAssigned-Port %u, Flags [ %s ]" \ |
---|
248 | "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u", |
---|
249 | EXTRACT_16BITS(mpcp.reg->assigned_port), |
---|
250 | bittok2str(mpcp_reg_flag_values, "Reserved", mpcp.reg->flags), |
---|
251 | EXTRACT_16BITS(mpcp.reg->sync_time), |
---|
252 | mpcp.reg->echoed_pending_grants); |
---|
253 | break; |
---|
254 | |
---|
255 | case MPCP_OPCODE_REG_ACK: |
---|
256 | if (!TTEST2(*tptr, sizeof(const struct mpcp_reg_ack_t))) |
---|
257 | goto trunc; |
---|
258 | mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr; |
---|
259 | printf("\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \ |
---|
260 | "\n\tEchoed-Sync-Time %u ticks", |
---|
261 | EXTRACT_16BITS(mpcp.reg_ack->echoed_assigned_port), |
---|
262 | bittok2str(mpcp_reg_ack_flag_values, "Reserved", mpcp.reg_ack->flags), |
---|
263 | EXTRACT_16BITS(mpcp.reg_ack->echoed_sync_time)); |
---|
264 | break; |
---|
265 | |
---|
266 | default: |
---|
267 | /* unknown opcode - hexdump for now */ |
---|
268 | print_unknown_data(pptr, "\n\t", length); |
---|
269 | break; |
---|
270 | } |
---|
271 | |
---|
272 | return; |
---|
273 | |
---|
274 | trunc: |
---|
275 | printf("\n\t[|MPCP]"); |
---|
276 | } |
---|