For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / asn1 / t125 / packet-t125-template.c
1 /* packet-t125.c
2  * Routines for t125 packet dissection
3  * Copyright 2007, Ronnie Sahlberg
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
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <glib.h>
32 #include <epan/packet.h>
33
34 #include <epan/asn1.h>
35 #include "packet-ber.h"
36 #include "packet-per.h"
37
38 #include "packet-t124.h"
39
40 #define PNAME  "MULTIPOINT-COMMUNICATION-SERVICE T.125"
41 #define PSNAME "T.125"
42 #define PFNAME "t125"
43
44
45 /* Initialize the protocol and registered fields */
46 static int proto_t125 = -1;
47 static proto_tree *top_tree = NULL;
48 #include "packet-t125-hf.c"
49
50 /* Initialize the subtree pointers */
51 static int ett_t125 = -1;
52
53 static int hf_t125_connectData = -1;
54 static int hf_t125_heur = -1;
55
56 #include "packet-t125-ett.c"
57
58 static heur_dissector_list_t t125_heur_subdissector_list;
59
60 #include "packet-t125-fn.c"
61
62 static int
63 dissect_t125(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree)
64 {
65   proto_item *item = NULL;
66   proto_tree *tree = NULL;
67   gint8 class;
68   gboolean pc;
69   gint32 tag;
70
71   top_tree = parent_tree;
72
73   col_set_str(pinfo->cinfo, COL_PROTOCOL, "T.125");
74   col_clear(pinfo->cinfo, COL_INFO);
75
76   item = proto_tree_add_item(parent_tree, proto_t125, tvb, 0, tvb_length(tvb), ENC_NA);
77   tree = proto_item_add_subtree(item, ett_t125);
78
79   get_ber_identifier(tvb, 0, &class, &pc, &tag);
80
81   if ( (class==BER_CLASS_APP) && (tag>=101) && (tag<=104) ){
82     dissect_ConnectMCSPDU_PDU(tvb, pinfo, tree);
83   } else  {
84     t124_set_top_tree(top_tree);
85     dissect_DomainMCSPDU_PDU(tvb, pinfo, tree);
86   }
87
88   return tvb_length(tvb);
89 }
90
91 static gboolean
92 dissect_t125_heur(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree)
93 {
94   gint8 class;
95   gboolean pc;
96   gint32 tag;
97   guint32 choice_index = 100;
98   asn1_ctx_t asn1_ctx;
99
100   asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
101
102   /* could be BER */
103   get_ber_identifier(tvb, 0, &class, &pc, &tag);
104   /* or PER */
105   dissect_per_constrained_integer(tvb, 0, &asn1_ctx,
106                                   NULL, hf_t125_heur, 0, 42,
107                                   &choice_index, FALSE);
108
109   /* is this strong enough ? */
110   if ( ((class==BER_CLASS_APP) && ((tag>=101) && (tag<=104))) ||
111        (choice_index <=42)) {
112
113     dissect_t125(tvb, pinfo, parent_tree);
114
115     return TRUE;
116   }
117
118   return FALSE;
119 }
120
121
122 /*--- proto_register_t125 -------------------------------------------*/
123 void proto_register_t125(void) {
124
125   /* List of fields */
126   static hf_register_info hf[] = {
127     { &hf_t125_connectData,
128       { "connectData", "t125.connectData",
129         FT_NONE, BASE_NONE, NULL, 0,
130         NULL, HFILL }},
131     { &hf_t125_heur,
132       { "heuristic", "t125.heuristic",
133         FT_UINT32, BASE_DEC, NULL, 0,
134         NULL, HFILL }},
135 #include "packet-t125-hfarr.c"
136   };
137
138   /* List of subtrees */
139   static gint *ett[] = {
140           &ett_t125,
141 #include "packet-t125-ettarr.c"
142   };
143
144   /* Register protocol */
145   proto_t125 = proto_register_protocol(PNAME, PSNAME, PFNAME);
146   /* Register fields and subtrees */
147   proto_register_field_array(proto_t125, hf, array_length(hf));
148   proto_register_subtree_array(ett, array_length(ett));
149
150   register_heur_dissector_list("t125", &t125_heur_subdissector_list);
151
152   new_register_dissector("t125", dissect_t125, proto_t125);
153 }
154
155
156 /*--- proto_reg_handoff_t125 ---------------------------------------*/
157 void proto_reg_handoff_t125(void) {
158
159   heur_dissector_add("cotp", dissect_t125_heur, proto_t125);
160   heur_dissector_add("cotp_is", dissect_t125_heur, proto_t125);
161 }