2 * Routines for decoding MDS Port Analyzer Adapter (FC in Eth) Header
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
15 #include <epan/proto_data.h>
17 #include "packet-fc.h"
19 #define BRDWLK_MAX_PACKET_CNT 0xFFFF
20 #define BRDWLK_TRUNCATED_BIT 0x8
21 #define BRDWLK_HAS_PLEN 0x1
23 #define FCM_DELIM_SOFC1 0x01
24 #define FCM_DELIM_SOFI1 0x02
25 #define FCM_DELIM_SOFI2 0x04
26 #define FCM_DELIM_SOFI3 0x06
27 #define FCM_DELIM_SOFN1 0x03
28 #define FCM_DELIM_SOFN2 0x05
29 #define FCM_DELIM_SOFN3 0x07
30 #define FCM_DELIM_SOFF 0x08
31 #define FCM_DELIM_SOFC4 0x09
32 #define FCM_DELIM_SOFI4 0x0A
33 #define FCM_DELIM_SOFN4 0x0B
35 #define FCM_DELIM_EOFT 0x01
36 #define FCM_DELIM_EOFDT 0x02
37 #define FCM_DELIM_EOFN 0x03
38 #define FCM_DELIM_EOFA 0x04
39 #define FCM_DELIM_EOFNI 0x07
40 #define FCM_DELIM_EOFDTI 0x06
41 #define FCM_DELIM_EOFRT 0x0A
42 #define FCM_DELIM_EOFRTI 0x0E
43 #define FCM_DELIM_NOEOF 0xF0
44 #define FCM_DELIM_EOFJUMBO 0xF1
46 void proto_register_brdwlk(void);
47 void proto_reg_handoff_brdwlk(void);
49 static const value_string brdwlk_sof_vals
[] = {
50 {FCM_DELIM_SOFI1
, "SOFi1"},
51 {FCM_DELIM_SOFI2
, "SOFi2"},
52 {FCM_DELIM_SOFI3
, "SOFi3"},
53 {FCM_DELIM_SOFN1
, "SOFn1"},
54 {FCM_DELIM_SOFN2
, "SOFn2"},
55 {FCM_DELIM_SOFN3
, "SOFn3"},
56 {FCM_DELIM_SOFF
, "SOFf"},
60 static const value_string brdwlk_eof_vals
[] = {
61 {FCM_DELIM_EOFDT
, "EOFdt"},
62 {FCM_DELIM_EOFA
, "EOFa"},
63 {FCM_DELIM_EOFN
, "EOFn"},
64 {FCM_DELIM_EOFT
, "EOFt"},
68 static int hf_brdwlk_sof
;
69 static int hf_brdwlk_eof
;
70 static int hf_brdwlk_error
;
71 static int hf_brdwlk_vsan
;
72 static int hf_brdwlk_pktcnt
;
73 static int hf_brdwlk_drop
;
74 static int hf_brdwlk_plen
;
75 static int hf_brdwlk_error_plp
;
76 static int hf_brdwlk_error_ef
;
77 static int hf_brdwlk_error_nd
;
78 static int hf_brdwlk_error_tr
;
79 static int hf_brdwlk_error_badcrc
;
80 static int hf_brdwlk_error_ff
;
81 static int hf_brdwlk_error_jumbo
;
82 static int hf_brdwlk_error_ctrl
;
84 /* Initialize the subtree pointers */
85 static int ett_brdwlk
;
86 static int ett_brdwlk_error
;
88 static int proto_brdwlk
;
90 static uint16_t packet_count
;
91 static bool first_pkt
= true; /* start of capture */
93 static dissector_handle_t fc_dissector_handle
;
94 static dissector_handle_t brdwlk_handle
;
97 static const true_false_string tfs_error_plp
= {
98 "Packet Length is PRESENT",
99 "Packet length is NOT present"
101 static const true_false_string tfs_error_ef
= {
102 "This is an Empty Frame",
105 static const true_false_string tfs_error_nd
= {
106 "This Frame has NO Data",
107 "This frame carries data"
109 static const true_false_string tfs_error_tr
= {
110 "This frame is TRUNCATED",
111 "This frame is NOT truncated"
113 static const true_false_string tfs_error_crc
= {
114 "This Frame has a BAD FC CRC",
115 "This frame has a valid crc"
117 static const true_false_string tfs_error_ff
= {
121 static const true_false_string tfs_error_jumbo
= {
122 "This is a JUMBO FC Frame",
123 "This is a NORMAL FC Frame"
125 static const true_false_string tfs_error_ctrl
= {
126 "Ctrl Characters inside the frame",
127 "No ctrl chars inside the frame"
131 dissect_brdwlk_err(proto_tree
*parent_tree
, tvbuff_t
*tvb
, int offset
)
133 static int * const flags
[] = {
134 &hf_brdwlk_error_plp
,
138 &hf_brdwlk_error_badcrc
,
140 &hf_brdwlk_error_jumbo
,
141 &hf_brdwlk_error_ctrl
,
145 proto_tree_add_bitmask_with_flags(parent_tree
, tvb
, offset
, hf_brdwlk_error
, ett_brdwlk_error
, flags
, ENC_NA
, BMT_NO_FALSE
|BMT_NO_TFS
);
148 /* Code to actually dissect the packets */
150 dissect_brdwlk(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
153 /* Set up structures needed to add the protocol subtree and manage it */
154 proto_item
*ti
, *hidden_item
;
155 proto_tree
*brdwlk_tree
;
157 uint8_t error
, eof
, sof
;
160 int len
, reported_len
, plen
;
162 bool dropped_packets
;
165 /* Make entries in Protocol column and Info column on summary display */
166 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Boardwalk");
168 col_clear(pinfo
->cinfo
, COL_INFO
);
170 sof
= (tvb_get_uint8(tvb
, offset
) & 0xF0) >> 4;
173 if ((sof
== FCM_DELIM_SOFI3
) || (sof
== FCM_DELIM_SOFI2
) || (sof
== FCM_DELIM_SOFI1
)
174 || (sof
== FCM_DELIM_SOFI4
)) {
175 fc_data
.sof_eof
= FC_DATA_SOF_FIRST_FRAME
;
177 else if (sof
== FCM_DELIM_SOFF
) {
178 fc_data
.sof_eof
= FC_DATA_SOF_SOFF
;
181 ti
= proto_tree_add_protocol_format(tree
, proto_brdwlk
, tvb
, 0,
182 hdrlen
, "Boardwalk");
184 brdwlk_tree
= proto_item_add_subtree(ti
, ett_brdwlk
);
186 proto_tree_add_item(brdwlk_tree
, hf_brdwlk_sof
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
187 proto_tree_add_item(brdwlk_tree
, hf_brdwlk_vsan
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
189 /* Locate EOF which is the last 4 bytes of the frame */
190 len
= tvb_captured_length_remaining(tvb
, hdrlen
);
191 reported_len
= tvb_reported_length_remaining(tvb
, hdrlen
);
192 if (reported_len
< 4) {
194 * This packet is claimed not to even have enough data for
196 * Don't try to process the EOF.
200 else if (len
< reported_len
) {
202 * This packet is claimed to have enough data for a 4-byte EOF,
203 * but we didn't capture all of the packet.
204 * Slice off the 4-byte EOF from the reported length, and trim
205 * the captured length so it's no more than the reported length;
206 * that will slice off what of the EOF, if any, is in the
210 if (len
> reported_len
)
215 * We have the entire packet, and it includes a 4-byte EOF.
216 * Slice it off, and put it into the tree if we're building
221 offset
= tvb_reported_length(tvb
) - 4;
222 pkt_cnt
= tvb_get_ntohs(tvb
, offset
);
224 proto_tree_add_uint(brdwlk_tree
, hf_brdwlk_pktcnt
, tvb
, offset
,
227 dropped_packets
= false;
228 if (pinfo
->fd
->visited
) {
230 * This isn't the first pass, so we can't use the global
231 * "packet_count" variable to determine whether there were
232 * any dropped frames or not.
233 * We therefore attach a non-null pointer as frame data to
234 * any frame preceded by dropped packets.
236 if (p_get_proto_data(wmem_file_scope(), pinfo
, proto_brdwlk
, 0) != NULL
)
237 dropped_packets
= true;
240 * This is the first pass, so we have to use the global
241 * "packet_count" variable to determine whether there were
242 * any dropped frames or not.
244 * XXX - can there be more than one stream of packets, so that
245 * we can't just use a global variable?
247 if (pkt_cnt
!= packet_count
+ 1) {
249 (pkt_cnt
!= 0 || (packet_count
!= BRDWLK_MAX_PACKET_CNT
))) {
250 dropped_packets
= true;
253 * Mark this frame as having been preceded by dropped
254 * packets. (The data we use as the frame data doesn't
255 * matter - it just matters that it's non-null.)
257 p_add_proto_data(wmem_file_scope(), pinfo
, proto_brdwlk
, 0, &packet_count
);
262 hidden_item
= proto_tree_add_boolean(brdwlk_tree
, hf_brdwlk_drop
,
263 tvb
, offset
, 0, dropped_packets
);
264 proto_item_set_hidden(hidden_item
);
266 packet_count
= pkt_cnt
;
268 error
=tvb_get_uint8(tvb
, offset
+2);
269 dissect_brdwlk_err(brdwlk_tree
, tvb
, offset
+2);
271 eof
= tvb_get_uint8(tvb
, offset
+3);
272 if (eof
!= FCM_DELIM_EOFN
) {
273 fc_data
.sof_eof
|= FC_DATA_EOF_LAST_FRAME
;
275 else if (eof
!= FCM_DELIM_EOFT
) {
276 fc_data
.sof_eof
|= FC_DATA_EOF_INVALID
;
279 proto_tree_add_item(brdwlk_tree
, hf_brdwlk_eof
, tvb
, offset
+3,
282 if ((error
& BRDWLK_HAS_PLEN
) && tree
) {
283 /* In newer Boardwalks, if this bit is set, the actual frame length
284 * is also provided. This length is the size between SOF & EOF
287 plen
= tvb_get_ntohl(tvb
, offset
-4);
289 proto_tree_add_uint(brdwlk_tree
, hf_brdwlk_plen
, tvb
, offset
-4,
293 /* XXX - this would throw an exception if it would increase
294 * the reported length.
296 if (error
& BRDWLK_TRUNCATED_BIT
) {
297 tvb_set_reported_length(tvb
, plen
);
303 fc_data
.ethertype
= ETHERTYPE_BRDWALK
;
304 next_tvb
= tvb_new_subset_length_caplen(tvb
, 2, len
, reported_len
);
305 call_dissector_with_data(fc_dissector_handle
, next_tvb
, pinfo
, tree
, &fc_data
);
306 return tvb_captured_length(tvb
);
316 /* Register the protocol with Wireshark */
318 /* this format is require because a script is used to build the C function
319 that calls all the protocol registration.
323 proto_register_brdwlk(void)
326 /* Setup list of header fields See Section 1.6.1 for details*/
327 static hf_register_info hf
[] = {
329 {"SOF", "brdwlk.sof", FT_UINT8
, BASE_HEX
, VALS(brdwlk_sof_vals
),
332 {"EOF", "brdwlk.eof", FT_UINT8
, BASE_HEX
, VALS(brdwlk_eof_vals
),
335 {"Error", "brdwlk.error", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
,
338 {"Packet Count", "brdwlk.pktcnt", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
341 {"Packet Dropped", "brdwlk.drop", FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
344 {"VSAN", "brdwlk.vsan", FT_UINT16
, BASE_DEC
, NULL
, 0x0FFF, NULL
,
347 {"Original Packet Length", "brdwlk.plen", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
,
349 { &hf_brdwlk_error_plp
,
350 {"Packet Length Present", "brdwlk.error.plp", FT_BOOLEAN
, 8, TFS(&tfs_error_plp
), 0x01, NULL
,
352 { &hf_brdwlk_error_ef
,
353 {"Empty Frame", "brdwlk.error.ef", FT_BOOLEAN
, 8, TFS(&tfs_error_ef
), 0x02, NULL
,
355 { &hf_brdwlk_error_nd
,
356 {"No Data", "brdwlk.error.nd", FT_BOOLEAN
, 8, TFS(&tfs_error_nd
), 0x04, NULL
,
358 { &hf_brdwlk_error_tr
,
359 {"Truncated", "brdwlk.error.tr", FT_BOOLEAN
, 8, TFS(&tfs_error_tr
), 0x08, NULL
,
361 { &hf_brdwlk_error_badcrc
,
362 {"CRC", "brdwlk.error.crc", FT_BOOLEAN
, 8, TFS(&tfs_error_crc
), 0x10, NULL
,
364 { &hf_brdwlk_error_ff
,
365 {"Fifo Full", "brdwlk.error.ff", FT_BOOLEAN
, 8, TFS(&tfs_error_ff
), 0x20, NULL
,
367 { &hf_brdwlk_error_jumbo
,
368 {"Jumbo FC Frame", "brdwlk.error.jumbo", FT_BOOLEAN
, 8, TFS(&tfs_error_jumbo
), 0x40, NULL
,
370 { &hf_brdwlk_error_ctrl
,
371 {"Ctrl Char Inside Frame", "brdwlk.error.ctrl", FT_BOOLEAN
, 8, TFS(&tfs_error_ctrl
), 0x80, NULL
,
375 /* Setup protocol subtree array */
376 static int *ett
[] = {
381 /* Register the protocol name and description */
382 proto_brdwlk
= proto_register_protocol("Boardwalk", "Boardwalk", "brdwlk");
384 /* Required function calls to register the header fields and subtrees used */
385 proto_register_field_array(proto_brdwlk
, hf
, array_length(hf
));
386 proto_register_subtree_array(ett
, array_length(ett
));
388 register_init_routine(&brdwlk_init
);
390 /* Register the dissector */
391 brdwlk_handle
= register_dissector("brdwlk", dissect_brdwlk
, proto_brdwlk
);
396 proto_reg_handoff_brdwlk(void)
398 dissector_add_uint("ethertype", ETHERTYPE_BRDWALK
, brdwlk_handle
);
399 dissector_add_uint("ethertype", 0xABCD, brdwlk_handle
);
400 fc_dissector_handle
= find_dissector_add_dependency("fc", proto_brdwlk
);
404 * Editor modelines - https://www.wireshark.org/tools/modelines.html
409 * indent-tabs-mode: nil
412 * vi: set shiftwidth=4 tabstop=8 expandtab:
413 * :indentSize=4:tabSize=8:noTabs=true: