HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-fractalgeneratorprotocol.c
blob9615e96d1489e3515c8f9ead844afc1679b5ed68
1 /* packet-fractalgeneratorprotocol.c
2 * Routines for the Fractal Generator Protocol, a test application of the
3 * rsplib RSerPool implementation
4 * http://www.tdr.wiwi.uni-due.de/forschung/forschungsprojekte/reliable-server-pooling//
6 * Copyright 2006 by Thomas Dreibholz <dreibh [AT] exp-math.uni-essen.de>
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * Copied from README.developer
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "config.h"
33 #include <epan/packet.h>
34 #include <epan/sctpppids.h>
37 #define FRACTALGENERATORPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY 0x29097601
40 /* Initialize the protocol and registered fields */
41 static int proto_fractalgeneratorprotocol = -1;
42 static int hf_message_type = -1;
43 static int hf_message_flags = -1;
44 static int hf_message_length = -1;
45 static int hf_data_start_x = -1;
46 static int hf_data_start_y = -1;
47 static int hf_data_points = -1;
48 static int hf_parameter_width = -1;
49 static int hf_parameter_height = -1;
50 static int hf_parameter_maxiterations = -1;
51 static int hf_parameter_algorithmid = -1;
52 static int hf_parameter_c1real = -1;
53 static int hf_parameter_c1imag = -1;
54 static int hf_parameter_c2real = -1;
55 static int hf_parameter_c2imag = -1;
56 static int hf_parameter_n = -1;
57 static int hf_buffer = -1;
59 /* Initialize the subtree pointers */
60 static gint ett_fractalgeneratorprotocol = -1;
62 /* Dissectors for messages. This is specific to FractalGeneratorProtocol */
63 #define MESSAGE_TYPE_LENGTH 1
64 #define MESSAGE_FLAGS_LENGTH 1
65 #define MESSAGE_LENGTH_LENGTH 2
67 #define MESSAGE_TYPE_OFFSET 0
68 #define MESSAGE_FLAGS_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
69 #define MESSAGE_LENGTH_OFFSET (MESSAGE_FLAGS_OFFSET + MESSAGE_FLAGS_OFFSET)
70 #define MESSAGE_VALUE_OFFSET (MESSAGE_LENGTH_OFFSET + MESSAGE_LENGTH_LENGTH)
73 #define DATA_STARTX_LENGTH 4
74 #define DATA_STARTY_LENGTH 4
75 #define DATA_POINTS_LENGTH 4
76 #define DATA_BUFFER_LENGTH 4
78 #define DATA_STARTX_OFFSET MESSAGE_VALUE_OFFSET
79 #define DATA_STARTY_OFFSET (DATA_STARTX_OFFSET + DATA_STARTX_LENGTH)
80 #define DATA_POINTS_OFFSET (DATA_STARTY_OFFSET + DATA_STARTY_LENGTH)
81 #define DATA_BUFFER_OFFSET (DATA_POINTS_OFFSET + DATA_POINTS_LENGTH)
84 #define PARAMETER_WIDTH_LENGTH 4
85 #define PARAMETER_HEIGHT_LENGTH 4
86 #define PARAMETER_MAXITERATIONS_LENGTH 4
87 #define PARAMETER_ALGORITHMID_LENGTH 4
88 #define PARAMETER_C1REAL_LENGTH 8
89 #define PARAMETER_C1IMAG_LENGTH 8
90 #define PARAMETER_C2REAL_LENGTH 8
91 #define PARAMETER_C2IMAG_LENGTH 8
92 #define PARAMETER_N_LENGTH 8
94 #define PARAMETER_WIDTH_OFFSET MESSAGE_VALUE_OFFSET
95 #define PARAMETER_HEIGHT_OFFSET (PARAMETER_WIDTH_OFFSET + PARAMETER_WIDTH_LENGTH)
96 #define PARAMETER_MAXITERATIONS_OFFSET (PARAMETER_HEIGHT_OFFSET + PARAMETER_HEIGHT_LENGTH)
97 #define PARAMETER_ALGORITHMID_OFFSET (PARAMETER_MAXITERATIONS_OFFSET + PARAMETER_MAXITERATIONS_LENGTH)
98 #define PARAMETER_C1REAL_OFFSET (PARAMETER_ALGORITHMID_OFFSET + PARAMETER_ALGORITHMID_LENGTH)
99 #define PARAMETER_C1IMAG_OFFSET (PARAMETER_C1REAL_OFFSET + PARAMETER_C1REAL_LENGTH)
100 #define PARAMETER_C2REAL_OFFSET (PARAMETER_C1IMAG_OFFSET + PARAMETER_C1IMAG_LENGTH)
101 #define PARAMETER_C2IMAG_OFFSET (PARAMETER_C2REAL_OFFSET + PARAMETER_C2REAL_LENGTH)
102 #define PARAMETER_N_OFFSET (PARAMETER_C2IMAG_OFFSET + PARAMETER_C2IMAG_LENGTH)
104 #define FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE 0x01
105 #define FRACTALGENERATOR_DATA_MESSAGE_TYPE 0x02
108 static const value_string message_type_values[] = {
109 { FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE, "FractalGenerator Parameter" },
110 { FRACTALGENERATOR_DATA_MESSAGE_TYPE, "FractalGenerator Data" },
111 { 0, NULL }
115 static void
116 dissect_fractalgeneratorprotocol_parameter_message(tvbuff_t *message_tvb, proto_tree *message_tree)
118 proto_tree_add_item(message_tree, hf_parameter_width, message_tvb, PARAMETER_WIDTH_OFFSET, PARAMETER_WIDTH_LENGTH, ENC_BIG_ENDIAN);
119 proto_tree_add_item(message_tree, hf_parameter_height, message_tvb, PARAMETER_HEIGHT_OFFSET, PARAMETER_HEIGHT_LENGTH, ENC_BIG_ENDIAN);
120 proto_tree_add_item(message_tree, hf_parameter_maxiterations, message_tvb, PARAMETER_MAXITERATIONS_OFFSET, PARAMETER_MAXITERATIONS_LENGTH, ENC_BIG_ENDIAN);
121 proto_tree_add_item(message_tree, hf_parameter_algorithmid, message_tvb, PARAMETER_ALGORITHMID_OFFSET, PARAMETER_ALGORITHMID_LENGTH, ENC_BIG_ENDIAN);
122 proto_tree_add_item(message_tree, hf_parameter_c1real, message_tvb, PARAMETER_C1REAL_OFFSET, PARAMETER_C1REAL_LENGTH, ENC_BIG_ENDIAN);
123 proto_tree_add_item(message_tree, hf_parameter_c1imag, message_tvb, PARAMETER_C1IMAG_OFFSET, PARAMETER_C1IMAG_LENGTH, ENC_BIG_ENDIAN);
124 proto_tree_add_item(message_tree, hf_parameter_c2real, message_tvb, PARAMETER_C2REAL_OFFSET, PARAMETER_C2REAL_LENGTH, ENC_BIG_ENDIAN);
125 proto_tree_add_item(message_tree, hf_parameter_c2imag, message_tvb, PARAMETER_C2IMAG_OFFSET, PARAMETER_C2IMAG_LENGTH, ENC_BIG_ENDIAN);
126 proto_tree_add_item(message_tree, hf_parameter_n, message_tvb, PARAMETER_N_OFFSET, PARAMETER_N_LENGTH, ENC_BIG_ENDIAN);
130 static void
131 dissect_fractalgeneratorprotocol_data_message(tvbuff_t *message_tvb, proto_tree *message_tree)
133 guint16 buffer_length;
135 proto_tree_add_item(message_tree, hf_data_start_x, message_tvb, DATA_STARTX_OFFSET, DATA_STARTX_LENGTH, ENC_BIG_ENDIAN);
136 proto_tree_add_item(message_tree, hf_data_start_y, message_tvb, DATA_STARTY_OFFSET, DATA_STARTY_LENGTH, ENC_BIG_ENDIAN);
137 proto_tree_add_item(message_tree, hf_data_points, message_tvb, DATA_POINTS_OFFSET, DATA_POINTS_LENGTH, ENC_BIG_ENDIAN);
139 buffer_length = tvb_get_ntohl(message_tvb, DATA_POINTS_OFFSET)*4;
140 if (buffer_length > 0) {
141 proto_tree_add_item(message_tree, hf_buffer, message_tvb, DATA_BUFFER_OFFSET, buffer_length, ENC_NA);
146 static void
147 dissect_fractalgeneratorprotocol_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *fractalgeneratorprotocol_tree)
149 guint8 type;
151 type = tvb_get_guint8(message_tvb, MESSAGE_TYPE_OFFSET);
152 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(type, message_type_values, "Unknown FractalGeneratorProtocol type"));
154 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_type, message_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, ENC_BIG_ENDIAN);
155 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_flags, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
156 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_length, message_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
157 switch (type) {
158 case FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE:
159 dissect_fractalgeneratorprotocol_parameter_message(message_tvb, fractalgeneratorprotocol_tree);
160 break;
161 case FRACTALGENERATOR_DATA_MESSAGE_TYPE:
162 dissect_fractalgeneratorprotocol_data_message(message_tvb, fractalgeneratorprotocol_tree);
163 break;
167 static int
168 dissect_fractalgeneratorprotocol(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
170 proto_item *fractalgeneratorprotocol_item;
171 proto_tree *fractalgeneratorprotocol_tree;
173 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FractalGeneratorProtocol");
175 /* In the interest of speed, if "tree" is NULL, don't do any work not
176 necessary to generate protocol tree items. */
177 if (tree) {
178 /* create the fractalgeneratorprotocol protocol tree */
179 fractalgeneratorprotocol_item = proto_tree_add_item(tree, proto_fractalgeneratorprotocol, message_tvb, 0, -1, ENC_NA);
180 fractalgeneratorprotocol_tree = proto_item_add_subtree(fractalgeneratorprotocol_item, ett_fractalgeneratorprotocol);
181 } else {
182 fractalgeneratorprotocol_tree = NULL;
184 /* dissect the message */
185 dissect_fractalgeneratorprotocol_message(message_tvb, pinfo, fractalgeneratorprotocol_tree);
186 return(TRUE);
189 /* Register the protocol with Wireshark */
190 void
191 proto_register_fractalgeneratorprotocol(void)
194 /* Setup list of header fields */
195 static hf_register_info hf[] = {
196 { &hf_message_type, { "Type", "fractalgeneratorprotocol.message_type", FT_UINT8, BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
197 { &hf_message_flags, { "Flags", "fractalgeneratorprotocol.message_flags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
198 { &hf_message_length, { "Length", "fractalgeneratorprotocol.message_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
199 { &hf_data_start_x, { "StartX", "fractalgeneratorprotocol.data_start_x", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
200 { &hf_data_start_y, { "StartY", "fractalgeneratorprotocol.data_start_y", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
201 { &hf_data_points, { "Points", "fractalgeneratorprotocol.data_points", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
202 { &hf_parameter_width, { "Width", "fractalgeneratorprotocol.parameter_width", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
203 { &hf_parameter_height, { "Height", "fractalgeneratorprotocol.parameter_height", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
204 { &hf_parameter_maxiterations, { "MaxIterations", "fractalgeneratorprotocol.parameter_maxiterations", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
205 { &hf_parameter_algorithmid, { "AlgorithmID", "fractalgeneratorprotocol.parameter_algorithmid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
206 { &hf_parameter_c1real, { "C1Real", "fractalgeneratorprotocol.parameter_c1real", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
207 { &hf_parameter_c1imag, { "C1Imag", "fractalgeneratorprotocol.parameter_c1imag", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
208 { &hf_parameter_c2real, { "C2Real", "fractalgeneratorprotocol.parameter_c2real", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
209 { &hf_parameter_c2imag, { "C2Imag", "fractalgeneratorprotocol.parameter_c2imag", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
210 { &hf_parameter_n, { "N", "fractalgeneratorprotocol.parameter_n", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
211 { &hf_buffer, { "Buffer", "fractalgeneratorprotocol.buffer", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
214 /* Setup protocol subtree array */
215 static gint *ett[] = {
216 &ett_fractalgeneratorprotocol
219 /* Register the protocol name and description */
220 proto_fractalgeneratorprotocol = proto_register_protocol("Fractal Generator Protocol", "FractalGeneratorProtocol", "fractalgeneratorprotocol");
222 /* Required function calls to register the header fields and subtrees used */
223 proto_register_field_array(proto_fractalgeneratorprotocol, hf, array_length(hf));
224 proto_register_subtree_array(ett, array_length(ett));
228 void
229 proto_reg_handoff_fractalgeneratorprotocol(void)
231 dissector_handle_t fractalgeneratorprotocol_handle;
233 fractalgeneratorprotocol_handle = new_create_dissector_handle(dissect_fractalgeneratorprotocol, proto_fractalgeneratorprotocol);
234 dissector_add_uint("sctp.ppi", FRACTALGENERATORPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY, fractalgeneratorprotocol_handle);
235 dissector_add_uint("sctp.ppi", FGP_PAYLOAD_PROTOCOL_ID, fractalgeneratorprotocol_handle);