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>
30 #include "interface.h"
34 #define MPCP_TIMESTAMP_LEN 4
35 #define MPCP_TIMESTAMP_DURATION_LEN 2
37 struct mpcp_common_header_t
{
39 u_int8_t timestamp
[MPCP_TIMESTAMP_LEN
];
42 #define MPCP_OPCODE_PAUSE 0x0001
43 #define MPCP_OPCODE_GATE 0x0002
44 #define MPCP_OPCODE_REPORT 0x0003
45 #define MPCP_OPCODE_REG_REQ 0x0004
46 #define MPCP_OPCODE_REG 0x0005
47 #define MPCP_OPCODE_REG_ACK 0x0006
49 static const struct tok mpcp_opcode_values
[] = {
50 { MPCP_OPCODE_PAUSE
, "Pause" },
51 { MPCP_OPCODE_GATE
, "Gate" },
52 { MPCP_OPCODE_REPORT
, "Report" },
53 { MPCP_OPCODE_REG_REQ
, "Register Request" },
54 { MPCP_OPCODE_REG
, "Register" },
55 { MPCP_OPCODE_REG_ACK
, "Register ACK" },
59 #define MPCP_GRANT_NUMBER_LEN 1
60 #define MPCP_GRANT_NUMBER_MASK 0x7
61 static const struct tok mpcp_grant_flag_values
[] = {
62 { 0x08, "Discovery" },
63 { 0x10, "Force Grant #1" },
64 { 0x20, "Force Grant #2" },
65 { 0x40, "Force Grant #3" },
66 { 0x80, "Force Grant #4" },
71 u_int8_t starttime
[MPCP_TIMESTAMP_LEN
];
72 u_int8_t duration
[MPCP_TIMESTAMP_DURATION_LEN
];
75 struct mpcp_reg_req_t
{
77 u_int8_t pending_grants
;
81 static const struct tok mpcp_reg_req_flag_values
[] = {
88 u_int8_t assigned_port
[2];
90 u_int8_t sync_time
[MPCP_TIMESTAMP_DURATION_LEN
];
91 u_int8_t echoed_pending_grants
;
94 static const struct tok mpcp_reg_flag_values
[] = {
102 #define MPCP_REPORT_QUEUESETS_LEN 1
103 #define MPCP_REPORT_REPORTBITMAP_LEN 1
104 static const struct tok mpcp_report_bitmap_values
[] = {
116 struct mpcp_reg_ack_t
{
118 u_int8_t echoed_assigned_port
[2];
119 u_int8_t echoed_sync_time
[MPCP_TIMESTAMP_DURATION_LEN
];
122 static const struct tok mpcp_reg_ack_flag_values
[] = {
129 mpcp_print(register const u_char
*pptr
, register u_int length
) {
132 const struct mpcp_common_header_t
*common_header
;
133 const struct mpcp_grant_t
*grant
;
134 const struct mpcp_reg_req_t
*reg_req
;
135 const struct mpcp_reg_t
*reg
;
136 const struct mpcp_reg_ack_t
*reg_ack
;
142 u_int8_t grant_numbers
, grant
;
143 u_int8_t queue_sets
, queue_set
, report_bitmap
, report
;
146 mpcp
.common_header
= (const struct mpcp_common_header_t
*)pptr
;
148 if (!TTEST2(*tptr
, sizeof(const struct mpcp_common_header_t
)))
150 opcode
= EXTRACT_16BITS(mpcp
.common_header
->opcode
);
151 printf("MPCP, Opcode %s", tok2str(mpcp_opcode_values
, "Unknown (%u)", opcode
));
152 if (opcode
!= MPCP_OPCODE_PAUSE
) {
153 printf(", Timestamp %u ticks", EXTRACT_32BITS(mpcp
.common_header
->timestamp
));
155 printf(", length %u", length
);
160 tptr
+= sizeof(const struct mpcp_common_header_t
);
163 case MPCP_OPCODE_PAUSE
:
166 case MPCP_OPCODE_GATE
:
167 if (!TTEST2(*tptr
, MPCP_GRANT_NUMBER_LEN
))
169 grant_numbers
= *tptr
& MPCP_GRANT_NUMBER_MASK
;
170 printf("\n\tGrant Numbers %u, Flags [ %s ]",
172 bittok2str(mpcp_grant_flag_values
,
174 *tptr
&~ MPCP_GRANT_NUMBER_MASK
));
177 for (grant
= 1; grant
<= grant_numbers
; grant
++) {
178 if (!TTEST2(*tptr
, sizeof(const struct mpcp_grant_t
)))
180 mpcp
.grant
= (const struct mpcp_grant_t
*)tptr
;
181 printf("\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
183 EXTRACT_32BITS(mpcp
.grant
->starttime
),
184 EXTRACT_16BITS(mpcp
.grant
->duration
));
185 tptr
+= sizeof(const struct mpcp_grant_t
);
188 if (!TTEST2(*tptr
, MPCP_TIMESTAMP_DURATION_LEN
))
190 printf("\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr
));
194 case MPCP_OPCODE_REPORT
:
195 if (!TTEST2(*tptr
, MPCP_REPORT_QUEUESETS_LEN
))
198 tptr
+=MPCP_REPORT_QUEUESETS_LEN
;
199 printf("\n\tTotal Queue-Sets %u", queue_sets
);
201 for (queue_set
= 1; queue_set
< queue_sets
; queue_set
++) {
202 if (!TTEST2(*tptr
, MPCP_REPORT_REPORTBITMAP_LEN
))
204 report_bitmap
= *(tptr
);
205 printf("\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
207 bittok2str(mpcp_report_bitmap_values
, "Unknown", report_bitmap
));
211 while (report_bitmap
!= 0) {
212 if (report_bitmap
& 1) {
213 if (!TTEST2(*tptr
, MPCP_TIMESTAMP_DURATION_LEN
))
215 printf("\n\t Q%u Report, Duration %u ticks",
217 EXTRACT_16BITS(tptr
));
218 tptr
+=MPCP_TIMESTAMP_DURATION_LEN
;
221 report_bitmap
= report_bitmap
>> 1;
226 case MPCP_OPCODE_REG_REQ
:
227 if (!TTEST2(*tptr
, sizeof(const struct mpcp_reg_req_t
)))
229 mpcp
.reg_req
= (const struct mpcp_reg_req_t
*)tptr
;
230 printf("\n\tFlags [ %s ], Pending-Grants %u",
231 bittok2str(mpcp_reg_req_flag_values
, "Reserved", mpcp
.reg_req
->flags
),
232 mpcp
.reg_req
->pending_grants
);
235 case MPCP_OPCODE_REG
:
236 if (!TTEST2(*tptr
, sizeof(const struct mpcp_reg_t
)))
238 mpcp
.reg
= (const struct mpcp_reg_t
*)tptr
;
239 printf("\n\tAssigned-Port %u, Flags [ %s ]" \
240 "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
241 EXTRACT_16BITS(mpcp
.reg
->assigned_port
),
242 bittok2str(mpcp_reg_flag_values
, "Reserved", mpcp
.reg
->flags
),
243 EXTRACT_16BITS(mpcp
.reg
->sync_time
),
244 mpcp
.reg
->echoed_pending_grants
);
247 case MPCP_OPCODE_REG_ACK
:
248 if (!TTEST2(*tptr
, sizeof(const struct mpcp_reg_ack_t
)))
250 mpcp
.reg_ack
= (const struct mpcp_reg_ack_t
*)tptr
;
251 printf("\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \
252 "\n\tEchoed-Sync-Time %u ticks",
253 EXTRACT_16BITS(mpcp
.reg_ack
->echoed_assigned_port
),
254 bittok2str(mpcp_reg_ack_flag_values
, "Reserved", mpcp
.reg_ack
->flags
),
255 EXTRACT_16BITS(mpcp
.reg_ack
->echoed_sync_time
));
259 /* unknown opcode - hexdump for now */
260 print_unknown_data(gndo
,pptr
, "\n\t", length
);
267 printf("\n\t[|MPCP]");
271 * c-style: whitesmith