Add format_text_wmem.
[metze/wireshark/wip.git] / epan / dissectors / packet-marker.c
1 /* packet-marker.c
2  * Routines for Link Aggregation Marker protocol dissection.
3  * IEEE Std 802.1AX
4  *
5  * Copyright 2002 Steve Housley <steve_housley@3com.com>
6  * Copyright 2005 Dominique Bastien <dbastien@accedian.com>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <epan/packet.h>
30 #include <epan/slow_protocol_subtypes.h>
31
32 /* General declarations */
33 void proto_register_marker(void);
34 void proto_reg_handoff_marker(void);
35
36 /* MARKER TLVs subtype */
37 #define MARKERPDU_END_MARKER            0x0
38 #define MARKERPDU_MARKER_INFO           0x1
39 #define MARKERPDU_MARKER_RESPONSE       0x2
40
41 static const value_string marker_vals[] = {
42     { MARKERPDU_MARKER_INFO,     "Marker Information" },
43     { MARKERPDU_MARKER_RESPONSE, "Marker Response Information" },
44     { 0, NULL }
45 };
46
47 /* Initialise the protocol and registered fields */
48 static int proto_marker = -1;
49
50 static int hf_marker_version_number = -1;
51 static int hf_marker_tlv_type = -1;
52 static int hf_marker_tlv_length = -1;
53 static int hf_marker_req_port = -1;
54 static int hf_marker_req_system = -1;
55 static int hf_marker_req_trans_id = -1;
56
57 /* Initialise the subtree pointers */
58
59 static gint ett_marker = -1;
60
61 /*
62  * Name: dissect_marker
63  *
64  * Description:
65  *    This function is used to dissect the Link Aggregation Marker Protocol
66  *    slow protocols defined in IEEE802.3 clause 43.5 (The PDUs are defined
67  *    in section 43.5.3.2). The TLV types are 0x01 for a marker TLV and 0x02
68  *    for a marker response. A value of 0x00 indicates an end of message.
69  *
70  * Input Arguments:
71  *    tvb:   buffer associated with the rcv packet (see tvbuff.h).
72  *    pinfo: structure associated with the rcv packet (see packet_info.h).
73  *    tree:  the protocol tree associated with the rcv packet (see proto.h).
74  *
75  * Return Values: None
76  *
77  * Notes:
78  *    Dominique Bastien (dbastien@accedian.com)
79  *      + add support for MARKER and MARKER Response PDUs.
80  */
81 static int
82 dissect_marker(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
83 {
84     int     offset = 0;
85     guint8  raw_octet;
86
87     proto_tree *marker_tree;
88     proto_item *marker_item;
89
90
91     col_set_str(pinfo->cinfo, COL_PROTOCOL, "Marker");
92     col_set_str(pinfo->cinfo, COL_INFO, "Marker Protocol");
93
94     if (tree)
95     {
96         marker_item = proto_tree_add_protocol_format(tree, proto_marker, tvb,
97                             0, -1, "Marker Protocol");
98         marker_tree = proto_item_add_subtree(marker_item, ett_marker);
99
100         /* Version Number */
101         proto_tree_add_item(marker_tree, hf_marker_version_number, tvb,
102                 offset, 1, ENC_BIG_ENDIAN);
103         offset += 1;
104
105         while (1)
106         {
107             /* TLV Type */
108             raw_octet = tvb_get_guint8(tvb, offset);
109
110             if (raw_octet == MARKERPDU_END_MARKER)
111                 break;
112
113             proto_tree_add_uint(marker_tree, hf_marker_tlv_type, tvb,
114                     offset, 1, raw_octet);
115             offset += 1;
116
117             /* TLV Length */
118             proto_tree_add_item(marker_tree, hf_marker_tlv_length, tvb,
119                     offset, 1, ENC_BIG_ENDIAN);
120             offset += 1;
121
122             /* Requester Port */
123             proto_tree_add_item(marker_tree, hf_marker_req_port, tvb,
124                     offset, 2, ENC_BIG_ENDIAN);
125             offset += 2;
126
127             /* Requester System */
128             proto_tree_add_item(marker_tree, hf_marker_req_system, tvb,
129                     offset, 6, ENC_NA);
130             offset += 6;
131
132             /* Requester Transaction ID */
133             proto_tree_add_item(marker_tree, hf_marker_req_trans_id, tvb,
134                     offset, 4, ENC_BIG_ENDIAN);
135             offset += 4;
136
137             /* Pad to align */
138             offset += 2;
139         }
140     }
141     return tvb_captured_length(tvb);
142 }
143
144 /* Register the protocol with Wireshark */
145 void
146 proto_register_marker(void)
147 {
148 /* Setup list of header fields */
149
150     static hf_register_info hf[] = {
151         { &hf_marker_version_number,
152           { "Version Number",    "marker.version",
153             FT_UINT8,    BASE_HEX,    NULL,    0x0,
154             "Marker protocol version", HFILL }},
155
156         { &hf_marker_tlv_type,
157           { "TLV Type",    "marker.tlvType",
158             FT_UINT8,    BASE_HEX,    VALS(marker_vals),    0x0,
159             NULL, HFILL }},
160
161         { &hf_marker_tlv_length,
162           { "TLV Length",            "marker.tlvLen",
163             FT_UINT8,    BASE_HEX,    NULL,    0x0,
164             "Length of the Actor TLV", HFILL }},
165
166         { &hf_marker_req_port,
167           { "Requester Port",  "marker.requesterPort",
168             FT_UINT16,    BASE_DEC,    NULL,    0x0,
169             NULL, HFILL }},
170
171         { &hf_marker_req_system,
172           { "Requester System",  "marker.requesterSystem",
173             FT_ETHER,    BASE_NONE,    NULL,    0x0,
174             "Requester System ID encoded as a MAC address", HFILL }},
175
176         { &hf_marker_req_trans_id,
177           { "Requester Transaction ID",  "marker.requesterTransId",
178             FT_UINT32,    BASE_DEC,    NULL,    0x0,
179             NULL, HFILL }},
180     };
181
182     /* Setup protocol subtree array */
183
184     static gint *ett[] = {
185         &ett_marker,
186     };
187
188     /* Register the protocol name and description */
189
190     proto_marker = proto_register_protocol("Marker", "Link Aggregation Marker Protocol", "marker");
191
192     /* Required function calls to register the header fields and subtrees used */
193
194     proto_register_field_array(proto_marker, hf, array_length(hf));
195     proto_register_subtree_array(ett, array_length(ett));
196 }
197
198 void
199 proto_reg_handoff_marker(void)
200 {
201     dissector_handle_t marker_handle;
202
203     marker_handle = create_dissector_handle(dissect_marker, proto_marker);
204     dissector_add_uint("slow.subtype", MARKER_SUBTYPE, marker_handle);
205 }
206
207 /*
208  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
209  *
210  * Local variables:
211  * c-basic-offset: 4
212  * tab-width: 8
213  * indent-tabs-mode: nil
214  * End:
215  *
216  * vi: set shiftwidth=4 tabstop=8 expandtab:
217  * :indentSize=4:tabSize=8:noTabs=true:
218  */