Move 3 ASN1 dissectors to 'clean' group; move 1 PIDL dissector to 'dirty' group.
[metze/wireshark/wip.git] / epan / dissectors / packet-atmtcp.c
1 /* packet-atmtcp.c
2  * Routines for ATM over TCP dissection
3  * Copyright 2011, Alexis La Goutte <alexis.lagoutte at gmail dot com>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
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.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 /* Specification...
27  * http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob;f=include/linux/atm_tcp.h;hb=HEAD
28  * http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob;f=drivers/atm/atmtcp.c;hb=HEAD
29  */
30
31 #include "config.h"
32
33 #include <glib.h>
34
35 #include <epan/packet.h>
36 #include <epan/prefs.h>
37
38 void proto_reg_handoff_atmtcp(void);
39
40 static int proto_atmtcp = -1;
41 static int hf_atmtcp_vpi = -1;
42 static int hf_atmtcp_vci = -1;
43 static int hf_atmtcp_length = -1;
44
45 static guint global_atmtcp_tcp_port = 2812;
46
47 static gint ett_atmtcp = -1;
48
49 static dissector_handle_t data_handle;
50
51 #define ATMTCP_HDR_MAGIC        (~0)    /* this length indicates a command */
52 #define ATMTCP_CTRL_OPEN        1       /* request/reply */
53 #define ATMTCP_CTRL_CLOSE       2       /* request/reply */
54
55 static int
56 dissect_atmtcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
57 {
58
59     proto_item *ti;
60     proto_tree *atmtcp_tree;
61     guint       offset = 0;
62     gint32      length;
63     tvbuff_t   *next_tvb;
64
65     col_set_str(pinfo->cinfo, COL_PROTOCOL, "ATMTCP");
66
67     col_set_str(pinfo->cinfo, COL_INFO, "ATMTCP");
68
69     if (tree) {
70         ti = proto_tree_add_item(tree, proto_atmtcp, tvb, 0, -1, ENC_NA);
71
72         atmtcp_tree = proto_item_add_subtree(ti, ett_atmtcp);
73
74         /* VPI */
75         proto_tree_add_item(atmtcp_tree, hf_atmtcp_vpi, tvb, offset, 2, ENC_NA);
76     }
77     offset += 2;
78
79
80     if (tree) {
81         /* VCI */
82         proto_tree_add_item(atmtcp_tree, hf_atmtcp_vci, tvb, offset, 2, ENC_NA);
83     }
84     offset += 2;
85
86
87     if (tree) {
88         /* Length  */
89         proto_tree_add_item(atmtcp_tree, hf_atmtcp_length, tvb, offset, 4, ENC_NA);
90     }
91     length = tvb_get_ntohl(tvb, offset);
92     if(length == ATMTCP_HDR_MAGIC)
93     {
94         col_append_fstr(pinfo->cinfo, COL_INFO, " Command");
95     }
96     else
97     {
98         col_append_fstr(pinfo->cinfo, COL_INFO, " Data");
99     }
100     offset += 4;
101
102     /* Data (for the moment...) */
103     next_tvb = tvb_new_subset_remaining(tvb, offset);
104     call_dissector(data_handle, next_tvb, pinfo, tree);
105     return tvb_length(tvb);
106 }
107
108
109 void
110 proto_register_atmtcp(void)
111 {
112     module_t *atmtcp_module;
113
114
115     static hf_register_info hf[] = {
116         { &hf_atmtcp_vpi,
117             { "VPI",           "atmtcp.vpi", FT_UINT16, BASE_DEC, NULL, 0x0,
118               "Virtual Path Identifier", HFILL }
119         },
120         { &hf_atmtcp_vci,
121             { "VCI",           "atmtcp.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
122               "Virtual Channel Identifier", HFILL }
123         },
124         { &hf_atmtcp_length,
125             { "Length",        "atmtcp.length", FT_UINT32, BASE_DEC, NULL, 0x0,
126               "length of data", HFILL }
127         }
128     };
129
130
131     static gint *ett[] = {
132         &ett_atmtcp
133     };
134
135
136     proto_atmtcp = proto_register_protocol("ATM over TCP", "ATMTCP", "atmtcp");
137
138     proto_register_field_array(proto_atmtcp, hf, array_length(hf));
139     proto_register_subtree_array(ett, array_length(ett));
140
141
142     atmtcp_module = prefs_register_protocol(proto_atmtcp, proto_reg_handoff_atmtcp);
143
144     prefs_register_uint_preference(atmtcp_module, "tcp.port", "ATMTCP TCP Port",
145                                     "ATMTCP TCP port if other than the default",
146                                     10, &global_atmtcp_tcp_port);
147 }
148
149
150 void
151 proto_reg_handoff_atmtcp(void)
152 {
153     static gboolean initialized = FALSE;
154     static dissector_handle_t atmtcp_handle;
155     static int current_port;
156
157     if (!initialized) {
158         atmtcp_handle = new_create_dissector_handle(dissect_atmtcp, proto_atmtcp);
159         data_handle = find_dissector("data");
160         initialized = TRUE;
161     } else {
162         dissector_delete_uint("tcp.port", current_port, atmtcp_handle);
163     }
164
165     current_port = global_atmtcp_tcp_port;
166
167     dissector_add_uint("tcp.port", current_port, atmtcp_handle);
168 }
169
170 /*
171  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
172  *
173  * Local variables:
174  * c-basic-offset: 4
175  * tab-width: 8
176  * indent-tabs-mode: nil
177  * End:
178  *
179  * vi: set shiftwidth=4 tabstop=8 expandtab:
180  * :indentSize=4:tabSize=8:noTabs=true:
181  */