]> The Tcpdump Group git mirrors - tcpdump/blob - print-mpcp.c
Update ND_PRINT() as a variadic macro
[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 tptr=pptr;
138 mpcp.common_header = (const struct mpcp_common_header_t *)pptr;
139
140 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_common_header_t));
141 opcode = EXTRACT_BE_U_2(mpcp.common_header->opcode);
142 ND_PRINT("MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode));
143 if (opcode != MPCP_OPCODE_PAUSE) {
144 ND_PRINT(", Timestamp %u ticks", EXTRACT_BE_U_4(mpcp.common_header->timestamp));
145 }
146 ND_PRINT(", length %u", length);
147
148 if (!ndo->ndo_vflag)
149 return;
150
151 tptr += sizeof(struct mpcp_common_header_t);
152
153 switch (opcode) {
154 case MPCP_OPCODE_PAUSE:
155 break;
156
157 case MPCP_OPCODE_GATE:
158 ND_TCHECK_LEN(tptr, MPCP_GRANT_NUMBER_LEN);
159 grant_numbers = EXTRACT_U_1(tptr) & MPCP_GRANT_NUMBER_MASK;
160 ND_PRINT("\n\tGrant Numbers %u, Flags [ %s ]",
161 grant_numbers,
162 bittok2str(mpcp_grant_flag_values,
163 "?",
164 EXTRACT_U_1(tptr) & ~MPCP_GRANT_NUMBER_MASK));
165 tptr++;
166
167 for (grant = 1; grant <= grant_numbers; grant++) {
168 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_grant_t));
169 mpcp.grant = (const struct mpcp_grant_t *)tptr;
170 ND_PRINT("\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
171 grant,
172 EXTRACT_BE_U_4(mpcp.grant->starttime),
173 EXTRACT_BE_U_2(mpcp.grant->duration));
174 tptr += sizeof(struct mpcp_grant_t);
175 }
176
177 ND_TCHECK_2(tptr);
178 ND_PRINT("\n\tSync-Time %u ticks", EXTRACT_BE_U_2(tptr));
179 break;
180
181
182 case MPCP_OPCODE_REPORT:
183 ND_TCHECK_LEN(tptr, MPCP_REPORT_QUEUESETS_LEN);
184 queue_sets = EXTRACT_U_1(tptr);
185 tptr+=MPCP_REPORT_QUEUESETS_LEN;
186 ND_PRINT("\n\tTotal Queue-Sets %u", queue_sets);
187
188 for (queue_set = 1; queue_set < queue_sets; queue_set++) {
189 ND_TCHECK_LEN(tptr, MPCP_REPORT_REPORTBITMAP_LEN);
190 report_bitmap = EXTRACT_U_1(tptr);
191 ND_PRINT("\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
192 queue_sets,
193 bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap));
194 tptr++;
195
196 report=1;
197 while (report_bitmap != 0) {
198 if (report_bitmap & 1) {
199 ND_TCHECK_2(tptr);
200 ND_PRINT("\n\t Q%u Report, Duration %u ticks",
201 report,
202 EXTRACT_BE_U_2(tptr));
203 tptr += 2;
204 }
205 report++;
206 report_bitmap = report_bitmap >> 1;
207 }
208 }
209 break;
210
211 case MPCP_OPCODE_REG_REQ:
212 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_req_t));
213 mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr;
214 ND_PRINT("\n\tFlags [ %s ], Pending-Grants %u",
215 bittok2str(mpcp_reg_req_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg_req->flags)),
216 EXTRACT_U_1(mpcp.reg_req->pending_grants));
217 break;
218
219 case MPCP_OPCODE_REG:
220 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_t));
221 mpcp.reg = (const struct mpcp_reg_t *)tptr;
222 ND_PRINT("\n\tAssigned-Port %u, Flags [ %s ]"
223 "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
224 EXTRACT_BE_U_2(mpcp.reg->assigned_port),
225 bittok2str(mpcp_reg_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg->flags)),
226 EXTRACT_BE_U_2(mpcp.reg->sync_time),
227 EXTRACT_U_1(mpcp.reg->echoed_pending_grants));
228 break;
229
230 case MPCP_OPCODE_REG_ACK:
231 ND_TCHECK_LEN(tptr, sizeof(struct mpcp_reg_ack_t));
232 mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr;
233 ND_PRINT("\n\tEchoed-Assigned-Port %u, Flags [ %s ]"
234 "\n\tEchoed-Sync-Time %u ticks",
235 EXTRACT_BE_U_2(mpcp.reg_ack->echoed_assigned_port),
236 bittok2str(mpcp_reg_ack_flag_values, "Reserved", EXTRACT_U_1(mpcp.reg_ack->flags)),
237 EXTRACT_BE_U_2(mpcp.reg_ack->echoed_sync_time));
238 break;
239
240 default:
241 /* unknown opcode - hexdump for now */
242 print_unknown_data(ndo,pptr, "\n\t", length);
243 break;
244 }
245
246 return;
247
248 trunc:
249 ND_PRINT("\n\t[|MPCP]");
250 }
251 /*
252 * Local Variables:
253 * c-style: whitesmith
254 * c-basic-offset: 8
255 * End:
256 */