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.
38 #include <epan/packet.h>
39 #include <epan/prefs.h>
40 #include <epan/strutil.h>
42 void proto_reg_handoff_cpfi(void);
44 #define CPFI_DEFAULT_UDP_PORT 5000
45 #define CPFI_DEFAULT_TTOT_UDP_PORT 5001
47 #define FIRST_TIO_CARD_ADDRESS 0x380
51 #define CPFI_FRAME_TYPE_MASK 0xF0000000
52 #define CPFI_FRAME_TYPE_SHIFT 28
53 #define CPFI_SOURCE_MASK 0x0FFC0000
54 #define CPFI_SOURCE_SHIFT 18
55 #define CPFI_DEST_MASK 0x0003FF00
56 #define CPFI_DEST_SHIFT 8
57 #define CPFI_SOF_TYPE_MASK 0x000000F0
58 #define CPFI_SPEED_MASK 0x0000000C
59 #define CPFI_OPM_ERROR_MASK 0x00000002
60 #define CPFI_FROM_LCM_MASK 0x00000001
63 #define CPFI_EOF_TYPE_MASK 0x78000000
64 #define CPFI_EOF_ERROR_MASK 0x7FE00000
66 /* configurable parameters */
67 static guint gbl_cpfi_udp_port = CPFI_DEFAULT_UDP_PORT;
68 static guint gbl_cpfi_ttot_udp_port = CPFI_DEFAULT_TTOT_UDP_PORT;
69 static gboolean cpfi_arrow_moves = TRUE;
71 /* Initialize the protocol and registered fields */
72 static int proto_cpfi = -1;
73 static int hf_cpfi_word_one = -1;
74 static int hf_cpfi_word_two = -1;
76 static int hf_cpfi_frame_type = -1;
77 static int hf_cpfi_source = -1;
78 static int hf_cpfi_dest = -1;
79 static int hf_cpfi_SOF_type = -1;
80 static int hf_cpfi_speed = -1;
81 static int hf_cpfi_OPM_error = -1;
82 static int hf_cpfi_from_LCM = -1;
84 static int hf_cpfi_CRC_32 = -1;
85 static int hf_cpfi_EOF_type = -1;
87 static int hf_cpfi_t_instance = -1;
88 static int hf_cpfi_t_src_instance = -1;
89 static int hf_cpfi_t_dst_instance = -1;
90 static int hf_cpfi_t_board = -1;
91 static int hf_cpfi_t_src_board = -1;
92 static int hf_cpfi_t_dst_board = -1;
93 static int hf_cpfi_t_port = -1;
94 static int hf_cpfi_t_src_port = -1;
95 static int hf_cpfi_t_dst_port = -1;
99 static guint8 frame_type;
100 static char src_str[20];
101 static char dst_str[20];
102 static char l_to_r_arrow[] = "-->";
103 static char r_to_l_arrow[] = "<--";
104 static const char *left = src_str;
105 static const char *right = dst_str;
106 static const char *arrow = l_to_r_arrow;
107 static const char direction_and_port_string[] = "[%s %s %s] ";
110 /* Initialize the subtree pointers */
111 static gint ett_cpfi = -1;
112 static gint ett_cpfi_header = -1;
113 static gint ett_cpfi_footer = -1;
115 static dissector_handle_t fc_handle;
116 static dissector_handle_t data_handle;
119 static const value_string sof_type_vals[] = {
134 static const value_string speed_vals[] = {
142 static const value_string eof_type_vals[] = {
156 dissect_cpfi_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
160 guint8 src_instance = 0;
161 guint8 src_board = 0;
164 guint8 dst_instance = 0;
165 guint8 dst_board = 0;
167 proto_item *extra_item = NULL;
168 proto_tree *extra_tree = NULL;
169 proto_item *hidden_item;
171 /* add a tree for the header */
174 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Header");
175 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_header);
178 /* Extract the common header, and get the bits we need */
179 word1 = tvb_get_ntohl (tvb, 0);
180 word2 = tvb_get_ntohl (tvb, sizeof(word1));
182 /* Figure out where the frame came from. dstTDA is source of frame! */
183 tda = (word1 & CPFI_DEST_MASK) >> CPFI_DEST_SHIFT;
184 if ( tda >= FIRST_TIO_CARD_ADDRESS )
186 g_strlcpy(src_str, " CPFI", sizeof(src_str));
187 src = 0; /* Make it smallest */
191 const guint8 *srcmac;
193 /* Make sure this is an Ethernet address. */
194 DISSECTOR_ASSERT(pinfo->src.type == AT_ETHER);
195 srcmac = pinfo->src.data;
197 src_instance = srcmac[2]-1;
198 src_board = tda >> 4;
199 src_port = tda & 0x0f;
200 src = (1 << 24) + (src_instance << 16) + (src_board << 8) + src_port;
201 g_snprintf(src_str, sizeof(src_str), "%u.%u.%u", src_instance, src_board, src_port);
204 /* Figure out where the frame is going. srcTDA is destination of frame! */
205 tda = (word1 & CPFI_SOURCE_MASK) >> CPFI_SOURCE_SHIFT;
206 if ( tda >= FIRST_TIO_CARD_ADDRESS )
208 g_strlcpy(dst_str, " CPFI", sizeof(dst_str));
209 dst = 0; /* Make it smallest */
213 const guint8 *dstmac;
215 /* Make sure this is an Ethernet address. */
216 DISSECTOR_ASSERT(pinfo->dst.type == AT_ETHER);
217 dstmac = pinfo->dst.data;
219 dst_instance = dstmac[2]-1;
220 dst_board = tda >> 4;
221 dst_port = tda & 0x0f;
222 dst = (1 << 24) + (dst_instance << 16) + (dst_board << 8) + dst_port;
223 g_snprintf(dst_str, sizeof(dst_str), "%u.%u.%u", dst_instance, dst_board, dst_port);
226 /* Set up the source and destination and arrow per user configuration. */
227 if ( cpfi_arrow_moves && (dst < src) )
230 arrow = r_to_l_arrow;
236 arrow = l_to_r_arrow;
241 /* For "real" TDAs (i.e. not for microTDAs), add hidden addresses to allow filtering */
244 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &src_instance);
245 PROTO_ITEM_SET_HIDDEN(hidden_item);
246 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_instance, tvb, 0, 1, &src_instance);
247 PROTO_ITEM_SET_HIDDEN(hidden_item);
248 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &src_board);
249 PROTO_ITEM_SET_HIDDEN(hidden_item);
250 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_board, tvb, 0, 1, &src_board);
251 PROTO_ITEM_SET_HIDDEN(hidden_item);
252 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &src_port);
253 PROTO_ITEM_SET_HIDDEN(hidden_item);
254 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_src_port, tvb, 0, 1, &src_port);
255 PROTO_ITEM_SET_HIDDEN(hidden_item);
259 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &dst_instance);
260 PROTO_ITEM_SET_HIDDEN(hidden_item);
261 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_instance, tvb, 0, 1, &dst_instance);
262 PROTO_ITEM_SET_HIDDEN(hidden_item);
263 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &dst_board);
264 PROTO_ITEM_SET_HIDDEN(hidden_item);
265 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_board, tvb, 0, 1, &dst_board);
266 PROTO_ITEM_SET_HIDDEN(hidden_item);
267 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &dst_port);
268 PROTO_ITEM_SET_HIDDEN(hidden_item);
269 hidden_item = proto_tree_add_bytes(extra_tree, hf_cpfi_t_dst_port, tvb, 0, 1, &dst_port);
270 PROTO_ITEM_SET_HIDDEN(hidden_item);
273 /* add word 1 components to the protocol tree */
274 proto_tree_add_item(extra_tree, hf_cpfi_word_one , tvb, 0, 4, ENC_BIG_ENDIAN);
276 proto_tree_add_item(extra_tree, hf_cpfi_frame_type, tvb, 0, 4, ENC_BIG_ENDIAN);
277 proto_tree_add_item(extra_tree, hf_cpfi_source , tvb, 0, 4, ENC_BIG_ENDIAN);
278 proto_tree_add_item(extra_tree, hf_cpfi_dest , tvb, 0, 4, ENC_BIG_ENDIAN);
279 proto_tree_add_item(extra_tree, hf_cpfi_SOF_type , tvb, 0, 4, ENC_BIG_ENDIAN);
280 proto_tree_add_item(extra_tree, hf_cpfi_speed , tvb, 0, 4, ENC_BIG_ENDIAN);
281 proto_tree_add_item(extra_tree, hf_cpfi_OPM_error , tvb, 0, 4, ENC_BIG_ENDIAN);
282 proto_tree_add_item(extra_tree, hf_cpfi_from_LCM , tvb, 0, 4, ENC_BIG_ENDIAN);
284 /* add word 2 components to the protocol tree */
285 proto_tree_add_item(extra_tree, hf_cpfi_word_two , tvb, 4, 4, ENC_BIG_ENDIAN);
291 dissect_cpfi_footer(tvbuff_t *tvb, proto_tree *tree)
293 proto_item *extra_item = NULL;
294 proto_tree *extra_tree = NULL;
296 /* add a tree for the footer */
299 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Footer");
300 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_footer);
304 proto_tree_add_item(extra_tree, hf_cpfi_CRC_32 , tvb, 0, 4, ENC_BIG_ENDIAN);
305 proto_tree_add_item(extra_tree, hf_cpfi_EOF_type, tvb, 4, 4, ENC_BIG_ENDIAN);
311 dissect_cpfi(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
313 tvbuff_t *header_tvb, *body_tvb, *footer_tvb;
314 proto_item *cpfi_item = NULL;
315 proto_tree *cpfi_tree = NULL;
316 gint length, reported_length, body_length, reported_body_length;
318 frame_type = (tvb_get_ntohl (message_tvb, 0) & CPFI_FRAME_TYPE_MASK) >> CPFI_FRAME_TYPE_SHIFT;
320 /* If this is not a CPFI frame, return 0 to let another dissector try to
323 if ( !((frame_type == 9) && fc_handle) )
326 /* If we don't have Ethernet addresses, can't do further dissection... */
327 if (pinfo->dst.type != AT_ETHER || pinfo->src.type != AT_ETHER)
330 length = tvb_length_remaining(message_tvb, 8);
331 reported_length = tvb_reported_length_remaining(message_tvb, 8);
332 if (reported_length < 8)
334 /* We don't even have enough for the footer. */
338 /* Length of packet, minus the footer. */
339 reported_body_length = reported_length - 8;
340 /* How much of that do we have in the tvbuff? */
341 body_length = length;
342 if (body_length > reported_body_length)
343 body_length = reported_body_length;
345 length = tvb_length_remaining(message_tvb, 8+body_length);
348 /* The footer wasn't captured at all.
349 XXX - we'd like to throw a BoundsError if that's the case. */
353 /* In the interest of speed, if "tree" is NULL, don't do any work not
354 necessary to generate protocol tree items. */
356 /* create the protocol tree */
357 cpfi_item = proto_tree_add_item(tree, proto_cpfi, message_tvb, 0, -1, ENC_NA);
358 cpfi_tree = proto_item_add_subtree(cpfi_item, ett_cpfi);
361 /* Set up the frame controls - can we do better than this? */
363 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
364 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
365 pinfo->sof_eof |= PINFO_EOF_INVALID;
367 /* dissect the message */
369 /* extract and process the header */
370 header_tvb = tvb_new_subset(message_tvb, 0, 8, 8);
371 dissect_cpfi_header(header_tvb, pinfo, cpfi_tree);
373 body_tvb = tvb_new_subset(message_tvb, 8, body_length, reported_body_length);
374 call_dissector(fc_handle, body_tvb, pinfo, tree);
376 /* add more info, now that FC added it's */
377 proto_item_append_text(cpfi_item, direction_and_port_string, left, arrow, right);
378 col_prepend_fstr(pinfo->cinfo, COL_INFO, direction_and_port_string, left, arrow, right);
381 footer_tvb = tvb_new_subset(message_tvb, 8+body_length, length, 8);
382 dissect_cpfi_footer(footer_tvb, cpfi_tree);
384 return(tvb_length(message_tvb));
388 /* Register the protocol with Wireshark */
390 proto_register_cpfi(void)
392 module_t *cpfi_module;
394 /* Setup list of header fields */
395 static hf_register_info hf[] = {
398 { "Word one", "cpfi.word_one",
399 FT_UINT32, BASE_HEX, NULL, 0x0,
402 { "Word two", "cpfi.word_two",
403 FT_UINT32, BASE_HEX, NULL, 0x0,
406 { &hf_cpfi_frame_type,
407 { "FrmType", "cpfi.frmtype",
408 FT_UINT32, BASE_HEX, NULL, CPFI_FRAME_TYPE_MASK,
409 "Frame Type", HFILL}},
411 { "srcTDA", "cpfi.srcTDA",
412 FT_UINT32, BASE_HEX, NULL, CPFI_SOURCE_MASK,
413 "Source TDA (10 bits)", HFILL}},
415 { "dstTDA", "cpfi.dstTDA",
416 FT_UINT32, BASE_HEX, NULL, CPFI_DEST_MASK,
417 "Source TDA (10 bits)", HFILL}},
419 { "SOFtype", "cpfi.SOFtype",
420 FT_UINT32, BASE_HEX, VALS(sof_type_vals), CPFI_SOF_TYPE_MASK,
423 { "speed", "cpfi.speed",
424 FT_UINT32, BASE_HEX, VALS(speed_vals), CPFI_SPEED_MASK,
426 { &hf_cpfi_OPM_error,
427 { "OPMerror", "cpfi.OPMerror",
428 FT_BOOLEAN, 32, NULL, CPFI_OPM_ERROR_MASK,
429 "OPM Error?", HFILL}},
431 { "fromLCM", "cpfi.fromLCM",
432 FT_BOOLEAN, 32, NULL, CPFI_FROM_LCM_MASK,
433 "from LCM?", HFILL}},
436 { "CRC-32", "cpfi.crc-32",
437 FT_UINT32, BASE_HEX, NULL, 0x0,
441 { "EOFtype", "cpfi.EOFtype",
442 FT_UINT32, BASE_HEX, VALS(eof_type_vals), CPFI_EOF_TYPE_MASK,
445 { &hf_cpfi_t_instance,
446 { "Instance", "cpfi.instance",
448 NULL, 0x0, NULL, HFILL}},
450 { &hf_cpfi_t_src_instance,
451 { "Source Instance", "cpfi.src_instance",
453 NULL, 0x0, NULL, HFILL}},
455 { &hf_cpfi_t_dst_instance,
456 { "Destination Instance", "cpfi.dst_instance",
458 NULL, 0x0, NULL, HFILL}},
461 { "Board", "cpfi.board",
463 NULL, 0x0, NULL, HFILL}},
465 { &hf_cpfi_t_src_board,
466 { "Source Board", "cpfi.src_board",
468 NULL, 0x0, NULL, HFILL}},
470 { &hf_cpfi_t_dst_board,
471 { "Destination Board", "cpfi.dst_board",
473 NULL, 0x0, NULL, HFILL}},
476 { "Port", "cpfi.port",
478 NULL, 0x0, NULL, HFILL}},
480 { &hf_cpfi_t_src_port,
481 { "Source Port", "cpfi.src_port",
483 NULL, 0x0, NULL, HFILL}},
485 { &hf_cpfi_t_dst_port,
486 { "Destination Port", "cpfi.dst_port",
488 NULL, 0x0, NULL, HFILL}},
492 /* Setup protocol subtree array */
493 static gint *ett[] = {
500 /* Register the protocol name and description */
501 proto_cpfi = proto_register_protocol("Cross Point Frame Injector", "CPFI", "cpfi");
503 /* Required function calls to register the header fields and subtrees used */
504 proto_register_field_array(proto_cpfi, hf, array_length(hf));
505 proto_register_subtree_array(ett, array_length(ett));
507 /* Register our configuration options for CPFI */
508 cpfi_module = prefs_register_protocol(proto_cpfi, proto_reg_handoff_cpfi);
509 prefs_register_uint_preference(cpfi_module, "udp.port", "CPFI UDP Port",
510 "Set the port for CPFI messages (if other"
511 " than the default of 5000)",
512 10, &gbl_cpfi_udp_port);
513 prefs_register_uint_preference(cpfi_module, "udp.port2", "InstanceToInstance UDP Port",
514 "Set the port for InstanceToInstance messages (if other"
515 " than the default of 5001)",
516 10, &gbl_cpfi_ttot_udp_port);
517 prefs_register_bool_preference(cpfi_module, "arrow_ctl",
518 "Enable Active Arrow Control",
519 "Control the way the '-->' is displayed."
520 " When enabled, keeps the 'lowest valued' endpoint of the src-dest pair"
521 " on the left, and the arrow moves to distinguish source from dest."
522 " When disabled, keeps the arrow pointing right so the source of the frame"
523 " is always on the left.",
529 proto_reg_handoff_cpfi(void)
531 static gboolean cpfi_init_complete = FALSE;
532 static dissector_handle_t cpfi_handle;
533 static dissector_handle_t ttot_handle;
534 static guint cpfi_udp_port;
535 static guint cpfi_ttot_udp_port;
537 if ( !cpfi_init_complete )
539 fc_handle = find_dissector("fc");
540 data_handle = find_dissector("data");
541 cpfi_handle = new_create_dissector_handle(dissect_cpfi, proto_cpfi);
542 ttot_handle = new_create_dissector_handle(dissect_cpfi, proto_cpfi);
543 cpfi_init_complete = TRUE;
547 dissector_delete_uint("udp.port", cpfi_udp_port, cpfi_handle);
548 dissector_delete_uint("udp.port", cpfi_ttot_udp_port, ttot_handle);
551 cpfi_udp_port = gbl_cpfi_udp_port;
552 cpfi_ttot_udp_port = gbl_cpfi_ttot_udp_port;
554 dissector_add_uint("udp.port", cpfi_udp_port, cpfi_handle);
555 dissector_add_uint("udp.port", cpfi_ttot_udp_port, ttot_handle);