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