2 * Routines for 802.1CB R-tag ethernet header disassembly
4 * Copyright 2020, Rene Nielsen <rene.nielsen@microchip.com>
5 * In association with Microchip Technology Inc.
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/packet.h>
17 #include <epan/capture_dissectors.h>
18 #include <wsutil/pint.h>
19 #include <epan/addr_resolv.h>
21 #include "packet-ipx.h"
22 #include "packet-llc.h"
23 #include <epan/etypes.h>
24 #include <epan/prefs.h>
26 void proto_register_ieee8021cb(void);
27 void proto_reg_handoff_ieee8021cb(void);
29 static dissector_handle_t ieee8021cb_handle
;
30 static dissector_handle_t ethertype_handle
;
32 static capture_dissector_handle_t ieee8021cb_cap_handle
;
33 static capture_dissector_handle_t ipx_cap_handle
;
34 static capture_dissector_handle_t llc_cap_handle
;
36 /* GLOBALS ************************************************************/
38 static int proto_ieee8021cb
;
40 /* dot1cb R-tag fields */
41 static int hf_ieee8021cb_res
;
42 static int hf_ieee8021cb_seq
;
44 /* Encapsulated protocol */
45 static int hf_ieee8021cb_etype
;
47 static int ett_ieee8021cb
;
49 #define IEEE8021CB_LEN 6
52 capture_ieee8021cb(const unsigned char *pd
, int offset
, int len
, capture_packet_info_t
*cpinfo
, const union wtap_pseudo_header
*pseudo_header
)
56 if (!BYTES_ARE_IN_FRAME(offset
, len
, IEEE8021CB_LEN
+ 1))
59 encap_proto
= pntoh16( &pd
[offset
+ IEEE8021CB_LEN
- 2] );
60 if (encap_proto
<= IEEE_802_3_MAX_LEN
) {
61 if ( pd
[offset
+ IEEE8021CB_LEN
] == 0xff
62 && pd
[offset
+ IEEE8021CB_LEN
+ 1] == 0xff ) {
63 return call_capture_dissector(ipx_cap_handle
, pd
, offset
+ IEEE8021CB_LEN
, len
, cpinfo
, pseudo_header
);
66 return call_capture_dissector(llc_cap_handle
, pd
, offset
+ IEEE8021CB_LEN
, len
, cpinfo
, pseudo_header
);
70 return try_capture_dissector("ethertype", encap_proto
, pd
, offset
+ IEEE8021CB_LEN
, len
, cpinfo
, pseudo_header
);
73 /* Dissector *************************************************************/
75 int dissect_ieee8021cb(tvbuff_t
*tvb
, packet_info
*pinfo
,
76 proto_tree
*tree
, void* data _U_
)
78 proto_tree
*ptree
= NULL
;
80 ethertype_data_t ethertype_data
;
81 proto_tree
*ieee8021cb_tree
;
83 /* add info to column display */
84 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "802.1CB R-Tag");
85 col_clear(pinfo
->cinfo
, COL_INFO
);
87 seq
= tvb_get_ntohs(tvb
, 2);
88 pro
= tvb_get_ntohs(tvb
, 4);
90 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "SEQ: %u", seq
);
92 /* create the protocol tree */
93 ptree
= proto_tree_add_item(tree
, proto_ieee8021cb
, tvb
, 0, IEEE8021CB_LEN
, ENC_NA
);
94 ieee8021cb_tree
= proto_item_add_subtree(ptree
, ett_ieee8021cb
);
97 proto_tree_add_uint(ieee8021cb_tree
, hf_ieee8021cb_seq
, tvb
, 2, 2, seq
);
98 proto_tree_add_uint(ieee8021cb_tree
, hf_ieee8021cb_etype
, tvb
, 4, 2, pro
);
100 proto_item_append_text(ptree
, ", SEQ: %u", seq
);
102 ethertype_data
.fh_tree
= ieee8021cb_tree
;
103 ethertype_data
.fcs_len
= 0;
104 ethertype_data
.etype
= pro
;
105 ethertype_data
.payload_offset
= IEEE8021CB_LEN
;
107 /* 802.1CB tags are always followed by an ethertype; call next dissector
108 based on ethertype */
109 call_dissector_with_data(ethertype_handle
, tvb
, pinfo
, tree
, ðertype_data
);
111 return tvb_captured_length(tvb
);
115 proto_register_ieee8021cb(void)
117 static hf_register_info hf_1cb
[] = {
118 { &hf_ieee8021cb_res
, {
119 "Reserved", "ieee8021cb.reserved", FT_UINT16
, BASE_HEX
,
120 NULL
, 0x0, NULL
, HFILL
}},
121 { &hf_ieee8021cb_seq
, {
122 "SEQ", "ieee8021cb.seq", FT_UINT16
, BASE_HEX_DEC
,
123 NULL
, 0x0, NULL
, HFILL
}},
124 { &hf_ieee8021cb_etype
, {
125 "Type", "ieee8021cb.etype", FT_UINT16
, BASE_HEX
,
126 VALS(etype_vals
), 0x0, "Ethertype", HFILL
}}
129 static int *ett
[] = {
134 proto_ieee8021cb
= proto_register_protocol("802.1CB Redundancy Tag", "R-Tag", "ieee8021cb");
135 proto_register_field_array(proto_ieee8021cb
, hf_1cb
, array_length(hf_1cb
));
136 proto_register_subtree_array(ett
, array_length(ett
));
138 ieee8021cb_handle
= register_dissector("ieee8021cb", dissect_ieee8021cb
, proto_ieee8021cb
);
139 ieee8021cb_cap_handle
= register_capture_dissector("ieee8021cb", capture_ieee8021cb
, proto_ieee8021cb
);
143 proto_reg_handoff_ieee8021cb(void)
146 dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB
, ieee8021cb_handle
);
147 ethertype_handle
= find_dissector_add_dependency("ethertype", proto_ieee8021cb
);
148 capture_dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB
, ieee8021cb_cap_handle
);
150 ipx_cap_handle
= find_capture_dissector("ipx");
151 llc_cap_handle
= find_capture_dissector("llc");
155 * Editor modelines - https://www.wireshark.org/tools/modelines.html
160 * indent-tabs-mode: nil
163 * ex: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: