blob: 9da3582d540919237f2a64e866db54c9629de600 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Copyright (c) 1998-2006 The TCPDUMP project
3 *
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.
14 *
15 * support for the IEEE MPCP protocol as per 802.3ah
16 *
17 * Original code by Hannes Gredler (hannes@juniper.net)
18 */
19
Elliott Hughes892a68b2015-10-19 14:43:53 -070020#define NETDISSECT_REWORKED
JP Abgrall53f17a92014-02-12 14:02:41 -080021#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <tcpdump-stdinc.h>
26
JP Abgrall53f17a92014-02-12 14:02:41 -080027#include "interface.h"
28#include "extract.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080029
30#define MPCP_TIMESTAMP_LEN 4
31#define MPCP_TIMESTAMP_DURATION_LEN 2
32
33struct mpcp_common_header_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070034 uint8_t opcode[2];
35 uint8_t timestamp[MPCP_TIMESTAMP_LEN];
JP Abgrall53f17a92014-02-12 14:02:41 -080036};
37
38#define MPCP_OPCODE_PAUSE 0x0001
39#define MPCP_OPCODE_GATE 0x0002
40#define MPCP_OPCODE_REPORT 0x0003
41#define MPCP_OPCODE_REG_REQ 0x0004
42#define MPCP_OPCODE_REG 0x0005
43#define MPCP_OPCODE_REG_ACK 0x0006
44
45static const struct tok mpcp_opcode_values[] = {
46 { MPCP_OPCODE_PAUSE, "Pause" },
47 { MPCP_OPCODE_GATE, "Gate" },
48 { MPCP_OPCODE_REPORT, "Report" },
49 { MPCP_OPCODE_REG_REQ, "Register Request" },
50 { MPCP_OPCODE_REG, "Register" },
51 { MPCP_OPCODE_REG_ACK, "Register ACK" },
52 { 0, NULL}
53};
54
55#define MPCP_GRANT_NUMBER_LEN 1
Elliott Hughes892a68b2015-10-19 14:43:53 -070056#define MPCP_GRANT_NUMBER_MASK 0x7
JP Abgrall53f17a92014-02-12 14:02:41 -080057static const struct tok mpcp_grant_flag_values[] = {
58 { 0x08, "Discovery" },
59 { 0x10, "Force Grant #1" },
60 { 0x20, "Force Grant #2" },
61 { 0x40, "Force Grant #3" },
62 { 0x80, "Force Grant #4" },
63 { 0, NULL}
64};
65
66struct mpcp_grant_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070067 uint8_t starttime[MPCP_TIMESTAMP_LEN];
68 uint8_t duration[MPCP_TIMESTAMP_DURATION_LEN];
JP Abgrall53f17a92014-02-12 14:02:41 -080069};
70
71struct mpcp_reg_req_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070072 uint8_t flags;
73 uint8_t pending_grants;
JP Abgrall53f17a92014-02-12 14:02:41 -080074};
75
76
77static const struct tok mpcp_reg_req_flag_values[] = {
78 { 1, "Register" },
79 { 3, "De-Register" },
80 { 0, NULL}
81};
82
83struct mpcp_reg_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070084 uint8_t assigned_port[2];
85 uint8_t flags;
86 uint8_t sync_time[MPCP_TIMESTAMP_DURATION_LEN];
87 uint8_t echoed_pending_grants;
JP Abgrall53f17a92014-02-12 14:02:41 -080088};
89
90static const struct tok mpcp_reg_flag_values[] = {
91 { 1, "Re-Register" },
92 { 2, "De-Register" },
93 { 3, "ACK" },
94 { 4, "NACK" },
95 { 0, NULL}
96};
97
98#define MPCP_REPORT_QUEUESETS_LEN 1
99#define MPCP_REPORT_REPORTBITMAP_LEN 1
100static const struct tok mpcp_report_bitmap_values[] = {
101 { 0x01, "Q0" },
102 { 0x02, "Q1" },
103 { 0x04, "Q2" },
104 { 0x08, "Q3" },
105 { 0x10, "Q4" },
106 { 0x20, "Q5" },
107 { 0x40, "Q6" },
108 { 0x80, "Q7" },
109 { 0, NULL}
110};
111
112struct mpcp_reg_ack_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700113 uint8_t flags;
114 uint8_t echoed_assigned_port[2];
115 uint8_t echoed_sync_time[MPCP_TIMESTAMP_DURATION_LEN];
JP Abgrall53f17a92014-02-12 14:02:41 -0800116};
117
118static const struct tok mpcp_reg_ack_flag_values[] = {
119 { 0, "NACK" },
120 { 1, "ACK" },
121 { 0, NULL}
122};
123
124void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700125mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int length)
126{
JP Abgrall53f17a92014-02-12 14:02:41 -0800127 union {
128 const struct mpcp_common_header_t *common_header;
129 const struct mpcp_grant_t *grant;
130 const struct mpcp_reg_req_t *reg_req;
131 const struct mpcp_reg_t *reg;
132 const struct mpcp_reg_ack_t *reg_ack;
133 } mpcp;
134
135
136 const u_char *tptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700137 uint16_t opcode;
138 uint8_t grant_numbers, grant;
139 uint8_t queue_sets, queue_set, report_bitmap, report;
JP Abgrall53f17a92014-02-12 14:02:41 -0800140
141 tptr=pptr;
142 mpcp.common_header = (const struct mpcp_common_header_t *)pptr;
143
Elliott Hughes892a68b2015-10-19 14:43:53 -0700144 ND_TCHECK2(*tptr, sizeof(const struct mpcp_common_header_t));
JP Abgrall53f17a92014-02-12 14:02:41 -0800145 opcode = EXTRACT_16BITS(mpcp.common_header->opcode);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700146 ND_PRINT((ndo, "MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800147 if (opcode != MPCP_OPCODE_PAUSE) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700148 ND_PRINT((ndo, ", Timestamp %u ticks", EXTRACT_32BITS(mpcp.common_header->timestamp)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800149 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700150 ND_PRINT((ndo, ", length %u", length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800151
Elliott Hughes892a68b2015-10-19 14:43:53 -0700152 if (!ndo->ndo_vflag)
JP Abgrall53f17a92014-02-12 14:02:41 -0800153 return;
154
155 tptr += sizeof(const struct mpcp_common_header_t);
156
157 switch (opcode) {
158 case MPCP_OPCODE_PAUSE:
159 break;
160
161 case MPCP_OPCODE_GATE:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700162 ND_TCHECK2(*tptr, MPCP_GRANT_NUMBER_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800163 grant_numbers = *tptr & MPCP_GRANT_NUMBER_MASK;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700164 ND_PRINT((ndo, "\n\tGrant Numbers %u, Flags [ %s ]",
JP Abgrall53f17a92014-02-12 14:02:41 -0800165 grant_numbers,
166 bittok2str(mpcp_grant_flag_values,
167 "?",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700168 *tptr &~ MPCP_GRANT_NUMBER_MASK)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800169 tptr++;
170
171 for (grant = 1; grant <= grant_numbers; grant++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700172 ND_TCHECK2(*tptr, sizeof(const struct mpcp_grant_t));
173 mpcp.grant = (const struct mpcp_grant_t *)tptr;
174 ND_PRINT((ndo, "\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
JP Abgrall53f17a92014-02-12 14:02:41 -0800175 grant,
176 EXTRACT_32BITS(mpcp.grant->starttime),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700177 EXTRACT_16BITS(mpcp.grant->duration)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800178 tptr += sizeof(const struct mpcp_grant_t);
179 }
180
Elliott Hughes892a68b2015-10-19 14:43:53 -0700181 ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN);
182 ND_PRINT((ndo, "\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800183 break;
184
185
186 case MPCP_OPCODE_REPORT:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700187 ND_TCHECK2(*tptr, MPCP_REPORT_QUEUESETS_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800188 queue_sets = *tptr;
189 tptr+=MPCP_REPORT_QUEUESETS_LEN;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700190 ND_PRINT((ndo, "\n\tTotal Queue-Sets %u", queue_sets));
JP Abgrall53f17a92014-02-12 14:02:41 -0800191
192 for (queue_set = 1; queue_set < queue_sets; queue_set++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700193 ND_TCHECK2(*tptr, MPCP_REPORT_REPORTBITMAP_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -0800194 report_bitmap = *(tptr);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700195 ND_PRINT((ndo, "\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
JP Abgrall53f17a92014-02-12 14:02:41 -0800196 queue_sets,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700197 bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800198 tptr++;
199
200 report=1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700201 while (report_bitmap != 0) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800202 if (report_bitmap & 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700203 ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN);
204 ND_PRINT((ndo, "\n\t Q%u Report, Duration %u ticks",
JP Abgrall53f17a92014-02-12 14:02:41 -0800205 report,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700206 EXTRACT_16BITS(tptr)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800207 tptr+=MPCP_TIMESTAMP_DURATION_LEN;
208 }
209 report++;
210 report_bitmap = report_bitmap >> 1;
211 }
212 }
213 break;
214
215 case MPCP_OPCODE_REG_REQ:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700216 ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_req_t));
217 mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr;
218 ND_PRINT((ndo, "\n\tFlags [ %s ], Pending-Grants %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800219 bittok2str(mpcp_reg_req_flag_values, "Reserved", mpcp.reg_req->flags),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700220 mpcp.reg_req->pending_grants));
JP Abgrall53f17a92014-02-12 14:02:41 -0800221 break;
222
223 case MPCP_OPCODE_REG:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700224 ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_t));
225 mpcp.reg = (const struct mpcp_reg_t *)tptr;
226 ND_PRINT((ndo, "\n\tAssigned-Port %u, Flags [ %s ]" \
JP Abgrall53f17a92014-02-12 14:02:41 -0800227 "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
228 EXTRACT_16BITS(mpcp.reg->assigned_port),
229 bittok2str(mpcp_reg_flag_values, "Reserved", mpcp.reg->flags),
230 EXTRACT_16BITS(mpcp.reg->sync_time),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700231 mpcp.reg->echoed_pending_grants));
JP Abgrall53f17a92014-02-12 14:02:41 -0800232 break;
233
234 case MPCP_OPCODE_REG_ACK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700235 ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_ack_t));
236 mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr;
237 ND_PRINT((ndo, "\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \
JP Abgrall53f17a92014-02-12 14:02:41 -0800238 "\n\tEchoed-Sync-Time %u ticks",
239 EXTRACT_16BITS(mpcp.reg_ack->echoed_assigned_port),
240 bittok2str(mpcp_reg_ack_flag_values, "Reserved", mpcp.reg_ack->flags),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700241 EXTRACT_16BITS(mpcp.reg_ack->echoed_sync_time)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800242 break;
243
244 default:
245 /* unknown opcode - hexdump for now */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700246 print_unknown_data(ndo,pptr, "\n\t", length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800247 break;
248 }
249
250 return;
251
252trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700253 ND_PRINT((ndo, "\n\t[|MPCP]"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800254}
Elliott Hughes892a68b2015-10-19 14:43:53 -0700255/*
256 * Local Variables:
257 * c-style: whitesmith
258 * c-basic-offset: 8
259 * End:
260 */