2 * Routines for CPFI Cross Point Frame Injector dissection
3 * CPFI - Cross Point Frame Injector is a CNT proprietary
4 * protocol used to carry Fibre Channel data over UDP
6 * Copyright 2003, Dave Sclarsky <dave_sclarsky[AT]cnt.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * Copied from packet-m2tp.c
15 * Thanks to Heinz Prantner for his motivation and assistance
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #include <epan/packet.h>
41 #include <epan/prefs.h>
42 #include <epan/strutil.h>
44 void proto_reg_handoff_cpfi(void);
46 #define CPFI_DEFAULT_UDP_PORT 5000
47 #define CPFI_DEFAULT_TTOT_UDP_PORT 5001
48 #define FIRST_TIO_CARD_ADDRESS 0x380
52 #define CPFI_FRAME_TYPE_MASK 0xF0000000
53 #define CPFI_FRAME_TYPE_SHIFT 28
54 #define CPFI_SOURCE_MASK 0x0FFC0000
55 #define CPFI_SOURCE_SHIFT 18
56 #define CPFI_DEST_MASK 0x0003FF00
57 #define CPFI_DEST_SHIFT 8
58 #define CPFI_SOF_TYPE_MASK 0x000000F0
59 #define CPFI_SPEED_MASK 0x0000000C
60 #define CPFI_OPM_ERROR_MASK 0x00000002
61 #define CPFI_FROM_LCM_MASK 0x00000001
64 #define CPFI_EOF_TYPE_MASK 0x78000000
65 #define CPFI_EOF_ERROR_MASK 0x7FE00000
67 /* configurable parameters */
68 static guint cpfi_udp_port = CPFI_DEFAULT_UDP_PORT;
69 static guint cpfi_ttot_udp_port = CPFI_DEFAULT_TTOT_UDP_PORT;
70 static gboolean cpfi_arrow_moves = TRUE;
72 /* Initialize the protocol and registered fields */
73 static int proto_cpfi = -1;
74 static int hf_cpfi_word_one = -1;
75 static int hf_cpfi_word_two = -1;
77 static int hf_cpfi_frame_type = -1;
78 static int hf_cpfi_source = -1;
79 static int hf_cpfi_dest = -1;
80 static int hf_cpfi_SOF_type = -1;
81 static int hf_cpfi_speed = -1;
82 static int hf_cpfi_OPM_error = -1;
83 static int hf_cpfi_from_LCM = -1;
85 static int hf_cpfi_CRC_32 = -1;
86 static int hf_cpfi_EOF_type = -1;
88 static int hf_cpfi_t_instance = -1;
89 static int hf_cpfi_t_src_instance = -1;
90 static int hf_cpfi_t_dst_instance = -1;
91 static int hf_cpfi_t_board = -1;
92 static int hf_cpfi_t_src_board = -1;
93 static int hf_cpfi_t_dst_board = -1;
94 static int hf_cpfi_t_port = -1;
95 static int hf_cpfi_t_src_port = -1;
96 static int hf_cpfi_t_dst_port = -1;
100 static guint8 frame_type;
101 static char src_str[20];
102 static char dst_str[20];
103 static char l_to_r_arrow[] = "-->";
104 static char r_to_l_arrow[] = "<--";
105 static const char *left = src_str;
106 static const char *right = dst_str;
107 static const char *arrow = l_to_r_arrow;
108 static const char direction_and_port_string[] = "[%s %s %s] ";
111 /* Initialize the subtree pointers */
112 static gint ett_cpfi = -1;
113 static gint ett_cpfi_header = -1;
114 static gint ett_cpfi_footer = -1;
116 static dissector_handle_t fc_handle;
117 static dissector_handle_t data_handle;
120 static const value_string sof_type_vals[] = {
135 static const value_string speed_vals[] = {
143 static const value_string eof_type_vals[] = {
157 dissect_cpfi_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
161 guint8 src_instance = 0;
162 guint8 src_board = 0;
165 guint8 dst_instance = 0;
166 guint8 dst_board = 0;
168 proto_item *extra_item = NULL;
169 proto_tree *extra_tree = NULL;
170 proto_item *hidden_item;
172 /* add a tree for the header */
175 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Header");
176 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_header);
179 /* Extract the common header, and get the bits we need */
180 word1 = tvb_get_ntohl (tvb, 0);
181 word2 = tvb_get_ntohl (tvb, sizeof(word1));
183 /* Figure out where the frame came from. dstTDA is source of frame! */
184 tda = (word1 & CPFI_DEST_MASK) >> CPFI_DEST_SHIFT;
185 if ( tda >= FIRST_TIO_CARD_ADDRESS )
187 g_strlcpy(src_str, " CPFI", sizeof(src_str));
188 src = 0; /* Make it smallest */
192 const guint8 *srcmac;
194 /* Make sure this is an Ethernet address. */
195 DISSECTOR_ASSERT(pinfo->src.type == AT_ETHER);
196 srcmac = pinfo->src.data;
198 src_instance = srcmac[2]-1;
199 src_board = tda >> 4;
200 src_port = tda & 0x0f;
201 src = (1 << 24) + (src_instance << 16) + (src_board << 8) + src_port;
202 g_snprintf(src_str, sizeof(src_str), "%u.%u.%u", src_instance, src_board, src_port);
205 /* Figure out where the frame is going. srcTDA is destination of frame! */
206 tda = (word1 & CPFI_SOURCE_MASK) >> CPFI_SOURCE_SHIFT;
207 if ( tda >= FIRST_TIO_CARD_ADDRESS )
209 g_strlcpy(dst_str, " CPFI", sizeof(dst_str));
210 dst = 0; /* Make it smallest */
214 const guint8 *dstmac;
216 /* Make sure this is an Ethernet address. */
217 DISSECTOR_ASSERT(pinfo->dst.type == AT_ETHER);
218 dstmac = pinfo->dst.data;
220 dst_instance = dstmac[2]-1;
221 dst_board = tda >> 4;
222 dst_port = tda & 0x0f;
223 dst = (1 << 24) + (dst_instance << 16) + (dst_board << 8) + dst_port;
224 g_snprintf(dst_str, sizeof(dst_str), "%u.%u.%u", dst_instance, dst_board, dst_port);
227 /* Set up the source and destination and arrow per user configuration. */
228 if ( cpfi_arrow_moves && (dst < src) )
231 arrow = r_to_l_arrow;
237 arrow = l_to_r_arrow;
242 /* For "real" TDAs (i.e. not for microTDAs), add hidden addresses to allow filtering */
245 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &src_instance);
246 PROTO_ITEM_SET_HIDDEN(hidden_item);
247 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_instance, tvb, 0, 1, &src_instance);
248 PROTO_ITEM_SET_HIDDEN(hidden_item);
249 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &src_board);
250 PROTO_ITEM_SET_HIDDEN(hidden_item);
251 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_board, tvb, 0, 1, &src_board);
252 PROTO_ITEM_SET_HIDDEN(hidden_item);
253 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &src_port);
254 PROTO_ITEM_SET_HIDDEN(hidden_item);
255 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_port, tvb, 0, 1, &src_port);
256 PROTO_ITEM_SET_HIDDEN(hidden_item);
260 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &dst_instance);
261 PROTO_ITEM_SET_HIDDEN(hidden_item);
262 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_instance, tvb, 0, 1, &dst_instance);
263 PROTO_ITEM_SET_HIDDEN(hidden_item);
264 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &dst_board);
265 PROTO_ITEM_SET_HIDDEN(hidden_item);
266 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_board, tvb, 0, 1, &dst_board);
267 PROTO_ITEM_SET_HIDDEN(hidden_item);
268 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &dst_port);
269 PROTO_ITEM_SET_HIDDEN(hidden_item);
270 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_port, tvb, 0, 1, &dst_port);
271 PROTO_ITEM_SET_HIDDEN(hidden_item);
274 /* add word 1 components to the protocol tree */
275 proto_tree_add_item(extra_tree, hf_cpfi_word_one , tvb, 0, 4, FALSE);
277 proto_tree_add_item(extra_tree, hf_cpfi_frame_type, tvb, 0, 4, FALSE);
278 proto_tree_add_item(extra_tree, hf_cpfi_source , tvb, 0, 4, FALSE);
279 proto_tree_add_item(extra_tree, hf_cpfi_dest , tvb, 0, 4, FALSE);
280 proto_tree_add_item(extra_tree, hf_cpfi_SOF_type , tvb, 0, 4, FALSE);
281 proto_tree_add_item(extra_tree, hf_cpfi_speed , tvb, 0, 4, FALSE);
282 proto_tree_add_item(extra_tree, hf_cpfi_OPM_error , tvb, 0, 4, FALSE);
283 proto_tree_add_item(extra_tree, hf_cpfi_from_LCM , tvb, 0, 4, FALSE);
285 /* add word 2 components to the protocol tree */
286 proto_tree_add_item(extra_tree, hf_cpfi_word_two , tvb, 4, 4, FALSE);
292 dissect_cpfi_footer(tvbuff_t *tvb, proto_tree *tree)
294 proto_item *extra_item = NULL;
295 proto_tree *extra_tree = NULL;
297 /* add a tree for the footer */
300 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Footer");
301 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_footer);
305 proto_tree_add_item(extra_tree, hf_cpfi_CRC_32 , tvb, 0, 4, FALSE);
306 proto_tree_add_item(extra_tree, hf_cpfi_EOF_type, tvb, 4, 4, FALSE);
312 dissect_cpfi(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
314 tvbuff_t *header_tvb, *body_tvb, *footer_tvb;
315 proto_item *cpfi_item = NULL;
316 proto_tree *cpfi_tree = NULL;
317 gint length, reported_length, body_length, reported_body_length;
319 frame_type = (tvb_get_ntohl (message_tvb, 0) & CPFI_FRAME_TYPE_MASK) >> CPFI_FRAME_TYPE_SHIFT;
321 /* If this is not a CPFI frame, return 0 to let another dissector try to
324 if ( !((frame_type == 9) && fc_handle) )
327 /* If we don't have Ethernet addresses, can't do further dissection... */
328 if (pinfo->dst.type != AT_ETHER || pinfo->src.type != AT_ETHER)
331 length = tvb_length_remaining(message_tvb, 8);
332 reported_length = tvb_reported_length_remaining(message_tvb, 8);
333 if (reported_length < 8)
335 /* We don't even have enough for the footer. */
339 /* Length of packet, minus the footer. */
340 reported_body_length = reported_length - 8;
341 /* How much of that do we have in the tvbuff? */
342 body_length = length;
343 if (body_length > reported_body_length)
344 body_length = reported_body_length;
346 length = tvb_length_remaining(message_tvb, 8+body_length);
349 /* The footer wasn't captured at all.
350 XXX - we'd like to throw a BoundsError if that's the case. */
354 /* In the interest of speed, if "tree" is NULL, don't do any work not
355 necessary to generate protocol tree items. */
357 /* create the protocol tree */
358 cpfi_item = proto_tree_add_item(tree, proto_cpfi, message_tvb, 0, -1, FALSE);
359 cpfi_tree = proto_item_add_subtree(cpfi_item, ett_cpfi);
362 /* Set up the frame controls - can we do better than this? */
364 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
365 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
366 pinfo->sof_eof |= PINFO_EOF_INVALID;
368 /* dissect the message */
370 /* extract and process the header */
371 header_tvb = tvb_new_subset(message_tvb, 0, 8, 8);
372 dissect_cpfi_header(header_tvb, pinfo, cpfi_tree);
374 body_tvb = tvb_new_subset(message_tvb, 8, body_length, reported_body_length);
375 call_dissector(fc_handle, body_tvb, pinfo, tree);
377 /* add more info, now that FC added it's */
378 proto_item_append_text(cpfi_item, direction_and_port_string, left, arrow, right);
379 if (check_col(pinfo->cinfo, COL_INFO))
381 col_prepend_fstr(pinfo->cinfo, COL_INFO, direction_and_port_string, left, arrow, right);
385 footer_tvb = tvb_new_subset(message_tvb, 8+body_length, length, 8);
386 dissect_cpfi_footer(footer_tvb, cpfi_tree);
388 return(tvb_length(message_tvb));
392 /* Register the protocol with Wireshark */
394 proto_register_cpfi(void)
396 module_t *cpfi_module;
398 /* Setup list of header fields */
399 static hf_register_info hf[] = {
402 { "Word one", "cpfi.word_one",
403 FT_UINT32, BASE_HEX, NULL, 0x0,
406 { "Word two", "cfpi.word_two",
407 FT_UINT32, BASE_HEX, NULL, 0x0,
410 { &hf_cpfi_frame_type,
411 { "FrmType", "cpfi.frmtype",
412 FT_UINT32, BASE_HEX, NULL, CPFI_FRAME_TYPE_MASK,
413 "Frame Type", HFILL}},
415 { "srcTDA", "cpfi.srcTDA",
416 FT_UINT32, BASE_HEX, NULL, CPFI_SOURCE_MASK,
417 "Source TDA (10 bits)", HFILL}},
419 { "dstTDA", "cpfi.dstTDA",
420 FT_UINT32, BASE_HEX, NULL, CPFI_DEST_MASK,
421 "Source TDA (10 bits)", HFILL}},
423 { "SOFtype", "cpfi.SOFtype",
424 FT_UINT32, BASE_HEX, VALS(sof_type_vals), CPFI_SOF_TYPE_MASK,
427 { "speed", "cpfi.speed",
428 FT_UINT32, BASE_HEX, VALS(speed_vals), CPFI_SPEED_MASK,
430 { &hf_cpfi_OPM_error,
431 { "OPMerror", "cpfi.OPMerror",
432 FT_BOOLEAN, 32, NULL, CPFI_OPM_ERROR_MASK,
433 "OPM Error?", HFILL}},
435 { "fromLCM", "cpfi.fromLCM",
436 FT_BOOLEAN, 32, NULL, CPFI_FROM_LCM_MASK,
437 "from LCM?", HFILL}},
440 { "CRC-32", "cpfi.crc-32",
441 FT_UINT32, BASE_HEX, NULL, 0x0,
445 { "EOFtype", "cpfi.EOFtype",
446 FT_UINT32, BASE_HEX, VALS(eof_type_vals), CPFI_EOF_TYPE_MASK,
449 { &hf_cpfi_t_instance,
450 { "Instance", "cpfi.instance",
452 NULL, 0x0, "", HFILL}},
454 { &hf_cpfi_t_src_instance,
455 { "Source Instance", "cpfi.src_instance",
457 NULL, 0x0, "", HFILL}},
459 { &hf_cpfi_t_dst_instance,
460 { "Destination Instance", "cpfi.dst_instance",
462 NULL, 0x0, "", HFILL}},
465 { "Board", "cpfi.board",
467 NULL, 0x0, "", HFILL}},
469 { &hf_cpfi_t_src_board,
470 { "Source Board", "cpfi.src_board",
472 NULL, 0x0, "", HFILL}},
474 { &hf_cpfi_t_dst_board,
475 { "Destination Board", "cpfi.dst_board",
477 NULL, 0x0, "", HFILL}},
480 { "Port", "cpfi.port",
482 NULL, 0x0, "", HFILL}},
484 { &hf_cpfi_t_src_port,
485 { "Source Port", "cpfi.src_port",
487 NULL, 0x0, "", HFILL}},
489 { &hf_cpfi_t_dst_port,
490 { "Destination Port", "cpfi.dst_port",
492 NULL, 0x0, "", HFILL}},
496 /* Setup protocol subtree array */
497 static gint *ett[] = {
504 /* Register the protocol name and description */
505 proto_cpfi = proto_register_protocol("Cross Point Frame Injector ", "CPFI", "cpfi");
507 /* Required function calls to register the header fields and subtrees used */
508 proto_register_field_array(proto_cpfi, hf, array_length(hf));
509 proto_register_subtree_array(ett, array_length(ett));
511 /* Register our configuration options for CPFI */
512 cpfi_module = prefs_register_protocol(proto_cpfi, proto_reg_handoff_cpfi);
513 prefs_register_uint_preference(cpfi_module, "udp.port", "CPFI UDP Port",
514 "Set the port for CPFI messages (if other"
515 " than the default of 5000)",
517 prefs_register_uint_preference(cpfi_module, "udp.port2", "InstanceToInstance UDP Port",
518 "Set the port for InstanceToInstance messages (if other"
519 " than the default of 5001)",
520 10, &cpfi_ttot_udp_port);
521 prefs_register_bool_preference(cpfi_module, "arrow_ctl",
522 "Enable Active Arrow Control",
523 "Control the way the '-->' is displayed."
524 " When enabled, keeps the 'lowest valued' endpoint of the src-dest pair"
525 " on the left, and the arrow moves to distinguish source from dest."
526 " When disabled, keeps the arrow pointing right so the source of the frame"
527 " is always on the left.",
533 proto_reg_handoff_cpfi(void)
535 static int cpfi_init_complete = FALSE;
536 static dissector_handle_t cpfi_handle;
537 static dissector_handle_t ttot_handle;
538 if ( !cpfi_init_complete )
540 cpfi_init_complete = TRUE;
541 fc_handle = find_dissector("fc");
542 data_handle = find_dissector("data");
543 cpfi_handle = new_create_dissector_handle(dissect_cpfi, proto_cpfi);
544 ttot_handle = new_create_dissector_handle(dissect_cpfi, proto_cpfi);
548 dissector_delete("udp.port", cpfi_udp_port, cpfi_handle);
549 dissector_delete("udp.port", cpfi_ttot_udp_port, ttot_handle);
552 dissector_add("udp.port", cpfi_udp_port, cpfi_handle);
553 dissector_add("udp.port", cpfi_ttot_udp_port, ttot_handle);