2 * Copyright (c) 1998-2006 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * support for the IEEE MPCP protocol as per 802.3ah
17 * Original code by Hannes Gredler (hannes@juniper.net)
24 #include <tcpdump-stdinc.h>
26 #include "netdissect.h"
29 #define MPCP_TIMESTAMP_LEN 4
30 #define MPCP_TIMESTAMP_DURATION_LEN 2
32 struct mpcp_common_header_t
{
34 u_int8_t timestamp
[MPCP_TIMESTAMP_LEN
];
37 #define MPCP_OPCODE_PAUSE 0x0001
38 #define MPCP_OPCODE_GATE 0x0002
39 #define MPCP_OPCODE_REPORT 0x0003
40 #define MPCP_OPCODE_REG_REQ 0x0004
41 #define MPCP_OPCODE_REG 0x0005
42 #define MPCP_OPCODE_REG_ACK 0x0006
44 static const struct tok mpcp_opcode_values
[] = {
45 { MPCP_OPCODE_PAUSE
, "Pause" },
46 { MPCP_OPCODE_GATE
, "Gate" },
47 { MPCP_OPCODE_REPORT
, "Report" },
48 { MPCP_OPCODE_REG_REQ
, "Register Request" },
49 { MPCP_OPCODE_REG
, "Register" },
50 { MPCP_OPCODE_REG_ACK
, "Register ACK" },
54 #define MPCP_GRANT_NUMBER_LEN 1
55 #define MPCP_GRANT_NUMBER_MASK 0x7
56 static const struct tok mpcp_grant_flag_values
[] = {
57 { 0x08, "Discovery" },
58 { 0x10, "Force Grant #1" },
59 { 0x20, "Force Grant #2" },
60 { 0x40, "Force Grant #3" },
61 { 0x80, "Force Grant #4" },
66 u_int8_t starttime
[MPCP_TIMESTAMP_LEN
];
67 u_int8_t duration
[MPCP_TIMESTAMP_DURATION_LEN
];
70 struct mpcp_reg_req_t
{
72 u_int8_t pending_grants
;
76 static const struct tok mpcp_reg_req_flag_values
[] = {
83 u_int8_t assigned_port
[2];
85 u_int8_t sync_time
[MPCP_TIMESTAMP_DURATION_LEN
];
86 u_int8_t echoed_pending_grants
;
89 static const struct tok mpcp_reg_flag_values
[] = {
97 #define MPCP_REPORT_QUEUESETS_LEN 1
98 #define MPCP_REPORT_REPORTBITMAP_LEN 1
99 static const struct tok mpcp_report_bitmap_values
[] = {
111 struct mpcp_reg_ack_t
{
113 u_int8_t echoed_assigned_port
[2];
114 u_int8_t echoed_sync_time
[MPCP_TIMESTAMP_DURATION_LEN
];
117 static const struct tok mpcp_reg_ack_flag_values
[] = {
124 mpcp_print(netdissect_options
*ndo
, register const u_char
*pptr
, register u_int length
) {
127 const struct mpcp_common_header_t
*common_header
;
128 const struct mpcp_grant_t
*grant
;
129 const struct mpcp_reg_req_t
*reg_req
;
130 const struct mpcp_reg_t
*reg
;
131 const struct mpcp_reg_ack_t
*reg_ack
;
137 u_int8_t grant_numbers
, grant
;
138 u_int8_t queue_sets
, queue_set
, report_bitmap
, report
;
141 mpcp
.common_header
= (const struct mpcp_common_header_t
*)pptr
;
143 if (!ND_TTEST2(*tptr
, sizeof(const struct mpcp_common_header_t
)))
145 opcode
= EXTRACT_16BITS(mpcp
.common_header
->opcode
);
146 ND_PRINT((ndo
, "MPCP, Opcode %s", tok2str(mpcp_opcode_values
, "Unknown (%u)", opcode
)));
147 if (opcode
!= MPCP_OPCODE_PAUSE
) {
148 ND_PRINT((ndo
, ", Timestamp %u ticks", EXTRACT_32BITS(mpcp
.common_header
->timestamp
)));
150 ND_PRINT((ndo
, ", length %u", length
));
155 tptr
+= sizeof(const struct mpcp_common_header_t
);
158 case MPCP_OPCODE_PAUSE
:
161 case MPCP_OPCODE_GATE
:
162 if (!ND_TTEST2(*tptr
, MPCP_GRANT_NUMBER_LEN
))
164 grant_numbers
= *tptr
& MPCP_GRANT_NUMBER_MASK
;
165 ND_PRINT((ndo
, "\n\tGrant Numbers %u, Flags [ %s ]",
167 bittok2str(mpcp_grant_flag_values
,
169 *tptr
&~ MPCP_GRANT_NUMBER_MASK
)));
172 for (grant
= 1; grant
<= grant_numbers
; grant
++) {
173 if (!ND_TTEST2(*tptr
, sizeof(const struct mpcp_grant_t
)))
175 mpcp
.grant
= (const struct mpcp_grant_t
*)tptr
;
176 ND_PRINT((ndo
, "\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
178 EXTRACT_32BITS(mpcp
.grant
->starttime
),
179 EXTRACT_16BITS(mpcp
.grant
->duration
)));
180 tptr
+= sizeof(const struct mpcp_grant_t
);
183 if (!ND_TTEST2(*tptr
, MPCP_TIMESTAMP_DURATION_LEN
))
185 ND_PRINT((ndo
, "\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr
)));
189 case MPCP_OPCODE_REPORT
:
190 if (!ND_TTEST2(*tptr
, MPCP_REPORT_QUEUESETS_LEN
))
193 tptr
+=MPCP_REPORT_QUEUESETS_LEN
;
194 ND_PRINT((ndo
, "\n\tTotal Queue-Sets %u", queue_sets
));
196 for (queue_set
= 1; queue_set
< queue_sets
; queue_set
++) {
197 if (!ND_TTEST2(*tptr
, MPCP_REPORT_REPORTBITMAP_LEN
))
199 report_bitmap
= *(tptr
);
200 ND_PRINT((ndo
, "\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
202 bittok2str(mpcp_report_bitmap_values
, "Unknown", report_bitmap
)));
206 while (report_bitmap
!= 0) {
207 if (report_bitmap
& 1) {
208 if (!ND_TTEST2(*tptr
, MPCP_TIMESTAMP_DURATION_LEN
))
210 ND_PRINT((ndo
, "\n\t Q%u Report, Duration %u ticks",
212 EXTRACT_16BITS(tptr
)));
213 tptr
+=MPCP_TIMESTAMP_DURATION_LEN
;
216 report_bitmap
= report_bitmap
>> 1;
221 case MPCP_OPCODE_REG_REQ
:
222 if (!ND_TTEST2(*tptr
, sizeof(const struct mpcp_reg_req_t
)))
224 mpcp
.reg_req
= (const struct mpcp_reg_req_t
*)tptr
;
225 ND_PRINT((ndo
, "\n\tFlags [ %s ], Pending-Grants %u",
226 bittok2str(mpcp_reg_req_flag_values
, "Reserved", mpcp
.reg_req
->flags
),
227 mpcp
.reg_req
->pending_grants
));
230 case MPCP_OPCODE_REG
:
231 if (!ND_TTEST2(*tptr
, sizeof(const struct mpcp_reg_t
)))
233 mpcp
.reg
= (const struct mpcp_reg_t
*)tptr
;
234 ND_PRINT((ndo
, "\n\tAssigned-Port %u, Flags [ %s ]" \
235 "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
236 EXTRACT_16BITS(mpcp
.reg
->assigned_port
),
237 bittok2str(mpcp_reg_flag_values
, "Reserved", mpcp
.reg
->flags
),
238 EXTRACT_16BITS(mpcp
.reg
->sync_time
),
239 mpcp
.reg
->echoed_pending_grants
));
242 case MPCP_OPCODE_REG_ACK
:
243 if (!ND_TTEST2(*tptr
, sizeof(const struct mpcp_reg_ack_t
)))
245 mpcp
.reg_ack
= (const struct mpcp_reg_ack_t
*)tptr
;
246 ND_PRINT((ndo
, "\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \
247 "\n\tEchoed-Sync-Time %u ticks",
248 EXTRACT_16BITS(mpcp
.reg_ack
->echoed_assigned_port
),
249 bittok2str(mpcp_reg_ack_flag_values
, "Reserved", mpcp
.reg_ack
->flags
),
250 EXTRACT_16BITS(mpcp
.reg_ack
->echoed_sync_time
)));
254 /* unknown opcode - hexdump for now */
255 print_unknown_data(ndo
,pptr
, "\n\t", length
);
262 ND_PRINT((ndo
, "\n\t[|MPCP]"));
266 * c-style: whitesmith