1 /* packet-nasdaq-soup.c
2 * Routines for NASDAQ SOUP 2.0 Protocol dissection
3 * Copyright 2007,2008 Didier Gautheron <dgautheron@magic.fr>
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
27 * http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/souptcp.pdf
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" },
50 static const value_string reject_code_val
[] = {
51 { 'A', "Not authorized" },
52 { 'S', "Session not available" },
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;
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
);
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
);
95 case 'A': /* login accept */
96 proto_tree_add_item(tree
, hf_nasdaq_soup_session
, tvb
, offset
, 10, ENC_ASCII
|ENC_NA
);
99 proto_tree_add_item(tree
, hf_nasdaq_soup_seq_number
, tvb
, offset
, 10, ENC_ASCII
|ENC_NA
);
102 case 'J': /* login reject */
103 proto_tree_add_item(tree
, hf_nasdaq_soup_reject_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
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);
112 proto_tree_add_item(tree
, hf_nasdaq_soup_message
, tvb
, offset
, linelen
-1, ENC_ASCII
|ENC_NA
);
114 offset
+= linelen
-1;
117 case 'L': /* login request */
118 proto_tree_add_item(tree
, hf_nasdaq_soup_username
, tvb
, offset
, 6, ENC_ASCII
|ENC_NA
);
121 proto_tree_add_item(tree
, hf_nasdaq_soup_password
, tvb
, offset
, 10, ENC_ASCII
|ENC_NA
);
124 proto_tree_add_item(tree
, hf_nasdaq_soup_session
, tvb
, offset
, 10, ENC_ASCII
|ENC_NA
);
127 proto_tree_add_item(tree
, hf_nasdaq_soup_seq_number
, tvb
, offset
, 10, ENC_ASCII
|ENC_NA
);
131 case 'H': /* server heartbeat */
132 case 'O': /* logout request */
133 case 'R': /* client heartbeat */
138 proto_tree_add_item(tree
, hf_nasdaq_soup_message
, tvb
, offset
, linelen
-1, ENC_ASCII
|ENC_NA
);
139 offset
+= linelen
-1;
143 proto_tree_add_item(tree
, hf_nasdaq_soup_packet_eol
, tvb
, offset
, 1, ENC_ASCII
|ENC_NA
);
145 call_dissector(nasdaq_itch_handle
, new_tvb
, pinfo
, parent_tree
);
150 /* ---------------------------- */
152 dissect_nasdaq_soup(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
155 proto_tree
*nasdaq_soup_tree
= NULL
;
156 guint8 nasdaq_soup_type
;
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
);
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
;
178 nasdaq_soup_type
= tvb_get_guint8(tvb
, offset
);
180 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Nasdaq-SOUP");
181 col_clear(pinfo
->cinfo
, COL_INFO
);
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)"));
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
);
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,
219 { &hf_nasdaq_soup_reject_code
,
220 { "Login Reject Code", "nasdaq-soup.reject_code",
221 FT_UINT8
, BASE_DEC
, VALS(reject_code_val
), 0x0,
224 { &hf_nasdaq_soup_message
,
225 { "Message", "nasdaq-soup.message",
226 FT_STRING
, BASE_NONE
, NULL
, 0x0,
229 { &hf_nasdaq_soup_text
,
230 { "Debug Text", "nasdaq-soup.text",
231 FT_STRING
, BASE_NONE
, NULL
, 0x0,
234 { &hf_nasdaq_soup_username
,
235 { "User Name", "nasdaq-soup.username",
236 FT_STRING
, BASE_NONE
, NULL
, 0x0,
239 { &hf_nasdaq_soup_password
,
240 { "Password", "nasdaq-soup.password",
241 FT_STRING
, BASE_NONE
, NULL
, 0x0,
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,
254 { &hf_nasdaq_soup_packet_eol
,
255 { "End Of Packet", "nasdaq-soup.packet_eol",
256 FT_STRING
, BASE_NONE
, NULL
, 0x0,
260 /* Setup protocol subtree array */
261 static gint
*ett
[] = {
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.
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" */