]> The Tcpdump Group git mirrors - tcpdump/blob - print-mpcp.c
Remove useless comments
[tcpdump] / print-mpcp.c
1 /*
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 * Original code by Hannes Gredler (hannes@gredler.at)
16 */
17
18 /* \summary: IEEE 802.3ah Multi-Point Control Protocol (MPCP) printer */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "netdissect-stdinc.h"
25
26 #include "netdissect.h"
27 #include "extract.h"
28
29 struct mpcp_common_header_t {
30 nd_uint16_t opcode;
31 nd_uint32_t timestamp;
32 };
33
34 #define MPCP_OPCODE_PAUSE 0x0001
35 #define MPCP_OPCODE_GATE 0x0002
36 #define MPCP_OPCODE_REPORT 0x0003
37 #define MPCP_OPCODE_REG_REQ 0x0004
38 #define MPCP_OPCODE_REG 0x0005
39 #define MPCP_OPCODE_REG_ACK 0x0006
40
41 static const struct tok mpcp_opcode_values[] = {
42 { MPCP_OPCODE_PAUSE, "Pause" },
43 { MPCP_OPCODE_GATE, "Gate" },
44 { MPCP_OPCODE_REPORT, "Report" },
45 { MPCP_OPCODE_REG_REQ, "Register Request" },
46 { MPCP_OPCODE_REG, "Register" },
47 { MPCP_OPCODE_REG_ACK, "Register ACK" },
48 { 0, NULL}
49 };
50
51 #define MPCP_GRANT_NUMBER_LEN 1
52 #define MPCP_GRANT_NUMBER_MASK 0x7
53 static const struct tok mpcp_grant_flag_values[] = {
54 { 0x08, "Discovery" },
55 { 0x10, "Force Grant #1" },
56 { 0x20, "Force Grant #2" },
57 { 0x40, "Force Grant #3" },
58 { 0x80, "Force Grant #4" },
59 { 0, NULL}
60 };
61
62 struct mpcp_grant_t {
63 nd_uint32_t starttime;
64 nd_uint16_t duration;
65 };
66
67 struct mpcp_reg_req_t {
68 nd_uint8_t flags;
69 nd_uint8_t pending_grants;
70 };
71
72
73 static const struct tok mpcp_reg_req_flag_values[] = {
74 { 1, "Register" },
75 { 3, "De-Register" },
76 { 0, NULL}
77 };
78
79 struct mpcp_reg_t {
80 nd_uint16_t assigned_port;
81 nd_uint8_t flags;
82 nd_uint16_t sync_time;
83 nd_uint8_t echoed_pending_grants;
84 };
85
86 static const struct tok mpcp_reg_flag_values[] = {
87 { 1, "Re-Register" },
88 { 2, "De-Register" },
89 { 3, "ACK" },
90 { 4, "NACK" },
91 { 0, NULL}
92 };
93
94 #define MPCP_REPORT_QUEUESETS_LEN 1
95 #define MPCP_REPORT_REPORTBITMAP_LEN 1
96 static const struct tok mpcp_report_bitmap_values[] = {
97 { 0x01, "Q0" },
98 { 0x02, "Q1" },
99 { 0x04, "Q2" },
100 { 0x08, "Q3" },
101 { 0x10, "Q4" },
102 { 0x20, "Q5" },
103 { 0x40, "Q6" },
104 { 0x80, "Q7" },
105 { 0, NULL}
106 };
107
108 struct mpcp_reg_ack_t {
109 nd_uint8_t flags;
110 nd_uint16_t echoed_assigned_port;
111 nd_uint16_t echoed_sync_time;
112 };
113
114 static const struct tok mpcp_reg_ack_flag_values[] = {
115 { 0, "NACK" },
116 { 1, "ACK" },
117 { 0, NULL}
118 };
119
120 void
121 mpcp_print(netdissect_options *ndo, const u_char *pptr, u_int length)
122 {
123 union {
124 const struct mpcp_common_header_t *common_header;
125 const struct mpcp_grant_t *grant;
126 const struct mpcp_reg_req_t *reg_req;
127 const struct mpcp_reg_t *reg;
128 const struct mpcp_reg_ack_t *reg_ack;
129 } mpcp;
130
131
132 const u_char *tptr;
133 uint16_t opcode;
134 uint8_t grant_numbers, grant;
135 uint8_t queue_sets, queue_set, report_bitmap, report;
136
137 ndo->ndo_protocol = "mpcp";
138 tptr=pptr;
139 mpcp.common_header = (const struct mpcp_common_header_t *)pptr;
140
141 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_common_header_t));
142 opcode = EXTRACT_BE_U_2(mpcp.common_header->opcode);
143 ND_PRINT("MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode));
144 if (opcode != MPCP_OPCODE_PAUSE) {
145 ND_PRINT(", Timestamp %u ticks", EXTRACT_BE_U_4(mpcp.common_header->timestamp));
146 }
147 ND_PRINT(", length %u", length);
148
149 if (!ndo->ndo_vflag)
150 return;
151
152 tptr += sizeof(struct mpcp_common_header_t);
153
154 switch (opcode) {
155 case MPCP_OPCODE_PAUSE:
156 break;
157
158 case MPCP_OPCODE_GATE:
159 ND_TCHECK_LEN(tptr, MPCP_GRANT_NUMBER_LEN);
160 grant_numbers = EXTRACT_U_1(tptr) & MPCP_GRANT_NUMBER_MASK;
161 ND_PRINT("\n\tGrant Numbers %u, Flags [ %s ]",
162 grant_numbers,
163 bittok2str(mpcp_grant_flag_values,
164 "?",
165 EXTRACT_U_1(tptr) & ~MPCP_GRANT_NUMBER_MASK));
166 tptr++;
167
168 for (grant = 1; grant <= grant_numbers; grant++) {
169 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_grant_t));
170 mpcp.grant = (const struct mpcp_grant_t *)tptr;
171 ND_PRINT("\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
172 grant,
173 EXTRACT_BE_U_4(mpcp.grant->starttime),
174 EXTRACT_BE_U_2(mpcp.grant->duration));
175 tptr += sizeof(struct mpcp_grant_t);
176 }
177
178 ND_TCHECK_2(tptr);
179 ND_PRINT("\n\tSync-Time %u ticks", EXTRACT_BE_U_2(tptr));
180 break;
181
182
183 case MPCP_OPCODE_REPORT:
184 ND_TCHECK_LEN(tptr, MPCP_REPORT_QUEUESETS_LEN);
185 queue_sets = EXTRACT_U_1(tptr);
186 tptr+=MPCP_REPORT_QUEUESETS_LEN;
187 ND_PRINT("\n\tTotal Queue-Sets %u", queue_sets);
188
189 for (queue_set = 1; queue_set < queue_sets; queue_set++) {
190 ND_TCHECK_LEN(tptr, MPCP_REPORT_REPORTBITMAP_LEN);
191 report_bitmap = EXTRACT_U_1(tptr);
192 ND_PRINT("\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
193 queue_sets,
194 bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap));
195 tptr++;
196
197 report=1;
198 while (report_bitmap != 0) {
199 if (report_bitmap & 1) {
200 ND_TCHECK_2(tptr);
201 ND_PRINT("\n\t Q%u Report, Duration %u ticks",
202 report,
203 EXTRACT_BE_U_2(tptr));
204 tptr += 2;
205 }
206 report++;
207 report_bitmap = report_bitmap >> 1;
208 }
209 }
210 break;
211
212 case MPCP_OPCODE_REG_REQ:
213 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_req_t));
214 mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr;
215 ND_PRINT("\n\tFlags [ %s ], Pending-Grants %u",
216 bittok2str(mpcp_reg_req_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg_req->flags)),
217 EXTRACT_U_1(mpcp.reg_req->pending_grants));
218 break;
219
220 case MPCP_OPCODE_REG:
221 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_t));
222 mpcp.reg = (const struct mpcp_reg_t *)tptr;
223 ND_PRINT("\n\tAssigned-Port %u, Flags [ %s ]"
224 "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
225 EXTRACT_BE_U_2(mpcp.reg->assigned_port),
226 bittok2str(mpcp_reg_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg->flags)),
227 EXTRACT_BE_U_2(mpcp.reg->sync_time),
228 EXTRACT_U_1(mpcp.reg->echoed_pending_grants));
229 break;
230
231 case MPCP_OPCODE_REG_ACK:
232 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_ack_t));
233 mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr;
234 ND_PRINT("\n\tEchoed-Assigned-Port %u, Flags [ %s ]"
235 "\n\tEchoed-Sync-Time %u ticks",
236 EXTRACT_BE_U_2(mpcp.reg_ack->echoed_assigned_port),
237 bittok2str(mpcp_reg_ack_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg_ack->flags)),
238 EXTRACT_BE_U_2(mpcp.reg_ack->echoed_sync_time));
239 break;
240
241 default:
242 /* unknown opcode - hexdump for now */
243 print_unknown_data(ndo,pptr, "\n\t", length);
244 break;
245 }
246
247 return;
248
249 trunc:
250 ND_PRINT("\n\t[|MPCP]");
251 }