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