2 * Routines for decoding MDS Port Analyzer Adapter (FC in Eth) Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
5 * $Id: packet-brdwlk.c,v 1.2 2003/01/23 07:01:52 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * Copied from WHATEVER_FILE_YOU_USED (where "WHATEVER_FILE_YOU_USED"
12 * is a dissector file; if you just copied this from README.developer,
13 * don't bother with the "Copied from" - you don't even need to put
14 * in a "Copied from" if you copied an existing dissector, especially
15 * if the bulk of the code in the new dissector is your code)
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 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
50 #ifdef NEED_SNPRINTF_H
51 # include "snprintf.h"
54 #include <epan/packet.h>
57 #define BRDWLK_MAX_PACKET_CNT 0xFFFF
58 #define BRDWLK_TRUNCATED_BIT 0x8
60 #define FCM_DELIM_SOFC1 0x01
61 #define FCM_DELIM_SOFI1 0x02
62 #define FCM_DELIM_SOFI2 0x04
63 #define FCM_DELIM_SOFI3 0x06
64 #define FCM_DELIM_SOFN1 0x03
65 #define FCM_DELIM_SOFN2 0x05
66 #define FCM_DELIM_SOFN3 0x07
67 #define FCM_DELIM_SOFF 0x08
68 #define FCM_DELIM_SOFC4 0x09
69 #define FCM_DELIM_SOFI4 0x0A
70 #define FCM_DELIM_SOFN4 0x0B
72 #define FCM_DELIM_EOFT 0x01
73 #define FCM_DELIM_EOFDT 0x02
74 #define FCM_DELIM_EOFN 0x03
75 #define FCM_DELIM_EOFA 0x04
76 #define FCM_DELIM_EOFNI 0x07
77 #define FCM_DELIM_EOFDTI 0x06
78 #define FCM_DELIM_EOFRT 0x0A
79 #define FCM_DELIM_EOFRTI 0x0E
80 #define FCM_DELIM_NOEOF 0xF0
81 #define FCM_DELIM_EOFJUMBO 0xF1
83 static const value_string brdwlk_sof_vals[] = {
84 {FCM_DELIM_SOFI1, "SOFi1"},
85 {FCM_DELIM_SOFI2, "SOFi2"},
86 {FCM_DELIM_SOFI3, "SOFi3"},
87 {FCM_DELIM_SOFN1, "SOFn1"},
88 {FCM_DELIM_SOFN2, "SOFn2"},
89 {FCM_DELIM_SOFN3, "SOFn3"},
90 {FCM_DELIM_SOFF, "SOFf"},
94 static const value_string brdwlk_eof_vals[] = {
95 {FCM_DELIM_EOFDT, "EOFdt"},
96 {FCM_DELIM_EOFA, "EOFa"},
97 {FCM_DELIM_EOFN, "EOFn"},
98 {FCM_DELIM_EOFT, "EOFt"},
102 static const value_string brdwlk_frametype_vals[] = {
106 static const value_string brdwlk_error_vals[] = {
110 static int hf_brdwlk_sof = -1;
111 static int hf_brdwlk_eof = -1;
112 static int hf_brdwlk_error = -1;
113 static int hf_brdwlk_vsan = -1;
114 static int hf_brdwlk_pktcnt = -1;
115 static int hf_brdwlk_drop = -1;
117 /* Initialize the subtree pointers */
118 static gint ett_brdwlk = -1;
120 static gint proto_brdwlk = -1;
122 static guint16 packet_count = 0;
123 static gboolean first_pkt = TRUE; /* start of capture */
125 static dissector_handle_t data_handle;
126 static dissector_handle_t fc_dissector_handle;
129 brdwlk_err_to_str (guint8 error, char *str)
135 strcat (str, "Empty Frame, ");
139 strcat (str, "No Data, ");
143 strcat (str, "Truncated, ");
147 strcat (str, "Bad FC CRC, ");
151 strcat (str, "Fifo Full, ");
155 strcat (str, "Jumbo FC Frame, ");
159 strcat (str, "Ctrl Char Inside Frame");
166 /* Code to actually dissect the packets */
168 dissect_brdwlk (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
171 /* Set up structures needed to add the protocol subtree and manage it */
173 proto_tree *brdwlk_tree;
181 /* Make entries in Protocol column and Info column on summary display */
182 if (check_col(pinfo->cinfo, COL_PROTOCOL))
183 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Boardwalk");
185 if (check_col(pinfo->cinfo, COL_INFO))
186 col_clear(pinfo->cinfo, COL_INFO);
189 ti = proto_tree_add_protocol_format (tree, proto_brdwlk, tvb, 0,
190 hdrlen, "Boardwalk");
192 brdwlk_tree = proto_item_add_subtree (ti, ett_brdwlk);
194 proto_tree_add_item (brdwlk_tree, hf_brdwlk_sof, tvb, offset, 1, 0);
195 proto_tree_add_item (brdwlk_tree, hf_brdwlk_vsan, tvb, offset, 2, 0);
197 pinfo->vsan = (tvb_get_ntohs (tvb, offset) & 0xFFF);
199 /* Locate EOF which is the last 4 bytes of the frame */
200 offset = tvb_reported_length (tvb) - 4;
201 proto_tree_add_item (brdwlk_tree, hf_brdwlk_pktcnt, tvb, offset,
203 pkt_cnt = tvb_get_ntohs (tvb, offset);
204 if (pkt_cnt != packet_count + 1) {
206 (!pkt_cnt && (packet_count == BRDWLK_MAX_PACKET_CNT))) {
207 proto_tree_add_boolean_hidden (brdwlk_tree, hf_brdwlk_drop, tvb,
211 proto_tree_add_boolean_hidden (brdwlk_tree, hf_brdwlk_drop, tvb,
215 packet_count = pkt_cnt;
217 error = tvb_get_guint8 (tvb, offset+2);
218 proto_tree_add_uint_format (brdwlk_tree, hf_brdwlk_error, tvb, offset+2,
219 1, error, "Error: 0x%x (%s)",
220 error, brdwlk_err_to_str (error, errstr));
222 /* If received frame is truncated, set is_truncated flag */
223 if (error & BRDWLK_TRUNCATED_BIT) {
224 pinfo->is_truncated = TRUE;
228 proto_tree_add_item (brdwlk_tree, hf_brdwlk_eof, tvb, offset+3,
232 next_tvb = tvb_new_subset (tvb, 2, -1, -1);
233 if (fc_dissector_handle) {
234 call_dissector (fc_dissector_handle, next_tvb, pinfo, tree);
239 /* Register the protocol with Ethereal */
241 /* this format is require because a script is used to build the C function
242 that calls all the protocol registration.
246 proto_register_brdwlk (void)
249 /* Setup list of header fields See Section 1.6.1 for details*/
250 static hf_register_info hf[] = {
252 {"SOF", "brdwlk.sof", FT_UINT8, BASE_HEX, VALS (brdwlk_sof_vals),
253 0xF0, "SOF", HFILL}},
255 {"EOF", "brdwlk.eof", FT_UINT8, BASE_HEX, VALS (brdwlk_eof_vals),
258 {"Error", "brdwlk.error", FT_UINT8, BASE_DEC, NULL, 0x0, "Error",
261 {"Packet Count", "brdwlk.pktcnt", FT_UINT16, BASE_DEC, NULL, 0x0,
264 {"Packet Dropped", "brdwlk.drop", FT_BOOLEAN, BASE_DEC, NULL, 0x0,
267 {"VSAN", "brdwlk.vsan", FT_UINT16, BASE_DEC, NULL, 0xFFF, "",
271 /* Setup protocol subtree array */
272 static gint *ett[] = {
276 /* Register the protocol name and description */
277 proto_brdwlk = proto_register_protocol("Boardwalk",
278 "Boardwalk", "brdwlk");
280 /* Required function calls to register the header fields and subtrees used */
281 proto_register_field_array(proto_brdwlk, hf, array_length(hf));
282 proto_register_subtree_array(ett, array_length(ett));
287 /* If this dissector uses sub-dissector registration add a registration routine.
288 This format is required because a script is used to find these routines and
289 create the code that calls these routines.
292 proto_reg_handoff_brdwlk(void)
294 dissector_handle_t brdwlk_handle;
296 brdwlk_handle = create_dissector_handle (dissect_brdwlk, proto_brdwlk);
297 dissector_add("ethertype", ETHERTYPE_BRDWALK, brdwlk_handle);
298 data_handle = find_dissector("data");
299 fc_dissector_handle = find_dissector ("fc");