diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index b1518cb1e6..db998594f1 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -533,7 +533,7 @@ DISSECTOR_SRC = \ packet-isns.c \ packet-isup.c \ packet-isup_thin.c \ - packet-itch.c \ + packet-nasdaq-itch.c \ packet-iua.c \ packet-iuup.c \ packet-iwarp-ddp-rdmap.c\ @@ -756,7 +756,7 @@ DISSECTOR_SRC = \ packet-sndcp.c \ packet-sndcp-xid.c \ packet-socks.c \ - packet-soup.c \ + packet-nasdaq-soup.c \ packet-spp.c \ packet-spray.c \ packet-srp.c \ diff --git a/epan/dissectors/packet-nasdaq-itch.c b/epan/dissectors/packet-nasdaq-itch.c new file mode 100644 index 0000000000..a7862cb6af --- /dev/null +++ b/epan/dissectors/packet-nasdaq-itch.c @@ -0,0 +1,664 @@ +/* packet-nasdaq-itch.c + * Routines for NASDAQ TotalView-ITCH version 2.00/3.00 (with Chi-X extension) Protocol dissection + * Copyright 2007,2008 Didier Gautheron + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Documentation: + * http://www.nasdaqtrader.com/Trader.aspx?id=DPSpecs + * ex: + * http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/tv-itch2a.pdf + * http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/tvitch-v3.pdf + * + * Chi-X + * http://www.chi-x.com/docs/Chi-X%20CHIXMD.pdf + + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +/* Chi-X version */ +static gboolean nasdaq_itch_chi_x = TRUE; + +static const value_string message_types_val[] = { + { 'A', "Add Order " }, + { 'X', "Order Cancel " }, + { 'M', "Milliseconds " }, + { 'E', "Order Executed " }, + { 'T', "Second " }, + { 'P', "Trade Message Identifier " }, + { 'C', "Order Executed With Price " }, + { 'D', "Order Delete " }, + { 'Q', "Cross Trade " }, + { 'S', "System Event " }, + { 'R' , "Stock Directory " }, + { 'H', "Stock Trading Action " }, + { 'F', "Add Order (MPID) " }, + { 'I', "Net Order Imbalance Indicator (NOII) " }, + { 'B', "Broken Trade " }, + /* Chi-X msg with big size,price */ + { 'a', "Add Order (big)" }, + { 'p', "Trade Message Identifier (big)" }, + { 'e', "Order Executed (big)" }, + { 'x', "Order Cancel (big)" }, + { 0, NULL } +}; + +static char chix_msg[] = "apex"; + +static const value_string system_event_val[] = { + { 'O', "Start of Messages" }, + { 'S', "Start of System hours" }, + { 'Q', "Start of Market hours" }, + { 'M', "End of Market hours" }, + { 'E', "End of System hours" }, + { 'C', "End of Messages" }, + { 0, NULL } +}; + +static const value_string market_category_val[] = { + { 'T', "CQS (NYSE, Amex or regional exchange)" }, + { 'Q', "NASDAQ Global Select MarketSM" }, + { 'G', "NASDAQ Global MarketSM" }, + { 'S', "NASDAQ Capital Market" }, + { ' ', "Not available" }, + { 0, NULL } +}; + +static const value_string financial_status_val[] = { + { 'D', "Deficient" }, + { 'E', "Delinquent" }, + { 'Q', "Bankrupt" }, + { 'S', "Suspended" }, + { 'G', "Deficient and Bankrupt" }, + { 'H', "Deficient and Delinquent" }, + { 'J', "Delinquent and Bankrupt" }, + { 'K', "Deficient, Delinquent and Bankrupt" }, + { ' ', "Company is in compliance" }, + { 0, NULL } +}; + +static const value_string round_lots_only_val[] = { + { 'Y', "only round lots are accepted in this stock" }, + { 'N', "odd/mixed lots are allowed" }, + { 0, NULL } +}; + +/* Initialize the protocol and registered fields */ +static int proto_nasdaq_itch = -1; + +/* Initialize the subtree pointers */ +static gint ett_nasdaq_itch = -1; + +static int hf_nasdaq_itch_version = -1; + +static int hf_nasdaq_itch_message_type = -1; +static int hf_nasdaq_itch_market_category = -1; +static int hf_nasdaq_itch_financial_status = -1; +static int hf_nasdaq_itch_stock = -1; +static int hf_nasdaq_itch_round_lot_size = -1; +static int hf_nasdaq_itch_round_lots_only = -1; + +static int hf_nasdaq_itch_system_event = -1; +static int hf_nasdaq_itch_second = -1; +static int hf_nasdaq_itch_millisecond = -1; + +static int hf_nasdaq_itch_message = -1; + +static int hf_nasdaq_itch_trading_state = -1; +static int hf_nasdaq_itch_reserved = -1; +static int hf_nasdaq_itch_reason = -1; +static int hf_nasdaq_itch_order_reference = -1; +static int hf_nasdaq_itch_buy_sell = -1; +static int hf_nasdaq_itch_shares = -1; +static int hf_nasdaq_itch_price = -1; +static int hf_nasdaq_itch_attribution = -1; +static int hf_nasdaq_itch_executed = -1; +static int hf_nasdaq_itch_match = -1; +static int hf_nasdaq_itch_printable = -1; +static int hf_nasdaq_itch_execution_price = -1; +static int hf_nasdaq_itch_canceled = -1; +static int hf_nasdaq_itch_cross = -1; + +#define PINFO_COL(a) (check_col((a)->cinfo, COL_INFO)) + +/* atou(ll) like functions for NOT 0 terminated string + assume it doesn't overflow +*/ + +static guint32 nasdaq_itch_atou(const char *str_value, int size) +{ + int i; + const char *ptr = str_value; + guint32 value = 0; + + for (i = 0; i < size && *ptr == ' '; i++, ptr++) { + continue; + } + + for (; i < size; i++, ptr++) { + value = value*10 + *ptr - '0'; + } + return value; +} + +/* ---------------------- */ +static guint64 nasdaq_itch_atoull(const char *str_value, int size) +{ + int i; + const char *ptr = str_value; + guint64 value = 0; + + for (i = 0; i < size && *ptr == ' '; i++, ptr++) { + continue; + } + + for (; i < size; i++, ptr++) { + value = value*10 + *ptr - '0'; + } + return value; +} + +/* ---------------------- */ +static int +order_ref_number(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset) +{ + gint col_info = PINFO_COL(pinfo); + const char *str_value = tvb_get_ptr(tvb, offset, 9); + + if (nasdaq_itch_tree || col_info) { + guint32 value = nasdaq_itch_atou(str_value, 9); + + proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_order_reference, tvb, offset, 9, value); + if (col_info) { + col_append_fstr(pinfo->cinfo, COL_INFO, "%u ", value); + } + } + return offset+9; +} + +/* -------------------------- */ +static int +time_stamp(tvbuff_t *tvb, proto_tree *nasdaq_itch_tree, int id, int offset, int size) +{ + const char *str_value = tvb_get_ptr(tvb, offset, size); + + if (nasdaq_itch_tree) { + guint32 ms, val; + char *display = ""; + + ms = val = nasdaq_itch_atou(str_value, size); + switch (size) { + case 3: + display = ep_strdup_printf(" %03u" , val); + break; + case 5: + ms = val *1000; + case 8: /* 0 86 400 000 */ + display = ep_strdup_printf(" %u (%02u:%02u:%02u.%03u)", val, + ms/3600000, (ms % 3600000)/60000, (ms % 60000)/1000, ms %1000); + break; + } + proto_tree_add_uint_format_value(nasdaq_itch_tree, id, tvb, offset, size, val, "%s", display); + } + return offset+size; +} + +/* -------------------------- */ +static int +number_of_shares(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int id, int offset, int big) +{ + gint col_info = PINFO_COL(pinfo); + gint size = (big)?10:6; + const char *str_value = tvb_get_ptr(tvb, offset, size); + + if (nasdaq_itch_tree || col_info) { + guint32 value = nasdaq_itch_atou(str_value, size); + + proto_tree_add_uint(nasdaq_itch_tree, id, tvb, offset, size, value); + if (col_info) { + col_append_fstr(pinfo->cinfo, COL_INFO, "qty %u ", value); + } + } + return offset +size; +} + +/* -------------------------- */ +static int +price(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int id, int offset, int big) +{ + gint col_info = PINFO_COL(pinfo); + gint size = (big)?19:10; + + if (nasdaq_itch_tree || col_info) { + const char *str_value = tvb_get_ptr(tvb, offset, size); + gdouble value = nasdaq_itch_atoull(str_value, size)/((big)?1000000.0:10000.0); + + proto_tree_add_double(nasdaq_itch_tree, id, tvb, offset, size, value); + if (col_info) { + col_append_fstr(pinfo->cinfo, COL_INFO, "price %g ", value); + } + } + return offset+size; +} + +/* -------------------------- */ +static int +stock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset) +{ + gint col_info = PINFO_COL(pinfo); + if (nasdaq_itch_tree || col_info) { + char *stock = tvb_get_ephemeral_string(tvb, offset, 6); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_stock, tvb, offset, 6, FALSE); + if (col_info) { + col_append_fstr(pinfo->cinfo, COL_INFO, "<%s> ", stock); + } + } + return offset+6; +} + +/* -------------------------- */ +static int +order(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset, int big) +{ + gint col_info = PINFO_COL(pinfo); + guint8 value; + + offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); + + value = tvb_get_guint8(tvb, offset); + if (col_info) { + col_append_fstr(pinfo->cinfo, COL_INFO, "%c ", value); + } + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_buy_sell, tvb, offset, 1, FALSE); + offset += 1; + + offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big); + + offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); + + offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big); + return offset; +} + +/* -------------------------- */ +static int +executed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset, int big) +{ + offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); + + offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_executed, offset, big); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, FALSE); + offset += 9; + return offset; +} + +/* ---------------------------- */ +static void +dissect_nasdaq_itch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + proto_item *ti; + proto_tree *nasdaq_itch_tree = NULL; + guint8 nasdaq_itch_type; + int offset = 0; + gint col_info; + int version = 3; + int big = 0; + + col_info = PINFO_COL(pinfo); + + if (check_col(pinfo->cinfo, COL_PROTOCOL)) + col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-ITCH"); + + nasdaq_itch_type = tvb_get_guint8(tvb, offset); + if (nasdaq_itch_type >= '0' && nasdaq_itch_type <= '9') { + version = 2; + nasdaq_itch_type = tvb_get_guint8(tvb, offset +8); + } + + if ((!nasdaq_itch_chi_x || version == 3) && strchr(chix_msg, nasdaq_itch_type)) { + nasdaq_itch_type = 0; /* unknown */ + } + if (col_info || tree) { + const gchar *rep = val_to_str(nasdaq_itch_type, message_types_val, "Unknown packet type (0x%02x) "); + if (col_info ) { + col_clear(pinfo->cinfo, COL_INFO); + col_add_str(pinfo->cinfo, COL_INFO, rep); + } + if (tree) { + proto_item *item; + + ti = proto_tree_add_protocol_format(tree, proto_nasdaq_itch, tvb, offset, -1, "Nasdaq TotalView-ITCH %s, %s", + version == 2?"2.0":"3.0", rep); + + nasdaq_itch_tree = proto_item_add_subtree(ti, ett_nasdaq_itch); + + item=proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_version, tvb, 0, 0, version); + PROTO_ITEM_SET_GENERATED(item); + } + } + + if (version == 2) { + offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 8); + } + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message_type, tvb, offset, 1, FALSE); + offset++; + + if (version == 3) { + switch (nasdaq_itch_type) { + case 'T': /* seconds */ + offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_second, offset, 5); + return; + + case 'M': /* milliseconds */ + offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 3); + return; + } + } + + switch (nasdaq_itch_type) { + case 'S': /* system event */ + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_system_event, tvb, offset, 1, FALSE); + offset++; + break; + + case 'R': /* Stock Directory */ + offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_market_category, tvb, offset, 1, FALSE); + offset += 1; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_financial_status, tvb, offset, 1, FALSE); + offset += 1; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lot_size, tvb, offset, 6, FALSE); + offset += 6; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lots_only, tvb, offset, 1, FALSE); + offset += 1; + break; + + case 'H': /* Stock trading action */ + offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_trading_state, tvb, offset, 1, FALSE); + offset += 1; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reserved, tvb, offset, 1, FALSE); + offset += 1; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reason, tvb, offset, 4, FALSE); + offset += 4; + break; + + case 'a' : + big = 1; + case 'A': /* Add order, no MPID */ + offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); + if (version == 2) { + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, FALSE); + offset += 1; + } + break; + + case 'F': /* Add order, MPID */ + offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_attribution, tvb, offset, 4, FALSE); + offset += 4; + break; + + case 'e' : + big = 1; + case 'E' : /* Order executed */ + offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big); + break; + + case 'C' : /* Order executed with price */ + offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big); + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, FALSE); + offset += 1; + + offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_execution_price, offset, big); + break; + + case 'x' : + big = 1; + case 'X' : /* Order cancel */ + offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); + offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_canceled, offset, big); + break; + + case 'D' : /* Order delete */ + offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); + offset += 9; + break; + + case 'p' : + big = 1; + case 'P' : /* Trade identifier */ + offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, FALSE); + offset += 9; + break; + + case 'Q' : /* Cross Trade */ + offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big); + + offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); + + offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, FALSE); + offset += 9; + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, FALSE); + offset += 1; + break; + + case 'B' : /* Broken Trade */ + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, FALSE); + offset += 9; + break; + + case 'I': /* NOII, FIXME */ + offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); + + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, FALSE); + offset += 1; + break; + + default: + /* unknow */ + proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message, tvb, offset, -1, FALSE); + offset += 5-1; + break; + } +} + +/* Register the protocol with Wireshark */ + +void +proto_register_nasdaq_itch(void) +{ + +/* Setup list of header fields See Section 1.6.1 for details*/ + static hf_register_info hf[] = { + { &hf_nasdaq_itch_version, + { "Version", "nasdaq-itch.version", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_message_type, + { "Message Type", "nasdaq-itch.message_type", + FT_UINT8, BASE_DEC, VALS(message_types_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_second, + { "Second", "nasdaq-itch.second", + FT_UINT32, BASE_DEC, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_millisecond, + { "Millisecond", "nasdaq-itch.millisecond", + FT_UINT32, BASE_DEC, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_system_event, + { "System Event", "nasdaq-itch.system_event", + FT_UINT8, BASE_DEC, VALS(system_event_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_market_category, + { "Market Category", "nasdaq-itch.market_category", + FT_UINT8, BASE_DEC, VALS(market_category_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_financial_status, + { "Financial Status Indicator", "nasdaq-itch.financial_status", + FT_UINT8, BASE_DEC, VALS(financial_status_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_stock, + { "Stock", "nasdaq-itch.stock", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_round_lot_size, + { "Round Lot Size", "nasdaq-itch.round_lot_size", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_round_lots_only, + { "Round Lots Only", "nasdaq-itch.round_lots_only", + FT_UINT8, BASE_DEC, VALS(round_lots_only_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_trading_state, + { "Trading State", "nasdaq-itch.trading_state", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_reserved, + { "Reserved", "nasdaq-itch.reserved", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_reason, + { "Reason", "nasdaq-itch.reason", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_order_reference, + { "Order Reference", "nasdaq-itch.order_reference", + FT_UINT32, BASE_DEC, NULL, 0x0, + "Order reference number", HFILL }}, + + { &hf_nasdaq_itch_buy_sell, + { "Buy/Sell", "nasdaq-itch.buy_sell", + FT_STRING, BASE_NONE, NULL, 0x0, + "Buy/Sell indicator", HFILL }}, + + { &hf_nasdaq_itch_shares, + { "Shares", "nasdaq-itch.shares", + FT_UINT32, BASE_DEC, NULL, 0x0, + "Number of shares", HFILL }}, + + { &hf_nasdaq_itch_price, + { "Price", "nasdaq-itch.price", + FT_DOUBLE, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_attribution, + { "Attribution", "nasdaq-itch.attribution", + FT_STRING, BASE_NONE, NULL, 0x0, + "Market participant identifier", HFILL }}, + + { &hf_nasdaq_itch_executed, + { "Executed Shares", "nasdaq-itch.executed", + FT_UINT32, BASE_DEC, NULL, 0x0, + "Number of shares executed", HFILL }}, + + { &hf_nasdaq_itch_match, + { "Matched", "nasdaq-itch.match", + FT_STRING, BASE_NONE, NULL, 0x0, + "Match number", HFILL }}, + + { &hf_nasdaq_itch_printable, + { "Printable", "nasdaq-itch.printable", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_execution_price, + { "Execution Price", "nasdaq-itch.execution_price", + FT_DOUBLE, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_itch_canceled, + { "Canceled Shares", "nasdaq-itch.canceled", + FT_UINT32, BASE_DEC, NULL, 0x0, + "Number of shares to be removed", HFILL }}, + + { &hf_nasdaq_itch_cross, + { "Cross Type", "nasdaq-itch.cross", + FT_STRING, BASE_NONE, NULL, 0x0, + "Cross trade type", HFILL }}, + + { &hf_nasdaq_itch_message, + { "Message", "nasdaq-itch.message", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }} + }; + +/* Setup protocol subtree array */ + static gint *ett[] = { + &ett_nasdaq_itch + }; + + module_t *nasdaq_itch_module; + + /* Register the protocol name and description */ + proto_nasdaq_itch = proto_register_protocol("Nasdaq TotalView-ITCH", "NASDAQ-ITCH", "nasdaq_itch"); + + /* Required function calls to register the header fields and subtrees used */ + proto_register_field_array(proto_nasdaq_itch, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + nasdaq_itch_module = prefs_register_protocol(proto_nasdaq_itch, NULL); + prefs_register_bool_preference(nasdaq_itch_module, "chi_x", "Decode Chi X extensions", + "Whether the Nasdaq ITCH dissector should decode Chi X extensions.", + &nasdaq_itch_chi_x); + + register_dissector("nasdaq-itch", dissect_nasdaq_itch, proto_nasdaq_itch); +} + + +/* If this dissector uses sub-dissector registration add a registration routine. + This format is required because a script is used to find these routines and + create the code that calls these routines. +*/ +void +proto_reg_handoff_nasdaq_itch(void) +{ +} + diff --git a/epan/dissectors/packet-nasdaq-soup.c b/epan/dissectors/packet-nasdaq-soup.c new file mode 100644 index 0000000000..200bc9e828 --- /dev/null +++ b/epan/dissectors/packet-nasdaq-soup.c @@ -0,0 +1,312 @@ +/* packet-nasdaq-soup.c + * Routines for NASDAQ SOUP 2.0 Protocol dissection + * Copyright 2007,2008 Didier Gautheron + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Documentation: http://www.nasdaqtrader.com/Trader.aspx?id=DPSpecs + * ex: + * http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/souptcp.pdf + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include "packet-tcp.h" + +static const value_string message_types_val[] = { + { 'S', "Sequenced Data" }, + { 'R', "Client Heartbeat" }, + { 'H', "Server Heartbeat" }, + { '+' , "Debug Packet" }, + { 'A', "Login Accepted" }, + { 'J', "Login Rejected" }, + { 'L', "Login Request" }, + { 'U', "Unsequenced Data" }, + { 'O', "Logout Request" }, + { 0, NULL } +}; + +static const value_string reject_code_val[] = { + { 'A', "Not authorized" }, + { 'S', "Session not available" }, + { 0, NULL } +}; + +/* Initialize the protocol and registered fields */ +static int proto_nasdaq_soup = -1; +static dissector_handle_t nasdaq_soup_handle; +static dissector_handle_t nasdaq_itch_handle; + +/* desegmentation of Nasdaq Soup */ +static gboolean nasdaq_soup_desegment = TRUE; + +static range_t *global_nasdaq_soup_tcp_range = NULL; +static range_t *nasdaq_soup_tcp_range = NULL; + +/* Initialize the subtree pointers */ +static gint ett_nasdaq_soup = -1; + +static int hf_nasdaq_soup_packet_type = -1; +static int hf_nasdaq_soup_message = -1; +static int hf_nasdaq_soup_text = -1; +static int hf_nasdaq_soup_packet_eol = -1; +static int hf_nasdaq_soup_username = -1; +static int hf_nasdaq_soup_password = -1; +static int hf_nasdaq_soup_session = -1; +static int hf_nasdaq_soup_seq_number = -1; +static int hf_nasdaq_soup_reject_code = -1; + +static void +dissect_nasdaq_soup_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, proto_tree *tree, int offset, int linelen) +{ + guint8 nasdaq_soup_type; + tvbuff_t *new_tvb = NULL; + + nasdaq_soup_type = tvb_get_guint8(tvb, offset); + proto_tree_add_item(tree, hf_nasdaq_soup_packet_type, tvb, offset, 1, FALSE); + offset++; + + switch (nasdaq_soup_type) { + case '+': /* debug msg */ + proto_tree_add_item(tree, hf_nasdaq_soup_text, tvb, offset, linelen -1, FALSE); + offset += linelen -1; + break; + case 'A': /* login accept */ + proto_tree_add_item(tree, hf_nasdaq_soup_session, tvb, offset, 10, FALSE); + offset += 10; + + proto_tree_add_item(tree, hf_nasdaq_soup_seq_number, tvb, offset, 10, FALSE); + offset += 10; + break; + case 'J': /* login reject */ + proto_tree_add_item(tree, hf_nasdaq_soup_reject_code, tvb, offset, 1, FALSE); + offset++; + break; + + case 'U': /* unsequenced data packed */ + case 'S': /* sequenced data packed */ + if (linelen > 1 && nasdaq_itch_handle) { + new_tvb = tvb_new_subset(tvb, offset,linelen -1,linelen -1); + } else { + proto_tree_add_item(tree, hf_nasdaq_soup_message, tvb, offset, linelen -1, FALSE); + } + offset += linelen -1; + break; + + case 'L': /* login request */ + proto_tree_add_item(tree, hf_nasdaq_soup_username, tvb, offset, 6, FALSE); + offset += 6; + + proto_tree_add_item(tree, hf_nasdaq_soup_password, tvb, offset, 10, FALSE); + offset += 10; + + proto_tree_add_item(tree, hf_nasdaq_soup_session, tvb, offset, 10, FALSE); + offset += 10; + + proto_tree_add_item(tree, hf_nasdaq_soup_seq_number, tvb, offset, 10, FALSE); + offset += 10; + break; + + case 'H': /* server heartbeat */ + case 'O': /* logout request */ + case 'R': /* client heartbeat */ + /* no payload */ + break; + default: + /* unknow */ + proto_tree_add_item(tree, hf_nasdaq_soup_message, tvb, offset, linelen -1, FALSE); + offset += linelen -1; + break; + } + + proto_tree_add_item(tree, hf_nasdaq_soup_packet_eol, tvb, offset, 1, FALSE); + if (new_tvb) { + call_dissector(nasdaq_itch_handle, new_tvb, pinfo, parent_tree); + } + return; +} + +/* ---------------------------- */ +static void +dissect_nasdaq_soup(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + proto_item *ti; + proto_tree *nasdaq_soup_tree = NULL; + guint8 nasdaq_soup_type; + int linelen; + gint next_offset; + int offset = 0; + gint col_info; + gint counter = 0; + + col_info = check_col(pinfo->cinfo, COL_INFO); + while (tvb_offset_exists(tvb, offset)) { + /* there's only a \n no \r */ + linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, nasdaq_soup_desegment && pinfo->can_desegment); + if (linelen == -1) { + /* + * We didn't find a line ending, and we're doing desegmentation; + * tell the TCP dissector where the data for this message starts + * in the data it handed us, and tell it we need one more byte + * (we may need more, but we'll try again if what we get next + * isn't enough), and return. + */ + pinfo->desegment_offset = offset; + pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT; + return; + } + + nasdaq_soup_type = tvb_get_guint8(tvb, offset); + if (counter == 0) { + if (check_col(pinfo->cinfo, COL_PROTOCOL)) + col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-SOUP"); + if (col_info) + col_clear(pinfo->cinfo, COL_INFO); + } + if (col_info ) { + if (counter) { + col_append_str(pinfo->cinfo, COL_INFO, "; "); + col_set_fence(pinfo->cinfo, COL_INFO); + } + col_append_str(pinfo->cinfo, COL_INFO, val_to_str(nasdaq_soup_type, message_types_val, "Unknown packet type (0x%02x)")); + } + counter++; + if (tree) { + ti = proto_tree_add_item(tree, proto_nasdaq_soup, tvb, offset, linelen +1, FALSE); + nasdaq_soup_tree = proto_item_add_subtree(ti, ett_nasdaq_soup); + } + dissect_nasdaq_soup_packet(tvb, pinfo, tree, nasdaq_soup_tree, offset, linelen); + offset = next_offset; + } +} + +/* Register the protocol with Wireshark */ +static void range_delete_nasdaq_soup_tcp_callback(guint32 port) { + dissector_delete("tcp.port", port, nasdaq_soup_handle); +} + +static void range_add_nasdaq_soup_tcp_callback(guint32 port) { + dissector_add("tcp.port", port, nasdaq_soup_handle); +} + +static void nasdaq_soup_prefs(void) +{ + range_foreach(nasdaq_soup_tcp_range, range_delete_nasdaq_soup_tcp_callback); + g_free(nasdaq_soup_tcp_range); + nasdaq_soup_tcp_range = range_copy(global_nasdaq_soup_tcp_range); + range_foreach(nasdaq_soup_tcp_range, range_add_nasdaq_soup_tcp_callback); +} + +void +proto_register_nasdaq_soup(void) +{ + +/* Setup list of header fields See Section 1.6.1 for details*/ + static hf_register_info hf[] = { + + { &hf_nasdaq_soup_packet_type, + { "Packet Type", "nasdaq-soup.packet_type", + FT_UINT8, BASE_DEC, VALS(message_types_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_reject_code, + { "Login Reject Code", "nasdaq-soup.reject_code", + FT_UINT8, BASE_DEC, VALS(reject_code_val), 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_message, + { "Message", "nasdaq-soup.message", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_text, + { "Debug Text", "nasdaq-soup.text", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_username, + { "User Name", "nasdaq-soup.username", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_password, + { "Password", "nasdaq-soup.password", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_session, + { "Session", "nasdaq-soup.session", + FT_STRING, BASE_NONE, NULL, 0x0, + "Session ID", HFILL }}, + + { &hf_nasdaq_soup_seq_number, + { "Sequence number", "nasdaq-soup.seq_number", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }}, + + { &hf_nasdaq_soup_packet_eol, + { "End Of Packet", "nasdaq-soup.packet_eol", + FT_STRING, BASE_NONE, NULL, 0x0, + NULL, HFILL }} + }; + + /* Setup protocol subtree array */ + static gint *ett[] = { + &ett_nasdaq_soup + }; + + module_t *nasdaq_soup_module; + + /* Register the protocol name and description */ + proto_nasdaq_soup = proto_register_protocol("Nasdaq-SoupTCP version 2.0","NASDAQ-SOUP", "nasdaq_soup"); + + /* Required function calls to register the header fields and subtrees used */ + proto_register_field_array(proto_nasdaq_soup, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + nasdaq_soup_module = prefs_register_protocol(proto_nasdaq_soup, nasdaq_soup_prefs); + prefs_register_bool_preference(nasdaq_soup_module, "desegment", + "Reassemble Nasdaq-SoupTCP messages spanning multiple TCP segments", + "Whether the Nasdaq-SoupTCP dissector should reassemble messages spanning multiple TCP segments.", + &nasdaq_soup_desegment); + + prefs_register_range_preference(nasdaq_soup_module, "tcp.port", "TCP Ports", "TCP Ports range", &global_nasdaq_soup_tcp_range, 65535); + + nasdaq_soup_tcp_range = range_empty(); +} + +/* If this dissector uses sub-dissector registration add a registration routine. + This format is required because a script is used to find these routines and + create the code that calls these routines. +*/ +void +proto_reg_handoff_nasdaq_soup(void) +{ + nasdaq_soup_handle = create_dissector_handle(dissect_nasdaq_soup, proto_nasdaq_soup); + nasdaq_itch_handle = find_dissector("nasdaq-itch"); + dissector_add_handle("tcp.port", nasdaq_soup_handle); /* for "decode-as" */ +} +