2 * Routines for decoding MDS Port Analyzer Adapter (FC in Eth) Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
44 #include <epan/packet.h>
45 #include <epan/etypes.h>
47 #define BRDWLK_MAX_PACKET_CNT 0xFFFF
48 #define BRDWLK_TRUNCATED_BIT 0x8
49 #define BRDWLK_HAS_PLEN 0x1
51 #define FCM_DELIM_SOFC1 0x01
52 #define FCM_DELIM_SOFI1 0x02
53 #define FCM_DELIM_SOFI2 0x04
54 #define FCM_DELIM_SOFI3 0x06
55 #define FCM_DELIM_SOFN1 0x03
56 #define FCM_DELIM_SOFN2 0x05
57 #define FCM_DELIM_SOFN3 0x07
58 #define FCM_DELIM_SOFF 0x08
59 #define FCM_DELIM_SOFC4 0x09
60 #define FCM_DELIM_SOFI4 0x0A
61 #define FCM_DELIM_SOFN4 0x0B
63 #define FCM_DELIM_EOFT 0x01
64 #define FCM_DELIM_EOFDT 0x02
65 #define FCM_DELIM_EOFN 0x03
66 #define FCM_DELIM_EOFA 0x04
67 #define FCM_DELIM_EOFNI 0x07
68 #define FCM_DELIM_EOFDTI 0x06
69 #define FCM_DELIM_EOFRT 0x0A
70 #define FCM_DELIM_EOFRTI 0x0E
71 #define FCM_DELIM_NOEOF 0xF0
72 #define FCM_DELIM_EOFJUMBO 0xF1
74 static const value_string brdwlk_sof_vals[] = {
75 {FCM_DELIM_SOFI1, "SOFi1"},
76 {FCM_DELIM_SOFI2, "SOFi2"},
77 {FCM_DELIM_SOFI3, "SOFi3"},
78 {FCM_DELIM_SOFN1, "SOFn1"},
79 {FCM_DELIM_SOFN2, "SOFn2"},
80 {FCM_DELIM_SOFN3, "SOFn3"},
81 {FCM_DELIM_SOFF, "SOFf"},
85 static const value_string brdwlk_eof_vals[] = {
86 {FCM_DELIM_EOFDT, "EOFdt"},
87 {FCM_DELIM_EOFA, "EOFa"},
88 {FCM_DELIM_EOFN, "EOFn"},
89 {FCM_DELIM_EOFT, "EOFt"},
93 static int hf_brdwlk_sof = -1;
94 static int hf_brdwlk_eof = -1;
95 static int hf_brdwlk_error = -1;
96 static int hf_brdwlk_vsan = -1;
97 static int hf_brdwlk_pktcnt = -1;
98 static int hf_brdwlk_drop = -1;
99 static int hf_brdwlk_plen = -1;
101 /* Initialize the subtree pointers */
102 static gint ett_brdwlk = -1;
104 static gint proto_brdwlk = -1;
106 static guint16 packet_count = 0;
107 static gboolean first_pkt = TRUE; /* start of capture */
109 static dissector_handle_t data_handle;
110 static dissector_handle_t fc_dissector_handle;
113 brdwlk_err_to_str (guint8 error, char *str)
119 strcat (str, "Packet Length Present");
123 strcat (str, "Empty Frame, ");
127 strcat (str, "No Data, ");
131 strcat (str, "Truncated, ");
135 strcat (str, "Bad FC CRC, ");
139 strcat (str, "Fifo Full, ");
143 strcat (str, "Jumbo FC Frame, ");
147 strcat (str, "Ctrl Char Inside Frame");
154 /* Code to actually dissect the packets */
156 dissect_brdwlk (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
159 /* Set up structures needed to add the protocol subtree and manage it */
161 proto_tree *brdwlk_tree = NULL;
163 guint8 error, eof, sof;
166 gint len, reported_len, plen;
168 gboolean dropped_packets;
171 /* Make entries in Protocol column and Info column on summary display */
172 if (check_col(pinfo->cinfo, COL_PROTOCOL))
173 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Boardwalk");
175 if (check_col(pinfo->cinfo, COL_INFO))
176 col_clear(pinfo->cinfo, COL_INFO);
178 pinfo->vsan = (tvb_get_ntohs (tvb, offset) & 0xFFF);
179 sof = (tvb_get_guint8 (tvb, offset) & 0xF0) >> 4;
181 if ((sof == FCM_DELIM_SOFI3) || (sof == FCM_DELIM_SOFI2) || (sof == FCM_DELIM_SOFI1)
182 || (sof == FCM_DELIM_SOFI4)) {
183 pinfo->sof_eof = PINFO_SOF_FIRST_FRAME;
185 else if (sof == FCM_DELIM_SOFF) {
186 pinfo->sof_eof = PINFO_SOF_SOFF;
190 ti = proto_tree_add_protocol_format (tree, proto_brdwlk, tvb, 0,
191 hdrlen, "Boardwalk");
193 brdwlk_tree = proto_item_add_subtree (ti, ett_brdwlk);
195 proto_tree_add_item (brdwlk_tree, hf_brdwlk_sof, tvb, offset, 1, 0);
196 proto_tree_add_item (brdwlk_tree, hf_brdwlk_vsan, tvb, offset, 2, 0);
200 /* Locate EOF which is the last 4 bytes of the frame */
201 len = tvb_length_remaining(tvb, hdrlen);
202 reported_len = tvb_reported_length_remaining(tvb, hdrlen);
203 if (reported_len < 4) {
205 * This packet is claimed not to even have enough data for
207 * Don't try to process the EOF.
211 else if (len < reported_len) {
213 * This packet is claimed to have enough data for a 4-byte EOF,
214 * but we didn't capture all of the packet.
215 * Slice off the 4-byte EOF from the reported length, and trim
216 * the captured length so it's no more than the reported length;
217 * that will slice off what of the EOF, if any, is in the
221 if (len > reported_len)
226 * We have the entire packet, and it includes a 4-byte EOF.
227 * Slice it off, and put it into the tree if we're building
232 offset = tvb_reported_length(tvb) - 4;
233 pkt_cnt = tvb_get_ntohs (tvb, offset);
235 proto_tree_add_uint (brdwlk_tree, hf_brdwlk_pktcnt, tvb, offset,
238 dropped_packets = FALSE;
239 if (pinfo->fd->flags.visited) {
241 * This isn't the first pass, so we can't use the global
242 * "packet_count" variable to determine whether there were
243 * any dropped frames or not.
244 * We therefore attach a non-null pointer as frame data to
245 * any frame preceded by dropped packets.
247 if (p_get_proto_data(pinfo->fd, proto_brdwlk) != NULL)
248 dropped_packets = TRUE;
251 * This is the first pass, so we have to use the global
252 * "packet_count" variable to determine whether there were
253 * any dropped frames or not.
255 * XXX - can there be more than one stream of packets, so that
256 * we can't just use a global variable?
258 if (pkt_cnt != packet_count + 1) {
260 (pkt_cnt != 0 || (packet_count != BRDWLK_MAX_PACKET_CNT))) {
261 dropped_packets = TRUE;
264 * Mark this frame as having been preceded by dropped
265 * packets. (The data we use as the frame data doesn't
266 * matter - it just matters that it's non-null.)
268 p_add_proto_data(pinfo->fd, proto_brdwlk, &packet_count);
273 proto_tree_add_boolean_hidden (brdwlk_tree, hf_brdwlk_drop,
274 tvb, offset, 0, dropped_packets);
277 packet_count = pkt_cnt;
279 error = tvb_get_guint8 (tvb, offset+2);
281 proto_tree_add_uint_format (brdwlk_tree, hf_brdwlk_error, tvb,
282 offset+2, 1, error, "Error: 0x%x (%s)",
284 brdwlk_err_to_str (error, errstr));
287 eof = tvb_get_guint8 (tvb, offset+3);
288 if (eof != FCM_DELIM_EOFN) {
289 pinfo->sof_eof |= PINFO_EOF_LAST_FRAME;
291 else if (eof != FCM_DELIM_EOFT) {
292 pinfo->sof_eof |= PINFO_EOF_INVALID;
296 proto_tree_add_item (brdwlk_tree, hf_brdwlk_eof, tvb, offset+3,
300 if ((error & BRDWLK_HAS_PLEN) && tree) {
301 /* In newer Boardwalks, if this bit is set, the actual frame length
302 * is also provided. This length is the size between SOF & EOF
305 plen = tvb_get_ntohl (tvb, offset-4);
307 proto_tree_add_uint (brdwlk_tree, hf_brdwlk_plen, tvb, offset-4,
311 /* XXX - this would throw an exception if it would increase
312 * the reported length.
314 if (error & BRDWLK_TRUNCATED_BIT) {
315 tvb_set_reported_length (tvb, plen);
321 next_tvb = tvb_new_subset (tvb, 2, len, reported_len);
322 if (fc_dissector_handle) {
323 call_dissector (fc_dissector_handle, next_tvb, pinfo, tree);
334 /* Register the protocol with Ethereal */
336 /* this format is require because a script is used to build the C function
337 that calls all the protocol registration.
341 proto_register_brdwlk (void)
344 /* Setup list of header fields See Section 1.6.1 for details*/
345 static hf_register_info hf[] = {
347 {"SOF", "brdwlk.sof", FT_UINT8, BASE_HEX, VALS (brdwlk_sof_vals),
348 0xF0, "SOF", HFILL}},
350 {"EOF", "brdwlk.eof", FT_UINT8, BASE_HEX, VALS (brdwlk_eof_vals),
351 0x0F, "EOF", HFILL}},
353 {"Error", "brdwlk.error", FT_UINT8, BASE_DEC, NULL, 0x0, "Error",
356 {"Packet Count", "brdwlk.pktcnt", FT_UINT16, BASE_DEC, NULL, 0x0,
359 {"Packet Dropped", "brdwlk.drop", FT_BOOLEAN, BASE_DEC, NULL, 0x0,
362 {"VSAN", "brdwlk.vsan", FT_UINT16, BASE_DEC, NULL, 0xFFF, "",
365 {"Original Packet Length", "brdwlk.plen", FT_UINT32, BASE_DEC, NULL, 0x0, "",
369 /* Setup protocol subtree array */
370 static gint *ett[] = {
374 /* Register the protocol name and description */
375 proto_brdwlk = proto_register_protocol("Boardwalk",
376 "Boardwalk", "brdwlk");
378 /* Required function calls to register the header fields and subtrees used */
379 proto_register_field_array(proto_brdwlk, hf, array_length(hf));
380 proto_register_subtree_array(ett, array_length(ett));
382 register_init_routine(&brdwlk_init);
386 /* If this dissector uses sub-dissector registration add a registration routine.
387 This format is required because a script is used to find these routines and
388 create the code that calls these routines.
391 proto_reg_handoff_brdwlk(void)
393 dissector_handle_t brdwlk_handle;
395 brdwlk_handle = create_dissector_handle (dissect_brdwlk, proto_brdwlk);
396 dissector_add("ethertype", ETHERTYPE_BRDWALK, brdwlk_handle);
397 dissector_add("ethertype", 0xABCD, brdwlk_handle);
398 data_handle = find_dissector("data");
399 fc_dissector_handle = find_dissector ("fc");