We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
[metze/wireshark/wip.git] / asn1 / t124 / packet-t124-template.c
1 /* packet-t124.c
2  * Routines for t124 packet dissection
3  * Copyright 2010, Graeme Lunt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/conversation.h>
32
33 #include <epan/asn1.h>
34 #include "packet-per.h"
35 #include "packet-ber.h"
36 #include "packet-t124.h"
37
38 #ifdef _MSC_VER
39 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
40 #pragma warning(disable:4146)
41 #endif
42
43 #define PNAME  "GENERIC-CONFERENCE-CONTROL T.124"
44 #define PSNAME "T.124"
45 #define PFNAME "t124"
46
47 /* Initialize the protocol and registered fields */
48 static int proto_t124 = -1;
49 static proto_tree *top_tree = NULL;
50
51 #include "packet-t124-hf.c"
52
53 /* Initialize the subtree pointers */
54 static int ett_t124 = -1;
55 static int ett_t124_connectGCCPDU = -1;
56
57 static int hf_t124_ConnectData = -1;
58 static int hf_t124_connectGCCPDU = -1;
59 static int hf_t124_DomainMCSPDU_PDU = -1;
60
61 static guint32 channelId = -1;
62
63 static const char *t124Identifier = NULL; /* extensions identifier */
64 static tvbuff_t *t124NSIdentifier = NULL; /* extensions non-standard identifier */
65 static dissector_table_t t124_ns_dissector_table=NULL;
66 static dissector_table_t t124_sd_dissector_table=NULL;
67
68 #include "packet-t124-ett.c"
69
70 #include "packet-t124-fn.c"
71
72 static const per_sequence_t t124Heur_sequence[] = {
73   { &hf_t124_t124Identifier , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_t124_Key },
74   { NULL, 0, 0, NULL }
75 };
76
77 void
78 register_t124_ns_dissector(const char *nsKey, dissector_t dissector, int proto)
79 {
80   dissector_handle_t dissector_handle;
81
82   dissector_handle=create_dissector_handle(dissector, proto);
83   dissector_add_string("t124.ns", nsKey, dissector_handle);
84 }
85
86 void register_t124_sd_dissector(packet_info *pinfo _U_, guint32 channelId, dissector_t dissector, int proto)
87 {
88   /* XXX: we should keep the sub-dissectors list per conversation
89      as the same channels may be used.
90      While we are just using RDP over T.124, then we can get away with it.
91   */
92
93   dissector_handle_t dissector_handle;
94
95   dissector_handle=create_dissector_handle(dissector, proto);
96   dissector_add_uint("t124.sd", channelId, dissector_handle);
97
98 }
99
100 guint32 t124_get_last_channelId(void)
101 {
102   return channelId;
103 }
104
105 void t124_set_top_tree(proto_tree *tree)
106 {
107   top_tree = tree;
108 }
109
110 int dissect_DomainMCSPDU_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
111   int offset = 0;
112   asn1_ctx_t asn1_ctx;
113   asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
114
115   offset = dissect_t124_DomainMCSPDU(tvb, offset, &asn1_ctx, tree, hf_t124_DomainMCSPDU_PDU);
116   offset += 7; offset >>= 3;
117   return offset;
118 }
119
120 static int
121 dissect_t124_new(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, void *data _U_)
122 {
123   proto_item *item = NULL;
124   proto_tree *tree = NULL;
125   asn1_ctx_t asn1_ctx;
126
127   top_tree = parent_tree;
128
129   col_set_str(pinfo->cinfo, COL_PROTOCOL, "T.125");
130   col_clear(pinfo->cinfo, COL_INFO);
131
132   item = proto_tree_add_item(parent_tree, proto_t124, tvb, 0, tvb_length(tvb), ENC_NA);
133   tree = proto_item_add_subtree(item, ett_t124);
134
135   asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
136   dissect_t124_ConnectData(tvb, 0, &asn1_ctx, tree, hf_t124_ConnectData);
137
138   return tvb_length(tvb);
139 }
140
141 static void
142 dissect_t124(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree)
143 {
144   dissect_t124_new(tvb, pinfo, parent_tree, NULL);
145 }
146
147 static gboolean
148 dissect_t124_heur(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, void *data _U_)
149 {
150   asn1_ctx_t asn1_ctx;
151
152   asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
153
154   t124Identifier = NULL;
155
156   (void) dissect_per_sequence(tvb, 0, &asn1_ctx, NULL, -1, -1, t124Heur_sequence);
157
158   if((t124Identifier != NULL) &&
159      (strcmp(t124Identifier, "0.0.20.124.0.1") == 0)) {
160
161     dissect_t124(tvb, pinfo, parent_tree);
162
163   }
164
165   return FALSE;
166 }
167
168 /*--- proto_register_t124 -------------------------------------------*/
169 void proto_register_t124(void) {
170
171   /* List of fields */
172   static hf_register_info hf[] = {
173     { &hf_t124_ConnectData,
174       { "ConnectData", "t124.ConnectData",
175         FT_NONE, BASE_NONE, NULL, 0,
176         NULL, HFILL }},
177     { &hf_t124_connectGCCPDU,
178       { "connectGCCPDU", "t124.connectGCCPDU",
179         FT_UINT32, BASE_DEC, VALS(t124_ConnectGCCPDU_vals), 0,
180         NULL, HFILL }},
181     { &hf_t124_DomainMCSPDU_PDU,
182       { "DomainMCSPDU", "t124.DomainMCSPDU",
183         FT_UINT32, BASE_DEC, VALS(t124_DomainMCSPDU_vals), 0,
184         NULL, HFILL }},
185 #include "packet-t124-hfarr.c"
186   };
187
188   /* List of subtrees */
189   static gint *ett[] = {
190           &ett_t124,
191           &ett_t124_connectGCCPDU,
192 #include "packet-t124-ettarr.c"
193   };
194   
195   /* Register protocol */
196   proto_t124 = proto_register_protocol(PNAME, PSNAME, PFNAME);
197   /* Register fields and subtrees */
198   proto_register_field_array(proto_t124, hf, array_length(hf));
199   proto_register_subtree_array(ett, array_length(ett));
200
201   t124_ns_dissector_table = register_dissector_table("t124.ns", "T.124 H.221 Non Standard Dissectors", FT_STRING, BASE_NONE);
202   t124_sd_dissector_table = register_dissector_table("t124.sd", "T.124 H.221 Send Data Dissectors", FT_UINT32, BASE_HEX);
203
204   new_register_dissector("t124", dissect_t124_new, proto_t124);
205
206 }
207
208 void
209 proto_reg_handoff_t124(void) {
210
211   register_ber_oid_dissector("0.0.20.124.0.1", dissect_t124, proto_t124, "Generic Conference Control");
212
213   heur_dissector_add("t125", dissect_t124_heur, proto_t124);
214
215 }