Associate dissector tables and heuristic subdissector lists with a protocol.
[metze/wireshark/wip.git] / epan / dissectors / asn1 / pcap / packet-pcap-template.c
1 /* packet-pcap.c
2  * Routines for UTRAN Iupc interface Positioning Calculation Application Part (PCAP) packet dissection
3  *
4  * Copyright 2008, Anders Broman <anders.broman@ericsson.com>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  *
24  * Based on the RANAP dissector
25  *
26  * References: ETSI TS 125 453 V7.9.0 (2008-02)
27  */
28
29 #include "config.h"
30
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33
34 #include <epan/strutil.h>
35 #include <epan/asn1.h>
36
37 #include "packet-ber.h"
38 #include "packet-per.h"
39 #include "packet-sccp.h"
40
41 #ifdef _MSC_VER
42 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
43 #pragma warning(disable:4146)
44 #endif
45
46 #define PNAME  "UTRAN Iupc interface Positioning Calculation Application Part (PCAP)"
47 #define PSNAME "PCAP"
48 #define PFNAME "pcap"
49
50 #define MAX_SSN 254
51
52 void proto_register_pcap(void);
53 void proto_reg_handoff_pcap(void);
54
55 static range_t *global_ssn_range;
56
57 static dissector_table_t sccp_ssn_table;
58
59 #include "packet-pcap-val.h"
60
61 static dissector_handle_t pcap_handle = NULL;
62
63 /* Initialize the protocol and registered fields */
64 static int proto_pcap = -1;
65
66 #include "packet-pcap-hf.c"
67
68 /* Initialize the subtree pointers */
69 static int ett_pcap = -1;
70
71 #include "packet-pcap-ett.c"
72
73 /* Global variables */
74 static guint32 ProcedureCode;
75 static guint32 ProtocolIE_ID;
76 /*static guint32 ProtocolExtensionID;*/
77
78 /* Dissector tables */
79 static dissector_table_t pcap_ies_dissector_table;
80 static dissector_table_t pcap_ies_p1_dissector_table;
81 static dissector_table_t pcap_ies_p2_dissector_table;
82 static dissector_table_t pcap_extension_dissector_table;
83 static dissector_table_t pcap_proc_imsg_dissector_table;
84 static dissector_table_t pcap_proc_sout_dissector_table;
85 static dissector_table_t pcap_proc_uout_dissector_table;
86 static dissector_table_t pcap_proc_out_dissector_table;
87
88 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
89 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
90 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
91 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
92 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
93 static int dissect_OutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
94
95 #include "packet-pcap-fn.c"
96
97 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
98 {
99   return (dissector_try_uint(pcap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
100 }
101
102 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
103 {
104   return (dissector_try_uint(pcap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
105 }
106
107 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
108 {
109   return (dissector_try_uint(pcap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
110 }
111
112 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
113 {
114   return (dissector_try_uint(pcap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
115 }
116
117 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
118 {
119   return (dissector_try_uint(pcap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
120 }
121
122 static int dissect_OutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
123 {
124   return (dissector_try_uint(pcap_proc_out_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
125 }
126
127 static int
128 dissect_pcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
129 {
130         proto_item      *pcap_item = NULL;
131         proto_tree      *pcap_tree = NULL;
132
133         /* make entry in the Protocol column on summary display */
134         col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCAP");
135
136         /* create the pcap protocol tree */
137         pcap_item = proto_tree_add_item(tree, proto_pcap, tvb, 0, -1, ENC_NA);
138         pcap_tree = proto_item_add_subtree(pcap_item, ett_pcap);
139
140         dissect_PCAP_PDU_PDU(tvb, pinfo, pcap_tree, NULL);
141         return tvb_captured_length(tvb);
142 }
143
144 /*--- proto_reg_handoff_pcap ---------------------------------------*/
145 void
146 proto_reg_handoff_pcap(void)
147 {
148     static gboolean prefs_initialized = FALSE;
149     static range_t *ssn_range;
150
151     if (! prefs_initialized) {
152         pcap_handle = find_dissector("pcap");
153         sccp_ssn_table = find_dissector_table("sccp.ssn");
154         prefs_initialized = TRUE;
155 #include "packet-pcap-dis-tab.c"
156     } else {
157         dissector_delete_uint_range("sccp.ssn", ssn_range, pcap_handle);
158         g_free(ssn_range);
159     }
160     ssn_range = range_copy(global_ssn_range);
161     dissector_add_uint_range("sccp.ssn", ssn_range, pcap_handle);
162 }
163
164 /*--- proto_register_pcap -------------------------------------------*/
165 void proto_register_pcap(void) {
166
167   /* List of fields */
168
169   static hf_register_info hf[] = {
170
171 #include "packet-pcap-hfarr.c"
172   };
173
174   /* List of subtrees */
175   static gint *ett[] = {
176                   &ett_pcap,
177 #include "packet-pcap-ettarr.c"
178   };
179
180   module_t *pcap_module;
181
182   /* Register protocol */
183   proto_pcap = proto_register_protocol(PNAME, PSNAME, PFNAME);
184   /* Register fields and subtrees */
185   proto_register_field_array(proto_pcap, hf, array_length(hf));
186   proto_register_subtree_array(ett, array_length(ett));
187
188   pcap_module = prefs_register_protocol(proto_pcap, proto_reg_handoff_pcap);
189
190   /* Register dissector */
191   register_dissector("pcap", dissect_pcap, proto_pcap);
192
193   /* Register dissector tables */
194   pcap_ies_dissector_table = register_dissector_table("pcap.ies", "PCAP-PROTOCOL-IES", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
195   pcap_ies_p1_dissector_table = register_dissector_table("pcap.ies.pair.first", "PCAP-PROTOCOL-IES-PAIR FirstValue", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
196   pcap_ies_p2_dissector_table = register_dissector_table("pcap.ies.pair.second", "PCAP-PROTOCOL-IES-PAIR SecondValue", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
197   pcap_extension_dissector_table = register_dissector_table("pcap.extension", "PCAP-PROTOCOL-EXTENSION", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
198   pcap_proc_imsg_dissector_table = register_dissector_table("pcap.proc.imsg", "PCAP-ELEMENTARY-PROCEDURE InitiatingMessage", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
199   pcap_proc_sout_dissector_table = register_dissector_table("pcap.proc.sout", "PCAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
200   pcap_proc_uout_dissector_table = register_dissector_table("pcap.proc.uout", "PCAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
201   pcap_proc_out_dissector_table = register_dissector_table("pcap.proc.out", "PCAP-ELEMENTARY-PROCEDURE Outcome", proto_pcap, FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
202
203
204   /* Preferences */
205   /* Set default SSNs */
206   range_convert_str(&global_ssn_range, "", MAX_SSN);
207
208   prefs_register_range_preference(pcap_module, "ssn", "SCCP SSNs",
209                                   "SCCP (and SUA) SSNs to decode as PCAP",
210                                   &global_ssn_range, MAX_SSN);
211 }
212
213
214
215