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
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
;
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" },
87 dissect_hpsw_tlv(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, int length
,
88 proto_tree
*tree
, proto_item
*ti
, uint8_t type
)
92 case HPFOO_DEVICE_NAME
:
94 proto_tree_add_item(tree
, hf_hpsw_device_name
, tvb
, offset
, length
, ENC_NA
|ENC_ASCII
);
96 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Device Name: Bad length %u", length
);
100 case HPFOO_DEVICE_VERSION
:
102 proto_tree_add_item(tree
, hf_hpsw_device_version
, tvb
, offset
, length
, ENC_NA
|ENC_ASCII
);
104 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Version: Bad length %u", length
);
108 case HPFOO_CONFIG_NAME
:
110 proto_tree_add_item(tree
, hf_hpsw_config_name
, tvb
, offset
, length
, ENC_NA
|ENC_ASCII
);
112 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Config Name: Bad length %u", length
);
116 case HPFOO_ROOT_MAC_ADDR
:
118 proto_tree_add_item(tree
, hf_hpsw_root_mac_addr
, tvb
, offset
, length
, ENC_NA
);
120 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Root MAC Addr: Bad length %u", length
);
126 proto_tree_add_item(tree
, hf_hpsw_ip_addr
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
128 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "IP Addr: Bad length %u", length
);
134 proto_tree_add_item(tree
, hf_hpsw_field_6
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
136 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Field 6: Bad length %u", length
);
142 proto_tree_add_item(tree
, hf_hpsw_domain
, tvb
, offset
, length
, ENC_NA
|ENC_ASCII
);
144 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Domain: Bad length %u", length
);
150 proto_tree_add_item(tree
, hf_hpsw_field_8
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
152 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Field 8: Bad length %u", length
);
158 proto_tree_add_item(tree
, hf_hpsw_field_9
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
160 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Field 9: Bad length %u", length
);
166 proto_tree_add_item(tree
, hf_hpsw_field_10
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
168 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Field 10: Bad length %u", length
);
172 case HPFOO_NEIGHBORS
:
175 proto_item_set_text(proto_tree_get_parent(tree
), "Number of neighbor MAC Addresses: %u", i
);
178 proto_tree_add_item(tree
, hf_hpsw_neighbor_mac_addr
, tvb
, offset
, 6, ENC_NA
);
182 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Neighbors: Bad length %u", length
);
188 proto_tree_add_item(tree
, hf_hpsw_field_12
, tvb
, offset
, length
, ENC_BIG_ENDIAN
);
190 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Field 12: Bad length %u", length
);
194 case HPFOO_DEVICE_ID
:
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
);
199 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Device ID: Bad length %u", length
);
203 case HPFOO_OWN_MAC_ADDR
:
205 proto_tree_add_item(tree
, hf_hpsw_own_mac_addr
, tvb
, offset
, length
, ENC_NA
);
207 expert_add_info_format(pinfo
, ti
, &ei_hpsw_tlvlength_bad
, "Own MAC Addr: Bad length %u", length
);
212 proto_tree_add_item(tree
, hf_hpsw_data
, tvb
, offset
, length
, ENC_NA
);
218 dissect_hpsw(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
221 proto_tree
*tlv_tree
;
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
);
236 proto_tree_add_item(hp_tree
, hf_hpsw_type
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
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)))
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"));
254 proto_tree_add_uint(tlv_tree
, hf_hpsw_tlvtype
, tvb
, offset
, 1, type
);
257 /* LENGTH (not inclusive of type and length bytes) */
258 ti
= proto_tree_add_uint(tlv_tree
, hf_hpsw_tlvlength
, tvb
, offset
, 1, length
);
261 dissect_hpsw_tlv(tvb
, pinfo
, offset
, length
, tlv_tree
, ti
, type
);
266 return tvb_captured_length(tvb
);
270 proto_register_hpsw(void)
272 static hf_register_info hf
[] = {
274 { "Version", "hpsw.version", FT_UINT8
, BASE_HEX
,
275 NULL
, 0x0, NULL
, HFILL
}},
277 { "Type", "hpsw.type", FT_UINT8
, BASE_HEX
,
278 NULL
, 0x0, NULL
, HFILL
}},
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
}},
298 { "IP Addr", "hpsw.ip_addr", FT_IPv4
, BASE_NONE
,
299 NULL
, 0x0, NULL
, HFILL
}},
301 { "Field 6", "hpsw.field_6", FT_UINT16
, BASE_HEX
,
302 NULL
, 0x0, NULL
, HFILL
}},
304 { "Domain", "hpsw.domain", FT_STRING
, BASE_NONE
,
305 NULL
, 0x0, NULL
, HFILL
}},
307 { "Field 8", "hpsw.field_8", FT_UINT16
, BASE_HEX
,
308 NULL
, 0x0, NULL
, HFILL
}},
310 { "Field 9", "hpsw.field_9", FT_UINT16
, BASE_HEX
,
311 NULL
, 0x0, NULL
, HFILL
}},
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
}},
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
}},
331 { "Data", "hpsw.data", FT_BYTES
, BASE_NONE
,
332 NULL
, 0x0, NULL
, HFILL
}},
335 static int *ett
[] = {
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
);
356 proto_reg_handoff_hpsw(void)
358 dissector_add_uint("hpext.dxsap", HPEXT_HPSW
, hpsw_handle
);
367 * indent-tabs-mode: nil
370 * ex: set shiftwidth=4 tabstop=8 expandtab:
371 * :indentSize=4:tabSize=8:noTabs=true: