HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-nasdaq-soup.c
blob6b11c16708ac8c7a5d1d66d5830e92cf56881034
1 /* packet-nasdaq-soup.c
2 * Routines for NASDAQ SOUP 2.0 Protocol dissection
3 * Copyright 2007,2008 Didier Gautheron <dgautheron@magic.fr>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Documentation: http://www.nasdaqtrader.com/Trader.aspx?id=DPSpecs
26 * ex:
27 * http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/souptcp.pdf
30 #include "config.h"
32 #include <epan/packet.h>
33 #include <epan/prefs.h>
35 #include "packet-tcp.h"
37 static const value_string message_types_val[] = {
38 { 'S', "Sequenced Data" },
39 { 'R', "Client Heartbeat" },
40 { 'H', "Server Heartbeat" },
41 { '+' , "Debug Packet" },
42 { 'A', "Login Accepted" },
43 { 'J', "Login Rejected" },
44 { 'L', "Login Request" },
45 { 'U', "Unsequenced Data" },
46 { 'O', "Logout Request" },
47 { 0, NULL }
50 static const value_string reject_code_val[] = {
51 { 'A', "Not authorized" },
52 { 'S', "Session not available" },
53 { 0, NULL }
56 /* Initialize the protocol and registered fields */
57 static int proto_nasdaq_soup = -1;
58 static dissector_handle_t nasdaq_soup_handle;
59 static dissector_handle_t nasdaq_itch_handle;
61 /* desegmentation of Nasdaq Soup */
62 static gboolean nasdaq_soup_desegment = TRUE;
64 static range_t *global_nasdaq_soup_tcp_range = NULL;
65 static range_t *nasdaq_soup_tcp_range = NULL;
67 /* Initialize the subtree pointers */
68 static gint ett_nasdaq_soup = -1;
70 static int hf_nasdaq_soup_packet_type = -1;
71 static int hf_nasdaq_soup_message = -1;
72 static int hf_nasdaq_soup_text = -1;
73 static int hf_nasdaq_soup_packet_eol = -1;
74 static int hf_nasdaq_soup_username = -1;
75 static int hf_nasdaq_soup_password = -1;
76 static int hf_nasdaq_soup_session = -1;
77 static int hf_nasdaq_soup_seq_number = -1;
78 static int hf_nasdaq_soup_reject_code = -1;
80 static void
81 dissect_nasdaq_soup_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, proto_tree *tree, int offset, int linelen)
83 guint8 nasdaq_soup_type;
84 tvbuff_t *new_tvb = NULL;
86 nasdaq_soup_type = tvb_get_guint8(tvb, offset);
87 proto_tree_add_item(tree, hf_nasdaq_soup_packet_type, tvb, offset, 1, ENC_BIG_ENDIAN);
88 offset++;
90 switch (nasdaq_soup_type) {
91 case '+': /* debug msg */
92 proto_tree_add_item(tree, hf_nasdaq_soup_text, tvb, offset, linelen -1, ENC_ASCII|ENC_NA);
93 offset += linelen -1;
94 break;
95 case 'A': /* login accept */
96 proto_tree_add_item(tree, hf_nasdaq_soup_session, tvb, offset, 10, ENC_ASCII|ENC_NA);
97 offset += 10;
99 proto_tree_add_item(tree, hf_nasdaq_soup_seq_number, tvb, offset, 10, ENC_ASCII|ENC_NA);
100 offset += 10;
101 break;
102 case 'J': /* login reject */
103 proto_tree_add_item(tree, hf_nasdaq_soup_reject_code, tvb, offset, 1, ENC_BIG_ENDIAN);
104 offset++;
105 break;
107 case 'U': /* unsequenced data packed */
108 case 'S': /* sequenced data packed */
109 if (linelen > 1 && nasdaq_itch_handle) {
110 new_tvb = tvb_new_subset(tvb, offset,linelen -1,linelen -1);
111 } else {
112 proto_tree_add_item(tree, hf_nasdaq_soup_message, tvb, offset, linelen -1, ENC_ASCII|ENC_NA);
114 offset += linelen -1;
115 break;
117 case 'L': /* login request */
118 proto_tree_add_item(tree, hf_nasdaq_soup_username, tvb, offset, 6, ENC_ASCII|ENC_NA);
119 offset += 6;
121 proto_tree_add_item(tree, hf_nasdaq_soup_password, tvb, offset, 10, ENC_ASCII|ENC_NA);
122 offset += 10;
124 proto_tree_add_item(tree, hf_nasdaq_soup_session, tvb, offset, 10, ENC_ASCII|ENC_NA);
125 offset += 10;
127 proto_tree_add_item(tree, hf_nasdaq_soup_seq_number, tvb, offset, 10, ENC_ASCII|ENC_NA);
128 offset += 10;
129 break;
131 case 'H': /* server heartbeat */
132 case 'O': /* logout request */
133 case 'R': /* client heartbeat */
134 /* no payload */
135 break;
136 default:
137 /* unknown */
138 proto_tree_add_item(tree, hf_nasdaq_soup_message, tvb, offset, linelen -1, ENC_ASCII|ENC_NA);
139 offset += linelen -1;
140 break;
143 proto_tree_add_item(tree, hf_nasdaq_soup_packet_eol, tvb, offset, 1, ENC_ASCII|ENC_NA);
144 if (new_tvb) {
145 call_dissector(nasdaq_itch_handle, new_tvb, pinfo, parent_tree);
147 return;
150 /* ---------------------------- */
151 static void
152 dissect_nasdaq_soup(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
154 proto_item *ti;
155 proto_tree *nasdaq_soup_tree = NULL;
156 guint8 nasdaq_soup_type;
157 int linelen;
158 gint next_offset;
159 int offset = 0;
160 gint counter = 0;
162 while (tvb_offset_exists(tvb, offset)) {
163 /* there's only a \n no \r */
164 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, nasdaq_soup_desegment && pinfo->can_desegment);
165 if (linelen == -1) {
167 * We didn't find a line ending, and we're doing desegmentation;
168 * tell the TCP dissector where the data for this message starts
169 * in the data it handed us, and tell it we need one more byte
170 * (we may need more, but we'll try again if what we get next
171 * isn't enough), and return.
173 pinfo->desegment_offset = offset;
174 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
175 return;
178 nasdaq_soup_type = tvb_get_guint8(tvb, offset);
179 if (counter == 0) {
180 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-SOUP");
181 col_clear(pinfo->cinfo, COL_INFO);
183 if (counter) {
184 col_append_str(pinfo->cinfo, COL_INFO, "; ");
185 col_set_fence(pinfo->cinfo, COL_INFO);
187 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(nasdaq_soup_type, message_types_val, "Unknown packet type (0x%02x)"));
189 counter++;
190 ti = proto_tree_add_item(tree, proto_nasdaq_soup, tvb, offset, linelen +1, ENC_NA);
191 nasdaq_soup_tree = proto_item_add_subtree(ti, ett_nasdaq_soup);
193 dissect_nasdaq_soup_packet(tvb, pinfo, tree, nasdaq_soup_tree, offset, linelen);
194 offset = next_offset;
198 /* Register the protocol with Wireshark */
199 static void nasdaq_soup_prefs(void)
201 dissector_delete_uint_range("tcp.port", nasdaq_soup_tcp_range, nasdaq_soup_handle);
202 g_free(nasdaq_soup_tcp_range);
203 nasdaq_soup_tcp_range = range_copy(global_nasdaq_soup_tcp_range);
204 dissector_add_uint_range("tcp.port", nasdaq_soup_tcp_range, nasdaq_soup_handle);
207 void
208 proto_register_nasdaq_soup(void)
211 /* Setup list of header fields See Section 1.6.1 for details*/
212 static hf_register_info hf[] = {
214 { &hf_nasdaq_soup_packet_type,
215 { "Packet Type", "nasdaq-soup.packet_type",
216 FT_UINT8, BASE_DEC, VALS(message_types_val), 0x0,
217 NULL, HFILL }},
219 { &hf_nasdaq_soup_reject_code,
220 { "Login Reject Code", "nasdaq-soup.reject_code",
221 FT_UINT8, BASE_DEC, VALS(reject_code_val), 0x0,
222 NULL, HFILL }},
224 { &hf_nasdaq_soup_message,
225 { "Message", "nasdaq-soup.message",
226 FT_STRING, BASE_NONE, NULL, 0x0,
227 NULL, HFILL }},
229 { &hf_nasdaq_soup_text,
230 { "Debug Text", "nasdaq-soup.text",
231 FT_STRING, BASE_NONE, NULL, 0x0,
232 NULL, HFILL }},
234 { &hf_nasdaq_soup_username,
235 { "User Name", "nasdaq-soup.username",
236 FT_STRING, BASE_NONE, NULL, 0x0,
237 NULL, HFILL }},
239 { &hf_nasdaq_soup_password,
240 { "Password", "nasdaq-soup.password",
241 FT_STRING, BASE_NONE, NULL, 0x0,
242 NULL, HFILL }},
244 { &hf_nasdaq_soup_session,
245 { "Session", "nasdaq-soup.session",
246 FT_STRING, BASE_NONE, NULL, 0x0,
247 "Session ID", HFILL }},
249 { &hf_nasdaq_soup_seq_number,
250 { "Sequence number", "nasdaq-soup.seq_number",
251 FT_STRING, BASE_NONE, NULL, 0x0,
252 NULL, HFILL }},
254 { &hf_nasdaq_soup_packet_eol,
255 { "End Of Packet", "nasdaq-soup.packet_eol",
256 FT_STRING, BASE_NONE, NULL, 0x0,
257 NULL, HFILL }}
260 /* Setup protocol subtree array */
261 static gint *ett[] = {
262 &ett_nasdaq_soup
265 module_t *nasdaq_soup_module;
267 /* Register the protocol name and description */
268 proto_nasdaq_soup = proto_register_protocol("Nasdaq-SoupTCP version 2.0","NASDAQ-SOUP", "nasdaq_soup");
270 /* Required function calls to register the header fields and subtrees used */
271 proto_register_field_array(proto_nasdaq_soup, hf, array_length(hf));
272 proto_register_subtree_array(ett, array_length(ett));
274 nasdaq_soup_module = prefs_register_protocol(proto_nasdaq_soup, nasdaq_soup_prefs);
275 prefs_register_bool_preference(nasdaq_soup_module, "desegment",
276 "Reassemble Nasdaq-SoupTCP messages spanning multiple TCP segments",
277 "Whether the Nasdaq-SoupTCP dissector should reassemble messages spanning multiple TCP segments.",
278 &nasdaq_soup_desegment);
280 prefs_register_range_preference(nasdaq_soup_module, "tcp.port", "TCP Ports", "TCP Ports range", &global_nasdaq_soup_tcp_range, 65535);
282 nasdaq_soup_tcp_range = range_empty();
285 /* If this dissector uses sub-dissector registration add a registration routine.
286 This format is required because a script is used to find these routines and
287 create the code that calls these routines.
289 void
290 proto_reg_handoff_nasdaq_soup(void)
292 nasdaq_soup_handle = create_dissector_handle(dissect_nasdaq_soup, proto_nasdaq_soup);
293 nasdaq_itch_handle = find_dissector("nasdaq-itch");
294 dissector_add_handle("tcp.port", nasdaq_soup_handle); /* for "decode-as" */