epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / packet-cisco-metadata.c
blob9b25c8bb63427ca39784ad7a9cfdf1b054b76db9
1 /* packet-cisco-metadata.c
2 * Routines for dissection of Cisco's MetaData protocol.
3 * draft-smith-kandula-sxp
4 * Copyright 2013 by Vaibhav Katkade (vkatkade[AT]cisco.com)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
17 #if 0
18 #include "packet-ieee8023.h"
19 #endif
21 void proto_register_cmd(void);
22 void proto_reg_handoff_cmd(void);
24 static dissector_handle_t cmd_eth_handle;
25 static dissector_handle_t cmd_gre_handle;
27 static dissector_handle_t ethertype_handle;
29 static dissector_table_t gre_dissector_table;
31 static int proto_cmd;
33 static int hf_cmd_version;
34 static int hf_cmd_length;
35 static int hf_cmd_options;
36 static int hf_cmd_sgt;
38 static int hf_eth_type;
39 static int hf_cmd_trailer;
41 static int ett_cmd;
43 static int
44 dissect_cmd_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
46 uint16_t encap_proto;
47 ethertype_data_t ethertype_data;
49 proto_tree *cmd_tree = NULL;
50 int offset = 0;
52 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMD");
53 col_clear(pinfo->cinfo, COL_INFO);
55 if (tree) {
56 proto_item *ti = proto_tree_add_item(tree, proto_cmd, tvb, 0, 8, ENC_NA);
58 cmd_tree = proto_item_add_subtree(ti, ett_cmd);
59 proto_tree_add_item(cmd_tree, hf_cmd_version, tvb, offset, 1, ENC_BIG_ENDIAN);
60 offset += 1;
61 proto_tree_add_item(cmd_tree, hf_cmd_length, tvb, offset, 1, ENC_BIG_ENDIAN);
62 offset += 1;
63 proto_tree_add_item(cmd_tree, hf_cmd_options, tvb, offset, 2, ENC_BIG_ENDIAN);
64 offset += 2;
65 proto_tree_add_item(cmd_tree, hf_cmd_sgt, tvb, offset, 2, ENC_BIG_ENDIAN);
66 /*offset += 2;*/
69 encap_proto = tvb_get_ntohs(tvb, 6);
71 /* This Logic to identify and decode IEEE 802.3 frames is not working correctly. Carry over code from packet-vlan.c
72 * Commenting it out for now will display as Unknown for L2 control frames instead of showing a wrong decode.
74 #if 0
75 if (encap_proto <= IEEE_802_3_MAX_LEN) {
76 bool is_802_2 = true;
78 /* Don't throw an exception for this check (even a BoundsError) */
79 if (tvb_captured_length_remaining(tvb, 4) >= 2) {
80 if (tvb_get_ntohs(tvb, 4) == 0xffff)
81 is_802_2 = false;
84 dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, cmd_tree, hf_eth_type, hf_cmd_trailer, 0);
85 } else {
86 #endif
88 proto_tree_add_uint(cmd_tree, hf_eth_type, tvb, 6, 2, encap_proto);
90 ethertype_data.etype = encap_proto;
91 ethertype_data.payload_offset = 8;
92 ethertype_data.fh_tree = cmd_tree;
93 ethertype_data.trailer_id = hf_cmd_trailer;
94 ethertype_data.fcs_len = 0;
96 call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, &ethertype_data);
97 return tvb_captured_length(tvb);
100 static int
101 dissect_cmd_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
103 proto_item *ti = NULL;
104 proto_tree *cmd_tree = NULL;
105 uint16_t encap_proto;
106 tvbuff_t *next_tvb;
107 int offset = 0;
109 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMD");
110 col_clear(pinfo->cinfo, COL_INFO);
112 if (tree) {
113 ti = proto_tree_add_item(tree, proto_cmd, tvb, 0, 6, ENC_NA);
114 cmd_tree = proto_item_add_subtree(ti, ett_cmd);
116 encap_proto = tvb_get_ntohs(tvb, 0);
117 proto_tree_add_item(cmd_tree, hf_eth_type, tvb, offset, 2, ENC_BIG_ENDIAN);
118 offset += 2;
120 proto_tree_add_item(cmd_tree, hf_cmd_version, tvb, offset, 1, ENC_BIG_ENDIAN);
121 offset += 1;
122 proto_tree_add_item(cmd_tree, hf_cmd_length, tvb, offset, 1, ENC_BIG_ENDIAN);
123 offset += 1;
124 proto_tree_add_item(cmd_tree, hf_cmd_options, tvb, offset, 2, ENC_BIG_ENDIAN);
125 offset += 2;
126 proto_tree_add_item(cmd_tree, hf_cmd_sgt, tvb, offset, 2, ENC_BIG_ENDIAN);
127 offset += 2;
129 next_tvb = tvb_new_subset_remaining(tvb, offset);
130 if (!dissector_try_uint(gre_dissector_table, encap_proto, next_tvb, pinfo, tree))
131 call_data_dissector(next_tvb, pinfo, tree);
132 return tvb_captured_length(tvb);
135 void
136 proto_register_cmd(void)
138 static hf_register_info hf[] = {
139 { &hf_cmd_version,
140 { "Version", "cmd.version", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
142 { &hf_cmd_length,
143 { "Length", "cmd.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
145 { &hf_cmd_options,
146 { "Options", "cmd.options", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
148 { &hf_cmd_sgt,
149 { "SGT", "cmd.sgt", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
151 { &hf_eth_type,
152 { "Type", "cmd.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0, NULL, HFILL }
154 { &hf_cmd_trailer,
155 { "Trailer", "cmd.trailer", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
159 static int *ett[] = {
160 &ett_cmd
163 proto_cmd = proto_register_protocol("Cisco MetaData", "Cisco MetaData", "cmd");
164 proto_register_field_array(proto_cmd, hf, array_length(hf));
165 proto_register_subtree_array(ett, array_length(ett));
167 cmd_eth_handle = register_dissector("cmd.eth", dissect_cmd_eth, proto_cmd);
168 cmd_gre_handle = register_dissector("cmd.gre", dissect_cmd_gre, proto_cmd);
171 void
172 proto_reg_handoff_cmd(void)
174 ethertype_handle = find_dissector_add_dependency("ethertype", proto_cmd);
176 gre_dissector_table = find_dissector_table("gre.proto");
178 dissector_add_uint("ethertype", ETHERTYPE_CMD, cmd_eth_handle);
179 dissector_add_uint("gre.proto", ETHERTYPE_CMD, cmd_gre_handle);
183 * Editor modelines - https://www.wireshark.org/tools/modelines.html
185 * Local variables:
186 * c-basic-offset: 4
187 * tab-width: 8
188 * indent-tabs-mode: nil
189 * End:
191 * vi: set shiftwidth=4 tabstop=8 expandtab:
192 * :indentSize=4:tabSize=8:noTabs=true: