aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-slowprotocols.c
blob: c2f4b94951f70e02165e70e6e9fd2ae1f0e3a1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* packet-slowprotocols.c
 * Routines for EtherType (0x8809) Slow Protocols disassembly.
 * IEEE Std 802.3, Annex 57A
 *
 * Copyright 2002 Steve Housley <steve_housley@3com.com>
 * Copyright 2005 Dominique Bastien <dbastien@accedian.com>
 * Copyright 2009 Artem Tamazov <artem.tamazov@telllabs.com>
 * Copyright 2010 Roberto Morro <roberto.morro[AT]tilab.com>
 * Copyright 2014 Philip Rosenberg-Watt <p.rosenberg-watt[at]cablelabs.com.>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/slow_protocol_subtypes.h>

/* General declarations */
void proto_register_slow_protocols(void);
void proto_reg_handoff_slow_protocols(void);

static dissector_table_t slow_protocols_dissector_table;

static const value_string subtype_vals[] = {
    { LACP_SUBTYPE   , "LACP" },
    { MARKER_SUBTYPE , "Marker Protocol" },
    { OAM_SUBTYPE    , "OAM" },
    { OSSP_SUBTYPE   , "Organization Specific Slow Protocol" },
    { 0, NULL }
};

/* Initialise the protocol and registered fields */
static int proto_slow = -1;

static int hf_slow_subtype = -1;

/* Initialise the subtree pointers */

static gint ett_slow = -1;

/*
 * Name: dissect_slow_protocols
 *
 * Description:
 *    This function is used to dissect the slow protocols defined in IEEE802.3
 *    CSMA/CD. The current slow protocols subtypes are define in Annex 57A of
 *    the 802.3 document. In case of an unsupported slow protocol, we only
 *    fill the protocol and info columns.
 *
 * Input Arguments:
 *    tvb:   buffer associated with the rcv packet (see tvbuff.h).
 *    pinfo: structure associated with the rcv packet (see packet_info.h).
 *    tree:  the protocol tree associated with the rcv packet (see proto.h).
 *
 * Return Values:
 *    None
 */
static int
dissect_slow_protocols(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    guint8      subtype;
    proto_tree *pdu_tree;
    proto_item *pdu_item;
    tvbuff_t   *next_tvb;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Slow Protocols");
    subtype = tvb_get_guint8(tvb, 0);
    col_add_fstr(pinfo->cinfo, COL_INFO, "Subtype = %u", subtype);

    if (tree)
    {
        pdu_item = proto_tree_add_item(tree, proto_slow, tvb, 0, 1, ENC_NA);
        pdu_tree = proto_item_add_subtree(pdu_item, ett_slow);

        /* Subtype */
        proto_tree_add_item(pdu_tree, hf_slow_subtype, tvb, 0, 1, ENC_BIG_ENDIAN);
    }

    next_tvb = tvb_new_subset_remaining(tvb, 1);
    if (!dissector_try_uint_new(slow_protocols_dissector_table, subtype,
                                next_tvb, pinfo, tree, TRUE, NULL))
        call_data_dissector(next_tvb, pinfo, tree);

    return tvb_captured_length(tvb);
}


/* Register the protocol with Wireshark */
void
proto_register_slow_protocols(void)
{
/* Setup list of header fields */

    static hf_register_info hf[] = {
        { &hf_slow_subtype,
          { "Slow Protocols subtype",    "slow.subtype",
            FT_UINT8,    BASE_HEX,    VALS(subtype_vals),    0x0,
            NULL, HFILL }},
    };

    /* Setup protocol subtree array */

    static gint *ett[] = {
        &ett_slow,
    };


    /* Register the protocol name and description */

    proto_slow = proto_register_protocol("Slow Protocols", "802.3 Slow protocols", "slow");

    /* Required function calls to register the header fields and subtrees used */

    proto_register_field_array(proto_slow, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    /* subdissector code */
    slow_protocols_dissector_table = register_dissector_table("slow.subtype",
                                                              "Slow protocol subtype",
                                                               proto_slow, FT_UINT8, BASE_DEC, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE);
}

void
proto_reg_handoff_slow_protocols(void)
{
    dissector_handle_t slow_protocols_handle;

    slow_protocols_handle = create_dissector_handle(dissect_slow_protocols, proto_slow);
    dissector_add_uint("ethertype", ETHERTYPE_SLOW_PROTOCOLS, slow_protocols_handle);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */