change a whole bunch of ethereal into wireshark
[obnox/wireshark/wip.git] / epan / dissectors / packet-nettl.c
1 /* packet-nettl.c
2  * Routines for nettl (HP-UX) record header dissection
3  *
4  * Original Author Mark C. Brown <mbrown@hp.com>
5  * Copyright (C) 2005 Hewlett-Packard Development Company, L.P.
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * Copied from packet-pagp.c
14  *
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.
19  *
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.
24  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <glib.h>
37 #include <epan/packet.h>
38 #include <epan/ipproto.h>
39 #include <wiretap/nettl.h>
40
41 /* Initialise the protocol and registered fields */
42
43 static int proto_nettl = -1;
44
45 static int hf_nettl_subsys = -1;
46 static int hf_nettl_devid = -1;
47 static int hf_nettl_kind = -1;
48 static int hf_nettl_pid = -1;
49 static int hf_nettl_uid = -1;
50
51 static dissector_handle_t eth_withoutfcs_handle;
52 static dissector_handle_t tr_handle;
53 static dissector_handle_t lapb_handle;
54 static dissector_handle_t x25_handle;
55 static dissector_handle_t data_handle;
56 static dissector_table_t wtap_dissector_table;
57 static dissector_table_t ip_proto_dissector_table;
58
59 /* Initialise the subtree pointers */
60
61 static gint ett_nettl = -1;
62
63 /* General declarations and macros */
64
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" },
73         { 0x04000000, "State" },
74         { 0x02000000, "Error" },
75         { 0x01000000, "Logging" },
76         { 0x00800000, "Loopback" },
77         { 0, NULL }
78 };
79
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, "FC" },
114         { 34, "SX25L2" },
115         { 35, "SX25L3" },
116         { 36, "NS_LS_SX25" },
117         { 37, "100VG" },
118         { 38, "ATM" },
119         { 64, "FTAM_INIT" },
120         { 65, "FTAM_RESP" },
121         { 70, "FTAM_VFS" },
122         { 72, "FTAM_USER" },
123         { 82, "OVS" },
124         { 84, "OVEXTERNAL" },
125         { 90, "OTS9000" },
126         { 91, "OTS9000-NETWORK" },
127         { 92, "OTS9000-TRANSPORT" },
128         { 93, "OTS9000-SESSION" },
129         { 94, "OTS9000-ACSE_PRES" },
130         { 95, "FDDI" },
131         { 116, "SHM" },
132         { 119, "ACSE_US" },
133         { 121, "HPS" },
134         { 122, "CM" },
135         { 123, "ULA_UTILS" },
136         { 124, "EM" },
137         { 129, "STREAMS" },
138         { 164, "LAN100" },
139         { 172, "EISA100BT" },
140         { 173, "BASE100" },
141         { 174, "EISA_FDDI" },
142         { 176, "PCI_FDDI" },
143         { 177, "HSC_FDDI" },
144         { 178, "GSC100BT" },
145         { 179, "PCI100BT" },
146         { 180, "SPP100BT" },
147         { 185, "GELAN" },
148         { 187, "PCITR" },
149         { 188, "HP_APA" },
150         { 189, "HP_APAPORT" },
151         { 190, "HP_APALACP" },
152         { 210, "BTLAN" },
153         { 227, "NS_LS_SCTP" },
154         { 233, "INTL100" },
155         { 244, "NS_LS_IPV6" },
156         { 245, "NS_LS_ICMPV6" },
157         { 246, "DLPI" },
158         { 247, "VLAN" },
159         { 249, "NS_LS_LOOPBACK6" },
160         { 250, "DHCPV6D" },
161         { 252, "IGELAN" },
162         { 253, "IETHER" },
163         { 265, "IXGBE" },
164         { 513, "KL_VM" },
165         { 514, "KL_PKM" },
166         { 515, "KL_DLKM" },
167         { 516, "KL_PM" },
168         { 517, "KL_VFS" },
169         { 518, "KL_VXFS" },
170         { 519, "KL_UFS" },
171         { 520, "KL_NFS" },
172         { 521, "KL_FSVM" },
173         { 522, "KL_WSIO" },
174         { 523, "KL_SIO" },
175         { 524, "KL_NET" },
176         { 525, "KL_MC" },
177         { 526, "KL_DYNTUNE" },
178         { 0, NULL }
179 };
180
181
182 /* Code to actually dissect the nettl record headers */
183
184 static void
185 dissect_nettl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
186 {
187       proto_tree *nettl_tree;
188       proto_item *nettl_item;
189
190       pinfo->current_proto = "nettl";
191
192       if (check_col(pinfo->cinfo, COL_HPUX_SUBSYS))
193             col_set_str(pinfo->cinfo, COL_HPUX_SUBSYS,
194                 val_to_str(pinfo->pseudo_header->nettl.subsys, subsystem, "Unknown"));
195       if (check_col(pinfo->cinfo, COL_HPUX_DEVID)) {
196             col_clear(pinfo->cinfo, COL_HPUX_DEVID);
197             col_add_fstr(pinfo->cinfo, COL_HPUX_DEVID, "%4d",
198                 pinfo->pseudo_header->nettl.devid);
199       }
200
201       if (tree) {
202             nettl_item = proto_tree_add_protocol_format(tree, proto_nettl, tvb,
203                 0, -1, "HP-UX Network Tracing and Logging (nettl) header");
204             nettl_tree = proto_item_add_subtree(nettl_item, ett_nettl);
205             proto_tree_add_uint_format(nettl_tree, hf_nettl_subsys, tvb,
206                 0, 0, pinfo->pseudo_header->nettl.subsys,
207                 "Subsystem: %d (%s)", pinfo->pseudo_header->nettl.subsys,
208                 val_to_str(pinfo->pseudo_header->nettl.subsys, subsystem, "Unknown"));
209             proto_tree_add_int(nettl_tree, hf_nettl_devid, tvb,
210                 0, 0, pinfo->pseudo_header->nettl.devid);
211             proto_tree_add_uint_format(nettl_tree, hf_nettl_kind, tvb,
212                 0, 0, pinfo->pseudo_header->nettl.kind,
213                 "Trace Kind: 0x%08x (%s)", pinfo->pseudo_header->nettl.kind,
214                 val_to_str(pinfo->pseudo_header->nettl.kind, trace_kind, "Unknown"));
215             proto_tree_add_int(nettl_tree, hf_nettl_pid, tvb,
216                 0, 0, pinfo->pseudo_header->nettl.pid);
217             proto_tree_add_uint(nettl_tree, hf_nettl_uid, tvb,
218                 0, 0, pinfo->pseudo_header->nettl.uid);
219
220       }
221
222       switch (pinfo->fd->lnk_t) {
223          case WTAP_ENCAP_NETTL_ETHERNET:
224             call_dissector(eth_withoutfcs_handle, tvb, pinfo, tree);
225             break;
226          case WTAP_ENCAP_NETTL_TOKEN_RING:
227             call_dissector(tr_handle, tvb, pinfo, tree);
228             break;
229          case WTAP_ENCAP_NETTL_FDDI:
230             if (!dissector_try_port(wtap_dissector_table,
231                         WTAP_ENCAP_FDDI_BITSWAPPED, tvb, pinfo, tree))
232                     call_dissector(data_handle, tvb, pinfo, tree);
233             break;
234          case WTAP_ENCAP_NETTL_RAW_IP:
235             if (!dissector_try_port(wtap_dissector_table,
236                         WTAP_ENCAP_RAW_IP, tvb, pinfo, tree))
237                     call_dissector(data_handle, tvb, pinfo, tree);
238             break;
239          case WTAP_ENCAP_NETTL_RAW_ICMP:
240             if (!dissector_try_port(ip_proto_dissector_table,
241                         IP_PROTO_ICMP, tvb, pinfo, tree))
242                     call_dissector(data_handle, tvb, pinfo, tree);
243             break;
244          case WTAP_ENCAP_NETTL_RAW_ICMPV6:
245             if (!dissector_try_port(ip_proto_dissector_table,
246                         IP_PROTO_ICMPV6, tvb, pinfo, tree))
247                     call_dissector(data_handle, tvb, pinfo, tree);
248             break;
249          case WTAP_ENCAP_NETTL_X25:
250             if (pinfo->pseudo_header->nettl.kind == NETTL_HDR_PDUIN)
251                 pinfo->p2p_dir = P2P_DIR_RECV;
252             else if (pinfo->pseudo_header->nettl.kind == NETTL_HDR_PDUOUT)
253                 pinfo->p2p_dir = P2P_DIR_SENT;
254             if (pinfo->pseudo_header->nettl.subsys == NETTL_SUBSYS_SX25L2)
255                 call_dissector(lapb_handle, tvb, pinfo, tree);
256             else
257                 call_dissector(x25_handle, tvb, pinfo, tree);
258             break;
259          default:
260             if (check_col(pinfo->cinfo, COL_PROTOCOL))
261                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
262             if (check_col(pinfo->cinfo, COL_INFO))
263                 col_add_fstr(pinfo->cinfo, COL_INFO,
264                 "Unsupported nettl subsytem: %d (%s)",
265                 pinfo->pseudo_header->nettl.subsys,
266                 val_to_str(pinfo->pseudo_header->nettl.subsys, subsystem, "Unknown"));
267             call_dissector(data_handle, tvb, pinfo, tree);
268       }
269 }
270
271
272 /* Register the protocol with Wireshark */
273
274 void
275 proto_register_nettl(void)
276 {
277 /* Setup list of header fields */
278
279   static hf_register_info hf[] = {
280
281         { &hf_nettl_subsys,
282         { "Subsystem", "nettl.subsys", FT_UINT16, BASE_DEC, VALS(subsystem), 0x0,
283                 "HP-UX Subsystem/Driver", HFILL }},
284
285         { &hf_nettl_devid,
286         { "Device ID", "nettl.devid", FT_INT32, BASE_DEC, NULL, 0x0,
287                 "HP-UX Device ID", HFILL }},
288
289         { &hf_nettl_kind,
290         { "Trace Kind", "nettl.kind", FT_UINT32, BASE_HEX, VALS(trace_kind), 0x0,
291                 "HP-UX Trace record kind", HFILL}},
292
293         { &hf_nettl_pid,
294         { "Process ID (pid/ktid)", "nettl.pid", FT_INT32, BASE_DEC, NULL, 0x0,
295                 "HP-UX Process/thread id", HFILL}},
296
297         { &hf_nettl_uid,
298         { "User ID (uid)", "nettl.uid", FT_UINT16, BASE_DEC, NULL, 0x0,
299                 "HP-UX User ID", HFILL}},
300
301   };
302
303   /* Setup protocol subtree array */
304
305   static gint *ett[] = {
306     &ett_nettl,
307   };
308
309   /* Register the protocol name and description */
310
311   proto_nettl = proto_register_protocol("HP-UX Network Tracing and Logging", "nettl", "nettl");
312
313   /* Required function calls to register the header fields and subtrees used */
314
315   proto_register_field_array(proto_nettl, hf, array_length(hf));
316   proto_register_subtree_array(ett, array_length(ett));
317
318 }
319
320
321 void
322 proto_reg_handoff_nettl(void)
323 {
324   dissector_handle_t nettl_handle;
325
326                                                                                 
327   /*
328    * Get handles for the Ethernet, Token Ring, FDDI, and RAW dissectors.
329   */
330   eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
331   tr_handle = find_dissector("tr");
332   lapb_handle = find_dissector("lapb");
333   x25_handle = find_dissector("x.25");
334   data_handle = find_dissector("data");
335   wtap_dissector_table = find_dissector_table("wtap_encap");
336   ip_proto_dissector_table = find_dissector_table("ip.proto");
337
338   nettl_handle = create_dissector_handle(dissect_nettl, proto_nettl);
339   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_ETHERNET, nettl_handle);
340   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_TOKEN_RING, nettl_handle);
341   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_FDDI, nettl_handle);
342   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_RAW_IP, nettl_handle);
343   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_RAW_ICMP, nettl_handle);
344   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_RAW_ICMPV6, nettl_handle);
345   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_X25, nettl_handle);
346   dissector_add("wtap_encap", WTAP_ENCAP_NETTL_UNKNOWN, nettl_handle);
347 }