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