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