2 * Routines for Vendor Specific Encodings dissection
3 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
5 * $Id: packet-vendor.c,v 1.3 2003/07/19 02:11:34 guy Exp $
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.
27 /* Notes to Adding dissectors for Vendor specific TLV's:
28 * 1. Create a dissect_<vendorname> function with the following prototype:
29 * dissect_foovendor(tvbuff_t *tvb, proto_tree *tree, guint8 vsif_len)
30 * 2. vsif_len will be the *entire* length of the vsif TLV (including the
31 * Vendor Id TLV, which is 5 bytes long).
32 * 3. Create a new 'case' statement in dissect_vsif, for your specific Vendor
34 * 4. In that 'case' statement you will make the following calls:
35 * (assume for this example that your vendor id is 0x000054)
36 * #define VENDOR_FOOVENDOR 0x00054
37 * case VENDOR_FOOVENDOR:
38 * proto_item_append_text (it, " (foo vendor)");
39 * dissect_foovendor (tvb, vsif_tree, vsif_len);
41 * 5. Please see dissect_cisco for an example of how to do this.
49 #include "plugins/plugin_api.h"
50 #include "plugins/plugin_api_defs.h"
51 #include "moduleinfo.h"
57 #ifdef HAVE_SYS_TYPES_H
58 # include <sys/types.h>
61 #ifdef HAVE_NETINET_IN_H
62 # include <netinet/in.h>
67 #ifdef NEED_SNPRINTF_H
68 # include "snprintf.h"
71 #include <epan/packet.h>
73 /* Define Vendor ID's here */
74 #define VENDOR_CISCO 0x00000C
76 /* Initialize the protocol and registered fields */
77 static int proto_docsis_vsif = -1;
78 static int hf_docsis_vsif = -1;
79 static int hf_docsis_vsif_vendorid = -1;
80 static int hf_docsis_vsif_vendor_unknown = -1;
81 static int hf_docsis_vsif_cisco_numphones = -1;
82 static int hf_docsis_vsif_cisco_ipprec = -1;
83 static int hf_docsis_vsif_cisco_ipprec_val = -1;
84 static int hf_docsis_vsif_cisco_ipprec_bw = -1;
85 static int hf_docsis_vsif_cisco_config_file = -1;
87 /* Initialize the subtree pointers */
88 static gint ett_docsis_vsif = -1;
89 static gint ett_docsis_vsif_ipprec = -1;
91 static const value_string vendorid_vals[] = {
92 {VENDOR_CISCO, "Cisco Systems, Inc."},
98 /* Forward Declarations for vendor specific dissectors */
99 static void dissect_cisco (tvbuff_t * tvb, proto_tree * tree,
102 /* Code to actually dissect the packets */
104 dissect_vsif (tvbuff_t * tvb, packet_info * pinfo _U_, proto_tree * tree)
107 proto_tree *vsif_tree;
113 /* get the total length of the VSIF TLV */
114 vsif_len = tvb_length_remaining (tvb, 0);
116 /* The first TLV in the VSIF encodings must be type 0x08 (Vendor ID) and
119 type = tvb_get_guint8 (tvb, 0);
122 THROW (ReportedBoundsError);
125 length = tvb_get_guint8 (tvb, 1);
128 THROW (ReportedBoundsError);
131 /* Extract the Value of the Vendor ID */
132 value = tvb_get_ntoh24 (tvb, 2);
136 proto_tree_add_protocol_format (tree, proto_docsis_vsif, tvb, 0,
137 tvb_length_remaining (tvb, 0),
139 vsif_tree = proto_item_add_subtree (it, ett_docsis_vsif);
140 proto_tree_add_item (vsif_tree, hf_docsis_vsif_vendorid, tvb, 2, 3, FALSE);
142 /* switch on the Vendor ID */
146 proto_item_append_text (it, " (Cisco)");
147 dissect_cisco (tvb, vsif_tree, vsif_len);
150 proto_item_append_text (it, " (Unknown)");
151 proto_tree_add_item (vsif_tree, hf_docsis_vsif_vendor_unknown, tvb,
162 /* Dissector for Cisco Vendor Specific TLV's */
164 #define NUM_PHONES 0x0a
165 #define IOS_CONFIG_FILE 0x80
167 #define IP_PREC_VAL 0x01
168 #define IP_PREC_BW 0x02
171 dissect_cisco (tvbuff_t * tvb, proto_tree * tree, guint8 vsif_len)
173 /* Start at pos = 5, since tvb includes the Vendor ID field */
176 proto_item *ipprec_it;
177 proto_tree *ipprec_tree;
180 while (pos < vsif_len)
182 /* Extract the type and length Fields from the TLV */
183 type = tvb_get_guint8 (tvb, pos++);
184 length = tvb_get_guint8 (tvb, pos++);
188 proto_tree_add_item (tree, hf_docsis_vsif_cisco_numphones, tvb,
193 proto_tree_add_text (tree, tvb, pos, length, "IP Precedence");
195 proto_item_add_subtree (ipprec_it, ett_docsis_vsif_ipprec);
196 /* Handle Sub-TLVs in IP Precedence */
197 templen = pos + length;
198 while (pos < templen)
200 type = tvb_get_guint8 (tvb, pos++);
201 length = tvb_get_guint8 (tvb, pos++);
206 THROW (ReportedBoundsError);
207 proto_tree_add_item (ipprec_tree,
208 hf_docsis_vsif_cisco_ipprec_val, tvb,
213 THROW (ReportedBoundsError);
214 proto_tree_add_item (ipprec_tree,
215 hf_docsis_vsif_cisco_ipprec_bw, tvb,
219 THROW (ReportedBoundsError);
224 case IOS_CONFIG_FILE:
225 proto_tree_add_item (tree, hf_docsis_vsif_cisco_config_file, tvb,
235 /* Register the protocol with Ethereal */
237 /* this format is require because a script is used to build the C function
238 that calls all the protocol registration.
243 proto_register_docsis_vsif (void)
246 /* Setup list of header fields See Section 1.6.1 for details*/
247 static hf_register_info hf[] = {
249 {"VSIF Encodings", "docsis.vsif",
250 FT_BYTES, BASE_HEX, NULL, 0x0,
251 "Vendor Specific Encodings", HFILL}
253 {&hf_docsis_vsif_vendorid,
254 {"Vendor Id", "docsis.vsif.vendorid",
255 FT_UINT24, BASE_HEX, VALS(vendorid_vals), 0x0,
256 "Vendor Identifier", HFILL}
258 {&hf_docsis_vsif_vendor_unknown,
259 {"VSIF Encodings", "docsis.vsif.unknown",
260 FT_BYTES, BASE_HEX, NULL, 0x0,
261 "Unknown Vendor", HFILL}
263 {&hf_docsis_vsif_cisco_numphones,
264 {"Number of phone lines", "docsis.vsif.cisco.numphones",
265 FT_UINT8, BASE_DEC, NULL, 0x0,
266 "Number of phone lines", HFILL}
268 {&hf_docsis_vsif_cisco_ipprec,
269 {"IP Precedence Encodings", "docsis.vsif.cisco.ipprec",
270 FT_BYTES, BASE_HEX, NULL, 0x0,
271 "IP Precedence Encodings", HFILL}
273 {&hf_docsis_vsif_cisco_ipprec_val,
274 {"IP Precedence Value", "docsis.vsif.cisco.ipprec.value",
275 FT_UINT8, BASE_DEC, NULL, 0x0,
276 "IP Precedence Value", HFILL}
278 {&hf_docsis_vsif_cisco_ipprec_bw,
279 {"IP Precedence Bandwidth", "docsis.vsif.cisco.ipprec.bw",
280 FT_UINT8, BASE_DEC, NULL, 0x0,
281 "IP Precedence Bandwidth", HFILL}
283 {&hf_docsis_vsif_cisco_config_file,
284 {"IOS Config File", "docsis.vsif.cisco.iosfile",
285 FT_STRING, BASE_DEC, NULL, 0x0,
286 "IOS Config File", HFILL}
290 /* Setup protocol subtree array */
291 static gint *ett[] = {
293 &ett_docsis_vsif_ipprec,
296 /* Register the protocol name and description */
298 proto_register_protocol ("DOCSIS Vendor Specific Endodings",
299 "DOCSIS VSIF", "docsis_vsif");
301 /* Required function calls to register the header fields and subtrees used */
302 proto_register_field_array (proto_docsis_vsif, hf, array_length (hf));
303 proto_register_subtree_array (ett, array_length (ett));
305 register_dissector ("docsis_vsif", dissect_vsif, proto_docsis_vsif);
309 /* If this dissector uses sub-dissector registration add a registration routine.
310 This format is required because a script is used to find these routines and
311 create the code that calls these routines.
314 proto_reg_handoff_docsis_vsif (void)
316 dissector_handle_t docsis_vsif_handle;
318 docsis_vsif_handle = find_dissector ("docsis_vsif");
319 dissector_add ("docsis", 0xFD, docsis_vsif_handle);