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>
8 * $Id: packet-cpfi.c,v 1.6 2003/12/21 05:51:33 jmayer Exp $
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.
38 #include <epan/packet.h>
41 void proto_reg_handoff_cpfi(void);
43 #define CPFI_DEFAULT_UDP_PORT 5000
46 #define CPFI_FRAME_TYPE_MASK 0xF0000000
47 #define CPFI_FRAME_TYPE_SHIFT 28
48 #define CPFI_SOURCE_MASK 0x0FFC0000
49 #define CPFI_SOURCE_SHIFT 18
50 #define CPFI_DEST_MASK 0x0003FF00
51 #define CPFI_DEST_SHIFT 8
52 #define CPFI_SOF_TYPE_MASK 0x000000F0
53 #define CPFI_SPEED_MASK 0x0000000C
54 #define CPFI_OPM_ERROR_MASK 0x00000002
55 #define CPFI_FROM_LCM_MASK 0x00000001
58 #define CPFI_EOF_TYPE_MASK 0x78000000
59 #define CPFI_EOF_ERROR_MASK 0x7FE00000
62 /* Initialize the protocol and registered fields */
63 static int proto_cpfi = -1;
64 static guint cpfi_configured_udp_port = CPFI_DEFAULT_UDP_PORT;
65 static guint cpfi_current_udp_port;
66 static int hf_cpfi_word_one = -1;
67 static int hf_cpfi_word_two = -1;
69 static int hf_cpfi_frame_type = -1;
70 static int hf_cpfi_source = -1;
71 static int hf_cpfi_dest = -1;
72 static int hf_cpfi_SOF_type = -1;
73 static int hf_cpfi_speed = -1;
74 static int hf_cpfi_OPM_error = -1;
75 static int hf_cpfi_from_LCM = -1;
77 static int hf_cpfi_CRC_32 = -1;
78 static int hf_cpfi_EOF_type = -1;
82 static guint8 frame_type;
85 const char *direction_and_port_string = "%u:%u";
87 /* Initialize the subtree pointers */
88 static gint ett_cpfi = -1;
89 static gint ett_cpfi_header = -1;
90 static gint ett_cpfi_footer = -1;
92 static dissector_handle_t fc_handle;
93 static dissector_handle_t data_handle;
96 static const value_string sof_type_vals[] = {
111 static const value_string speed_vals[] = {
119 static const value_string eof_type_vals[] = {
133 dissect_cpfi_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
136 proto_item *extra_item = NULL;
137 proto_tree *extra_tree = NULL;
139 /* add a tree for the header */
142 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Header");
143 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_header);
146 /* Extract the common header, and get the bits we need */
147 word1 = tvb_get_ntohl (tvb, 0);
148 word2 = tvb_get_ntohl (tvb, sizeof(word1));
150 frame_type = (word1 & CPFI_FRAME_TYPE_MASK) >> CPFI_FRAME_TYPE_SHIFT;
151 /* Choose either source or dest as the one to display */
152 if (pinfo->srcport == cpfi_current_udp_port)
154 direction_and_port_string = "[CPFI <-- % 2u/%-2u] ";
155 tda = (word1 & CPFI_DEST_MASK) >> CPFI_DEST_SHIFT;
159 direction_and_port_string = "[CPFI --> % 2u/%-2u] ";
160 tda = (word1 & CPFI_SOURCE_MASK) >> CPFI_SOURCE_SHIFT;
166 /* add word 1 components to the protocol tree */
167 proto_tree_add_item(extra_tree, hf_cpfi_word_one , tvb, 0, 4, FALSE);
169 proto_tree_add_item(extra_tree, hf_cpfi_frame_type, tvb, 0, 4, FALSE);
170 proto_tree_add_item(extra_tree, hf_cpfi_source , tvb, 0, 4, FALSE);
171 proto_tree_add_item(extra_tree, hf_cpfi_dest , tvb, 0, 4, FALSE);
172 proto_tree_add_item(extra_tree, hf_cpfi_SOF_type , tvb, 0, 4, FALSE);
173 proto_tree_add_item(extra_tree, hf_cpfi_speed , tvb, 0, 4, FALSE);
174 proto_tree_add_item(extra_tree, hf_cpfi_OPM_error , tvb, 0, 4, FALSE);
175 proto_tree_add_item(extra_tree, hf_cpfi_from_LCM , tvb, 0, 4, FALSE);
177 /* add word 2 components to the protocol tree */
178 proto_tree_add_item(extra_tree, hf_cpfi_word_two , tvb, 4, 4, FALSE);
184 dissect_cpfi_footer(tvbuff_t *tvb, proto_tree *tree)
186 proto_item *extra_item = NULL;
187 proto_tree *extra_tree = NULL;
189 /* add a tree for the footer */
192 extra_item = proto_tree_add_protocol_format(tree, proto_cpfi, tvb, 0, -1, "Footer");
193 extra_tree = proto_item_add_subtree(extra_item, ett_cpfi_footer);
197 proto_tree_add_item(extra_tree, hf_cpfi_CRC_32 , tvb, 0, 4, FALSE);
198 proto_tree_add_item(extra_tree, hf_cpfi_EOF_type, tvb, 4, 4, FALSE);
204 dissect_cpfi(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
206 tvbuff_t *header_tvb, *body_tvb, *footer_tvb;
207 proto_item *cpfi_item = NULL;
208 proto_tree *cpfi_tree = NULL;
209 gint length, reported_length, body_length, reported_body_length;
211 /* In the interest of speed, if "tree" is NULL, don't do any work not
212 necessary to generate protocol tree items. */
214 /* create the protocol tree */
215 cpfi_item = proto_tree_add_item(tree, proto_cpfi, message_tvb, 0, -1, FALSE);
216 cpfi_tree = proto_item_add_subtree(cpfi_item, ett_cpfi);
219 /* Set up the frame controls - can we do better than this? */
221 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
222 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
223 pinfo->sof_eof |= PINFO_EOF_INVALID;
225 /* dissect the message */
227 /* extract and process the header */
228 header_tvb = tvb_new_subset(message_tvb, 0, 8, 8);
229 dissect_cpfi_header(header_tvb, pinfo, cpfi_tree);
231 /* Got good CPFI frame? */
232 if ( (frame_type == 9) && fc_handle )
234 /* create a tvb for the rest of the fc frame (exclude the checksum and CPFI trailer) */
235 length = tvb_length_remaining(message_tvb, 8);
236 reported_length = tvb_reported_length_remaining(message_tvb, 8);
237 if (reported_length < 8)
239 /* We don't even have enough for the footer. */
240 body_tvb = tvb_new_subset(message_tvb, 8, -1, -1);
241 call_dissector(data_handle, body_tvb, pinfo, tree);
244 /* Length of packet, minus the footer. */
245 reported_body_length = reported_length - 8;
246 /* How much of that do we have in the tvbuff? */
247 body_length = length;
248 if (body_length > reported_body_length)
249 body_length = reported_body_length;
250 body_tvb = tvb_new_subset(message_tvb, 8, body_length, reported_body_length);
251 call_dissector(fc_handle, body_tvb, pinfo, tree);
253 /* add more info, now that FC added it's */
254 proto_item_append_text(cpfi_item, direction_and_port_string, board, port);
255 if (check_col(pinfo->cinfo, COL_INFO))
257 col_prepend_fstr(pinfo->cinfo, COL_INFO, direction_and_port_string, board, port);
261 length = tvb_length_remaining(message_tvb, 8+body_length);
264 /* The footer wasn't captured at all.
265 XXX - we'd like to throw a BoundsError if that's the case. */
268 footer_tvb = tvb_new_subset(message_tvb, 8+body_length, length, 8);
269 dissect_cpfi_footer(footer_tvb, cpfi_tree);
271 else if ( data_handle )
273 /* create a tvb for the rest of the frame */
274 body_tvb = tvb_new_subset(message_tvb, 8, -1, -1);
275 call_dissector(data_handle, body_tvb, pinfo, tree);
280 /* Register the protocol with Ethereal */
282 proto_register_cpfi(void)
284 module_t *cpfi_module;
286 /* Setup list of header fields */
287 static hf_register_info hf[] = {
289 { "Word one", "cpfi.word_one",
290 FT_UINT32, BASE_HEX, NULL, 0x0,
293 { "Word two", "cfpi.word_two",
294 FT_UINT32, BASE_HEX, NULL, 0x0,
297 { &hf_cpfi_frame_type,
298 { "FrmType", "cpfi.frmtype",
299 FT_UINT32, BASE_HEX, NULL, CPFI_FRAME_TYPE_MASK,
300 "Frame Type", HFILL}},
302 { "srcTDA", "cpfi.srcTDA",
303 FT_UINT32, BASE_HEX, NULL, CPFI_SOURCE_MASK,
304 "Source TDA (10 bits)", HFILL}},
306 { "dstTDA", "cpfi.dstTDA",
307 FT_UINT32, BASE_HEX, NULL, CPFI_DEST_MASK,
308 "Source TDA (10 bits)", HFILL}},
310 { "SOFtype", "cpfi.SOFtype",
311 FT_UINT32, BASE_HEX, VALS(sof_type_vals), CPFI_SOF_TYPE_MASK,
314 { "speed", "cpfi.speed",
315 FT_UINT32, BASE_HEX, VALS(speed_vals), CPFI_SPEED_MASK,
317 { &hf_cpfi_OPM_error,
318 { "OPMerror", "cpfi.OPMerror",
319 FT_BOOLEAN, 32, NULL, CPFI_OPM_ERROR_MASK,
320 "OPM Error?", HFILL}},
322 { "fromLCM", "cpfi.fromLCM",
323 FT_BOOLEAN, 32, NULL, CPFI_FROM_LCM_MASK,
324 "from LCM?", HFILL}},
327 { "CRC-32", "cpfi.crc-32",
328 FT_UINT32, BASE_HEX, NULL, 0x0,
332 { "EOFtype", "cpfi.EOFtype",
333 FT_UINT32, BASE_HEX, VALS(eof_type_vals), CPFI_EOF_TYPE_MASK,
338 /* Setup protocol subtree array */
339 static gint *ett[] = {
345 /* Register the protocol name and description */
346 proto_cpfi = proto_register_protocol("Cross Point Frame Injector ", "CPFI", "cpfi");
348 /* Required function calls to register the header fields and subtrees used */
349 proto_register_field_array(proto_cpfi, hf, array_length(hf));
350 proto_register_subtree_array(ett, array_length(ett));
352 /* Register our configuration options for CPFI */
353 cpfi_module = prefs_register_protocol(proto_cpfi, proto_reg_handoff_cpfi);
354 prefs_register_uint_preference(cpfi_module, "udp.port", "CPFI UDP Port",
355 "Set the port for CPFI messages (if other"
356 " than the default of 5000)",
357 10, &cpfi_configured_udp_port);
361 proto_reg_handoff_cpfi(void)
363 static int cpfi_init_complete = FALSE;
364 static dissector_handle_t cpfi_handle;
365 if ( !cpfi_init_complete )
367 cpfi_init_complete = TRUE;
368 fc_handle = find_dissector("fc");
369 data_handle = find_dissector("data");
370 cpfi_handle = create_dissector_handle(dissect_cpfi, proto_cpfi);
374 dissector_delete("udp.port", cpfi_current_udp_port, cpfi_handle);
377 /* remember udp port for later use */
378 cpfi_current_udp_port = cpfi_configured_udp_port;
380 dissector_add("udp.port", cpfi_current_udp_port, cpfi_handle);