We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
[metze/wireshark/wip.git] / asn1 / hnbap / packet-hnbap-template.c
1 /* packet-hnbap-template.c
2  * Routines for UMTS Node B Application Part(HNBAP) packet dissection
3  * Copyright 2010 Neil Piercy, ip.access Limited <Neil.Piercy@ipaccess.com>
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  * Ref: 3GPP TS 25.469 version 8.4.0 Release 8
26  */
27
28 #include "config.h"
29
30 #include <glib.h>
31 #include <string.h>
32
33 #include <epan/packet.h>
34 #include <epan/sctpppids.h>
35 #include <epan/asn1.h>
36 #include <epan/prefs.h>
37
38 #include "packet-per.h"
39
40 #ifdef _MSC_VER
41 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
42 #pragma warning(disable:4146)
43 #endif
44
45 #define PNAME  "UTRAN Iuh interface HNBAP signalling"
46 #define PSNAME "HNBAP"
47 #define PFNAME "hnbap"
48 /* Dissector will use SCTP PPID 20 or SCTP port. IANA assigned port = 29169*/
49 #define SCTP_PORT_HNBAP              29169
50
51 #include "packet-hnbap-val.h"
52
53 /* Initialize the protocol and registered fields */
54 static int proto_hnbap = -1;
55
56 #include "packet-hnbap-hf.c"
57
58 /* Initialize the subtree pointers */
59 static int ett_hnbap = -1;
60
61 #include "packet-hnbap-ett.c"
62
63 /* Global variables */
64 static guint32 ProcedureCode;
65 static guint32 ProtocolIE_ID;
66 static guint global_sctp_port = SCTP_PORT_HNBAP;
67
68 /* Dissector tables */
69 static dissector_table_t hnbap_ies_dissector_table;
70 static dissector_table_t hnbap_extension_dissector_table;
71 static dissector_table_t hnbap_proc_imsg_dissector_table;
72 static dissector_table_t hnbap_proc_sout_dissector_table;
73 static dissector_table_t hnbap_proc_uout_dissector_table;
74
75 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
76 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
77 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
78 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
79 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
80 void proto_reg_handoff_hnbap(void);
81
82 #include "packet-hnbap-fn.c"
83
84 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
85 {
86   return (dissector_try_uint_new(hnbap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE, NULL)) ? tvb_length(tvb) : 0;
87 }
88
89 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
90 {
91   return (dissector_try_uint_new(hnbap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE, NULL)) ? tvb_length(tvb) : 0;
92 }
93 #if 0
94 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
95 {
96   if (!ProcedureCode) return 0;
97   return (dissector_try_string(hnbap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
98 }
99
100 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
101 {
102   if (!ProcedureCode) return 0;
103   return (dissector_try_string(hnbap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
104 }
105
106 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
107 {
108   if (!ProcedureCode) return 0;
109   return (dissector_try_string(hnbap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
110 }
111 #endif
112
113 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
114 {
115   return (dissector_try_uint_new(hnbap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE, NULL)) ? tvb_length(tvb) : 0;
116 }
117
118 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
119 {
120   return (dissector_try_uint_new(hnbap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE, NULL)) ? tvb_length(tvb) : 0;
121 }
122
123 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
124 {
125   return (dissector_try_uint_new(hnbap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE, NULL)) ? tvb_length(tvb) : 0;
126 }
127
128 static void
129 dissect_hnbap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
130 {
131     proto_item  *hnbap_item = NULL;
132     proto_tree  *hnbap_tree = NULL;
133
134     /* make entry in the Protocol column on summary display */
135     col_set_str(pinfo->cinfo, COL_PROTOCOL, "HNBAP");
136
137     /* create the hnbap protocol tree */
138     hnbap_item = proto_tree_add_item(tree, proto_hnbap, tvb, 0, -1, ENC_NA);
139     hnbap_tree = proto_item_add_subtree(hnbap_item, ett_hnbap);
140
141     dissect_HNBAP_PDU_PDU(tvb, pinfo, hnbap_tree);
142 }
143
144 /*--- proto_register_hnbap -------------------------------------------*/
145 void proto_register_hnbap(void) {
146 module_t *hnbap_module;
147
148   /* List of fields */
149
150   static hf_register_info hf[] = {
151
152 #include "packet-hnbap-hfarr.c"
153   };
154
155   /* List of subtrees */
156   static gint *ett[] = {
157           &ett_hnbap,
158 #include "packet-hnbap-ettarr.c"
159   };
160
161
162   /* Register protocol */
163   proto_hnbap = proto_register_protocol(PNAME, PSNAME, PFNAME);
164   /* Register fields and subtrees */
165   proto_register_field_array(proto_hnbap, hf, array_length(hf));
166   proto_register_subtree_array(ett, array_length(ett));
167
168   /* Register dissector */
169   register_dissector("hnbap", dissect_hnbap, proto_hnbap);
170
171   /* Register dissector tables */
172   hnbap_ies_dissector_table = register_dissector_table("hnbap.ies", "HNBAP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
173   hnbap_extension_dissector_table = register_dissector_table("hnbap.extension", "HNBAP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
174   hnbap_proc_imsg_dissector_table = register_dissector_table("hnbap.proc.imsg", "HNBAP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
175   hnbap_proc_sout_dissector_table = register_dissector_table("hnbap.proc.sout", "HNBAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
176   hnbap_proc_uout_dissector_table = register_dissector_table("hnbap.proc.uout", "HNBAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
177
178   hnbap_module = prefs_register_protocol(proto_hnbap, proto_reg_handoff_hnbap);
179   prefs_register_uint_preference(hnbap_module, "port", "HNBAP SCTP Port", "Set the port for HNBAP messages (Default of 29169)", 10, &global_sctp_port);
180 }
181
182
183 /*--- proto_reg_handoff_hnbap ---------------------------------------*/
184 void
185 proto_reg_handoff_hnbap(void)
186 {
187         static gboolean initialized = FALSE;
188         static dissector_handle_t hnbap_handle;
189         static guint sctp_port;
190
191         if (!initialized) {
192                 hnbap_handle = find_dissector("hnbap");
193                 dissector_add_uint("sctp.ppi", HNBAP_PAYLOAD_PROTOCOL_ID, hnbap_handle);
194                 initialized = TRUE;
195 #include "packet-hnbap-dis-tab.c"
196
197         } else {
198                 dissector_delete_uint("sctp.port", sctp_port, hnbap_handle);
199         }
200         /* Set our port number for future use */
201         sctp_port = global_sctp_port;
202         dissector_add_uint("sctp.port", sctp_port, hnbap_handle);
203 }