1 /* packet-fractalgeneratorprotocol.c
2 * Routines for the Fractal Generator Protocol, a test application of the
3 * rsplib RSerPool implementation
4 * http://tdrwww.exp-math.uni-essen.de/dreibholz/rserpool/
6 * Copyright 2006 by Thomas Dreibholz <dreibh [AT] exp-math.uni-essen.de>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/packet.h>
36 #include <epan/sctpppids.h>
39 #define FRACTALGENERATORPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY 0x29097601
42 /* Initialize the protocol and registered fields */
43 static int proto_fractalgeneratorprotocol = -1;
44 static int hf_message_type = -1;
45 static int hf_message_flags = -1;
46 static int hf_message_length = -1;
47 static int hf_data_start_x = -1;
48 static int hf_data_start_y = -1;
49 static int hf_data_points = -1;
50 static int hf_parameter_width = -1;
51 static int hf_parameter_height = -1;
52 static int hf_parameter_maxiterations = -1;
53 static int hf_parameter_algorithmid = -1;
54 static int hf_parameter_c1real = -1;
55 static int hf_parameter_c1imag = -1;
56 static int hf_parameter_c2real = -1;
57 static int hf_parameter_c2imag = -1;
58 static int hf_parameter_n = -1;
59 static int hf_buffer = -1;
61 /* Initialize the subtree pointers */
62 static gint ett_fractalgeneratorprotocol = -1;
65 dissect_fractalgeneratorprotocol_message(tvbuff_t *, packet_info *, proto_tree *);
68 /* Dissectors for messages. This is specific to FractalGeneratorProtocol */
69 #define MESSAGE_TYPE_LENGTH 1
70 #define MESSAGE_FLAGS_LENGTH 1
71 #define MESSAGE_LENGTH_LENGTH 2
73 #define MESSAGE_TYPE_OFFSET 0
74 #define MESSAGE_FLAGS_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
75 #define MESSAGE_LENGTH_OFFSET (MESSAGE_FLAGS_OFFSET + MESSAGE_FLAGS_OFFSET)
76 #define MESSAGE_VALUE_OFFSET (MESSAGE_LENGTH_OFFSET + MESSAGE_LENGTH_LENGTH)
79 #define DATA_STARTX_LENGTH 4
80 #define DATA_STARTY_LENGTH 4
81 #define DATA_POINTS_LENGTH 4
82 #define DATA_BUFFER_LENGTH 4
84 #define DATA_STARTX_OFFSET MESSAGE_VALUE_OFFSET
85 #define DATA_STARTY_OFFSET (DATA_STARTX_OFFSET + DATA_STARTX_LENGTH)
86 #define DATA_POINTS_OFFSET (DATA_STARTY_OFFSET + DATA_STARTY_LENGTH)
87 #define DATA_BUFFER_OFFSET (DATA_POINTS_OFFSET + DATA_POINTS_LENGTH)
90 #define PARAMETER_WIDTH_LENGTH 4
91 #define PARAMETER_HEIGHT_LENGTH 4
92 #define PARAMETER_MAXITERATIONS_LENGTH 4
93 #define PARAMETER_ALGORITHMID_LENGTH 4
94 #define PARAMETER_C1REAL_LENGTH 8
95 #define PARAMETER_C1IMAG_LENGTH 8
96 #define PARAMETER_C2REAL_LENGTH 8
97 #define PARAMETER_C2IMAG_LENGTH 8
98 #define PARAMETER_N_LENGTH 8
100 #define PARAMETER_WIDTH_OFFSET MESSAGE_VALUE_OFFSET
101 #define PARAMETER_HEIGHT_OFFSET (PARAMETER_WIDTH_OFFSET + PARAMETER_WIDTH_LENGTH)
102 #define PARAMETER_MAXITERATIONS_OFFSET (PARAMETER_HEIGHT_OFFSET + PARAMETER_HEIGHT_LENGTH)
103 #define PARAMETER_ALGORITHMID_OFFSET (PARAMETER_MAXITERATIONS_OFFSET + PARAMETER_MAXITERATIONS_LENGTH)
104 #define PARAMETER_C1REAL_OFFSET (PARAMETER_ALGORITHMID_OFFSET + PARAMETER_ALGORITHMID_LENGTH)
105 #define PARAMETER_C1IMAG_OFFSET (PARAMETER_C1REAL_OFFSET + PARAMETER_C1REAL_LENGTH)
106 #define PARAMETER_C2REAL_OFFSET (PARAMETER_C1IMAG_OFFSET + PARAMETER_C1IMAG_LENGTH)
107 #define PARAMETER_C2IMAG_OFFSET (PARAMETER_C2REAL_OFFSET + PARAMETER_C2REAL_LENGTH)
108 #define PARAMETER_N_OFFSET (PARAMETER_C2IMAG_OFFSET + PARAMETER_C2IMAG_LENGTH)
110 #define FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE 0x01
111 #define FRACTALGENERATOR_DATA_MESSAGE_TYPE 0x02
114 static const value_string message_type_values[] = {
115 { FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE, "FractalGenerator Parameter" },
116 { FRACTALGENERATOR_DATA_MESSAGE_TYPE, "FractalGenerator Data" },
122 dissect_fractalgeneratorprotocol_parameter_message(tvbuff_t *message_tvb, proto_tree *message_tree)
124 proto_tree_add_item(message_tree, hf_parameter_width, message_tvb, PARAMETER_WIDTH_OFFSET, PARAMETER_WIDTH_LENGTH, ENC_BIG_ENDIAN);
125 proto_tree_add_item(message_tree, hf_parameter_height, message_tvb, PARAMETER_HEIGHT_OFFSET, PARAMETER_HEIGHT_LENGTH, ENC_BIG_ENDIAN);
126 proto_tree_add_item(message_tree, hf_parameter_maxiterations, message_tvb, PARAMETER_MAXITERATIONS_OFFSET, PARAMETER_MAXITERATIONS_LENGTH, ENC_BIG_ENDIAN);
127 proto_tree_add_item(message_tree, hf_parameter_algorithmid, message_tvb, PARAMETER_ALGORITHMID_OFFSET, PARAMETER_ALGORITHMID_LENGTH, ENC_BIG_ENDIAN);
128 proto_tree_add_item(message_tree, hf_parameter_c1real, message_tvb, PARAMETER_C1REAL_OFFSET, PARAMETER_C1REAL_LENGTH, ENC_BIG_ENDIAN);
129 proto_tree_add_item(message_tree, hf_parameter_c1imag, message_tvb, PARAMETER_C1IMAG_OFFSET, PARAMETER_C1IMAG_LENGTH, ENC_BIG_ENDIAN);
130 proto_tree_add_item(message_tree, hf_parameter_c2real, message_tvb, PARAMETER_C2REAL_OFFSET, PARAMETER_C2REAL_LENGTH, ENC_BIG_ENDIAN);
131 proto_tree_add_item(message_tree, hf_parameter_c2imag, message_tvb, PARAMETER_C2IMAG_OFFSET, PARAMETER_C2IMAG_LENGTH, ENC_BIG_ENDIAN);
132 proto_tree_add_item(message_tree, hf_parameter_n, message_tvb, PARAMETER_N_OFFSET, PARAMETER_N_LENGTH, ENC_BIG_ENDIAN);
137 dissect_fractalgeneratorprotocol_data_message(tvbuff_t *message_tvb, proto_tree *message_tree)
139 guint16 buffer_length;
141 proto_tree_add_item(message_tree, hf_data_start_x, message_tvb, DATA_STARTX_OFFSET, DATA_STARTX_LENGTH, ENC_BIG_ENDIAN);
142 proto_tree_add_item(message_tree, hf_data_start_y, message_tvb, DATA_STARTY_OFFSET, DATA_STARTY_LENGTH, ENC_BIG_ENDIAN);
143 proto_tree_add_item(message_tree, hf_data_points, message_tvb, DATA_POINTS_OFFSET, DATA_POINTS_LENGTH, ENC_BIG_ENDIAN);
145 buffer_length = tvb_get_ntohl(message_tvb, DATA_POINTS_OFFSET)*4;
146 if (buffer_length > 0) {
147 proto_tree_add_item(message_tree, hf_buffer, message_tvb, DATA_BUFFER_OFFSET, buffer_length, ENC_NA);
153 dissect_fractalgeneratorprotocol_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *fractalgeneratorprotocol_tree)
157 type = tvb_get_guint8(message_tvb, MESSAGE_TYPE_OFFSET);
158 if (pinfo && (check_col(pinfo->cinfo, COL_INFO))) {
159 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str(type, message_type_values, "Unknown FractalGeneratorProtocol type"));
161 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_type, message_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, ENC_BIG_ENDIAN);
162 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_flags, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
163 proto_tree_add_item(fractalgeneratorprotocol_tree, hf_message_length, message_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
165 case FRACTALGENERATOR_PARAMETER_MESSAGE_TYPE:
166 dissect_fractalgeneratorprotocol_parameter_message(message_tvb, fractalgeneratorprotocol_tree);
168 case FRACTALGENERATOR_DATA_MESSAGE_TYPE:
169 dissect_fractalgeneratorprotocol_data_message(message_tvb, fractalgeneratorprotocol_tree);
175 dissect_fractalgeneratorprotocol(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
177 proto_item *fractalgeneratorprotocol_item;
178 proto_tree *fractalgeneratorprotocol_tree;
180 /* pinfo is NULL only if dissect_fractalgeneratorprotocol_message is called from dissect_error cause */
182 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FractalGeneratorProtocol");
184 /* In the interest of speed, if "tree" is NULL, don't do any work not
185 necessary to generate protocol tree items. */
187 /* create the fractalgeneratorprotocol protocol tree */
188 fractalgeneratorprotocol_item = proto_tree_add_item(tree, proto_fractalgeneratorprotocol, message_tvb, 0, -1, ENC_NA);
189 fractalgeneratorprotocol_tree = proto_item_add_subtree(fractalgeneratorprotocol_item, ett_fractalgeneratorprotocol);
191 fractalgeneratorprotocol_tree = NULL;
193 /* dissect the message */
194 dissect_fractalgeneratorprotocol_message(message_tvb, pinfo, fractalgeneratorprotocol_tree);
198 /* Register the protocol with Wireshark */
200 proto_register_fractalgeneratorprotocol(void)
203 /* Setup list of header fields */
204 static hf_register_info hf[] = {
205 { &hf_message_type, { "Type", "fractalgeneratorprotocol.message_type", FT_UINT8, BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
206 { &hf_message_flags, { "Flags", "fractalgeneratorprotocol.message_flags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
207 { &hf_message_length, { "Length", "fractalgeneratorprotocol.message_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
208 { &hf_data_start_x, { "StartX", "fractalgeneratorprotocol.data_start_x", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
209 { &hf_data_start_y, { "StartY", "fractalgeneratorprotocol.data_start_y", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
210 { &hf_data_points, { "Points", "fractalgeneratorprotocol.data_points", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
211 { &hf_parameter_width, { "Width", "fractalgeneratorprotocol.parameter_width", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
212 { &hf_parameter_height, { "Height", "fractalgeneratorprotocol.parameter_height", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
213 { &hf_parameter_maxiterations, { "MaxIterations", "fractalgeneratorprotocol.parameter_maxiterations", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
214 { &hf_parameter_algorithmid, { "AlgorithmID", "fractalgeneratorprotocol.parameter_algorithmid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
215 { &hf_parameter_c1real, { "C1Real", "fractalgeneratorprotocol.parameter_c1real", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
216 { &hf_parameter_c1imag, { "C1Imag", "fractalgeneratorprotocol.parameter_c1imag", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
217 { &hf_parameter_c2real, { "C2Real", "fractalgeneratorprotocol.parameter_c2real", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
218 { &hf_parameter_c2imag, { "C2Imag", "fractalgeneratorprotocol.parameter_c2imag", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
219 { &hf_parameter_n, { "N", "fractalgeneratorprotocol.parameter_n", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
220 { &hf_buffer, { "Buffer", "fractalgeneratorprotocol.buffer", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
223 /* Setup protocol subtree array */
224 static gint *ett[] = {
225 &ett_fractalgeneratorprotocol
228 /* Register the protocol name and description */
229 proto_fractalgeneratorprotocol = proto_register_protocol("Fractal Generator Protocol", "FractalGeneratorProtocol", "fractalgeneratorprotocol");
231 /* Required function calls to register the header fields and subtrees used */
232 proto_register_field_array(proto_fractalgeneratorprotocol, hf, array_length(hf));
233 proto_register_subtree_array(ett, array_length(ett));
238 proto_reg_handoff_fractalgeneratorprotocol(void)
240 dissector_handle_t fractalgeneratorprotocol_handle;
242 fractalgeneratorprotocol_handle = new_create_dissector_handle(dissect_fractalgeneratorprotocol, proto_fractalgeneratorprotocol);
243 dissector_add_uint("sctp.ppi", FRACTALGENERATORPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY, fractalgeneratorprotocol_handle);
244 dissector_add_uint("sctp.ppi", FGP_PAYLOAD_PROTOCOL_ID, fractalgeneratorprotocol_handle);