1ea7b4bf5SPeter Avalos /*
2ea7b4bf5SPeter Avalos * Copyright (c) 1998-2006 The TCPDUMP project
3ea7b4bf5SPeter Avalos *
4ea7b4bf5SPeter Avalos * Redistribution and use in source and binary forms, with or without
5ea7b4bf5SPeter Avalos * modification, are permitted provided that: (1) source code
6ea7b4bf5SPeter Avalos * distributions retain the above copyright notice and this paragraph
7ea7b4bf5SPeter Avalos * in its entirety, and (2) distributions including binary code include
8ea7b4bf5SPeter Avalos * the above copyright notice and this paragraph in its entirety in
9ea7b4bf5SPeter Avalos * the documentation or other materials provided with the distribution.
10ea7b4bf5SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11ea7b4bf5SPeter Avalos * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12ea7b4bf5SPeter Avalos * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13ea7b4bf5SPeter Avalos * FOR A PARTICULAR PURPOSE.
14ea7b4bf5SPeter Avalos *
15411677aeSAaron LI * Original code by Hannes Gredler (hannes@gredler.at)
16ea7b4bf5SPeter Avalos */
17ea7b4bf5SPeter Avalos
18411677aeSAaron LI /* \summary: IEEE 802.3ah Multi-Point Control Protocol (MPCP) printer */
19ea7b4bf5SPeter Avalos
20ea7b4bf5SPeter Avalos #ifdef HAVE_CONFIG_H
21*ed775ee7SAntonio Huete Jimenez #include <config.h>
22ea7b4bf5SPeter Avalos #endif
23ea7b4bf5SPeter Avalos
24*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
25ea7b4bf5SPeter Avalos
26411677aeSAaron LI #include "netdissect.h"
27ea7b4bf5SPeter Avalos #include "extract.h"
28ea7b4bf5SPeter Avalos
29ea7b4bf5SPeter Avalos struct mpcp_common_header_t {
30*ed775ee7SAntonio Huete Jimenez nd_uint16_t opcode;
31*ed775ee7SAntonio Huete Jimenez nd_uint32_t timestamp;
32ea7b4bf5SPeter Avalos };
33ea7b4bf5SPeter Avalos
34ea7b4bf5SPeter Avalos #define MPCP_OPCODE_PAUSE 0x0001
35ea7b4bf5SPeter Avalos #define MPCP_OPCODE_GATE 0x0002
36ea7b4bf5SPeter Avalos #define MPCP_OPCODE_REPORT 0x0003
37ea7b4bf5SPeter Avalos #define MPCP_OPCODE_REG_REQ 0x0004
38ea7b4bf5SPeter Avalos #define MPCP_OPCODE_REG 0x0005
39ea7b4bf5SPeter Avalos #define MPCP_OPCODE_REG_ACK 0x0006
40ea7b4bf5SPeter Avalos
41ea7b4bf5SPeter Avalos static const struct tok mpcp_opcode_values[] = {
42ea7b4bf5SPeter Avalos { MPCP_OPCODE_PAUSE, "Pause" },
43ea7b4bf5SPeter Avalos { MPCP_OPCODE_GATE, "Gate" },
44ea7b4bf5SPeter Avalos { MPCP_OPCODE_REPORT, "Report" },
45ea7b4bf5SPeter Avalos { MPCP_OPCODE_REG_REQ, "Register Request" },
46ea7b4bf5SPeter Avalos { MPCP_OPCODE_REG, "Register" },
47ea7b4bf5SPeter Avalos { MPCP_OPCODE_REG_ACK, "Register ACK" },
48ea7b4bf5SPeter Avalos { 0, NULL}
49ea7b4bf5SPeter Avalos };
50ea7b4bf5SPeter Avalos
51ea7b4bf5SPeter Avalos #define MPCP_GRANT_NUMBER_LEN 1
52ea7b4bf5SPeter Avalos #define MPCP_GRANT_NUMBER_MASK 0x7
53ea7b4bf5SPeter Avalos static const struct tok mpcp_grant_flag_values[] = {
54ea7b4bf5SPeter Avalos { 0x08, "Discovery" },
55ea7b4bf5SPeter Avalos { 0x10, "Force Grant #1" },
56ea7b4bf5SPeter Avalos { 0x20, "Force Grant #2" },
57ea7b4bf5SPeter Avalos { 0x40, "Force Grant #3" },
58ea7b4bf5SPeter Avalos { 0x80, "Force Grant #4" },
59ea7b4bf5SPeter Avalos { 0, NULL}
60ea7b4bf5SPeter Avalos };
61ea7b4bf5SPeter Avalos
62ea7b4bf5SPeter Avalos struct mpcp_grant_t {
63*ed775ee7SAntonio Huete Jimenez nd_uint32_t starttime;
64*ed775ee7SAntonio Huete Jimenez nd_uint16_t duration;
65ea7b4bf5SPeter Avalos };
66ea7b4bf5SPeter Avalos
67ea7b4bf5SPeter Avalos struct mpcp_reg_req_t {
68*ed775ee7SAntonio Huete Jimenez nd_uint8_t flags;
69*ed775ee7SAntonio Huete Jimenez nd_uint8_t pending_grants;
70ea7b4bf5SPeter Avalos };
71ea7b4bf5SPeter Avalos
72ea7b4bf5SPeter Avalos
73ea7b4bf5SPeter Avalos static const struct tok mpcp_reg_req_flag_values[] = {
74ea7b4bf5SPeter Avalos { 1, "Register" },
75ea7b4bf5SPeter Avalos { 3, "De-Register" },
76ea7b4bf5SPeter Avalos { 0, NULL}
77ea7b4bf5SPeter Avalos };
78ea7b4bf5SPeter Avalos
79ea7b4bf5SPeter Avalos struct mpcp_reg_t {
80*ed775ee7SAntonio Huete Jimenez nd_uint16_t assigned_port;
81*ed775ee7SAntonio Huete Jimenez nd_uint8_t flags;
82*ed775ee7SAntonio Huete Jimenez nd_uint16_t sync_time;
83*ed775ee7SAntonio Huete Jimenez nd_uint8_t echoed_pending_grants;
84ea7b4bf5SPeter Avalos };
85ea7b4bf5SPeter Avalos
86ea7b4bf5SPeter Avalos static const struct tok mpcp_reg_flag_values[] = {
87ea7b4bf5SPeter Avalos { 1, "Re-Register" },
88ea7b4bf5SPeter Avalos { 2, "De-Register" },
89ea7b4bf5SPeter Avalos { 3, "ACK" },
90ea7b4bf5SPeter Avalos { 4, "NACK" },
91ea7b4bf5SPeter Avalos { 0, NULL}
92ea7b4bf5SPeter Avalos };
93ea7b4bf5SPeter Avalos
94ea7b4bf5SPeter Avalos #define MPCP_REPORT_QUEUESETS_LEN 1
95ea7b4bf5SPeter Avalos #define MPCP_REPORT_REPORTBITMAP_LEN 1
96ea7b4bf5SPeter Avalos static const struct tok mpcp_report_bitmap_values[] = {
97ea7b4bf5SPeter Avalos { 0x01, "Q0" },
98ea7b4bf5SPeter Avalos { 0x02, "Q1" },
99ea7b4bf5SPeter Avalos { 0x04, "Q2" },
100ea7b4bf5SPeter Avalos { 0x08, "Q3" },
101ea7b4bf5SPeter Avalos { 0x10, "Q4" },
102ea7b4bf5SPeter Avalos { 0x20, "Q5" },
103ea7b4bf5SPeter Avalos { 0x40, "Q6" },
104ea7b4bf5SPeter Avalos { 0x80, "Q7" },
105ea7b4bf5SPeter Avalos { 0, NULL}
106ea7b4bf5SPeter Avalos };
107ea7b4bf5SPeter Avalos
108ea7b4bf5SPeter Avalos struct mpcp_reg_ack_t {
109*ed775ee7SAntonio Huete Jimenez nd_uint8_t flags;
110*ed775ee7SAntonio Huete Jimenez nd_uint16_t echoed_assigned_port;
111*ed775ee7SAntonio Huete Jimenez nd_uint16_t echoed_sync_time;
112ea7b4bf5SPeter Avalos };
113ea7b4bf5SPeter Avalos
114ea7b4bf5SPeter Avalos static const struct tok mpcp_reg_ack_flag_values[] = {
115ea7b4bf5SPeter Avalos { 0, "NACK" },
116ea7b4bf5SPeter Avalos { 1, "ACK" },
117ea7b4bf5SPeter Avalos { 0, NULL}
118ea7b4bf5SPeter Avalos };
119ea7b4bf5SPeter Avalos
120ea7b4bf5SPeter Avalos void
mpcp_print(netdissect_options * ndo,const u_char * pptr,u_int length)121*ed775ee7SAntonio Huete Jimenez mpcp_print(netdissect_options *ndo, const u_char *pptr, u_int length)
122411677aeSAaron LI {
123*ed775ee7SAntonio Huete Jimenez const struct mpcp_common_header_t *mpcp_common_header;
124*ed775ee7SAntonio Huete Jimenez const struct mpcp_reg_req_t *mpcp_reg_req;
125*ed775ee7SAntonio Huete Jimenez const struct mpcp_reg_t *mpcp_reg;
126*ed775ee7SAntonio Huete Jimenez const struct mpcp_reg_ack_t *mpcp_reg_ack;
127ea7b4bf5SPeter Avalos
128ea7b4bf5SPeter Avalos
129ea7b4bf5SPeter Avalos const u_char *tptr;
130411677aeSAaron LI uint16_t opcode;
131*ed775ee7SAntonio Huete Jimenez uint32_t timestamp;
132411677aeSAaron LI uint8_t grant_numbers, grant;
133411677aeSAaron LI uint8_t queue_sets, queue_set, report_bitmap, report;
134ea7b4bf5SPeter Avalos
135*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "mpcp";
136ea7b4bf5SPeter Avalos tptr=pptr;
137*ed775ee7SAntonio Huete Jimenez mpcp_common_header = (const struct mpcp_common_header_t *)pptr;
138ea7b4bf5SPeter Avalos
139*ed775ee7SAntonio Huete Jimenez opcode = GET_BE_U_2(mpcp_common_header->opcode);
140*ed775ee7SAntonio Huete Jimenez timestamp = GET_BE_U_4(mpcp_common_header->timestamp);
141*ed775ee7SAntonio Huete Jimenez ND_PRINT("MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode));
142ea7b4bf5SPeter Avalos if (opcode != MPCP_OPCODE_PAUSE) {
143*ed775ee7SAntonio Huete Jimenez ND_PRINT(", Timestamp %u ticks", timestamp);
144ea7b4bf5SPeter Avalos }
145*ed775ee7SAntonio Huete Jimenez ND_PRINT(", length %u", length);
146ea7b4bf5SPeter Avalos
147411677aeSAaron LI if (!ndo->ndo_vflag)
148ea7b4bf5SPeter Avalos return;
149ea7b4bf5SPeter Avalos
150*ed775ee7SAntonio Huete Jimenez tptr += sizeof(struct mpcp_common_header_t);
151ea7b4bf5SPeter Avalos
152ea7b4bf5SPeter Avalos switch (opcode) {
153ea7b4bf5SPeter Avalos case MPCP_OPCODE_PAUSE:
154ea7b4bf5SPeter Avalos break;
155ea7b4bf5SPeter Avalos
156ea7b4bf5SPeter Avalos case MPCP_OPCODE_GATE:
157*ed775ee7SAntonio Huete Jimenez grant_numbers = GET_U_1(tptr) & MPCP_GRANT_NUMBER_MASK;
158*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tGrant Numbers %u, Flags [ %s ]",
159ea7b4bf5SPeter Avalos grant_numbers,
160ea7b4bf5SPeter Avalos bittok2str(mpcp_grant_flag_values,
161ea7b4bf5SPeter Avalos "?",
162*ed775ee7SAntonio Huete Jimenez GET_U_1(tptr) & ~MPCP_GRANT_NUMBER_MASK));
163ea7b4bf5SPeter Avalos tptr++;
164ea7b4bf5SPeter Avalos
165ea7b4bf5SPeter Avalos for (grant = 1; grant <= grant_numbers; grant++) {
166*ed775ee7SAntonio Huete Jimenez const struct mpcp_grant_t *mpcp_grant = (const struct mpcp_grant_t *)tptr;
167*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
168ea7b4bf5SPeter Avalos grant,
169*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(mpcp_grant->starttime),
170*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(mpcp_grant->duration));
171*ed775ee7SAntonio Huete Jimenez tptr += sizeof(struct mpcp_grant_t);
172ea7b4bf5SPeter Avalos }
173ea7b4bf5SPeter Avalos
174*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tSync-Time %u ticks", GET_BE_U_2(tptr));
175ea7b4bf5SPeter Avalos break;
176ea7b4bf5SPeter Avalos
177ea7b4bf5SPeter Avalos
178ea7b4bf5SPeter Avalos case MPCP_OPCODE_REPORT:
179*ed775ee7SAntonio Huete Jimenez queue_sets = GET_U_1(tptr);
180ea7b4bf5SPeter Avalos tptr+=MPCP_REPORT_QUEUESETS_LEN;
181*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tTotal Queue-Sets %u", queue_sets);
182ea7b4bf5SPeter Avalos
183ea7b4bf5SPeter Avalos for (queue_set = 1; queue_set < queue_sets; queue_set++) {
184*ed775ee7SAntonio Huete Jimenez report_bitmap = GET_U_1(tptr);
185*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
186ea7b4bf5SPeter Avalos queue_sets,
187*ed775ee7SAntonio Huete Jimenez bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap));
188ea7b4bf5SPeter Avalos tptr++;
189ea7b4bf5SPeter Avalos
190ea7b4bf5SPeter Avalos report=1;
191ea7b4bf5SPeter Avalos while (report_bitmap != 0) {
192ea7b4bf5SPeter Avalos if (report_bitmap & 1) {
193*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\t Q%u Report, Duration %u ticks",
194ea7b4bf5SPeter Avalos report,
195*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(tptr));
196*ed775ee7SAntonio Huete Jimenez tptr += 2;
197ea7b4bf5SPeter Avalos }
198ea7b4bf5SPeter Avalos report++;
199ea7b4bf5SPeter Avalos report_bitmap = report_bitmap >> 1;
200ea7b4bf5SPeter Avalos }
201ea7b4bf5SPeter Avalos }
202ea7b4bf5SPeter Avalos break;
203ea7b4bf5SPeter Avalos
204ea7b4bf5SPeter Avalos case MPCP_OPCODE_REG_REQ:
205*ed775ee7SAntonio Huete Jimenez mpcp_reg_req = (const struct mpcp_reg_req_t *)tptr;
206*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tFlags [ %s ], Pending-Grants %u",
207*ed775ee7SAntonio Huete Jimenez bittok2str(mpcp_reg_req_flag_values, "Reserved", GET_U_1(mpcp_reg_req->flags)),
208*ed775ee7SAntonio Huete Jimenez GET_U_1(mpcp_reg_req->pending_grants));
209ea7b4bf5SPeter Avalos break;
210ea7b4bf5SPeter Avalos
211ea7b4bf5SPeter Avalos case MPCP_OPCODE_REG:
212*ed775ee7SAntonio Huete Jimenez mpcp_reg = (const struct mpcp_reg_t *)tptr;
213*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tAssigned-Port %u, Flags [ %s ]"
214ea7b4bf5SPeter Avalos "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
215*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(mpcp_reg->assigned_port),
216*ed775ee7SAntonio Huete Jimenez bittok2str(mpcp_reg_flag_values, "Reserved", GET_U_1(mpcp_reg->flags)),
217*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(mpcp_reg->sync_time),
218*ed775ee7SAntonio Huete Jimenez GET_U_1(mpcp_reg->echoed_pending_grants));
219ea7b4bf5SPeter Avalos break;
220ea7b4bf5SPeter Avalos
221ea7b4bf5SPeter Avalos case MPCP_OPCODE_REG_ACK:
222*ed775ee7SAntonio Huete Jimenez mpcp_reg_ack = (const struct mpcp_reg_ack_t *)tptr;
223*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n\tEchoed-Assigned-Port %u, Flags [ %s ]"
224ea7b4bf5SPeter Avalos "\n\tEchoed-Sync-Time %u ticks",
225*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(mpcp_reg_ack->echoed_assigned_port),
226*ed775ee7SAntonio Huete Jimenez bittok2str(mpcp_reg_ack_flag_values, "Reserved", GET_U_1(mpcp_reg_ack->flags)),
227*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(mpcp_reg_ack->echoed_sync_time));
228ea7b4bf5SPeter Avalos break;
229ea7b4bf5SPeter Avalos
230ea7b4bf5SPeter Avalos default:
231ea7b4bf5SPeter Avalos /* unknown opcode - hexdump for now */
232411677aeSAaron LI print_unknown_data(ndo,pptr, "\n\t", length);
233ea7b4bf5SPeter Avalos break;
234ea7b4bf5SPeter Avalos }
235ea7b4bf5SPeter Avalos }
236