HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-nettl.c
blob1ef61f70c0b6a6e7bcd7240a2ea71fd7beb56140
1 /* packet-nettl.c
2 * Routines for nettl (HP-UX) record header dissection
4 * Original Author Mark C. Brown <mbrown@hp.com>
5 * Copyright (C) 2005 Hewlett-Packard Development Company, L.P.
7 * $Id$
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-pagp.c
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include "config.h"
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/ipproto.h>
35 #include <wiretap/nettl.h>
37 /* Initialize the protocol and registered fields */
39 static int proto_nettl = -1;
41 static int hf_nettl_subsys = -1;
42 static int hf_nettl_devid = -1;
43 static int hf_nettl_kind = -1;
44 static int hf_nettl_pid = -1;
45 static int hf_nettl_uid = -1;
47 static dissector_handle_t eth_withoutfcs_handle;
48 static dissector_handle_t tr_handle;
49 static dissector_handle_t lapb_handle;
50 static dissector_handle_t x25_handle;
51 static dissector_handle_t sctp_handle;
52 static dissector_handle_t data_handle;
53 static dissector_table_t wtap_dissector_table;
54 static dissector_table_t ip_proto_dissector_table;
55 static dissector_table_t tcp_subdissector_table;
57 #define TCP_PORT_TELNET 23
59 /* Initialize the subtree pointers */
61 static gint ett_nettl = -1;
63 /* General declarations and macros */
65 static const value_string trace_kind[] = {
66 { 0x80000000, "Incoming Header" },
67 { 0x40000000, "Outgoing Header" },
68 { 0x20000000, "Incoming PDU - PDUIN" },
69 { 0x20000000, "PDUIN" },
70 { 0x10000000, "Outgoing PDU - PDUOUT" },
71 { 0x10000000, "PDUOUT" },
72 { 0x08000000, "Procedure Trace" },
73 { 0x04000000, "State Trace" },
74 { 0x02000000, "Error Trace" },
75 { 0x01000000, "Logging" },
76 { 0x00800000, "Loopback" },
77 { 0, NULL }
80 static const value_string subsystem[] = {
81 { 0, "NS_LS_LOGGING" },
82 { 1, "NS_LS_NFT" },
83 { 2, "NS_LS_LOOPBACK" },
84 { 3, "NS_LS_NI" },
85 { 4, "NS_LS_IPC" },
86 { 5, "NS_LS_SOCKREGD" },
87 { 6, "NS_LS_TCP" },
88 { 7, "NS_LS_PXP" },
89 { 8, "NS_LS_UDP" },
90 { 9, "NS_LS_IP" },
91 { 10, "NS_LS_PROBE" },
92 { 11, "NS_LS_DRIVER" },
93 { 12, "NS_LS_RLBD" },
94 { 13, "NS_LS_BUFS" },
95 { 14, "NS_LS_CASE21" },
96 { 15, "NS_LS_ROUTER21" },
97 { 16, "NS_LS_NFS" },
98 { 17, "NS_LS_NETISR" },
99 { 18, "NS_LS_X25D" },
100 { 19, "NS_LS_NSE" },
101 { 20, "NS_LS_STRLOG" },
102 { 21, "NS_LS_TIRDWR" },
103 { 22, "NS_LS_TIMOD" },
104 { 23, "NS_LS_ICMP" },
105 { 24, "X25L2" },
106 { 25, "X25L3" },
107 { 26, "FILTER" },
108 { 27, "NAME" },
109 { 28, "ACC" },
110 { 29, "NS_LS_IGMP" },
111 { 31, "TOKEN" },
112 { 32, "HIPPI" },
113 { 33, "EISA_FC" },
114 { 34, "SX25L2" },
115 { 35, "SX25L3" },
116 { 36, "NS_LS_SX25" },
117 { 37, "100VG" },
118 { 38, "EISA_ATM" },
119 { 39, "SEAH_FDDI" },
120 { 40, "TELECOM_HLR" },
121 { 41, "TELECOM_SCE" },
122 { 42, "TELECOM_SMS" },
123 { 43, "TELECOM_NEM" },
124 { 50, "FORE_ATM" },
125 { 60, "TMOS_TOB" },
126 { 62, "TELECOM_SCP" },
127 { 63, "TELECOM_SS7" },
128 { 64, "FTAM_INIT" },
129 { 65, "FTAM_RESP" },
130 { 70, "FTAM_VFS" },
131 { 72, "FTAM_USER" },
132 { 82, "OVS" },
133 { 84, "OVEXTERNAL" },
134 { 90, "OTS9000" },
135 { 91, "OTS9000-NETWORK" },
136 { 92, "OTS9000-TRANSPORT" },
137 { 93, "OTS9000-SESSION" },
138 { 94, "OTS9000-ACSE_PRES" },
139 { 95, "FDDI" },
140 { 116, "SHM" },
141 { 119, "ACSE_US" },
142 { 121, "HPS" },
143 { 122, "CM" },
144 { 123, "ULA_UTILS" },
145 { 124, "EM" },
146 { 129, "STREAMS" },
147 { 164, "LAN100" },
148 { 172, "EISA100BT" },
149 { 173, "BASE100" },
150 { 174, "EISA_FDDI" },
151 { 176, "PCI_FDDI" },
152 { 177, "HSC_FDDI" },
153 { 178, "GSC100BT" },
154 { 179, "PCI100BT" },
155 { 180, "SPP100BT" },
156 { 181, "GLE" },
157 { 182, "FQE" },
158 { 185, "GELAN" },
159 { 187, "PCITR" },
160 { 188, "HP_APA" },
161 { 189, "HP_APAPORT" },
162 { 190, "HP_APALACP" },
163 { 210, "BTLAN" },
164 { 233, "INTL100" },
165 { 244, "NS_LS_IPV6" },
166 { 245, "NS_LS_ICMPV6" },
167 { 246, "DLPI" },
168 { 247, "VLAN" },
169 { 249, "NS_LS_LOOPBACK6" },
170 { 250, "DHCPV6D" },
171 { 252, "IGELAN" },
172 { 253, "IETHER" },
173 { 257, "WBEMProvider-LAN" },
174 { 258, "SYSADMIN" },
175 { 264, "LVMPROVIDER" },
176 { 265, "IXGBE" },
177 { 267, "NS_LS_TELNET" },
178 { 268, "NS_LS_SCTP" },
179 { 269, "HSSN" },
180 { 270, "IGSSN" },
181 { 271, "ICXGBE" },
182 { 275, "IEXGBE" },
183 { 277, "IOCXGBE" },
184 { 278, "IQXGBE" },
185 { 513, "KL_VM" },
186 { 514, "KL_PKM" },
187 { 515, "KL_DLKM" },
188 { 516, "KL_PM" },
189 { 517, "KL_VFS" },
190 { 518, "KL_VXFS" },
191 { 519, "KL_UFS" },
192 { 520, "KL_NFS" },
193 { 521, "KL_FSVM" },
194 { 522, "KL_WSIO" },
195 { 523, "KL_SIO" },
196 { 524, "KL_NET" },
197 { 525, "KL_MC" },
198 { 526, "KL_DYNTUNE" },
199 { 527, "KL_KEN" },
200 { 0, NULL }
204 /* Code to actually dissect the nettl record headers */
206 static void
207 dissect_nettl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
209 proto_tree *nettl_tree;
210 proto_item *nettl_item;
212 pinfo->current_proto = "nettl";
214 if (tree) {
215 nettl_item = proto_tree_add_protocol_format(tree, proto_nettl, tvb,
216 0, -1, "HP-UX Network Tracing and Logging (nettl) header");
217 nettl_tree = proto_item_add_subtree(nettl_item, ett_nettl);
218 proto_tree_add_uint_format_value(nettl_tree, hf_nettl_subsys, tvb,
219 0, 0, pinfo->pseudo_header->nettl.subsys, "%d (%s)", pinfo->pseudo_header->nettl.subsys,
220 val_to_str_const(pinfo->pseudo_header->nettl.subsys, subsystem, "Unknown"));
221 proto_tree_add_int(nettl_tree, hf_nettl_devid, tvb,
222 0, 0, pinfo->pseudo_header->nettl.devid);
223 proto_tree_add_uint_format_value(nettl_tree, hf_nettl_kind, tvb,
224 0, 0, pinfo->pseudo_header->nettl.kind,
225 "0x%08x (%s)", pinfo->pseudo_header->nettl.kind,
226 val_to_str_const(pinfo->pseudo_header->nettl.kind & ~NETTL_HDR_SUBSYSTEM_BITS_MASK, trace_kind, "Unknown"));
227 proto_tree_add_int(nettl_tree, hf_nettl_pid, tvb,
228 0, 0, pinfo->pseudo_header->nettl.pid);
229 proto_tree_add_uint(nettl_tree, hf_nettl_uid, tvb,
230 0, 0, pinfo->pseudo_header->nettl.uid);
233 switch (pinfo->fd->lnk_t) {
234 case WTAP_ENCAP_NETTL_ETHERNET:
235 call_dissector(eth_withoutfcs_handle, tvb, pinfo, tree);
236 break;
237 case WTAP_ENCAP_NETTL_TOKEN_RING:
238 call_dissector(tr_handle, tvb, pinfo, tree);
239 break;
240 case WTAP_ENCAP_NETTL_FDDI:
241 if (!dissector_try_uint(wtap_dissector_table,
242 WTAP_ENCAP_FDDI_BITSWAPPED, tvb, pinfo, tree))
243 call_dissector(data_handle, tvb, pinfo, tree);
244 break;
245 case WTAP_ENCAP_NETTL_RAW_IP:
246 if ( (pinfo->pseudo_header->nettl.kind & NETTL_HDR_PDU_MASK) == 0 )
247 /* not actually a data packet (PDU) trace record */
248 call_dissector(data_handle, tvb, pinfo, tree);
249 else if (pinfo->pseudo_header->nettl.subsys == NETTL_SUBSYS_NS_LS_SCTP )
250 call_dissector(sctp_handle, tvb, pinfo, tree);
251 else if (!dissector_try_uint(wtap_dissector_table,
252 WTAP_ENCAP_RAW_IP, tvb, pinfo, tree))
253 call_dissector(data_handle, tvb, pinfo, tree);
254 break;
255 case WTAP_ENCAP_NETTL_RAW_ICMP:
256 if (!dissector_try_uint(ip_proto_dissector_table,
257 IP_PROTO_ICMP, tvb, pinfo, tree))
258 call_dissector(data_handle, tvb, pinfo, tree);
259 break;
260 case WTAP_ENCAP_NETTL_RAW_ICMPV6:
261 if (!dissector_try_uint(ip_proto_dissector_table,
262 IP_PROTO_ICMPV6, tvb, pinfo, tree))
263 call_dissector(data_handle, tvb, pinfo, tree);
264 break;
265 case WTAP_ENCAP_NETTL_X25:
266 if (pinfo->pseudo_header->nettl.kind == NETTL_HDR_PDUIN)
267 pinfo->p2p_dir = P2P_DIR_RECV;
268 else if (pinfo->pseudo_header->nettl.kind == NETTL_HDR_PDUOUT)
269 pinfo->p2p_dir = P2P_DIR_SENT;
270 if (pinfo->pseudo_header->nettl.subsys == NETTL_SUBSYS_SX25L2)
271 call_dissector(lapb_handle, tvb, pinfo, tree);
272 else
273 call_dissector(x25_handle, tvb, pinfo, tree);
274 break;
275 case WTAP_ENCAP_NETTL_RAW_TELNET:
276 if (!dissector_try_uint(tcp_subdissector_table,
277 TCP_PORT_TELNET, tvb, pinfo, tree))
278 call_dissector(data_handle, tvb, pinfo, tree);
279 break;
280 default:
281 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
282 col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported nettl subsytem: %d (%s)",
283 pinfo->pseudo_header->nettl.subsys,
284 val_to_str_const(pinfo->pseudo_header->nettl.subsys, subsystem, "Unknown"));
285 call_dissector(data_handle, tvb, pinfo, tree);
290 /* Register the protocol with Wireshark */
292 void
293 proto_register_nettl(void)
295 /* Setup list of header fields */
297 static hf_register_info hf[] = {
299 { &hf_nettl_subsys,
300 { "Subsystem", "nettl.subsys", FT_UINT16, BASE_DEC, VALS(subsystem), 0x0,
301 "HP-UX Subsystem/Driver", HFILL }},
303 { &hf_nettl_devid,
304 { "Device ID", "nettl.devid", FT_INT32, BASE_DEC, NULL, 0x0,
305 "HP-UX Device ID", HFILL }},
307 { &hf_nettl_kind,
308 { "Trace Kind", "nettl.kind", FT_UINT32, BASE_HEX, VALS(trace_kind), 0x0,
309 "HP-UX Trace record kind", HFILL}},
311 { &hf_nettl_pid,
312 { "Process ID (pid/ktid)", "nettl.pid", FT_INT32, BASE_DEC, NULL, 0x0,
313 "HP-UX Process/thread id", HFILL}},
315 { &hf_nettl_uid,
316 { "User ID (uid)", "nettl.uid", FT_UINT16, BASE_DEC, NULL, 0x0,
317 "HP-UX User ID", HFILL}}
321 /* Setup protocol subtree array */
323 static gint *ett[] = {
324 &ett_nettl
327 /* Register the protocol name and description */
329 proto_nettl = proto_register_protocol("HP-UX Network Tracing and Logging", "nettl", "nettl");
331 /* Required function calls to register the header fields and subtrees used */
333 proto_register_field_array(proto_nettl, hf, array_length(hf));
334 proto_register_subtree_array(ett, array_length(ett));
339 void
340 proto_reg_handoff_nettl(void)
342 dissector_handle_t nettl_handle;
345 * Get handles for the Ethernet, Token Ring, FDDI, and RAW dissectors.
347 eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
348 tr_handle = find_dissector("tr");
349 lapb_handle = find_dissector("lapb");
350 x25_handle = find_dissector("x.25");
351 sctp_handle = find_dissector("sctp");
352 data_handle = find_dissector("data");
353 wtap_dissector_table = find_dissector_table("wtap_encap");
354 ip_proto_dissector_table = find_dissector_table("ip.proto");
355 tcp_subdissector_table = find_dissector_table("tcp.port");
357 nettl_handle = create_dissector_handle(dissect_nettl, proto_nettl);
358 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_ETHERNET, nettl_handle);
359 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_TOKEN_RING, nettl_handle);
360 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_FDDI, nettl_handle);
361 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_RAW_IP, nettl_handle);
362 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_RAW_ICMP, nettl_handle);
363 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_RAW_ICMPV6, nettl_handle);
364 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_RAW_TELNET, nettl_handle);
365 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_X25, nettl_handle);
366 dissector_add_uint("wtap_encap", WTAP_ENCAP_NETTL_UNKNOWN, nettl_handle);