2 * Routines for OUCH 4.x protocol dissection
3 * Copyright 2013 David Arnold <davida@pobox.com>
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
23 * Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301 USA.
28 /* OUCH is a stock exchange order entry protocol published and used by
29 * NASDAQ. This dissector supports versions 4.x, which differ from
30 * earlier versions by adopting binary encoding for numeric values.
32 * OUCH is usually encapsulated within NASDAQ's SoupBinTCP protocol,
33 * running over a TCP connection from the trading application to the
34 * exchange. SOUP provides framing, heartbeats and authentication;
35 * consequently none of these is present in OUCH.
37 * Other exchanges have created order entry protocols very similar to
38 * OUCH, but typically they differ in subtle ways (and continue to
39 * diverge as time progresses) so I have not attempted to dissect
40 * anything other than proper NASDAQ OUCH in this code.
42 * Specifications are available from NASDAQ's website, although the
43 * links to find them tend to move around over time. At the time of
44 * writing, the correct URL is:
46 * http://www.nasdaqtrader.com/content/technicalsupport/specifications/TradingProducts/OUCH4.2.pdf
52 #include <epan/packet.h>
53 #include <epan/prefs.h>
54 #include <epan/wmem/wmem.h>
56 #include "packet-tcp.h"
59 static const value_string pkt_type_val
[] = {
60 { 'O', "Enter Order" },
61 { 'U', "Replace Order" },
62 { 'X', "Cancel Order" },
63 { 'M', "Modify Order" }, /* Not in 4.0 or 4.1 */
64 { 'S', "System Event" },
66 { 'R', "Replaced" }, /* 'U' on the wire, but use 'R' to disambiguate */
68 { 'D', "AIQ Canceled" },
70 { 'B', "Broken Trade" },
71 { 'K', "Price Correction" },
73 { 'P', "Cancel Pending" },
74 { 'I', "Cancel Reject" },
79 static const value_string ouch_bbo_weight_indicator_val
[] = {
83 { '3', "Greater than 2%" },
84 { ' ', "Unspecified" },
85 { 'S', "Sets the QBBO while joining the NBBO" },
86 { 'N', "Improves the NBBO upon entry" },
90 static const value_string ouch_broken_trade_reason_val
[] = {
93 { 'S', "Supervisory" },
98 static const value_string ouch_buy_sell_indicator_val
[] = {
100 { 'S', "Sell Order" },
101 { 'T', "Sell Short" },
102 { 'E', "Sell Short Exempt" },
106 static const value_string ouch_cancel_reason_val
[] = {
107 { 'U', "User requested cancel" },
108 { 'I', "Immediate or Cancel order" },
110 { 'S', "Supervisory" },
111 { 'D', "Regulatory restriction" },
112 { 'Q', "Self-match prevention" },
113 { 'Z', "System cancel" },
117 static const value_string ouch_capacity_val
[] = {
120 { 'P', "Principal" },
125 static const value_string ouch_cross_type_val
[] = {
127 { 'O', "Opening Cross" },
128 { 'C', "Closing Cross" },
129 { 'I', "Intra-day Cross" },
130 { 'H', "Halt/IPO Cross" },
131 { 'R', "Retail" }, /* Not in 4.0 */
132 { 'S', "Supplemental Order" },
137 static const value_string ouch_customer_type_val
[] = {
138 { 'R', "Retail designated order" },
139 { 'N', "Not a retail designated order" },
140 { ' ', "Default configured for port" },
144 static const value_string ouch_display_val
[] = {
145 { 'A', "Attributable-Price to Display" },
146 { 'I', "Imbalance-Only" },
147 { 'L', "Post-Only and Attributable - Price to Display" },
148 { 'M', "Mid-Point Peg" },
149 { 'N', "Non-Display" },
150 { 'O', "Retail Order Type 1" }, /* Not in 4.0 */
151 { 'P', "Post-Only" },
152 { 'Q', "Retail Price Improvement Order" }, /* Not in 4.0 */
153 { 'R', "Round-Lot Only" },
154 { 'T', "Retail Order Type 2" }, /* Not in 4.0 */
155 { 'W', "Mid-point Peg Post Only" },
156 { 'Y', "Anonymous-Price to Comply" },
160 static const value_string ouch_event_code_val
[] = {
161 { 'S', "Start of Day" },
162 { 'E', "End of Day" },
166 static const value_string ouch_iso_eligibility_val
[] = {
168 { 'N', "Not eligible" },
172 static const value_string ouch_liquidity_flag_val
[] = {
175 { 'O', "Opening Cross (billable)" },
176 { 'M', "Opening Cross (non-billable)" },
177 { 'C', "Closing Cross (billable)" },
178 { 'L', "Closing Cross (non-billable)" },
179 { 'H', "Halt/IPO Cross (billable)" },
180 { 'K', "Halt/IPO Cross (non-billable)" },
181 { 'I', "Intraday/Post-Market Cross" },
182 { 'J', "Non-displayed adding liquidity" },
183 { 'm', "Removed liquidity at a midpoint" },
184 { 'k', "Added liquidity via a midpoint order" },
185 { '0', "Supplemental Order Execution" },
186 { '7', "Displayed, liquidity-adding order improves the NBBO" },
187 { '8', "Displayed, liquidity-adding order sets the QBBO while "
188 "joining the NBBO" },
190 { 'd', "Retail designated execution that removed liquidity" },
191 { 'e', "Retail designated execution that added displayed liquidity" },
192 { 'f', "Retail designated execution that added non-displayed liquidity" },
193 { 'j', "RPI (Retail Price Improving) order provides liquidity" },
194 { 'r', "Retail Order removes RPI liquidity" },
195 { 't', "Retail Order removes price improving non-displayed liquidity "
196 "other than RPI liquidity" },
197 { '6', "Liquidity Removing Order in designated securities" },
201 static const value_string ouch_order_state_val
[] = {
202 { 'L', "Order Live" },
203 { 'D', "Order Dead" },
207 static const value_string ouch_price_correction_reason_val
[] = {
208 { 'E', "Erroneous" },
210 { 'S', "Supervisory" },
215 static const value_string ouch_reject_reason_val
[] = {
216 { 'T', "Test Mode" },
218 { 'Z', "Shares exceeds configured safety threshold" },
219 { 'S', "Invalid Stock" },
220 { 'D', "Invalid Display Type" },
221 { 'C', "NASDAQ is Closed" },
222 { 'L', "Requested firm not authorized for requested clearing type on this account" },
223 { 'M', "Outside of permitted times for requested clearing type" },
224 { 'R', "This order is not allowed in this type of cross" },
225 { 'X', "Invalid Price" },
226 { 'N', "Invalid Minimum Quantity" },
228 { 'a', "Reject All enabled" },
229 { 'b', "Easy to Borrow (ETB) reject" },
230 { 'c', "Restricted symbol list reject" },
231 { 'd', "ISO order restriction" },
232 { 'e', "Odd lot order restriction" },
233 { 'f', "Mid-Point order restriction" },
234 { 'g', "Pre-market order restriction" },
235 { 'h', "Post-market order restriction" },
236 { 'i', "Short sale order restriction" },
237 { 'j', "On Open order restriction" },
238 { 'k', "On Close order restriction" },
239 { 'l', "Two sided quote reject" },
240 { 'm', "Exceeded shares limit" },
241 { 'n', "Exceeded dollar value limit" },
246 /* Initialize the protocol and registered fields */
247 static int proto_ouch
= -1;
248 static dissector_handle_t ouch_handle
;
250 static range_t
*global_ouch_range
= NULL
;
251 static range_t
*ouch_range
= NULL
;
253 /* Initialize the subtree pointers */
254 static gint ett_ouch
= -1;
256 static int hf_ouch_bbo_weight_indicator
= -1;
257 static int hf_ouch_broken_trade_reason
= -1;
258 static int hf_ouch_buy_sell_indicator
= -1;
259 static int hf_ouch_cancel_reason
= -1;
260 static int hf_ouch_capacity
= -1;
261 static int hf_ouch_cross_type
= -1;
262 static int hf_ouch_customer_type
= -1;
263 static int hf_ouch_decrement_shares
= -1;
264 static int hf_ouch_display
= -1;
265 static int hf_ouch_event_code
= -1;
266 static int hf_ouch_executed_shares
= -1;
267 static int hf_ouch_execution_price
= -1;
268 static int hf_ouch_existing_order_token
= -1;
269 static int hf_ouch_firm
= -1;
270 static int hf_ouch_iso_eligible
= -1;
271 static int hf_ouch_liquidity_flag
= -1;
272 static int hf_ouch_match_number
= -1;
273 static int hf_ouch_message
= -1;
274 static int hf_ouch_min_quantity
= -1;
275 static int hf_ouch_new_execution_price
= -1;
276 static int hf_ouch_order_reference_number
= -1;
277 static int hf_ouch_order_state
= -1;
278 static int hf_ouch_order_token
= -1;
279 static int hf_ouch_packet_type
= -1;
280 static int hf_ouch_previous_order_token
= -1;
281 static int hf_ouch_price
= -1;
282 static int hf_ouch_price_correction_reason
= -1;
283 static int hf_ouch_quantity_prevented_from_trading
= -1;
284 static int hf_ouch_reject_reason
= -1;
285 static int hf_ouch_replacement_order_token
= -1;
286 static int hf_ouch_shares
= -1;
287 static int hf_ouch_stock
= -1;
288 static int hf_ouch_tif
= -1;
289 static int hf_ouch_timestamp
= -1;
292 /** Format an OUCH timestamp into a useful string
294 * We use this function rather than a BASE_CUSTOM formatter because
295 * BASE_CUSTOM doesn't support passing a 64-bit value to the
296 * formatting function. */
298 ouch_tree_add_timestamp(
304 guint64 ts
= tvb_get_ntoh64(tvb
, offset
);
305 char *buf
= (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH
);
306 guint32 tmp
, hours
, mins
, secs
, nsecs
;
308 nsecs
= (guint32
)(ts
% G_GUINT64_CONSTANT(1000000000));
309 tmp
= (guint32
)(ts
/ G_GUINT64_CONSTANT(1000000000));
312 mins
= (tmp
% 3600) / 60;
315 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
317 hours
, mins
, secs
, nsecs
);
319 proto_tree_add_string(tree
, hf
, tvb
, offset
, 8, buf
);
323 /** BASE_CUSTOM formatter for BBO weight indicator code
325 * Displays the code value as a character, not its ASCII value, as
326 * would be done by BASE_DEC and friends. */
328 format_bbo_weight_indicator(
332 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
334 val_to_str_const(value
,
335 ouch_bbo_weight_indicator_val
,
340 /** BASE_CUSTOM formatter for broken trade reason code
342 * Displays the code value as a character, not its ASCII value, as
343 * would be done by BASE_DEC and friends. */
345 format_broken_trade_reason(
349 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
351 val_to_str_const(value
,
352 ouch_broken_trade_reason_val
,
357 /** BASE_CUSTOM formatter for buy/sell indicator code
359 * Displays the code value as a character, not its ASCII value, as
360 * would be done by BASE_DEC and friends. */
362 format_buy_sell_indicator(
366 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
368 val_to_str_const(value
, ouch_buy_sell_indicator_val
, "Unknown"),
372 /** BASE_CUSTOM formatter for cancel reason code
374 * Displays the code value as a character, not its ASCII value, as
375 * would be done by BASE_DEC and friends. */
377 format_cancel_reason(
381 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
383 val_to_str_const(value
, ouch_cancel_reason_val
, "Unknown"),
387 /** BASE_CUSTOM formatter for the capacity code
389 * Displays the code value as a character, not its ASCII value, as
390 * would be done by BASE_DEC and friends. */
396 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
398 val_to_str_const(value
, ouch_capacity_val
, "Unknown"),
402 /** BASE_CUSTOM formatter for the cross type code
404 * Displays the code value as a character, not its ASCII value, as
405 * would be done by BASE_DEC and friends. */
411 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
413 val_to_str_const(value
, ouch_cross_type_val
, "Unknown"),
417 /** BASE_CUSTOM formatter for the customer type code
419 * Displays the code value as a character, not its ASCII value, as
420 * would be done by BASE_DEC and friends. */
422 format_customer_type(
426 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
428 val_to_str_const(value
, ouch_customer_type_val
, "Unknown"),
432 /** BASE_CUSTOM formatter for the display code
434 * Displays the code value as a character, not its ASCII value, as
435 * would be done by BASE_DEC and friends. */
441 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
443 val_to_str_const(value
, ouch_display_val
, "Unknown"),
447 /** BASE_CUSTOM formatter for the system event code
449 * Displays the code value as a character, not its ASCII value, as
450 * would be done by BASE_DEC and friends. */
456 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
458 val_to_str_const(value
, ouch_event_code_val
, "Unknown"),
462 /** BASE_CUSTOM formatter for the ISO eligibility code
464 * Displays the code value as a character, not its ASCII value, as
465 * would be done by BASE_DEC and friends. */
467 format_iso_eligibility(
471 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
473 val_to_str_const(value
, ouch_iso_eligibility_val
, "Unknown"),
477 /** BASE_CUSTOM formatter for the liquidity flag code
479 * Displays the code value as a character, not its ASCII value, as
480 * would be done by BASE_DEC and friends. */
482 format_liquidity_flag(
486 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
488 val_to_str_const(value
, ouch_liquidity_flag_val
, "Unknown"),
492 /** BASE_CUSTOM formatter for order state code
494 * Displays the code value as a character, not its ASCII value, as
495 * would be done by BASE_DEC and friends. */
501 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
503 val_to_str_const(value
, ouch_order_state_val
, "Unknown"),
507 /** BASE_CUSTOM formatter for the packet type code
509 * Displays the code value as a character, not its ASCII value, as
510 * would be done by BASE_DEC and friends. */
516 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
518 val_to_str_const(value
, pkt_type_val
, "Unknown"),
522 /** BASE_CUSTOM formatter for prices
524 * OUCH prices are integers, with four implicit decimal places. So we
525 * insert the decimal point, and add a leading dollar sign as well. */
531 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
533 value
/ 10000, value
% 10000);
536 /** BASE_CUSTOM formatter for price correction reason code
538 * Displays the code value as a character, not its ASCII value, as
539 * would be done by BASE_DEC and friends. */
541 format_price_correction_reason(
545 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
547 val_to_str_const(value
,
548 ouch_price_correction_reason_val
,
553 /** BASE_CUSTOM formatter for the reject reason code
555 * Displays the code value as a character, not its ASCII value, as
556 * would be done by BASE_DEC and friends. */
558 format_reject_reason(
562 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
564 val_to_str_const(value
, ouch_reject_reason_val
, "Unknown"),
568 /** BASE_CUSTOM formatter for the Time In Force (TIF) code
570 * There are three reserved values for the TIF: 0, 99998 and 99999.
571 * These are trapped and displayed as an appropriate string. All
572 * other values are printed as a duration in hours, minutes and
585 g_snprintf(buf
, ITEM_LABEL_LENGTH
, "Immediate Or Cancel (%u)", value
);
589 g_snprintf(buf
, ITEM_LABEL_LENGTH
, "Market Hours (%u)", value
);
593 g_snprintf(buf
, ITEM_LABEL_LENGTH
, "System Hours (%u)", value
);
597 hours
= value
/ 3600;
598 mins
= (value
% 3600) / 60;
601 g_snprintf(buf
, ITEM_LABEL_LENGTH
,
602 "%uh %02um %02us (%u seconds)",
618 proto_tree
*ouch_tree
= NULL
;
619 const char *pkt_name
;
620 guint16 reported_len
;
624 /* Get the OUCH message type value */
625 pkt_type
= tvb_get_guint8(tvb
, 0);
626 reported_len
= tvb_reported_length(tvb
);
628 /* OUCH has two messages with the same code: Replace Order and
629 * Replaced. It's possible to tell which is which because clients
630 * send the Replace Order, and NASDAQ sends Replaced replies.
631 * Nonetheless, this complicates the switch, so instead we
632 * distinguish between them by length, and use 'R' for Replaced
633 * (like XPRS does). */
634 if (pkt_type
== 'U' && (reported_len
== 79 || reported_len
== 80)) {
638 /* Since we use the packet name a few times, get and save that value */
639 pkt_name
= val_to_str(pkt_type
, pkt_type_val
, "Unknown (%u)");
641 /* Set the protocol name in the summary display */
642 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "OUCH");
644 /* Set the packet name in the info column */
645 col_add_str(pinfo
->cinfo
, COL_INFO
, pkt_name
);
648 /* Create a sub-tree for the OUCH packet details */
649 ti
= proto_tree_add_item(tree
,
653 ouch_tree
= proto_item_add_subtree(ti
, ett_ouch
);
655 /* Append the packet name to the sub-tree item */
656 proto_item_append_text(ti
, ", %s", pkt_name
);
658 /* Packet type (from the buffer, not the modified one we use
660 proto_tree_add_item(ouch_tree
,
662 tvb
, offset
, 1, ENC_BIG_ENDIAN
);
666 case 'O': /* Enter Order */
667 proto_tree_add_item(ouch_tree
,
673 proto_tree_add_item(ouch_tree
,
674 hf_ouch_buy_sell_indicator
,
679 proto_tree_add_item(ouch_tree
,
685 proto_tree_add_item(ouch_tree
,
691 proto_tree_add_item(ouch_tree
,
697 proto_tree_add_item(ouch_tree
,
703 proto_tree_add_item(ouch_tree
,
709 proto_tree_add_item(ouch_tree
,
715 proto_tree_add_item(ouch_tree
,
721 proto_tree_add_item(ouch_tree
,
722 hf_ouch_iso_eligible
,
727 proto_tree_add_item(ouch_tree
,
728 hf_ouch_min_quantity
,
733 proto_tree_add_item(ouch_tree
,
739 if (reported_len
== 49) { /* Added in 4.1 */
740 proto_tree_add_item(ouch_tree
,
741 hf_ouch_customer_type
,
748 case 'A': /* Accepted */
749 ouch_tree_add_timestamp(ouch_tree
,
754 proto_tree_add_item(ouch_tree
,
760 proto_tree_add_item(ouch_tree
,
761 hf_ouch_buy_sell_indicator
,
766 proto_tree_add_item(ouch_tree
,
772 proto_tree_add_item(ouch_tree
,
778 proto_tree_add_item(ouch_tree
,
784 proto_tree_add_item(ouch_tree
,
790 proto_tree_add_item(ouch_tree
,
796 proto_tree_add_item(ouch_tree
,
802 proto_tree_add_item(ouch_tree
,
803 hf_ouch_order_reference_number
,
808 proto_tree_add_item(ouch_tree
,
814 proto_tree_add_item(ouch_tree
,
815 hf_ouch_iso_eligible
,
820 proto_tree_add_item(ouch_tree
,
821 hf_ouch_min_quantity
,
826 proto_tree_add_item(ouch_tree
,
832 proto_tree_add_item(ouch_tree
,
838 if (reported_len
== 66) { /* Added in 4.2 */
839 proto_tree_add_item(ouch_tree
,
840 hf_ouch_bbo_weight_indicator
,
847 case 'U': /* Replace Order */
848 proto_tree_add_item(ouch_tree
,
849 hf_ouch_existing_order_token
,
854 proto_tree_add_item(ouch_tree
,
855 hf_ouch_replacement_order_token
,
860 proto_tree_add_item(ouch_tree
,
866 proto_tree_add_item(ouch_tree
,
872 proto_tree_add_item(ouch_tree
,
878 proto_tree_add_item(ouch_tree
,
884 proto_tree_add_item(ouch_tree
,
885 hf_ouch_iso_eligible
,
890 proto_tree_add_item(ouch_tree
,
891 hf_ouch_min_quantity
,
897 case 'X': /* Cancel Order */
898 proto_tree_add_item(ouch_tree
,
904 proto_tree_add_item(ouch_tree
,
911 case 'M': /* Modify Order (from 4.2 onwards) */
912 proto_tree_add_item(ouch_tree
,
918 proto_tree_add_item(ouch_tree
,
919 hf_ouch_buy_sell_indicator
,
924 proto_tree_add_item(ouch_tree
,
931 case 'S': /* System Event */
932 ouch_tree_add_timestamp(ouch_tree
,
937 proto_tree_add_item(ouch_tree
,
944 case 'R': /* Replaced */
945 ouch_tree_add_timestamp(ouch_tree
,
950 proto_tree_add_item(ouch_tree
,
951 hf_ouch_replacement_order_token
,
956 proto_tree_add_item(ouch_tree
,
957 hf_ouch_buy_sell_indicator
,
962 proto_tree_add_item(ouch_tree
,
968 proto_tree_add_item(ouch_tree
,
974 proto_tree_add_item(ouch_tree
,
980 proto_tree_add_item(ouch_tree
,
986 proto_tree_add_item(ouch_tree
,
992 proto_tree_add_item(ouch_tree
,
998 proto_tree_add_item(ouch_tree
,
999 hf_ouch_order_reference_number
,
1004 proto_tree_add_item(ouch_tree
,
1010 proto_tree_add_item(ouch_tree
,
1011 hf_ouch_iso_eligible
,
1016 proto_tree_add_item(ouch_tree
,
1017 hf_ouch_min_quantity
,
1022 proto_tree_add_item(ouch_tree
,
1028 proto_tree_add_item(ouch_tree
,
1029 hf_ouch_order_state
,
1034 proto_tree_add_item(ouch_tree
,
1035 hf_ouch_previous_order_token
,
1040 if (reported_len
== 80) { /* Added in 4.2 */
1041 proto_tree_add_item(ouch_tree
,
1042 hf_ouch_bbo_weight_indicator
,
1049 case 'C': /* Canceled */
1050 ouch_tree_add_timestamp(ouch_tree
,
1055 proto_tree_add_item(ouch_tree
,
1056 hf_ouch_order_token
,
1061 proto_tree_add_item(ouch_tree
,
1062 hf_ouch_decrement_shares
,
1067 proto_tree_add_item(ouch_tree
,
1068 hf_ouch_cancel_reason
,
1074 case 'D': /* AIQ Canceled */
1075 ouch_tree_add_timestamp(ouch_tree
,
1080 proto_tree_add_item(ouch_tree
,
1081 hf_ouch_order_token
,
1086 proto_tree_add_item(ouch_tree
,
1087 hf_ouch_decrement_shares
,
1092 proto_tree_add_item(ouch_tree
,
1093 hf_ouch_cancel_reason
,
1098 proto_tree_add_item(ouch_tree
,
1099 hf_ouch_quantity_prevented_from_trading
,
1104 proto_tree_add_item(ouch_tree
,
1105 hf_ouch_execution_price
,
1110 proto_tree_add_item(ouch_tree
,
1111 hf_ouch_liquidity_flag
,
1117 case 'E': /* Executed */
1118 ouch_tree_add_timestamp(ouch_tree
,
1123 proto_tree_add_item(ouch_tree
,
1124 hf_ouch_order_token
,
1129 proto_tree_add_item(ouch_tree
,
1130 hf_ouch_executed_shares
,
1135 proto_tree_add_item(ouch_tree
,
1136 hf_ouch_execution_price
,
1141 proto_tree_add_item(ouch_tree
,
1142 hf_ouch_liquidity_flag
,
1147 proto_tree_add_item(ouch_tree
,
1148 hf_ouch_match_number
,
1154 case 'B': /* Broken Trade */
1155 ouch_tree_add_timestamp(ouch_tree
,
1160 proto_tree_add_item(ouch_tree
,
1161 hf_ouch_order_token
,
1166 proto_tree_add_item(ouch_tree
,
1167 hf_ouch_match_number
,
1172 proto_tree_add_item(ouch_tree
,
1173 hf_ouch_broken_trade_reason
,
1179 case 'K': /* Price Correction */
1180 ouch_tree_add_timestamp(ouch_tree
,
1185 proto_tree_add_item(ouch_tree
,
1186 hf_ouch_order_token
,
1191 proto_tree_add_item(ouch_tree
,
1192 hf_ouch_match_number
,
1197 proto_tree_add_item(ouch_tree
,
1198 hf_ouch_new_execution_price
,
1203 proto_tree_add_item(ouch_tree
,
1204 hf_ouch_price_correction_reason
,
1210 case 'J': /* Rejected Order */
1211 ouch_tree_add_timestamp(ouch_tree
,
1216 proto_tree_add_item(ouch_tree
,
1217 hf_ouch_order_token
,
1222 proto_tree_add_item(ouch_tree
,
1223 hf_ouch_reject_reason
,
1229 case 'P': /* Cancel Pending */
1230 ouch_tree_add_timestamp(ouch_tree
,
1235 proto_tree_add_item(ouch_tree
,
1236 hf_ouch_order_token
,
1242 case 'I': /* Cancel Reject */
1243 ouch_tree_add_timestamp(ouch_tree
,
1248 proto_tree_add_item(ouch_tree
,
1249 hf_ouch_order_token
,
1257 proto_tree_add_item(tree
,
1259 tvb
, offset
, -1, ENC_ASCII
|ENC_NA
);
1260 offset
+= reported_len
- 1;
1269 /* Register the protocol with Wireshark */
1274 dissector_delete_uint_range("tcp.port", ouch_range
, ouch_handle
);
1276 ouch_range
= range_copy(global_ouch_range
);
1277 dissector_add_uint_range("tcp.port", ouch_range
, ouch_handle
);
1281 /** Returns a guess if a packet is OUCH or not
1283 * Since SOUP doesn't have a sub-protocol type flag, we have to use a
1284 * heuristic decision to determine if the contained protocol is OUCH
1285 * or ITCH (or something else entirely). We look at the message type
1286 * code, and since we know that we're being called from SOUP, we can
1287 * check the passed-in length too: if the type code and the length
1288 * match, we guess at OUCH. */
1296 guint8 msg_type
= tvb_get_guint8(tvb
, 0);
1297 guint msg_len
= tvb_reported_length(tvb
);
1300 case 'O': /* Enter order (with or without optional customer type) */
1301 if (msg_len
!= 48 && msg_len
!= 49) {
1306 case 'U': /* Replace order or Replaced (4.0, 4.1) or Replaced (4.2) */
1307 if (msg_len
!= 47 && msg_len
!= 79 && msg_len
!= 80) {
1312 case 'X': /* Cancel order */
1313 if (msg_len
!= 19) {
1318 case 'S': /* System event */
1319 if (msg_len
!= 10) {
1324 case 'A': /* Accepted */
1325 if (msg_len
!= 65 && msg_len
!= 66) {
1330 case 'C': /* Canceled */
1331 if (msg_len
!= 28) {
1336 case 'D': /* AIQ Canceled */
1337 if (msg_len
!= 37) {
1341 case 'E': /* Executed */
1342 if (msg_len
!= 40) {
1347 case 'B': /* Broken Trade */
1348 if (msg_len
!= 32) {
1353 case 'K': /* Correction */
1354 if (msg_len
!= 36) {
1359 case 'J': /* Rejected */
1360 if (msg_len
!= 24) {
1365 case 'P': /* Cancel Pending */
1366 if (msg_len
!= 23) {
1371 case 'I': /* Cancel Reject */
1372 if (msg_len
!= 23) {
1378 /* Not a known OUCH message code */
1382 /* Peform dissection of this (initial) packet */
1383 dissect_ouch(tvb
, pinfo
, tree
, NULL
);
1390 proto_register_ouch(void)
1392 module_t
*ouch_module
;
1394 /* Setup list of header fields See Section 1.6.1 for details*/
1395 static hf_register_info hf
[] = {
1397 { &hf_ouch_bbo_weight_indicator
,
1398 { "BBO Weight Indicator", "ouch.bbo_weight_indicator",
1399 FT_UINT8
, BASE_CUSTOM
, format_bbo_weight_indicator
, 0x0,
1402 { &hf_ouch_broken_trade_reason
,
1403 { "Broken Trade Reason", "ouch.broken_trade_reason",
1404 FT_UINT8
, BASE_CUSTOM
, format_broken_trade_reason
, 0x0,
1407 { &hf_ouch_buy_sell_indicator
,
1408 { "Buy/Sell Indicator", "ouch.buy_sell_indicator",
1409 FT_UINT8
, BASE_CUSTOM
, format_buy_sell_indicator
, 0x0,
1412 { &hf_ouch_cancel_reason
,
1413 { "Cancel Reason", "ouch.cancel_reason",
1414 FT_UINT8
, BASE_CUSTOM
, format_cancel_reason
, 0x0,
1417 { &hf_ouch_capacity
,
1418 { "Capacity", "ouch.capacity",
1419 FT_UINT8
, BASE_CUSTOM
, format_capacity
, 0x0,
1422 { &hf_ouch_cross_type
,
1423 { "Cross Type", "ouch.cross_type",
1424 FT_UINT8
, BASE_CUSTOM
, format_cross_type
, 0x0,
1427 { &hf_ouch_customer_type
,
1428 { "Customer Type", "ouch.customer_type",
1429 FT_UINT8
, BASE_CUSTOM
, format_customer_type
, 0x0,
1432 { &hf_ouch_decrement_shares
,
1433 { "Decrement Shares", "ouch.decrement_shares",
1434 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1438 { "Display", "ouch.display",
1439 FT_UINT8
, BASE_CUSTOM
, format_display
, 0x0,
1442 { &hf_ouch_event_code
,
1443 { "Event Code", "ouch.event_code",
1444 FT_UINT8
, BASE_CUSTOM
, format_event_code
, 0x0,
1447 { &hf_ouch_executed_shares
,
1448 { "Executed Shares", "ouch.executed_shares",
1449 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1452 { &hf_ouch_execution_price
,
1453 { "Execution Price", "ouch.execution_price",
1454 FT_UINT32
, BASE_CUSTOM
, format_price
, 0x0,
1457 { &hf_ouch_existing_order_token
,
1458 { "Existing Order Token", "ouch.existing_order_token",
1459 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1463 { "Firm", "ouch.firm",
1464 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1467 { &hf_ouch_iso_eligible
,
1468 { "Intermarket Sweep Eligibility", "ouch.iso_eligible",
1469 FT_UINT8
, BASE_CUSTOM
, format_iso_eligibility
, 0x0,
1472 { &hf_ouch_liquidity_flag
,
1473 { "Liquidity Flag", "ouch.liquidity_flag",
1474 FT_UINT8
, BASE_CUSTOM
, format_liquidity_flag
, 0x0,
1477 { &hf_ouch_match_number
,
1478 { "Match Number", "ouch.match_number",
1479 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1483 { "Unknown Message", "ouch.unknown_message",
1484 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1487 { &hf_ouch_min_quantity
,
1488 { "Minimum Quantity", "ouch.min_quantity",
1489 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1492 { &hf_ouch_new_execution_price
,
1493 { "New Execution Price", "ouch.new_execution_price",
1494 FT_UINT32
, BASE_CUSTOM
, format_price
, 0x0,
1497 { &hf_ouch_order_reference_number
,
1498 { "Order Reference Number", "ouch.order_reference_number",
1499 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1502 { &hf_ouch_order_state
,
1503 { "Order State", "ouch.order_state",
1504 FT_UINT8
, BASE_CUSTOM
, format_order_state
, 0x0,
1507 { &hf_ouch_order_token
,
1508 { "Order Token", "ouch.order_token",
1509 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1512 { &hf_ouch_packet_type
,
1513 { "Packet Type", "ouch.packet_type",
1514 FT_UINT8
, BASE_CUSTOM
, format_packet_type
, 0x0,
1517 { &hf_ouch_previous_order_token
,
1518 { "Previous Order Token", "ouch.previous_order_token",
1519 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1523 { "Price", "ouch.price",
1524 FT_UINT32
, BASE_CUSTOM
, format_price
, 0x0,
1527 { &hf_ouch_price_correction_reason
,
1528 { "Price Correction Reason", "ouch.price_correction_reason",
1529 FT_UINT8
, BASE_CUSTOM
, format_price_correction_reason
, 0x0,
1532 { &hf_ouch_quantity_prevented_from_trading
,
1533 { "Quanity Prevented from Trading",
1534 "ouch.quantity_prevented_from_trading",
1535 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1538 { &hf_ouch_reject_reason
,
1539 { "Reject Reason", "ouch.reject_reason",
1540 FT_UINT8
, BASE_CUSTOM
, format_reject_reason
, 0x0,
1543 { &hf_ouch_replacement_order_token
,
1544 { "Replacement Order Token", "ouch.replacement_order_token",
1545 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1549 { "Shares", "ouch.shares",
1550 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1554 { "Stock", "ouch.stock",
1555 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1559 { "Time In Force", "ouch.tif",
1560 FT_UINT32
, BASE_CUSTOM
, format_tif
, 0x0,
1563 { &hf_ouch_timestamp
,
1564 { "Timestamp", "ouch.timestamp",
1565 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1569 /* Setup protocol subtree array */
1570 static gint
*ett
[] = {
1574 /* Register the protocol name and description */
1575 proto_ouch
= proto_register_protocol("OUCH", "OUCH", "ouch");
1577 /* Required function calls to register the header fields and
1579 proto_register_field_array(proto_ouch
, hf
, array_length(hf
));
1580 proto_register_subtree_array(ett
, array_length(ett
));
1582 ouch_module
= prefs_register_protocol(proto_ouch
, ouch_prefs
);
1584 prefs_register_range_preference(ouch_module
,
1590 ouch_range
= range_empty();
1594 /* If this dissector uses sub-dissector registration add a
1595 * registration routine. This format is required because a script is
1596 * used to find these routines and create the code that calls these
1599 proto_reg_handoff_ouch(void)
1601 ouch_handle
= new_create_dissector_handle(dissect_ouch
, proto_ouch
);
1602 heur_dissector_add("soupbintcp", dissect_ouch_heur
, proto_ouch
);
1608 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1613 * indent-tabs-mode: nil
1616 * vi: set shiftwidth=4 tabstop=8 expandtab:
1617 * :indentSize=4:tabSize=8:noTabs=true: