Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-hpsw.c
blobbf1e4dbfc46178c57d7b1400fa23a4e6ab9fb088
1 /* packet-hpsw.c
2 * Routines for HP Switch Config protocol
3 * Charlie Lenahan <clenahan@fortresstech.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
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/expert.h>
17 #include "packet-hpext.h"
19 void proto_register_hpsw(void);
20 void proto_reg_handoff_hpsw(void);
22 static int proto_hpsw;
24 static int hf_hpsw_version;
25 static int hf_hpsw_type;
26 static int hf_hpsw_tlvtype;
27 static int hf_hpsw_tlvlength;
28 static int hf_hpsw_field_10;
29 static int hf_hpsw_own_mac_addr;
30 static int hf_hpsw_neighbor_mac_addr;
31 static int hf_hpsw_field_6;
32 static int hf_hpsw_field_9;
33 static int hf_hpsw_device_version;
34 static int hf_hpsw_device_name;
35 static int hf_hpsw_ip_addr;
36 static int hf_hpsw_field_8;
37 static int hf_hpsw_domain;
38 static int hf_hpsw_field_12;
39 static int hf_hpsw_config_name;
40 static int hf_hpsw_root_mac_addr;
41 static int hf_hpsw_device_id;
42 static int hf_hpsw_device_id_data;
43 static int hf_hpsw_data;
46 static int ett_hpsw;
47 static int ett_hpsw_tlv;
49 static expert_field ei_hpsw_tlvlength_bad;
51 static dissector_handle_t hpsw_handle;
53 #define HPFOO_DEVICE_NAME 0x1
54 #define HPFOO_DEVICE_VERSION 0x2
55 #define HPFOO_CONFIG_NAME 0x3
56 #define HPFOO_ROOT_MAC_ADDR 0x4
57 #define HPFOO_IP_ADDR 0x5
58 #define HPFOO_FIELD_6 0x6
59 #define HPFOO_DOMAIN 0x7
60 #define HPFOO_FIELD_8 0x8
61 #define HPFOO_FIELD_9 0x9
62 #define HPFOO_FIELD_10 0xa
63 #define HPFOO_NEIGHBORS 0xb
64 #define HPFOO_FIELD_12 0xc
65 #define HPFOO_DEVICE_ID 0xd
66 #define HPFOO_OWN_MAC_ADDR 0xe
68 static const value_string hpsw_tlv_type_vals[] = {
69 { HPFOO_DEVICE_NAME, "Device Name" },
70 { HPFOO_DEVICE_VERSION, "Version" },
71 { HPFOO_CONFIG_NAME, "Config Name" },
72 { HPFOO_ROOT_MAC_ADDR, "Root MAC Addr" },
73 { HPFOO_IP_ADDR, "IP Addr" },
74 { HPFOO_FIELD_6, "Field 6" },
75 { HPFOO_DOMAIN, "Domain" },
76 { HPFOO_FIELD_8, "Field 8" },
77 { HPFOO_FIELD_9, "Field 9" },
78 { HPFOO_FIELD_10, "Field 10" },
79 { HPFOO_NEIGHBORS, "Neighbors" },
80 { HPFOO_FIELD_12, "Field 12" },
81 { HPFOO_DEVICE_ID, "Device ID" },
82 { HPFOO_OWN_MAC_ADDR, "2nd MAC Addr" },
83 { 0x00, NULL }
86 static void
87 dissect_hpsw_tlv(tvbuff_t *tvb, packet_info *pinfo, int offset, int length,
88 proto_tree *tree, proto_item *ti, uint8_t type)
90 switch (type) {
92 case HPFOO_DEVICE_NAME:
93 if (length > 0) {
94 proto_tree_add_item(tree, hf_hpsw_device_name, tvb, offset, length, ENC_NA|ENC_ASCII);
95 } else {
96 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Device Name: Bad length %u", length);
98 break;
100 case HPFOO_DEVICE_VERSION:
101 if (length > 0) {
102 proto_tree_add_item(tree, hf_hpsw_device_version, tvb, offset, length, ENC_NA|ENC_ASCII);
103 } else {
104 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Version: Bad length %u", length);
106 break;
108 case HPFOO_CONFIG_NAME:
109 if (length > 0) {
110 proto_tree_add_item(tree, hf_hpsw_config_name, tvb, offset, length, ENC_NA|ENC_ASCII);
111 } else {
112 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Config Name: Bad length %u", length);
114 break;
116 case HPFOO_ROOT_MAC_ADDR:
117 if (length == 6) {
118 proto_tree_add_item(tree, hf_hpsw_root_mac_addr, tvb, offset, length, ENC_NA);
119 } else {
120 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Root MAC Addr: Bad length %u", length);
122 break;
124 case HPFOO_IP_ADDR:
125 if (length == 4) {
126 proto_tree_add_item(tree, hf_hpsw_ip_addr, tvb, offset, length, ENC_BIG_ENDIAN);
127 } else {
128 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "IP Addr: Bad length %u", length);
130 break;
132 case HPFOO_FIELD_6:
133 if (length == 2) {
134 proto_tree_add_item(tree, hf_hpsw_field_6, tvb, offset, length, ENC_BIG_ENDIAN);
135 } else {
136 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 6: Bad length %u", length);
138 break;
140 case HPFOO_DOMAIN:
141 if (length > 0) {
142 proto_tree_add_item(tree, hf_hpsw_domain, tvb, offset, length, ENC_NA|ENC_ASCII);
143 } else {
144 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Domain: Bad length %u", length);
146 break;
148 case HPFOO_FIELD_8:
149 if (length == 2) {
150 proto_tree_add_item(tree, hf_hpsw_field_8, tvb, offset, length, ENC_BIG_ENDIAN);
151 } else {
152 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 8: Bad length %u", length);
154 break;
156 case HPFOO_FIELD_9:
157 if (length == 2) {
158 proto_tree_add_item(tree, hf_hpsw_field_9, tvb, offset, length, ENC_BIG_ENDIAN);
159 } else {
160 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 9: Bad length %u", length);
162 break;
164 case HPFOO_FIELD_10:
165 if (length == 4) {
166 proto_tree_add_item(tree, hf_hpsw_field_10, tvb, offset, length, ENC_BIG_ENDIAN);
167 } else {
168 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 10: Bad length %u", length);
170 break;
172 case HPFOO_NEIGHBORS:
173 if (!(length % 6))
174 { int i = length/6;
175 proto_item_set_text(proto_tree_get_parent(tree), "Number of neighbor MAC Addresses: %u", i);
176 for ( ; i; i--)
178 proto_tree_add_item(tree, hf_hpsw_neighbor_mac_addr, tvb, offset, 6, ENC_NA);
179 offset += 6;
181 } else {
182 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Neighbors: Bad length %u", length);
184 break;
186 case HPFOO_FIELD_12:
187 if (length == 1) {
188 proto_tree_add_item(tree, hf_hpsw_field_12, tvb, offset, length, ENC_BIG_ENDIAN);
189 } else {
190 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Field 12: Bad length %u", length);
192 break;
194 case HPFOO_DEVICE_ID:
195 if (length > 6) {
196 proto_tree_add_item(tree, hf_hpsw_device_id, tvb, offset, 6, ENC_NA);
197 proto_tree_add_item(tree, hf_hpsw_device_id_data, tvb, offset+6, length-6, ENC_NA);
198 } else {
199 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Device ID: Bad length %u", length);
201 break;
203 case HPFOO_OWN_MAC_ADDR:
204 if (length == 6) {
205 proto_tree_add_item(tree, hf_hpsw_own_mac_addr, tvb, offset, length, ENC_NA);
206 } else {
207 expert_add_info_format(pinfo, ti, &ei_hpsw_tlvlength_bad, "Own MAC Addr: Bad length %u", length);
209 break;
211 default:
212 proto_tree_add_item(tree, hf_hpsw_data, tvb, offset, length, ENC_NA);
213 break;
217 static int
218 dissect_hpsw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
220 proto_tree *hp_tree;
221 proto_tree *tlv_tree;
222 proto_item *ti;
223 uint8_t version;
224 int offset = 0;
226 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HP");
227 col_set_str(pinfo->cinfo, COL_INFO, "HP Switch Protocol");
229 version = tvb_get_uint8(tvb, 0);
231 ti = proto_tree_add_item(tree, proto_hpsw, tvb, 0, -1, ENC_NA);
232 hp_tree = proto_item_add_subtree(ti, ett_hpsw);
233 proto_tree_add_uint(hp_tree, hf_hpsw_version, tvb, 0, 1, version);
234 offset += 1;
236 proto_tree_add_item(hp_tree, hf_hpsw_type, tvb, 1, 1, ENC_BIG_ENDIAN);
237 offset += 1;
239 while ( tvb_reported_length_remaining(tvb, offset) > 0 )
241 uint8_t type, length;
243 type = tvb_get_uint8(tvb, offset);
244 length = tvb_get_uint8(tvb, offset+1);
246 /* make sure still in valid tlv */
247 if (( length < 1 ) || ( length > tvb_reported_length_remaining(tvb, offset+2)))
248 break;
250 tlv_tree = proto_tree_add_subtree(hp_tree, tvb, offset, length+2, ett_hpsw_tlv, NULL,
251 val_to_str(type, hpsw_tlv_type_vals, "Unknown TLV type: 0x%02x"));
253 /* type */
254 proto_tree_add_uint(tlv_tree, hf_hpsw_tlvtype, tvb, offset, 1, type);
255 offset += 1;
257 /* LENGTH (not inclusive of type and length bytes) */
258 ti = proto_tree_add_uint(tlv_tree, hf_hpsw_tlvlength, tvb, offset, 1, length);
259 offset += 1;
261 dissect_hpsw_tlv(tvb, pinfo, offset, length, tlv_tree, ti, type);
263 offset += length;
266 return tvb_captured_length(tvb);
269 void
270 proto_register_hpsw(void)
272 static hf_register_info hf[] = {
273 { &hf_hpsw_version,
274 { "Version", "hpsw.version", FT_UINT8, BASE_HEX,
275 NULL, 0x0, NULL, HFILL }},
276 { &hf_hpsw_type,
277 { "Type", "hpsw.type", FT_UINT8, BASE_HEX,
278 NULL, 0x0, NULL, HFILL }},
279 { &hf_hpsw_tlvtype,
280 { "Type", "hpsw.tlv_type", FT_UINT8, BASE_HEX,
281 VALS(hpsw_tlv_type_vals), 0x0, NULL, HFILL }},
282 { &hf_hpsw_tlvlength,
283 { "Length", "hpsw.tlv_len", FT_UINT8, BASE_DEC,
284 NULL, 0x0, NULL, HFILL }},
285 { &hf_hpsw_device_name,
286 { "Device Name", "hpsw.device_name", FT_STRING, BASE_NONE,
287 NULL, 0x0, NULL, HFILL }},
288 { &hf_hpsw_device_version,
289 { "Version", "hpsw.device_version", FT_STRING, BASE_NONE,
290 NULL, 0x0, NULL, HFILL }},
291 { &hf_hpsw_config_name,
292 { "Config Name", "hpsw.config_name", FT_STRING, BASE_NONE,
293 NULL, 0x0, NULL, HFILL }},
294 { &hf_hpsw_root_mac_addr,
295 { "Root MAC Addr", "hpsw.root_mac_addr", FT_ETHER, BASE_NONE,
296 NULL, 0x0, NULL, HFILL }},
297 { &hf_hpsw_ip_addr,
298 { "IP Addr", "hpsw.ip_addr", FT_IPv4, BASE_NONE,
299 NULL, 0x0, NULL, HFILL }},
300 { &hf_hpsw_field_6,
301 { "Field 6", "hpsw.field_6", FT_UINT16, BASE_HEX,
302 NULL, 0x0, NULL, HFILL }},
303 { &hf_hpsw_domain,
304 { "Domain", "hpsw.domain", FT_STRING, BASE_NONE,
305 NULL, 0x0, NULL, HFILL }},
306 { &hf_hpsw_field_8,
307 { "Field 8", "hpsw.field_8", FT_UINT16, BASE_HEX,
308 NULL, 0x0, NULL, HFILL }},
309 { &hf_hpsw_field_9,
310 { "Field 9", "hpsw.field_9", FT_UINT16, BASE_HEX,
311 NULL, 0x0, NULL, HFILL }},
312 { &hf_hpsw_field_10,
313 { "Field 10", "hpsw.field_10", FT_UINT32, BASE_HEX,
314 NULL, 0x0, NULL, HFILL }},
315 { &hf_hpsw_neighbor_mac_addr,
316 { "MAC Addr", "hpsw.neighbor_mac_addr", FT_ETHER, BASE_NONE,
317 NULL, 0x0, NULL, HFILL }},
318 { &hf_hpsw_field_12,
319 { "Field 12", "hpsw.field_12", FT_UINT8, BASE_HEX,
320 NULL, 0x0, NULL, HFILL }},
321 { &hf_hpsw_own_mac_addr,
322 { "Own MAC Addr", "hpsw.own_mac_addr", FT_ETHER, BASE_NONE,
323 NULL, 0x0, NULL, HFILL }},
324 { &hf_hpsw_device_id,
325 { "Device ID", "hpsw.device_id", FT_ETHER, BASE_NONE,
326 NULL, 0x0, NULL, HFILL }},
327 { &hf_hpsw_device_id_data,
328 { "Data", "hpsw.device_id_data", FT_BYTES, BASE_NONE,
329 NULL, 0x0, NULL, HFILL }},
330 { &hf_hpsw_data,
331 { "Data", "hpsw.data", FT_BYTES, BASE_NONE,
332 NULL, 0x0, NULL, HFILL }},
335 static int *ett[] = {
336 &ett_hpsw,
337 &ett_hpsw_tlv
340 static ei_register_info ei[] = {
341 { &ei_hpsw_tlvlength_bad, { "hpsw.tlv_len.bad", PI_PROTOCOL, PI_WARN, "Bad length", EXPFILL }},
344 expert_module_t* expert_hpsw;
346 proto_hpsw = proto_register_protocol( "HP Switch Protocol", "HPSW", "hpsw");
347 proto_register_field_array(proto_hpsw, hf, array_length(hf));
348 proto_register_subtree_array(ett, array_length(ett));
349 expert_hpsw = expert_register_protocol(proto_hpsw);
350 expert_register_field_array(expert_hpsw, ei, array_length(ei));
352 hpsw_handle = register_dissector("hpsw", dissect_hpsw, proto_hpsw);
355 void
356 proto_reg_handoff_hpsw(void)
358 dissector_add_uint("hpext.dxsap", HPEXT_HPSW, hpsw_handle);
362 * Editor modelines
364 * Local Variables:
365 * c-basic-offset: 4
366 * tab-width: 8
367 * indent-tabs-mode: nil
368 * End:
370 * ex: set shiftwidth=4 tabstop=8 expandtab:
371 * :indentSize=4:tabSize=8:noTabs=true: