HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-hpsw.c
blob273265a1442042d3e5eb824cfdb40edb2d38aa68
1 /* packet-hpsw.c
2 * Routines for HP Switch Config protocol
3 * Charlie Lenahan <clenahan@fortresstech.com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/etypes.h>
31 #include <epan/expert.h>
33 #include "packet-hpext.h"
35 static int proto_hpsw = -1;
37 static int hf_hpsw_version = -1;
38 static int hf_hpsw_type = -1;
39 static int hf_hpsw_tlvtype = -1;
40 static int hf_hpsw_tlvlength = -1;
41 static int hf_hpsw_field_10 = -1;
42 static int hf_hpsw_own_mac_addr = -1;
43 static int hf_hpsw_neighbor_mac_addr = -1;
44 static int hf_hpsw_field_6 = -1;
45 static int hf_hpsw_field_9 = -1;
46 static int hf_hpsw_device_version = -1;
47 static int hf_hpsw_device_name = -1;
48 static int hf_hpsw_ip_addr = -1;
49 static int hf_hpsw_field_8 = -1;
50 static int hf_hpsw_domain = -1;
51 static int hf_hpsw_field_12 = -1;
52 static int hf_hpsw_config_name = -1;
53 static int hf_hpsw_root_mac_addr = -1;
54 static int hf_hpsw_device_id = -1;
55 static int hf_hpsw_device_id_data = -1;
58 static gint ett_hpsw = -1;
59 static gint ett_hpsw_tlv = -1;
61 static expert_field ei_hpsw_tlvlength_bad = EI_INIT;
63 #define HPFOO_DEVICE_NAME 0x1
64 #define HPFOO_DEVICE_VERSION 0x2
65 #define HPFOO_CONFIG_NAME 0x3
66 #define HPFOO_ROOT_MAC_ADDR 0x4
67 #define HPFOO_IP_ADDR 0x5
68 #define HPFOO_FIELD_6 0x6
69 #define HPFOO_DOMAIN 0x7
70 #define HPFOO_FIELD_8 0x8
71 #define HPFOO_FIELD_9 0x9
72 #define HPFOO_FIELD_10 0xa
73 #define HPFOO_NEIGHBORS 0xb
74 #define HPFOO_FIELD_12 0xc
75 #define HPFOO_DEVICE_ID 0xd
76 #define HPFOO_OWN_MAC_ADDR 0xe
78 static const value_string hpsw_tlv_type_vals[] = {
79 { HPFOO_DEVICE_NAME, "Device Name" },
80 { HPFOO_DEVICE_VERSION, "Version" },
81 { HPFOO_CONFIG_NAME, "Config Name" },
82 { HPFOO_ROOT_MAC_ADDR, "Root MAC Addr" },
83 { HPFOO_IP_ADDR, "IP Addr" },
84 { HPFOO_FIELD_6, "Field 6" },
85 { HPFOO_DOMAIN, "Domain" },
86 { HPFOO_FIELD_8, "Field 8" },
87 { HPFOO_FIELD_9, "Field 9" },
88 { HPFOO_FIELD_10, "Field 10" },
89 { HPFOO_NEIGHBORS, "Neighbors" },
90 { HPFOO_FIELD_12, "Field 12" },
91 { HPFOO_DEVICE_ID, "Device ID" },
92 { HPFOO_OWN_MAC_ADDR, "2nd MAC Addr" },
93 { 0x00, NULL }
96 static void
97 dissect_hpsw_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length,
98 proto_tree *tree, proto_item *ti, guint8 type)
100 switch (type) {
102 case HPFOO_DEVICE_NAME:
103 if (length > 0) {
104 proto_tree_add_item(tree, hf_hpsw_device_name, tvb, offset, length, ENC_NA|ENC_ASCII);
105 } else {
106 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Device Name: Bad length %u", length);
108 break;
110 case HPFOO_DEVICE_VERSION:
111 if (length > 0) {
112 proto_tree_add_item(tree, hf_hpsw_device_version, tvb, offset, length, ENC_NA|ENC_ASCII);
113 } else {
114 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Version: Bad length %u", length);
116 break;
118 case HPFOO_CONFIG_NAME:
119 if (length > 0) {
120 proto_tree_add_item(tree, hf_hpsw_config_name, tvb, offset, length, ENC_NA|ENC_ASCII);
121 } else {
122 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Config Name: Bad length %u", length);
124 break;
126 case HPFOO_ROOT_MAC_ADDR:
127 if (length == 6) {
128 proto_tree_add_item(tree, hf_hpsw_root_mac_addr, tvb, offset, length, ENC_NA);
129 } else {
130 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Root MAC Addr: Bad length %u", length);
132 break;
134 case HPFOO_IP_ADDR:
135 if (length == 4) {
136 proto_tree_add_item(tree, hf_hpsw_ip_addr, tvb, offset, length, ENC_BIG_ENDIAN);
137 } else {
138 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "IP Addr: Bad length %u", length);
140 break;
142 case HPFOO_FIELD_6:
143 if (length == 2) {
144 proto_tree_add_item(tree, hf_hpsw_field_6, tvb, offset, length, ENC_BIG_ENDIAN);
145 } else {
146 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 6: Bad length %u", length);
148 break;
150 case HPFOO_DOMAIN:
151 if (length > 0) {
152 proto_tree_add_item(tree, hf_hpsw_domain, tvb, offset, length, ENC_NA|ENC_ASCII);
153 } else {
154 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Domain: Bad length %u", length);
156 break;
158 case HPFOO_FIELD_8:
159 if (length == 2) {
160 proto_tree_add_item(tree, hf_hpsw_field_8, tvb, offset, length, ENC_BIG_ENDIAN);
161 } else {
162 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 8: Bad length %u", length);
164 break;
166 case HPFOO_FIELD_9:
167 if (length == 2) {
168 proto_tree_add_item(tree, hf_hpsw_field_9, tvb, offset, length, ENC_BIG_ENDIAN);
169 } else {
170 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 9: Bad length %u", length);
172 break;
174 case HPFOO_FIELD_10:
175 if (length == 4) {
176 proto_tree_add_item(tree, hf_hpsw_field_10, tvb, offset, length, ENC_BIG_ENDIAN);
177 } else {
178 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 10: Bad length %u", length);
180 break;
182 case HPFOO_NEIGHBORS:
183 if (!(length % 6))
184 { int i = length/6;
185 proto_item_set_text(ti, "Number of neighbor MAC Addresses: %u", i);
186 for ( ; i; i--)
188 proto_tree_add_item(tree, hf_hpsw_neighbor_mac_addr, tvb, offset, length, ENC_NA);
189 offset += 6;
191 } else {
192 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Neighbors: Bad length %u", length);
194 break;
196 case HPFOO_FIELD_12:
197 if (length == 1) {
198 proto_tree_add_item(tree, hf_hpsw_field_12, tvb, offset, length, ENC_NA);
199 } else {
200 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 12: Bad length %u", length);
202 break;
204 case HPFOO_DEVICE_ID:
205 if (length > 6) {
206 proto_tree_add_item(tree, hf_hpsw_device_id, tvb, offset, 6, ENC_NA);
207 proto_tree_add_item(tree, hf_hpsw_device_id_data, tvb, offset+6, length-6, ENC_NA);
208 } else {
209 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Device ID: Bad length %u", length);
211 break;
213 case HPFOO_OWN_MAC_ADDR:
214 if (length == 6) {
215 proto_tree_add_item(tree, hf_hpsw_own_mac_addr, tvb, offset, length, ENC_NA);
216 } else {
217 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Own MAC Addr: Bad length %u", length);
219 break;
221 default:
222 proto_tree_add_text(tree, tvb, offset, length, "Data");
223 break;
227 static void
228 dissect_hpsw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
230 proto_tree *hp_tree = NULL;
231 proto_tree *tlv_tree = NULL;
232 proto_item *ti = NULL;
233 guint8 version;
235 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HP");
237 col_set_str(pinfo->cinfo, COL_INFO, "HP Switch Protocol");
239 version = tvb_get_guint8(tvb, 0);
241 if (tree) {
242 guint16 offset =0;
244 ti = proto_tree_add_item(tree, proto_hpsw, tvb, 0, -1, ENC_NA);
245 hp_tree = proto_item_add_subtree(ti, ett_hpsw);
246 proto_tree_add_uint(hp_tree, hf_hpsw_version, tvb, 0, 1, version);
247 offset++;
249 proto_tree_add_item(hp_tree, hf_hpsw_type, tvb, 1, 1, ENC_BIG_ENDIAN);
250 offset++;
252 while ( tvb_reported_length_remaining(tvb, offset) > 0 )
254 guint8 type,length;
256 type = tvb_get_guint8(tvb, offset);
257 length = tvb_get_guint8(tvb, offset+1);
259 /* make sure still in valid tlv */
260 if (( length < 1 ) || ( length > tvb_length_remaining(tvb,offset+2)))
261 break;
263 ti = proto_tree_add_text(hp_tree,tvb,offset,length+2,"%s",
264 val_to_str(type,hpsw_tlv_type_vals,"Unknown TLV type: 0x%02x"));
266 tlv_tree=proto_item_add_subtree(ti,ett_hpsw_tlv);
268 /* type */
269 proto_tree_add_uint(tlv_tree, hf_hpsw_tlvtype, tvb, offset, 1, type);
270 offset++;
272 /* LENGTH (not inclusive of type and length bytes) */
273 proto_tree_add_uint(tlv_tree, hf_hpsw_tlvlength, tvb, offset, 1, length);
274 offset++;
276 dissect_hpsw_tlv(tvb,pinfo,offset,length,tlv_tree,ti,type);
278 offset += length;
285 void
286 proto_register_hpsw(void)
288 static hf_register_info hf[] = {
289 { &hf_hpsw_version,
290 { "Version", "hpsw.version", FT_UINT8, BASE_HEX,
291 NULL, 0x0, NULL, HFILL }},
292 { &hf_hpsw_type,
293 { "Type", "hpsw.type", FT_UINT8, BASE_HEX,
294 NULL, 0x0, NULL, HFILL }},
295 { &hf_hpsw_tlvtype,
296 { "Type", "hpsw.tlv_type", FT_UINT8, BASE_HEX,
297 VALS(hpsw_tlv_type_vals), 0x0, NULL, HFILL }},
298 { &hf_hpsw_tlvlength,
299 { "Length", "hpsw.tlv_len", FT_UINT8, BASE_DEC,
300 NULL, 0x0, NULL, HFILL }},
301 { &hf_hpsw_device_name, { "Device Name", "hpsw.device_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
302 { &hf_hpsw_device_version, { "Version", "hpsw.device_version", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
303 { &hf_hpsw_config_name, { "Config Name", "hpsw.config_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
304 { &hf_hpsw_root_mac_addr, { "Root MAC Addr", "hpsw.root_mac_addr", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
305 { &hf_hpsw_ip_addr, { "IP Addr", "hpsw.ip_addr", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
306 { &hf_hpsw_field_6, { "Field 6", "hpsw.field_6", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
307 { &hf_hpsw_domain, { "Domain", "hpsw.domain", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
308 { &hf_hpsw_field_8, { "Field 8", "hpsw.field_8", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
309 { &hf_hpsw_field_9, { "Field 9", "hpsw.field_9", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
310 { &hf_hpsw_field_10, { "Field 10", "hpsw.field_10", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
311 { &hf_hpsw_neighbor_mac_addr, { "MAC Addr", "hpsw.neighbor_mac_addr", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
312 { &hf_hpsw_field_12, { "Field 12", "hpsw.field_12", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
313 { &hf_hpsw_own_mac_addr, { "Own MAC Addr", "hpsw.own_mac_addr", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
314 { &hf_hpsw_device_id, { "Device ID", "hpsw.device_id", FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
315 { &hf_hpsw_device_id_data, { "Data", "hpsw.device_id_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
318 static gint *ett[] = {
319 &ett_hpsw,
320 &ett_hpsw_tlv
323 static ei_register_info ei[] = {
324 { &ei_hpsw_tlvlength_bad, { "hpsw.tlv_len.bad", PI_PROTOCOL, PI_WARN, "Bad length", EXPFILL }},
327 expert_module_t* expert_hpsw;
329 proto_hpsw = proto_register_protocol( "HP Switch Protocol", "HPSW", "hpsw");
330 proto_register_field_array(proto_hpsw, hf, array_length(hf));
331 proto_register_subtree_array(ett, array_length(ett));
332 expert_hpsw = expert_register_protocol(proto_hpsw);
333 expert_register_field_array(expert_hpsw, ei, array_length(ei));
335 register_dissector("hpsw", dissect_hpsw, proto_hpsw);
338 void
339 proto_reg_handoff_hpsw(void)
341 dissector_handle_t hpsw_handle;
343 hpsw_handle = find_dissector("hpsw");
345 dissector_add_uint("hpext.dxsap", HPEXT_HPSW, hpsw_handle);
349 * Editor modelines
351 * Local Variables:
352 * c-basic-offset: 4
353 * tab-width: 8
354 * indent-tabs-mode: nil
355 * End:
357 * ex: set shiftwidth=4 tabstop=8 expandtab:
358 * :indentSize=4:tabSize=8:noTabs=true: