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 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
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>
43 void proto_reg_handoff_cpfi(void);
45 #define CPFI_DEFAULT_UDP_PORT 5000
46 #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 cpfi_udp_port = CPFI_DEFAULT_UDP_PORT;
68 static guint 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;
170 /* add a tree for the header */
173 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Header");
174 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_header);
177 /* Extract the common header, and get the bits we need */
178 word1 = tvb_get_ntohl (tvb, 0);
179 word2 = tvb_get_ntohl (tvb, sizeof(word1));
181 /* Get the frame type, for later use */
182 frame_type = (word1 & CPFI_FRAME_TYPE_MASK) >> CPFI_FRAME_TYPE_SHIFT;
184 /* Figure out where the frame came from. dstTDA is source of frame! */
185 tda = (word1 & CPFI_DEST_MASK) >> CPFI_DEST_SHIFT;
186 if ( tda >= FIRST_TIO_CARD_ADDRESS )
188 strncpy(src_str, " CPFI", sizeof(src_str));
189 src = 0; /* Make it smallest */
193 src_instance = pinfo->src.data[2]-1;
194 src_board = tda >> 4;
195 src_port = tda & 0x0f;
196 src = (1 << 24) + (src_instance << 16) + (src_board << 8) + src_port;
197 snprintf(src_str, sizeof(src_str), "%u.%u.%u", src_instance, src_board, src_port);
200 /* Figure out where the frame is going. srcTDA is destination of frame! */
201 tda = (word1 & CPFI_SOURCE_MASK) >> CPFI_SOURCE_SHIFT;
202 if ( tda >= FIRST_TIO_CARD_ADDRESS )
204 strncpy(dst_str, " CPFI", sizeof(dst_str));
205 dst = 0; /* Make it smallest */
209 dst_instance = pinfo->dst.data[2]-1;
210 dst_board = tda >> 4;
211 dst_port = tda & 0x0f;
212 dst = (1 << 24) + (dst_instance << 16) + (dst_board << 8) + dst_port;
213 snprintf(dst_str, sizeof(dst_str), "%u.%u.%u", dst_instance, dst_board, dst_port);
216 /* Set up the source and destination and arrow per user configuration. */
217 if ( cpfi_arrow_moves && (dst < src) )
220 arrow = r_to_l_arrow;
226 arrow = l_to_r_arrow;
231 /* For "real" TDAs (i.e. not for microTDAs), add hidden addresses to allow filtering */
234 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &src_instance);
235 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_src_instance, tvb, 0, 1, &src_instance);
236 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &src_board);
237 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_src_board, tvb, 0, 1, &src_board);
238 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &src_port);
239 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_src_port, tvb, 0, 1, &src_port);
243 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_instance, tvb, 0, 1, &dst_instance);
244 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_dst_instance, tvb, 0, 1, &dst_instance);
245 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_board, tvb, 0, 1, &dst_board);
246 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_dst_board, tvb, 0, 1, &dst_board);
247 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_port, tvb, 0, 1, &dst_port);
248 proto_tree_add_bytes_hidden(extra_tree, hf_cpfi_t_dst_port, tvb, 0, 1, &dst_port);
251 /* add word 1 components to the protocol tree */
252 proto_tree_add_item(extra_tree, hf_cpfi_word_one , tvb, 0, 4, FALSE);
254 proto_tree_add_item(extra_tree, hf_cpfi_frame_type, tvb, 0, 4, FALSE);
255 proto_tree_add_item(extra_tree, hf_cpfi_source , tvb, 0, 4, FALSE);
256 proto_tree_add_item(extra_tree, hf_cpfi_dest , tvb, 0, 4, FALSE);
257 proto_tree_add_item(extra_tree, hf_cpfi_SOF_type , tvb, 0, 4, FALSE);
258 proto_tree_add_item(extra_tree, hf_cpfi_speed , tvb, 0, 4, FALSE);
259 proto_tree_add_item(extra_tree, hf_cpfi_OPM_error , tvb, 0, 4, FALSE);
260 proto_tree_add_item(extra_tree, hf_cpfi_from_LCM , tvb, 0, 4, FALSE);
262 /* add word 2 components to the protocol tree */
263 proto_tree_add_item(extra_tree, hf_cpfi_word_two , tvb, 4, 4, FALSE);
269 dissect_cpfi_footer(tvbuff_t *tvb, proto_tree *tree)
271 proto_item *extra_item = NULL;
272 proto_tree *extra_tree = NULL;
274 /* add a tree for the footer */
277 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Footer");
278 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_footer);
282 proto_tree_add_item(extra_tree, hf_cpfi_CRC_32 , tvb, 0, 4, FALSE);
283 proto_tree_add_item(extra_tree, hf_cpfi_EOF_type, tvb, 4, 4, FALSE);
289 dissect_cpfi(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
291 tvbuff_t *header_tvb, *body_tvb, *footer_tvb;
292 proto_item *cpfi_item = NULL;
293 proto_tree *cpfi_tree = NULL;
294 gint length, reported_length, body_length, reported_body_length;
296 /* In the interest of speed, if "tree" is NULL, don't do any work not
297 necessary to generate protocol tree items. */
299 /* create the protocol tree */
300 cpfi_item = proto_tree_add_item(tree, proto_cpfi, message_tvb, 0, -1, FALSE);
301 cpfi_tree = proto_item_add_subtree(cpfi_item, ett_cpfi);
304 /* Set up the frame controls - can we do better than this? */
306 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
307 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
308 pinfo->sof_eof |= PINFO_EOF_INVALID;
310 /* dissect the message */
312 /* extract and process the header */
313 header_tvb = tvb_new_subset(message_tvb, 0, 8, 8);
314 dissect_cpfi_header(header_tvb, pinfo, cpfi_tree);
316 /* Got good CPFI frame? */
317 if ( (frame_type == 9) && fc_handle )
319 /* create a tvb for the rest of the fc frame (exclude the checksum and CPFI trailer) */
320 length = tvb_length_remaining(message_tvb, 8);
321 reported_length = tvb_reported_length_remaining(message_tvb, 8);
322 if (reported_length < 8)
324 /* We don't even have enough for the footer. */
325 body_tvb = tvb_new_subset(message_tvb, 8, -1, -1);
326 call_dissector(data_handle, body_tvb, pinfo, tree);
329 /* Length of packet, minus the footer. */
330 reported_body_length = reported_length - 8;
331 /* How much of that do we have in the tvbuff? */
332 body_length = length;
333 if (body_length > reported_body_length)
334 body_length = reported_body_length;
335 body_tvb = tvb_new_subset(message_tvb, 8, body_length, reported_body_length);
336 call_dissector(fc_handle, body_tvb, pinfo, tree);
338 /* add more info, now that FC added it's */
339 proto_item_append_text(cpfi_item, direction_and_port_string, left, arrow, right);
340 if (check_col(pinfo->cinfo, COL_INFO))
342 col_prepend_fstr(pinfo->cinfo, COL_INFO, direction_and_port_string, left, arrow, right);
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. */
353 footer_tvb = tvb_new_subset(message_tvb, 8+body_length, length, 8);
354 dissect_cpfi_footer(footer_tvb, cpfi_tree);
356 else if ( data_handle )
358 /* create a tvb for the rest of the frame */
359 body_tvb = tvb_new_subset(message_tvb, 8, -1, -1);
360 call_dissector(data_handle, body_tvb, pinfo, tree);
365 /* Register the protocol with Ethereal */
367 proto_register_cpfi(void)
369 module_t *cpfi_module;
371 /* Setup list of header fields */
372 static hf_register_info hf[] = {
375 { "Word one", "cpfi.word_one",
376 FT_UINT32, BASE_HEX, NULL, 0x0,
379 { "Word two", "cfpi.word_two",
380 FT_UINT32, BASE_HEX, NULL, 0x0,
383 { &hf_cpfi_frame_type,
384 { "FrmType", "cpfi.frmtype",
385 FT_UINT32, BASE_HEX, NULL, CPFI_FRAME_TYPE_MASK,
386 "Frame Type", HFILL}},
388 { "srcTDA", "cpfi.srcTDA",
389 FT_UINT32, BASE_HEX, NULL, CPFI_SOURCE_MASK,
390 "Source TDA (10 bits)", HFILL}},
392 { "dstTDA", "cpfi.dstTDA",
393 FT_UINT32, BASE_HEX, NULL, CPFI_DEST_MASK,
394 "Source TDA (10 bits)", HFILL}},
396 { "SOFtype", "cpfi.SOFtype",
397 FT_UINT32, BASE_HEX, VALS(sof_type_vals), CPFI_SOF_TYPE_MASK,
400 { "speed", "cpfi.speed",
401 FT_UINT32, BASE_HEX, VALS(speed_vals), CPFI_SPEED_MASK,
403 { &hf_cpfi_OPM_error,
404 { "OPMerror", "cpfi.OPMerror",
405 FT_BOOLEAN, 32, NULL, CPFI_OPM_ERROR_MASK,
406 "OPM Error?", HFILL}},
408 { "fromLCM", "cpfi.fromLCM",
409 FT_BOOLEAN, 32, NULL, CPFI_FROM_LCM_MASK,
410 "from LCM?", HFILL}},
413 { "CRC-32", "cpfi.crc-32",
414 FT_UINT32, BASE_HEX, NULL, 0x0,
418 { "EOFtype", "cpfi.EOFtype",
419 FT_UINT32, BASE_HEX, VALS(eof_type_vals), CPFI_EOF_TYPE_MASK,
422 { &hf_cpfi_t_instance,
423 { "Instance", "cpfi.instance",
425 NULL, 0x0, "", HFILL}},
427 { &hf_cpfi_t_src_instance,
428 { "Source Instance", "cpfi.src_instance",
430 NULL, 0x0, "", HFILL}},
432 { &hf_cpfi_t_dst_instance,
433 { "Destination Instance", "cpfi.dst_instance",
435 NULL, 0x0, "", HFILL}},
438 { "Board", "cpfi.board",
440 NULL, 0x0, "", HFILL}},
442 { &hf_cpfi_t_src_board,
443 { "Source Board", "cpfi.src_board",
445 NULL, 0x0, "", HFILL}},
447 { &hf_cpfi_t_dst_board,
448 { "Destination Board", "cpfi.dst_board",
450 NULL, 0x0, "", HFILL}},
453 { "Port", "cpfi.port",
455 NULL, 0x0, "", HFILL}},
457 { &hf_cpfi_t_src_port,
458 { "Source Port", "cpfi.src_port",
460 NULL, 0x0, "", HFILL}},
462 { &hf_cpfi_t_dst_port,
463 { "Destination Port", "cpfi.dst_port",
465 NULL, 0x0, "", HFILL}},
469 /* Setup protocol subtree array */
470 static gint *ett[] = {
477 /* Register the protocol name and description */
478 proto_cpfi = proto_register_protocol("Cross Point Frame Injector ", "CPFI", "cpfi");
480 /* Required function calls to register the header fields and subtrees used */
481 proto_register_field_array(proto_cpfi, hf, array_length(hf));
482 proto_register_subtree_array(ett, array_length(ett));
484 /* Register our configuration options for CPFI */
485 cpfi_module = prefs_register_protocol(proto_cpfi, proto_reg_handoff_cpfi);
486 prefs_register_uint_preference(cpfi_module, "udp.port", "CPFI UDP Port",
487 "Set the port for CPFI messages (if other"
488 " than the default of 5000)",
490 prefs_register_uint_preference(cpfi_module, "udp.port2", "InstanceToInstance UDP Port",
491 "Set the port for InstanceToInstance messages (if other"
492 " than the default of 5001)",
493 10, &cpfi_ttot_udp_port);
494 prefs_register_bool_preference(cpfi_module, "arrow_ctl",
495 "Enable Active Arrow Control",
496 "Control the way the '-->' is displayed."
497 " When enabled, keeps the 'lowest valued' endpoint of the src-dest pair"
498 " on the left, and the arrow moves to distinguish source from dest."
499 " When disabled, keeps the arrow pointing right so the source of the frame"
500 " is always on the left.",
506 proto_reg_handoff_cpfi(void)
508 static int cpfi_init_complete = FALSE;
509 static dissector_handle_t cpfi_handle;
510 static dissector_handle_t ttot_handle;
511 if ( !cpfi_init_complete )
513 cpfi_init_complete = TRUE;
514 fc_handle = find_dissector("fc");
515 data_handle = find_dissector("data");
516 cpfi_handle = create_dissector_handle(dissect_cpfi, proto_cpfi);
517 ttot_handle = create_dissector_handle(dissect_cpfi, proto_cpfi);
521 dissector_delete("udp.port", cpfi_udp_port, cpfi_handle);
522 dissector_delete("udp.port", cpfi_ttot_udp_port, ttot_handle);
525 dissector_add("udp.port", cpfi_udp_port, cpfi_handle);
526 dissector_add("udp.port", cpfi_ttot_udp_port, ttot_handle);