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