If we implement new style dissectors, register them as such.
[obnox/wireshark/wip.git] / asn1 / h501 / packet-h501-template.c
1 /* packet-h501.c
2  * Routines for H.501 packet dissection
3  * 2007  Tomas Kukosa
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
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (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
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/conversation.h>
34 #include <epan/oids.h>
35 #include <epan/asn1.h>
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "packet-tpkt.h"
41 #include "packet-per.h"
42 #include "packet-h225.h"
43 #include "packet-h235.h"
44
45 #define PNAME  "H.501 Mobility"
46 #define PSNAME "H.501"
47 #define PFNAME "h501"
48
49 /* Initialize the protocol and registered fields */
50 int proto_h501 = -1;
51 #include "packet-h501-hf.c"
52
53 /* Initialize the subtree pointers */
54 static int ett_h501 = -1;
55 #include "packet-h501-ett.c"
56
57 /* Dissectors */
58 static dissector_handle_t h501_pdu_handle = NULL;
59 static dissector_handle_t h501_udp_handle = NULL;
60 static dissector_handle_t h501_tcp_handle = NULL;
61
62 /* Preferences */
63 static guint h501_udp_port = 2099;
64 static guint h501_tcp_port = 2099;
65 static gboolean h501_desegment_tcp = TRUE;
66
67 /* Gloabl variables */
68 static guint saved_h501_udp_port;
69 static guint saved_h501_tcp_port;
70
71 void proto_reg_handoff_h501(void);
72
73 #include "packet-h501-fn.c"
74
75 static int
76 dissect_h501_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
77 {
78   proto_item  *ti = NULL;
79   proto_tree  *h501_tree = NULL;
80
81   if (check_col(pinfo->cinfo, COL_PROTOCOL))
82     col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
83
84   ti = proto_tree_add_item(tree, proto_h501, tvb, 0, -1, FALSE);
85   h501_tree = proto_item_add_subtree(ti, ett_h501);
86
87   return dissect_Message_PDU(tvb, pinfo, h501_tree);
88 }
89
90 static int
91 dissect_h501_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
92 {
93   dissect_tpkt_encap(tvb, pinfo, tree, FALSE, h501_pdu_handle);
94   return tvb_length(tvb);
95 }
96
97 static int
98 dissect_h501_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
99 {
100   dissect_tpkt_encap(tvb, pinfo, tree, h501_desegment_tcp, h501_pdu_handle);
101   return tvb_length(tvb);
102 }
103
104 /*--- proto_register_h501 ----------------------------------------------*/
105 void proto_register_h501(void) {
106   module_t *h501_module;
107
108   /* List of fields */
109   static hf_register_info hf[] = {
110 #include "packet-h501-hfarr.c"
111   };
112
113   /* List of subtrees */
114   static gint *ett[] = {
115     &ett_h501,
116 #include "packet-h501-ettarr.c"
117   };
118
119   /* Register protocol */
120   proto_h501 = proto_register_protocol(PNAME, PSNAME, PFNAME);
121
122   /* Register fields and subtrees */
123   proto_register_field_array(proto_h501, hf, array_length(hf));
124   proto_register_subtree_array(ett, array_length(ett));
125
126   new_register_dissector(PFNAME, dissect_h501_pdu, proto_h501);
127   h501_pdu_handle = find_dissector(PFNAME);
128
129   h501_udp_handle = new_create_dissector_handle(dissect_h501_udp, proto_h501);
130   h501_tcp_handle = new_create_dissector_handle(dissect_h501_tcp, proto_h501);
131
132   h501_module = prefs_register_protocol(proto_h501, proto_reg_handoff_h501);
133   prefs_register_uint_preference(h501_module, "udp.port",
134                                  "UDP port",
135                                  "Port to be decoded as h501",
136                                  10, &h501_udp_port);
137   prefs_register_uint_preference(h501_module, "tcp.port",
138                                  "TCP port",
139                                  "Port to be decoded as h501",
140                                  10, &h501_tcp_port);
141   prefs_register_bool_preference(h501_module, "desegment",
142                                  "Desegment H.501 over TCP",
143                                  "Desegment H.501 messages that span more TCP segments",
144                                  &h501_desegment_tcp);
145
146 }
147
148 /*--- proto_reg_handoff_h501 -------------------------------------------*/
149 void proto_reg_handoff_h501(void) 
150 {
151   static gboolean h501_prefs_initialized = FALSE;
152
153   if (h501_prefs_initialized) {
154     dissector_delete("udp.port", saved_h501_udp_port, h501_udp_handle);
155     dissector_delete("tcp.port", saved_h501_tcp_port, h501_tcp_handle);
156   } else {
157     h501_prefs_initialized = TRUE;
158   }
159
160   /* Set our port number for future use */
161   saved_h501_udp_port = h501_udp_port;
162   dissector_add("udp.port", saved_h501_udp_port, h501_udp_handle);
163   saved_h501_tcp_port = h501_tcp_port;
164   dissector_add("tcp.port", saved_h501_tcp_port, h501_tcp_handle);
165
166 }
167