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