2 * Routines for decoding MDS Port Analyzer Adapter (FC in Eth) Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/etypes.h>
33 #define BRDWLK_MAX_PACKET_CNT 0xFFFF
34 #define BRDWLK_TRUNCATED_BIT 0x8
35 #define BRDWLK_HAS_PLEN 0x1
37 #define FCM_DELIM_SOFC1 0x01
38 #define FCM_DELIM_SOFI1 0x02
39 #define FCM_DELIM_SOFI2 0x04
40 #define FCM_DELIM_SOFI3 0x06
41 #define FCM_DELIM_SOFN1 0x03
42 #define FCM_DELIM_SOFN2 0x05
43 #define FCM_DELIM_SOFN3 0x07
44 #define FCM_DELIM_SOFF 0x08
45 #define FCM_DELIM_SOFC4 0x09
46 #define FCM_DELIM_SOFI4 0x0A
47 #define FCM_DELIM_SOFN4 0x0B
49 #define FCM_DELIM_EOFT 0x01
50 #define FCM_DELIM_EOFDT 0x02
51 #define FCM_DELIM_EOFN 0x03
52 #define FCM_DELIM_EOFA 0x04
53 #define FCM_DELIM_EOFNI 0x07
54 #define FCM_DELIM_EOFDTI 0x06
55 #define FCM_DELIM_EOFRT 0x0A
56 #define FCM_DELIM_EOFRTI 0x0E
57 #define FCM_DELIM_NOEOF 0xF0
58 #define FCM_DELIM_EOFJUMBO 0xF1
60 void proto_register_brdwlk(void);
61 void proto_reg_handoff_brdwlk(void);
63 static const value_string brdwlk_sof_vals[] = {
64 {FCM_DELIM_SOFI1, "SOFi1"},
65 {FCM_DELIM_SOFI2, "SOFi2"},
66 {FCM_DELIM_SOFI3, "SOFi3"},
67 {FCM_DELIM_SOFN1, "SOFn1"},
68 {FCM_DELIM_SOFN2, "SOFn2"},
69 {FCM_DELIM_SOFN3, "SOFn3"},
70 {FCM_DELIM_SOFF, "SOFf"},
74 static const value_string brdwlk_eof_vals[] = {
75 {FCM_DELIM_EOFDT, "EOFdt"},
76 {FCM_DELIM_EOFA, "EOFa"},
77 {FCM_DELIM_EOFN, "EOFn"},
78 {FCM_DELIM_EOFT, "EOFt"},
82 static int hf_brdwlk_sof = -1;
83 static int hf_brdwlk_eof = -1;
84 static int hf_brdwlk_error = -1;
85 static int hf_brdwlk_vsan = -1;
86 static int hf_brdwlk_pktcnt = -1;
87 static int hf_brdwlk_drop = -1;
88 static int hf_brdwlk_plen = -1;
89 static int hf_brdwlk_error_plp = -1;
90 static int hf_brdwlk_error_ef = -1;
91 static int hf_brdwlk_error_nd = -1;
92 static int hf_brdwlk_error_tr = -1;
93 static int hf_brdwlk_error_badcrc = -1;
94 static int hf_brdwlk_error_ff = -1;
95 static int hf_brdwlk_error_jumbo = -1;
96 static int hf_brdwlk_error_ctrl = -1;
98 /* Initialize the subtree pointers */
99 static gint ett_brdwlk = -1;
100 static gint ett_brdwlk_error = -1;
102 static gint proto_brdwlk = -1;
104 static guint16 packet_count = 0;
105 static gboolean first_pkt = TRUE; /* start of capture */
107 static dissector_handle_t fc_dissector_handle;
110 static const true_false_string tfs_error_plp = {
111 "Packet Length is PRESENT",
112 "Packet length is NOT present"
114 static const true_false_string tfs_error_ef = {
115 "This is an Empty Frame",
118 static const true_false_string tfs_error_nd = {
119 "This Frame has NO Data",
120 "This frame carries data"
122 static const true_false_string tfs_error_tr = {
123 "This frame is TRUNCATED",
124 "This frame is NOT truncated"
126 static const true_false_string tfs_error_crc = {
127 "This Frame has a BAD FC CRC",
128 "This frame has a valid crc"
130 static const true_false_string tfs_error_ff = {
134 static const true_false_string tfs_error_jumbo = {
135 "This is a JUMBO FC Frame",
136 "This is a NORMAL FC Frame"
138 static const true_false_string tfs_error_ctrl = {
139 "Ctrl Characters inside the frame",
140 "No ctrl chars inside the frame"
144 dissect_brdwlk_err(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
146 proto_item *item = NULL;
147 proto_tree *tree = NULL;
150 flags = tvb_get_guint8(tvb, offset);
152 item=proto_tree_add_uint(parent_tree, hf_brdwlk_error,
153 tvb, offset, 1, flags);
154 tree=proto_item_add_subtree(item, ett_brdwlk_error);
158 proto_tree_add_boolean(tree, hf_brdwlk_error_plp, tvb, offset, 1, flags);
160 proto_item_append_text(item, " Packet Length Present");
162 flags &= (~( 0x01 ));
164 proto_tree_add_boolean(tree, hf_brdwlk_error_ef, tvb, offset, 1, flags);
166 proto_item_append_text(item, " Empty Frame");
168 flags &= (~( 0x02 ));
170 proto_tree_add_boolean(tree, hf_brdwlk_error_nd, tvb, offset, 1, flags);
172 proto_item_append_text(item, " No Data");
174 flags &= (~( 0x04 ));
176 proto_tree_add_boolean(tree, hf_brdwlk_error_tr, tvb, offset, 1, flags);
178 proto_item_append_text(item, " Truncated");
180 flags &= (~( 0x08 ));
182 proto_tree_add_boolean(tree, hf_brdwlk_error_badcrc, tvb, offset, 1, flags);
184 proto_item_append_text(item, " Bad FC CRC");
186 flags &= (~( 0x10 ));
188 proto_tree_add_boolean(tree, hf_brdwlk_error_ff, tvb, offset, 1, flags);
190 proto_item_append_text(item, " Fifo Full");
192 flags &= (~( 0x20 ));
194 proto_tree_add_boolean(tree, hf_brdwlk_error_jumbo, tvb, offset, 1, flags);
196 proto_item_append_text(item, " Jumbo FC Frame");
198 flags &= (~( 0x40 ));
200 proto_tree_add_boolean(tree, hf_brdwlk_error_ctrl, tvb, offset, 1, flags);
202 proto_item_append_text(item, " Ctrl Char Inside Frame");
204 /*flags &= (~( 0x80 ));*/
207 /* Code to actually dissect the packets */
209 dissect_brdwlk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
212 /* Set up structures needed to add the protocol subtree and manage it */
213 proto_item *ti, *hidden_item;
214 proto_tree *brdwlk_tree = NULL;
216 guint8 error, eof, sof;
219 gint len, reported_len, plen;
221 gboolean dropped_packets;
223 /* Make entries in Protocol column and Info column on summary display */
224 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Boardwalk");
226 col_clear(pinfo->cinfo, COL_INFO);
228 pinfo->vsan = (tvb_get_ntohs(tvb, offset) & 0xFFF);
229 sof = (tvb_get_guint8(tvb, offset) & 0xF0) >> 4;
231 if ((sof == FCM_DELIM_SOFI3) || (sof == FCM_DELIM_SOFI2) || (sof == FCM_DELIM_SOFI1)
232 || (sof == FCM_DELIM_SOFI4)) {
233 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
235 else if (sof == FCM_DELIM_SOFF) {
236 pinfo->sof_eof = PINFO_SOF_SOFF;
240 ti = proto_tree_add_protocol_format(tree, proto_brdwlk, tvb, 0,
241 hdrlen, "Boardwalk");
243 brdwlk_tree = proto_item_add_subtree(ti, ett_brdwlk);
245 proto_tree_add_item(brdwlk_tree, hf_brdwlk_sof, tvb, offset, 1, ENC_BIG_ENDIAN);
246 proto_tree_add_item(brdwlk_tree, hf_brdwlk_vsan, tvb, offset, 2, ENC_BIG_ENDIAN);
250 /* Locate EOF which is the last 4 bytes of the frame */
251 len = tvb_length_remaining(tvb, hdrlen);
252 reported_len = tvb_reported_length_remaining(tvb, hdrlen);
253 if (reported_len < 4) {
255 * This packet is claimed not to even have enough data for
257 * Don't try to process the EOF.
261 else if (len < reported_len) {
263 * This packet is claimed to have enough data for a 4-byte EOF,
264 * but we didn't capture all of the packet.
265 * Slice off the 4-byte EOF from the reported length, and trim
266 * the captured length so it's no more than the reported length;
267 * that will slice off what of the EOF, if any, is in the
271 if (len > reported_len)
276 * We have the entire packet, and it includes a 4-byte EOF.
277 * Slice it off, and put it into the tree if we're building
282 offset = tvb_reported_length(tvb) - 4;
283 pkt_cnt = tvb_get_ntohs(tvb, offset);
285 proto_tree_add_uint(brdwlk_tree, hf_brdwlk_pktcnt, tvb, offset,
288 dropped_packets = FALSE;
289 if (pinfo->fd->flags.visited) {
291 * This isn't the first pass, so we can't use the global
292 * "packet_count" variable to determine whether there were
293 * any dropped frames or not.
294 * We therefore attach a non-null pointer as frame data to
295 * any frame preceded by dropped packets.
297 if (p_get_proto_data(pinfo->fd, proto_brdwlk, 0) != NULL)
298 dropped_packets = TRUE;
301 * This is the first pass, so we have to use the global
302 * "packet_count" variable to determine whether there were
303 * any dropped frames or not.
305 * XXX - can there be more than one stream of packets, so that
306 * we can't just use a global variable?
308 if (pkt_cnt != packet_count + 1) {
310 (pkt_cnt != 0 || (packet_count != BRDWLK_MAX_PACKET_CNT))) {
311 dropped_packets = TRUE;
314 * Mark this frame as having been preceded by dropped
315 * packets. (The data we use as the frame data doesn't
316 * matter - it just matters that it's non-null.)
318 p_add_proto_data(pinfo->fd, proto_brdwlk, 0, &packet_count);
323 hidden_item = proto_tree_add_boolean(brdwlk_tree, hf_brdwlk_drop,
324 tvb, offset, 0, dropped_packets);
325 PROTO_ITEM_SET_HIDDEN(hidden_item);
328 packet_count = pkt_cnt;
330 error=tvb_get_guint8(tvb, offset+2);
331 dissect_brdwlk_err(brdwlk_tree, tvb, offset+2);
333 eof = tvb_get_guint8(tvb, offset+3);
334 if (eof != FCM_DELIM_EOFN) {
335 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
337 else if (eof != FCM_DELIM_EOFT) {
338 pinfo->sof_eof |= PINFO_EOF_INVALID;
342 proto_tree_add_item(brdwlk_tree, hf_brdwlk_eof, tvb, offset+3,
346 if ((error & BRDWLK_HAS_PLEN) && tree) {
347 /* In newer Boardwalks, if this bit is set, the actual frame length
348 * is also provided. This length is the size between SOF & EOF
351 plen = tvb_get_ntohl(tvb, offset-4);
353 proto_tree_add_uint(brdwlk_tree, hf_brdwlk_plen, tvb, offset-4,
357 /* XXX - this would throw an exception if it would increase
358 * the reported length.
360 if (error & BRDWLK_TRUNCATED_BIT) {
361 tvb_set_reported_length(tvb, plen);
367 next_tvb = tvb_new_subset(tvb, 2, len, reported_len);
368 call_dissector(fc_dissector_handle, next_tvb, pinfo, tree);
378 /* Register the protocol with Wireshark */
380 /* this format is require because a script is used to build the C function
381 that calls all the protocol registration.
385 proto_register_brdwlk(void)
388 /* Setup list of header fields See Section 1.6.1 for details*/
389 static hf_register_info hf[] = {
391 {"SOF", "brdwlk.sof", FT_UINT8, BASE_HEX, VALS(brdwlk_sof_vals),
394 {"EOF", "brdwlk.eof", FT_UINT8, BASE_HEX, VALS(brdwlk_eof_vals),
397 {"Error", "brdwlk.error", FT_UINT8, BASE_HEX, NULL, 0x0, NULL,
400 {"Packet Count", "brdwlk.pktcnt", FT_UINT16, BASE_DEC, NULL, 0x0,
403 {"Packet Dropped", "brdwlk.drop", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
406 {"VSAN", "brdwlk.vsan", FT_UINT16, BASE_DEC, NULL, 0xFFF, NULL,
409 {"Original Packet Length", "brdwlk.plen", FT_UINT32, BASE_DEC, NULL, 0x0, NULL,
411 { &hf_brdwlk_error_plp,
412 {"Packet Length Present", "brdwlk.error.plp", FT_BOOLEAN, 8, TFS(&tfs_error_plp), 0x01, NULL,
414 { &hf_brdwlk_error_ef,
415 {"Empty Frame", "brdwlk.error.ef", FT_BOOLEAN, 8, TFS(&tfs_error_ef), 0x02, NULL,
417 { &hf_brdwlk_error_nd,
418 {"No Data", "brdwlk.error.nd", FT_BOOLEAN, 8, TFS(&tfs_error_nd), 0x04, NULL,
420 { &hf_brdwlk_error_tr,
421 {"Truncated", "brdwlk.error.tr", FT_BOOLEAN, 8, TFS(&tfs_error_tr), 0x08, NULL,
423 { &hf_brdwlk_error_badcrc,
424 {"CRC", "brdwlk.error.crc", FT_BOOLEAN, 8, TFS(&tfs_error_crc), 0x10, NULL,
426 { &hf_brdwlk_error_ff,
427 {"Fifo Full", "brdwlk.error.ff", FT_BOOLEAN, 8, TFS(&tfs_error_ff), 0x20, NULL,
429 { &hf_brdwlk_error_jumbo,
430 {"Jumbo FC Frame", "brdwlk.error.jumbo", FT_BOOLEAN, 8, TFS(&tfs_error_jumbo), 0x40, NULL,
432 { &hf_brdwlk_error_ctrl,
433 {"Ctrl Char Inside Frame", "brdwlk.error.ctrl", FT_BOOLEAN, 8, TFS(&tfs_error_ctrl), 0x80, NULL,
437 /* Setup protocol subtree array */
438 static gint *ett[] = {
443 /* Register the protocol name and description */
444 proto_brdwlk = proto_register_protocol("Boardwalk",
445 "Boardwalk", "brdwlk");
447 /* Required function calls to register the header fields and subtrees used */
448 proto_register_field_array(proto_brdwlk, hf, array_length(hf));
449 proto_register_subtree_array(ett, array_length(ett));
451 register_init_routine(&brdwlk_init);
456 proto_reg_handoff_brdwlk(void)
458 dissector_handle_t brdwlk_handle;
460 brdwlk_handle = create_dissector_handle(dissect_brdwlk, proto_brdwlk);
461 dissector_add_uint("ethertype", ETHERTYPE_BRDWALK, brdwlk_handle);
462 dissector_add_uint("ethertype", 0xABCD, brdwlk_handle);
463 fc_dissector_handle = find_dissector("fc");