2 * Routines for OUCH 4.x protocol dissection
3 * Copyright (C) 2013, 2015, 2016 David Arnold <d@0x1.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 /* OUCH is a stock exchange order entry protocol published and used by
13 * NASDAQ. This dissector supports versions 4.x, which differ from
14 * earlier versions by adopting binary encoding for numeric values.
16 * OUCH is usually encapsulated within NASDAQ's SoupBinTCP protocol,
17 * running over a TCP connection from the trading application to the
18 * exchange. SOUP provides framing, heartbeats and authentication;
19 * consequently none of these is present in OUCH.
21 * Other exchanges have created order entry protocols very similar to
22 * OUCH, but typically they differ in subtle ways (and continue to
23 * diverge as time progresses) so I have not attempted to dissect
24 * anything other than proper NASDAQ OUCH in this code.
26 * Specifications are available from NASDAQ's website, although the
27 * links to find them tend to move around over time. At the time of
28 * writing, the correct URL is:
30 * http://www.nasdaqtrader.com/content/technicalsupport/specifications/TradingProducts/OUCH4.2.pdf
36 #include <epan/packet.h>
38 void proto_register_ouch(void);
39 void proto_reg_handoff_ouch(void);
41 static const value_string pkt_type_val[] = {
42 { 'O', "Enter Order" },
43 { 'U', "Replace Order" },
44 { 'X', "Cancel Order" },
45 { 'M', "Modify Order" },
46 { 'S', "System Event" },
48 { 'R', "Replaced" }, /* 'U' on the wire, but use 'R' to disambiguate */
50 { 'D', "AIQ Canceled" },
52 { 'F', "Trade Correction" },
53 { 'G', "Executed with Reference Price" },
54 { 'B', "Broken Trade" },
55 { 'K', "Price Correction" },
57 { 'P', "Cancel Pending" },
58 { 'I', "Cancel Reject" },
59 { 'T', "Order Priority Update" },
60 { 'm', "Order Modified" }, /* 'M' on the wire; 'm' to disambiguate */
65 static const value_string ouch_bbo_weight_indicator_val[] = {
69 { '3', "Greater than 2%" },
70 { ' ', "Unspecified" },
71 { 'S', "Sets the QBBO while joining the NBBO" },
72 { 'N', "Improves the NBBO upon entry" },
76 static const value_string ouch_broken_trade_reason_val[] = {
79 { 'S', "Supervisory" },
84 static const value_string ouch_buy_sell_indicator_val[] = {
86 { 'S', "Sell Order" },
87 { 'T', "Sell Short" },
88 { 'E', "Sell Short Exempt" },
92 static const value_string ouch_cancel_reason_val[] = {
93 { 'C', "Cross cancel" },
94 { 'D', "Regulatory restriction" },
97 { 'I', "Immediate or Cancel order" },
98 { 'K', "Market Collars" },
99 { 'Q', "Self-match prevention" },
100 { 'S', "Supervisory" },
102 { 'U', "User requested cancel" },
103 { 'X', "Open Protection" },
104 { 'Z', "System cancel" },
108 static const value_string ouch_capacity_val[] = {
111 { 'P', "Principal" },
116 static const value_string ouch_cross_type_val[] = {
118 { 'O', "Opening Cross" },
119 { 'C', "Closing Cross" },
120 { 'I', "Intra-day Cross" }, /* Seems to have been removed */
121 { 'H', "Halt/IPO Cross" },
122 { 'R', "Retail" }, /* Not in 4.0 */
123 { 'S', "Supplemental Order" },
128 static const value_string ouch_customer_type_val[] = {
129 { 'R', "Retail designated order" },
130 { 'N', "Not a retail designated order" },
131 { ' ', "Default configured for port" },
135 static const value_string ouch_display_val[] = {
136 { 'A', "Attributable-Price to Display" },
137 { 'I', "Imbalance-Only" },
138 { 'L', "Post-Only and Attributable - Price to Display" },
139 { 'M', "Mid-Point Peg" },
140 { 'N', "Non-Display" },
141 { 'O', "Retail Order Type 1" }, /* Not in 4.0 */
142 { 'P', "Post-Only" },
143 { 'Q', "Retail Price Improvement Order" }, /* Not in 4.0 */
144 { 'R', "Round-Lot Only" }, /* Seems to have been removed? */
145 { 'T', "Retail Order Type 2" }, /* Not in 4.0 */
146 { 'W', "Mid-point Peg Post Only" },
147 { 'Y', "Anonymous-Price to Comply" },
148 { 'Z', "Entered as displayed bu changed to non-displayed "
149 "(Priced to comply)" }, /* New in 4.2 */
153 static const value_string ouch_event_code_val[] = {
154 { 'S', "Start of Day" },
155 { 'E', "End of Day" },
159 static const value_string ouch_iso_eligibility_val[] = {
161 { 'N', "Not eligible" },
165 static const value_string ouch_liquidity_flag_val[] = {
166 { '0', "Supplemental Order Execution" },
167 { '4', "Added displayed liquidity in a Group A Symbol" },
168 { '5', "Added non-displayed liquidity in a Group A Symbol" },
169 { '6', "Removed liquidity in a Group A Symbol" },
170 { '7', "Displayed, liquidity-adding order improves the NBBO" },
171 { '8', "Displayed, liquidity-adding order sets the QBBO while joining the NBBO" },
173 { 'C', "Closing Cross" },
174 { 'H', "Halt/IPO Cross" },
175 { 'I', "Intraday/Post-Market Cross" }, /* Seems to have been removed */
176 { 'J', "Non-displayed adding liquidity" },
177 { 'K', "Halt Cross" },
178 { 'L', "Closing Cross (imbalance-only)" },
179 { 'M', "Opening Cross (imbalance-only)" },
180 { 'N', "Halt Cross, orders entered in pilot symbols during the LULD Trading Pause" },
181 { 'O', "Opening Cross" },
183 { 'W', "Added post-only" }, /* Removed 4.2 2013/02/05 */
184 { 'a', "Added displayed liquidity in a SCIP Symbol" },
185 { 'b', "Displayed, liquidity-adding order improves the NBBO in pilot symbol during specified LULD Pricing Pilot timeframe" },
186 { 'c', "Added displayed liquidity in a pilot symbol during specified LULD Pricing Pilot timeframe" },
187 { 'd', "Retail designated execution that removed liquidity" },
188 { 'e', "Retail designated execution that added displayed liquidity" },
189 { 'f', "Retail designated execution that added non-displayed liquidity" },
190 { 'g', "Added non-displayed mid-point liquidity in a Group A Symbol" },
191 { 'h', "Removed liquidity in a pilot symbol during specified LULD Pricing Pilot timeframe" },
192 { 'j', "RPI (Retail Price Improving) order provides liquidity" },
193 { 'k', "Added liquidity via a midpoint order" },
194 { 'm', "Removed liquidity at a midpoint" },
195 { 'r', "Retail Order removes RPI liquidity" },
196 { 't', "Retail Order removes price improving non-displayed liquidity other than RPI liquidity" },
197 { 'x', "Displayed, liquidity-adding order improves the NBBO in a SCIP Symbol" },
198 { 'y', "Displayed, liquidity-adding order set the QBBO while joining the NBBO in a SCIP Symbol" },
202 static const value_string ouch_order_state_val[] = {
203 { 'L', "Order Live" },
204 { 'D', "Order Dead" },
208 static const value_string ouch_price_correction_reason_val[] = {
209 { 'E', "Erroneous" },
211 { 'S', "Supervisory" },
216 static const value_string ouch_reference_price_type_val[] = {
217 { 'I', "Intraday Indicative Value" },
221 static const value_string ouch_reject_reason_val[] = {
222 { 'T', "Test Mode" },
224 { 'Z', "Shares exceeds configured safety threshold" },
225 { 'S', "Invalid Stock" },
226 { 'D', "Invalid Display Type" },
227 { 'C', "NASDAQ is Closed" },
228 { 'L', "Requested firm not authorized for requested clearing "
229 "type on this account" },
230 { 'M', "Outside of permitted times for requested clearing type" },
231 { 'R', "This order is not allowed in this type of cross" },
232 { 'X', "Invalid Price" },
233 { 'N', "Invalid Minimum Quantity" },
235 { 'W', "Invalid Mid-point Post Only Price" },
236 { 'a', "Reject All enabled" },
237 { 'b', "Easy to Borrow (ETB) reject" },
238 { 'c', "Restricted symbol list reject" },
239 { 'd', "ISO order restriction" },
240 { 'e', "Odd lot order restriction" },
241 { 'f', "Mid-Point order restriction" },
242 { 'g', "Pre-market order restriction" },
243 { 'h', "Post-market order restriction" },
244 { 'i', "Short sale order restriction" },
245 { 'j', "On Open order restriction" },
246 { 'k', "On Close order restriction" },
247 { 'l', "Two sided quote reject" },
248 { 'm', "Exceeded shares limit" },
249 { 'n', "Exceeded dollar value limit" },
253 static const value_string ouch_trade_correction_reason_val[] = {
254 { 'N', "Adjusted to NAV" },
259 /* Initialize the protocol and registered fields */
260 static int proto_ouch = -1;
261 static dissector_handle_t ouch_handle;
263 /* Initialize the subtree pointers */
264 static gint ett_ouch = -1;
266 static int hf_ouch_bbo_weight_indicator = -1;
267 static int hf_ouch_broken_trade_reason = -1;
268 static int hf_ouch_buy_sell_indicator = -1;
269 static int hf_ouch_cancel_reason = -1;
270 static int hf_ouch_capacity = -1;
271 static int hf_ouch_cross_type = -1;
272 static int hf_ouch_customer_type = -1;
273 static int hf_ouch_decrement_shares = -1;
274 static int hf_ouch_display = -1;
275 static int hf_ouch_event_code = -1;
276 static int hf_ouch_executed_shares = -1;
277 static int hf_ouch_execution_price = -1;
278 static int hf_ouch_existing_order_token = -1;
279 static int hf_ouch_firm = -1;
280 static int hf_ouch_iso_eligible = -1;
281 static int hf_ouch_liquidity_flag = -1;
282 static int hf_ouch_match_number = -1;
283 static int hf_ouch_message = -1;
284 static int hf_ouch_min_quantity = -1;
285 static int hf_ouch_new_execution_price = -1;
286 static int hf_ouch_order_reference_number = -1;
287 static int hf_ouch_order_state = -1;
288 static int hf_ouch_order_token = -1;
289 static int hf_ouch_packet_type = -1;
290 static int hf_ouch_previous_order_token = -1;
291 static int hf_ouch_price = -1;
292 static int hf_ouch_price_correction_reason = -1;
293 static int hf_ouch_quantity_prevented_from_trading = -1;
294 static int hf_ouch_reference_price = -1;
295 static int hf_ouch_reference_price_type = -1;
296 static int hf_ouch_reject_reason = -1;
297 static int hf_ouch_replacement_order_token = -1;
298 static int hf_ouch_shares = -1;
299 static int hf_ouch_stock = -1;
300 static int hf_ouch_tif = -1;
301 static int hf_ouch_timestamp = -1;
302 static int hf_ouch_trade_correction_reason = -1;
305 /** Format an OUCH timestamp into a useful string
307 * We use this function rather than a BASE_CUSTOM formatter because
308 * BASE_CUSTOM doesn't support passing a 64-bit value to the
309 * formatting function. */
311 ouch_tree_add_timestamp(
317 guint64 ts = tvb_get_ntoh64(tvb, offset);
318 char *buf = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH);
319 guint32 tmp, hours, mins, secs, nsecs;
321 nsecs = (guint32)(ts % G_GUINT64_CONSTANT(1000000000));
322 tmp = (guint32)(ts / G_GUINT64_CONSTANT(1000000000));
325 mins = (tmp % 3600) / 60;
328 g_snprintf(buf, ITEM_LABEL_LENGTH,
330 hours, mins, secs, nsecs);
332 proto_tree_add_string(tree, hf, tvb, offset, 8, buf);
335 /** BASE_CUSTOM formatter for prices
337 * OUCH prices are integers, with four implicit decimal places. So we
338 * insert the decimal point, and add a leading dollar sign as well. */
344 if (value == 0x7fffffff) {
345 g_snprintf(buf, ITEM_LABEL_LENGTH, "%s", "Market");
347 g_snprintf(buf, ITEM_LABEL_LENGTH,
349 value / 10000, value % 10000);
353 /** BASE_CUSTOM formatter for reference price type code
355 * Displays the code value as a character, not its ASCII value, as
356 * would be done by BASE_DEC and friends. */
358 format_reference_price_type(
362 g_snprintf(buf, ITEM_LABEL_LENGTH,
364 val_to_str_const(value,
365 ouch_reference_price_type_val,
370 /** BASE_CUSTOM formatter for the Time In Force (TIF) code
372 * There are three reserved values for the TIF: 0, 99998 and 99999.
373 * These are trapped and displayed as an appropriate string. All
374 * other values are printed as a duration in hours, minutes and
387 g_snprintf(buf, ITEM_LABEL_LENGTH, "Immediate Or Cancel (%u)", value);
391 g_snprintf(buf, ITEM_LABEL_LENGTH, "Market Hours (%u)", value);
395 g_snprintf(buf, ITEM_LABEL_LENGTH, "System Hours (%u)", value);
399 hours = value / 3600;
400 mins = (value % 3600) / 60;
403 g_snprintf(buf, ITEM_LABEL_LENGTH,
404 "%uh %02um %02us (%u seconds)",
420 proto_tree *ouch_tree = NULL;
421 const char *pkt_name;
422 guint16 reported_len;
426 /* Get the OUCH message type value */
427 pkt_type = tvb_get_guint8(tvb, offset);
428 reported_len = tvb_reported_length(tvb);
430 /* OUCH has two messages with the same code: Replace Order and
431 * Replaced. It's possible to tell which is which because clients
432 * send the Replace Order, and NASDAQ sends Replaced replies.
433 * Nonetheless, this complicates the switch, so instead we
434 * distinguish between them by length, and use 'R' for Replaced
435 * (like XPRS does). */
436 if (pkt_type == 'U' && (reported_len == 79 || reported_len == 80)) {
440 /* OUCH has two messages with the same code: Modify Order and
441 * Modified. Again, one is sent by clients, the other sent by
442 * NASDAQ. We change Modified to 'm' for simplicity in the
444 if (pkt_type == 'M' && reported_len == 28) {
448 /* Since we use the packet name a few times, get and save that value */
449 pkt_name = val_to_str(pkt_type, pkt_type_val, "Unknown (%u)");
451 /* Set the protocol name in the summary display */
452 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OUCH");
454 /* Set the packet name in the info column */
455 col_add_str(pinfo->cinfo, COL_INFO, pkt_name);
458 /* Create a sub-tree for the OUCH packet details */
459 ti = proto_tree_add_item(tree,
463 ouch_tree = proto_item_add_subtree(ti, ett_ouch);
465 /* Append the packet name to the sub-tree item */
466 proto_item_append_text(ti, ", %s", pkt_name);
468 /* Packet type (using the cooked value). */
469 proto_tree_add_item(ouch_tree, hf_ouch_packet_type,
470 tvb, offset, 1, ENC_ASCII|ENC_NA);
474 case 'O': /* Enter Order */
475 proto_tree_add_item(ouch_tree,
481 proto_tree_add_item(ouch_tree,
482 hf_ouch_buy_sell_indicator,
487 proto_tree_add_item(ouch_tree,
493 proto_tree_add_item(ouch_tree,
499 proto_tree_add_item(ouch_tree,
505 proto_tree_add_item(ouch_tree,
511 proto_tree_add_item(ouch_tree,
517 proto_tree_add_item(ouch_tree,
523 proto_tree_add_item(ouch_tree,
529 proto_tree_add_item(ouch_tree,
530 hf_ouch_iso_eligible,
535 proto_tree_add_item(ouch_tree,
536 hf_ouch_min_quantity,
541 proto_tree_add_item(ouch_tree,
547 if (reported_len >= 49) { /* Added in 4.1 */
548 proto_tree_add_item(ouch_tree,
549 hf_ouch_customer_type,
556 case 'A': /* Accepted */
557 ouch_tree_add_timestamp(ouch_tree,
562 proto_tree_add_item(ouch_tree,
568 proto_tree_add_item(ouch_tree,
569 hf_ouch_buy_sell_indicator,
574 proto_tree_add_item(ouch_tree,
580 proto_tree_add_item(ouch_tree,
586 proto_tree_add_item(ouch_tree,
592 proto_tree_add_item(ouch_tree,
598 proto_tree_add_item(ouch_tree,
604 proto_tree_add_item(ouch_tree,
610 proto_tree_add_item(ouch_tree,
611 hf_ouch_order_reference_number,
616 proto_tree_add_item(ouch_tree,
622 proto_tree_add_item(ouch_tree,
623 hf_ouch_iso_eligible,
628 proto_tree_add_item(ouch_tree,
629 hf_ouch_min_quantity,
634 proto_tree_add_item(ouch_tree,
640 proto_tree_add_item(ouch_tree,
646 if (reported_len >= 66) { /* Added in 4.2 */
647 proto_tree_add_item(ouch_tree,
648 hf_ouch_bbo_weight_indicator,
655 case 'U': /* Replace Order */
656 proto_tree_add_item(ouch_tree,
657 hf_ouch_existing_order_token,
662 proto_tree_add_item(ouch_tree,
663 hf_ouch_replacement_order_token,
668 proto_tree_add_item(ouch_tree,
674 proto_tree_add_item(ouch_tree,
680 proto_tree_add_item(ouch_tree,
686 proto_tree_add_item(ouch_tree,
692 proto_tree_add_item(ouch_tree,
693 hf_ouch_iso_eligible,
698 proto_tree_add_item(ouch_tree,
699 hf_ouch_min_quantity,
705 case 'X': /* Cancel Order */
706 proto_tree_add_item(ouch_tree,
712 proto_tree_add_item(ouch_tree,
719 case 'M': /* Modify Order (from 4.2 onwards) */
720 proto_tree_add_item(ouch_tree,
726 proto_tree_add_item(ouch_tree,
727 hf_ouch_buy_sell_indicator,
732 proto_tree_add_item(ouch_tree,
739 case 'S': /* System Event */
740 ouch_tree_add_timestamp(ouch_tree,
745 proto_tree_add_item(ouch_tree,
752 case 'R': /* Replaced */
753 ouch_tree_add_timestamp(ouch_tree,
758 proto_tree_add_item(ouch_tree,
759 hf_ouch_replacement_order_token,
764 proto_tree_add_item(ouch_tree,
765 hf_ouch_buy_sell_indicator,
770 proto_tree_add_item(ouch_tree,
776 proto_tree_add_item(ouch_tree,
782 proto_tree_add_item(ouch_tree,
788 proto_tree_add_item(ouch_tree,
794 proto_tree_add_item(ouch_tree,
800 proto_tree_add_item(ouch_tree,
806 proto_tree_add_item(ouch_tree,
807 hf_ouch_order_reference_number,
812 proto_tree_add_item(ouch_tree,
818 proto_tree_add_item(ouch_tree,
819 hf_ouch_iso_eligible,
824 proto_tree_add_item(ouch_tree,
825 hf_ouch_min_quantity,
830 proto_tree_add_item(ouch_tree,
836 proto_tree_add_item(ouch_tree,
842 proto_tree_add_item(ouch_tree,
843 hf_ouch_previous_order_token,
848 if (reported_len >= 80) { /* Added in 4.2 */
849 proto_tree_add_item(ouch_tree,
850 hf_ouch_bbo_weight_indicator,
857 case 'C': /* Canceled */
858 ouch_tree_add_timestamp(ouch_tree,
863 proto_tree_add_item(ouch_tree,
869 proto_tree_add_item(ouch_tree,
870 hf_ouch_decrement_shares,
875 proto_tree_add_item(ouch_tree,
876 hf_ouch_cancel_reason,
882 case 'D': /* AIQ Canceled */
883 ouch_tree_add_timestamp(ouch_tree,
888 proto_tree_add_item(ouch_tree,
894 proto_tree_add_item(ouch_tree,
895 hf_ouch_decrement_shares,
900 proto_tree_add_item(ouch_tree,
901 hf_ouch_cancel_reason,
906 proto_tree_add_item(ouch_tree,
907 hf_ouch_quantity_prevented_from_trading,
912 proto_tree_add_item(ouch_tree,
913 hf_ouch_execution_price,
918 proto_tree_add_item(ouch_tree,
919 hf_ouch_liquidity_flag,
925 case 'E': /* Executed */
926 ouch_tree_add_timestamp(ouch_tree,
931 proto_tree_add_item(ouch_tree,
937 proto_tree_add_item(ouch_tree,
938 hf_ouch_executed_shares,
943 proto_tree_add_item(ouch_tree,
944 hf_ouch_execution_price,
949 proto_tree_add_item(ouch_tree,
950 hf_ouch_liquidity_flag,
955 proto_tree_add_item(ouch_tree,
956 hf_ouch_match_number,
962 case 'B': /* Broken Trade */
963 ouch_tree_add_timestamp(ouch_tree,
968 proto_tree_add_item(ouch_tree,
974 proto_tree_add_item(ouch_tree,
975 hf_ouch_match_number,
980 proto_tree_add_item(ouch_tree,
981 hf_ouch_broken_trade_reason,
987 case 'F': /* Trade Correction (4.2 onwards) */
988 ouch_tree_add_timestamp(ouch_tree,
993 proto_tree_add_item(ouch_tree,
999 proto_tree_add_item(ouch_tree,
1000 hf_ouch_executed_shares,
1005 proto_tree_add_item(ouch_tree,
1006 hf_ouch_execution_price,
1011 proto_tree_add_item(ouch_tree,
1012 hf_ouch_liquidity_flag,
1017 proto_tree_add_item(ouch_tree,
1018 hf_ouch_match_number,
1023 proto_tree_add_item(ouch_tree,
1024 hf_ouch_trade_correction_reason,
1030 case 'G': /* Executed with Reference Price (4.2 onwards) */
1031 ouch_tree_add_timestamp(ouch_tree,
1036 proto_tree_add_item(ouch_tree,
1037 hf_ouch_order_token,
1042 proto_tree_add_item(ouch_tree,
1043 hf_ouch_executed_shares,
1048 proto_tree_add_item(ouch_tree,
1049 hf_ouch_execution_price,
1054 proto_tree_add_item(ouch_tree,
1055 hf_ouch_liquidity_flag,
1060 proto_tree_add_item(ouch_tree,
1061 hf_ouch_match_number,
1066 proto_tree_add_item(ouch_tree,
1067 hf_ouch_reference_price,
1072 proto_tree_add_item(ouch_tree,
1073 hf_ouch_reference_price_type,
1079 case 'K': /* Price Correction */
1080 ouch_tree_add_timestamp(ouch_tree,
1085 proto_tree_add_item(ouch_tree,
1086 hf_ouch_order_token,
1091 proto_tree_add_item(ouch_tree,
1092 hf_ouch_match_number,
1097 proto_tree_add_item(ouch_tree,
1098 hf_ouch_new_execution_price,
1103 proto_tree_add_item(ouch_tree,
1104 hf_ouch_price_correction_reason,
1110 case 'J': /* Rejected Order */
1111 ouch_tree_add_timestamp(ouch_tree,
1116 proto_tree_add_item(ouch_tree,
1117 hf_ouch_order_token,
1122 proto_tree_add_item(ouch_tree,
1123 hf_ouch_reject_reason,
1129 case 'P': /* Cancel Pending */
1130 ouch_tree_add_timestamp(ouch_tree,
1135 proto_tree_add_item(ouch_tree,
1136 hf_ouch_order_token,
1142 case 'I': /* Cancel Reject */
1143 ouch_tree_add_timestamp(ouch_tree,
1148 proto_tree_add_item(ouch_tree,
1149 hf_ouch_order_token,
1155 case 'T': /* Order Priority Update (4.2 onwards) */
1156 ouch_tree_add_timestamp(ouch_tree,
1161 proto_tree_add_item(ouch_tree,
1162 hf_ouch_order_token,
1167 proto_tree_add_item(ouch_tree,
1173 proto_tree_add_item(ouch_tree,
1179 proto_tree_add_item(ouch_tree,
1180 hf_ouch_order_reference_number,
1186 case 'm': /* Order Modified (4.2 onwards) */
1187 ouch_tree_add_timestamp(ouch_tree,
1192 proto_tree_add_item(ouch_tree,
1193 hf_ouch_order_token,
1198 proto_tree_add_item(ouch_tree,
1199 hf_ouch_buy_sell_indicator,
1204 proto_tree_add_item(ouch_tree,
1213 proto_tree_add_item(tree,
1215 tvb, offset, -1, ENC_NA);
1216 offset += reported_len - 1;
1224 /** Returns a guess if a packet is OUCH or not
1226 * Since SOUP doesn't have a sub-protocol type flag, we have to use a
1227 * heuristic decision to determine if the contained protocol is OUCH
1228 * or ITCH (or something else entirely). We look at the message type
1229 * code, and since we know that we're being called from SOUP, we can
1230 * check the passed-in length too: if the type code and the length
1231 * match, we guess at OUCH. */
1239 guint8 msg_type = tvb_get_guint8(tvb, 0);
1240 guint msg_len = tvb_reported_length(tvb);
1243 case 'O': /* Enter order (with or without optional customer type) */
1244 if (msg_len != 48 && msg_len != 49) {
1249 case 'U': /* Replace order or Replaced (4.0, 4.1) or Replaced (4.2) */
1250 if (msg_len != 47 && msg_len != 79 && msg_len != 80) {
1255 case 'X': /* Cancel order */
1256 if (msg_len != 19) {
1261 case 'M': /* Modify Order or Order Modified (added 4.2) */
1262 if (msg_len != 20 && msg_len != 28) {
1267 case 'S': /* System event */
1268 if (msg_len != 10) {
1273 case 'A': /* Accepted */
1274 if (msg_len != 65 && msg_len != 66) {
1279 case 'C': /* Canceled */
1280 if (msg_len != 28) {
1285 case 'D': /* AIQ Canceled */
1286 if (msg_len != 37) {
1290 case 'E': /* Executed */
1291 if (msg_len != 40) {
1296 case 'F': /* Trade Correction */
1297 if (msg_len != 41) {
1302 case 'G': /* Executed with Reference Price */
1303 if (msg_len != 45) {
1308 case 'B': /* Broken Trade */
1309 if (msg_len != 32) {
1314 case 'K': /* Correction */
1315 if (msg_len != 36) {
1320 case 'J': /* Rejected */
1321 if (msg_len != 24) {
1326 case 'P': /* Cancel Pending */
1327 if (msg_len != 23) {
1332 case 'I': /* Cancel Reject */
1333 if (msg_len != 23) {
1338 case 'T': /* Order Priority Update */
1339 if (msg_len != 36) {
1345 /* Not a known OUCH message code */
1349 /* Perform dissection of this (initial) packet */
1350 dissect_ouch(tvb, pinfo, tree, NULL);
1357 proto_register_ouch(void)
1359 /* Setup list of header fields See Section 1.6.1 for details*/
1360 static hf_register_info hf[] = {
1362 { &hf_ouch_bbo_weight_indicator,
1363 { "BBO Weight Indicator", "ouch.bbo_weight_indicator",
1364 FT_CHAR, BASE_HEX, VALS(ouch_bbo_weight_indicator_val), 0x0,
1367 { &hf_ouch_broken_trade_reason,
1368 { "Broken Trade Reason", "ouch.broken_trade_reason",
1369 FT_CHAR, BASE_HEX, VALS(ouch_broken_trade_reason_val), 0x0,
1372 { &hf_ouch_buy_sell_indicator,
1373 { "Buy/Sell Indicator", "ouch.buy_sell_indicator",
1374 FT_CHAR, BASE_HEX, VALS(ouch_buy_sell_indicator_val), 0x0,
1377 { &hf_ouch_cancel_reason,
1378 { "Cancel Reason", "ouch.cancel_reason",
1379 FT_CHAR, BASE_HEX, VALS(ouch_cancel_reason_val), 0x0,
1382 { &hf_ouch_capacity,
1383 { "Capacity", "ouch.capacity",
1384 FT_CHAR, BASE_HEX, VALS(ouch_capacity_val), 0x0,
1387 { &hf_ouch_cross_type,
1388 { "Cross Type", "ouch.cross_type",
1389 FT_CHAR, BASE_HEX, VALS(ouch_cross_type_val), 0x0,
1392 { &hf_ouch_customer_type,
1393 { "Customer Type", "ouch.customer_type",
1394 FT_CHAR, BASE_HEX, VALS(ouch_customer_type_val), 0x0,
1397 { &hf_ouch_decrement_shares,
1398 { "Decrement Shares", "ouch.decrement_shares",
1399 FT_UINT32, BASE_DEC, NULL, 0x0,
1403 { "Display", "ouch.display",
1404 FT_CHAR, BASE_HEX, VALS(ouch_display_val), 0x0,
1407 { &hf_ouch_event_code,
1408 { "Event Code", "ouch.event_code",
1409 FT_CHAR, BASE_HEX, VALS(ouch_event_code_val), 0x0,
1412 { &hf_ouch_executed_shares,
1413 { "Executed Shares", "ouch.executed_shares",
1414 FT_UINT32, BASE_DEC, NULL, 0x0,
1417 { &hf_ouch_execution_price,
1418 { "Execution Price", "ouch.execution_price",
1419 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_price), 0x0,
1422 { &hf_ouch_existing_order_token,
1423 { "Existing Order Token", "ouch.existing_order_token",
1424 FT_STRING, BASE_NONE, NULL, 0x0,
1428 { "Firm", "ouch.firm",
1429 FT_STRING, BASE_NONE, NULL, 0x0,
1432 { &hf_ouch_iso_eligible,
1433 { "Intermarket Sweep Eligibility", "ouch.iso_eligible",
1434 FT_CHAR, BASE_HEX, VALS(ouch_iso_eligibility_val), 0x0,
1437 { &hf_ouch_liquidity_flag,
1438 { "Liquidity Flag", "ouch.liquidity_flag",
1439 FT_CHAR, BASE_HEX, VALS(ouch_liquidity_flag_val), 0x0,
1442 { &hf_ouch_match_number,
1443 { "Match Number", "ouch.match_number",
1444 FT_UINT64, BASE_DEC, NULL, 0x0,
1448 { "Unknown Message", "ouch.unknown_message",
1449 FT_BYTES, BASE_NONE, NULL, 0x0,
1452 { &hf_ouch_min_quantity,
1453 { "Minimum Quantity", "ouch.min_quantity",
1454 FT_UINT32, BASE_DEC, NULL, 0x0,
1457 { &hf_ouch_new_execution_price,
1458 { "New Execution Price", "ouch.new_execution_price",
1459 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_price), 0x0,
1462 { &hf_ouch_order_reference_number,
1463 { "Order Reference Number", "ouch.order_reference_number",
1464 FT_UINT64, BASE_DEC, NULL, 0x0,
1467 { &hf_ouch_order_state,
1468 { "Order State", "ouch.order_state",
1469 FT_CHAR, BASE_HEX, VALS(ouch_order_state_val), 0x0,
1472 { &hf_ouch_order_token,
1473 { "Order Token", "ouch.order_token",
1474 FT_STRING, BASE_NONE, NULL, 0x0,
1477 { &hf_ouch_packet_type,
1478 { "Packet Type", "ouch.packet_type",
1479 FT_CHAR, BASE_HEX, VALS(pkt_type_val), 0x0,
1482 { &hf_ouch_previous_order_token,
1483 { "Previous Order Token", "ouch.previous_order_token",
1484 FT_STRING, BASE_NONE, NULL, 0x0,
1488 { "Price", "ouch.price",
1489 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_price), 0x0,
1492 { &hf_ouch_price_correction_reason,
1493 { "Price Correction Reason", "ouch.price_correction_reason",
1494 FT_CHAR, BASE_HEX, VALS(ouch_price_correction_reason_val), 0x0,
1497 { &hf_ouch_quantity_prevented_from_trading,
1498 { "Quantity Prevented from Trading",
1499 "ouch.quantity_prevented_from_trading",
1500 FT_UINT32, BASE_DEC, NULL, 0x0,
1503 { &hf_ouch_reference_price,
1504 { "Reference Price", "ouch.reference_price",
1505 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_price), 0x0,
1508 { &hf_ouch_reference_price_type,
1509 { "Reference Price Type", "ouch.reference_price_type",
1510 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_reference_price_type), 0x0,
1513 { &hf_ouch_reject_reason,
1514 { "Reject Reason", "ouch.reject_reason",
1515 FT_CHAR, BASE_HEX, VALS(ouch_reject_reason_val), 0x0,
1518 { &hf_ouch_replacement_order_token,
1519 { "Replacement Order Token", "ouch.replacement_order_token",
1520 FT_STRING, BASE_NONE, NULL, 0x0,
1524 { "Shares", "ouch.shares",
1525 FT_UINT32, BASE_DEC, NULL, 0x0,
1529 { "Stock", "ouch.stock",
1530 FT_STRING, BASE_NONE, NULL, 0x0,
1534 { "Time In Force", "ouch.tif",
1535 FT_UINT32, BASE_CUSTOM, CF_FUNC(format_tif), 0x0,
1538 { &hf_ouch_timestamp,
1539 { "Timestamp", "ouch.timestamp",
1540 FT_STRING, BASE_NONE, NULL, 0x0,
1543 { &hf_ouch_trade_correction_reason,
1544 { "Trade Correction Reason", "ouch.trade_correction_reason",
1545 FT_CHAR, BASE_HEX, VALS(ouch_trade_correction_reason_val), 0x0,
1549 /* Setup protocol subtree array */
1550 static gint *ett[] = {
1554 /* Register the protocol name and description */
1555 proto_ouch = proto_register_protocol("OUCH", "OUCH", "ouch");
1557 /* Required function calls to register the header fields and
1559 proto_register_field_array(proto_ouch, hf, array_length(hf));
1560 proto_register_subtree_array(ett, array_length(ett));
1564 /* If this dissector uses sub-dissector registration add a
1565 * registration routine. This format is required because a script is
1566 * used to find these routines and create the code that calls these
1569 proto_reg_handoff_ouch(void)
1571 ouch_handle = create_dissector_handle(dissect_ouch, proto_ouch);
1572 heur_dissector_add("soupbintcp", dissect_ouch_heur, "OUCH over SoupBinTCP", "ouch_soupbintcp", proto_ouch, HEURISTIC_ENABLE);
1573 dissector_add_uint_range_with_preference("tcp.port", "", ouch_handle);
1579 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1584 * indent-tabs-mode: nil
1587 * vi: set shiftwidth=4 tabstop=8 expandtab:
1588 * :indentSize=4:tabSize=8:noTabs=true: