24256a26514b683fe98718d5986b381d1a9c6622
[obnox/wireshark/wip.git] / asn1 / h323 / packet-h323-template.c
1 /* packet-h323.c
2  * Routines for H.323 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/oids.h>
33 #include <epan/asn1.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "packet-per.h"
39 #include "packet-h225.h"
40 #include "packet-h323.h"
41
42 #define PNAME  "H.323"
43 #define PSNAME "H.323"
44 #define PFNAME "h323"
45
46
47 /* Generic Extensible Framework */
48 gef_ctx_t* gef_ctx_alloc(gef_ctx_t *parent, const gchar *type) {
49   gef_ctx_t *gefx;
50
51   gefx = ep_alloc0(sizeof(gef_ctx_t));
52   gefx->signature = GEF_CTX_SIGNATURE;
53   gefx->parent = parent;
54   gefx->type = type;
55   return gefx;
56 }
57
58 gboolean gef_ctx_check_signature(gef_ctx_t *gefx) {
59   return gefx && (gefx->signature == GEF_CTX_SIGNATURE);
60 }
61
62 gef_ctx_t* gef_ctx_get(void *ptr) {
63   gef_ctx_t *gefx = (gef_ctx_t*)ptr;
64   asn1_ctx_t *actx = (asn1_ctx_t*)ptr;
65
66   if (!asn1_ctx_check_signature(actx)) 
67     actx = NULL;
68
69   if (actx)
70     gefx = actx->private_data;
71
72   if (!gef_ctx_check_signature(gefx)) 
73     gefx = NULL;
74
75   return gefx;
76 }
77
78 void gef_ctx_update_key(gef_ctx_t *gefx) {
79   const gchar *parent_key;
80
81   if (!gefx) return;
82   parent_key = (gefx->parent) ? gefx->parent->key : NULL;
83   gefx->key = ep_strdup_printf(
84     "%s%s"    /* parent prefix */
85     "%s%s%s"  /* type, id */
86     "%s%s"    /* subid */,
87     (parent_key) ? parent_key : "", (parent_key) ? "/" : "",
88     (gefx->type) ? gefx->type : "", (gefx->type && (gefx->id || gefx->subid)) ? "/" : "", (gefx->id) ? gefx->id : "",
89     (gefx->subid) ? "-" : "", (gefx->subid) ? gefx->subid : ""
90   );
91 }
92
93 /* Initialize the protocol and registered fields */
94 int proto_h323 = -1;
95 #include "packet-h323-hf.c"
96
97 /* Initialize the subtree pointers */
98 #include "packet-h323-ett.c"
99
100 #include "packet-h323-fn.c"
101
102 /*--- proto_register_h323 ----------------------------------------------*/
103 void proto_register_h323(void) {
104
105   /* List of fields */
106   static hf_register_info hf[] = {
107 #include "packet-h323-hfarr.c"
108   };
109
110   /* List of subtrees */
111   static gint *ett[] = {
112 #include "packet-h323-ettarr.c"
113   };
114
115   /* Register protocol */
116   proto_h323 = proto_register_protocol(PNAME, PSNAME, PFNAME);
117
118   /* Register fields and subtrees */
119   proto_register_field_array(proto_h323, hf, array_length(hf));
120   proto_register_subtree_array(ett, array_length(ett));
121
122 }
123
124
125 /*--- proto_reg_handoff_h323 -------------------------------------------*/
126 void proto_reg_handoff_h323(void) 
127 {
128   dissector_handle_t q931_handle; 
129
130   q931_handle = find_dissector("q931");
131
132   /* H.323, Annex M1, Tunnelling of signalling protocols (QSIG) in H.323 */
133   dissector_add_string("h225.tp", "1.3.12.9", q931_handle);
134
135   /* H.323, Annex M4, Tunnelling of narrow-band signalling syntax (NSS) for H.323 */
136   dissector_add_string("h225.gef.content", "GenericData/1000/1", 
137                        new_create_dissector_handle(dissect_RasTunnelledSignallingMessage_PDU, proto_h323));
138
139   /* H.323, Annex R, Robustness methods for H.323 entities */
140   dissector_add_string("h225.gef.content", "GenericData/1/1", 
141                        new_create_dissector_handle(dissect_RobustnessData_PDU, proto_h323));
142 }
143