Update Free Software Foundation address.
[metze/wireshark/wip.git] / asn1 / rua / packet-rua-template.c
1 /* packet-rua-template.c
2  * Routines for UMTS Home Node B RANAP User Adaptation (RUA) 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.468 version 8.1.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 RUA signalling"
48 #define PSNAME "RUA"
49 #define PFNAME "rua"
50 /* Dissector to use SCTP PPID 19 or a configured SCTP port. IANA assigned port = 29169*/
51 #define SCTP_PORT_RUA              29169;
52
53 #include "packet-rua-val.h"
54
55 /* Initialize the protocol and registered fields */
56 static int proto_rua = -1;
57
58 #include "packet-rua-hf.c"
59
60 /* Initialize the subtree pointers */
61 static int ett_rua = -1;
62
63  /* initialise sub-dissector handles */
64  static dissector_handle_t ranap_handle = NULL;
65
66 #include "packet-rua-ett.c"
67
68 /* Global variables */
69 static guint32 ProcedureCode;
70 static guint32 ProtocolIE_ID;
71 static guint global_sctp_port = SCTP_PORT_RUA;
72
73 /* Dissector tables */
74 static dissector_table_t rua_ies_dissector_table;
75 static dissector_table_t rua_extension_dissector_table;
76 static dissector_table_t rua_proc_imsg_dissector_table;
77 static dissector_table_t rua_proc_sout_dissector_table;
78 static dissector_table_t rua_proc_uout_dissector_table;
79
80 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
81 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
82 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
83 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
84 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
85
86 void proto_reg_handoff_rua(void);
87
88 #include "packet-rua-fn.c"
89
90 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
91 {
92   return (dissector_try_uint_new(rua_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
93 }
94
95 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 {
97   return (dissector_try_uint_new(rua_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
98 }
99
100 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
101 {
102   return (dissector_try_uint_new(rua_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
103 }
104
105 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
106 {
107   return (dissector_try_uint_new(rua_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
108 }
109
110 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
111 {
112   return (dissector_try_uint_new(rua_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
113 }
114
115 static void
116 dissect_rua(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
117 {
118     proto_item  *rua_item = NULL;
119     proto_tree  *rua_tree = NULL;
120
121     /* make entry in the Protocol column on summary display */
122     col_set_str(pinfo->cinfo, COL_PROTOCOL, "RUA");
123
124     /* create the rua protocol tree */
125     rua_item = proto_tree_add_item(tree, proto_rua, tvb, 0, -1, ENC_NA);
126     rua_tree = proto_item_add_subtree(rua_item, ett_rua);
127
128     dissect_RUA_PDU_PDU(tvb, pinfo, rua_tree);
129 }
130
131 /*--- proto_register_rua -------------------------------------------*/
132 void proto_register_rua(void) {
133 module_t *rua_module;
134
135   /* List of fields */
136
137   static hf_register_info hf[] = {
138
139 #include "packet-rua-hfarr.c"
140   };
141
142   /* List of subtrees */
143   static gint *ett[] = {
144           &ett_rua,
145 #include "packet-rua-ettarr.c"
146   };
147
148
149   /* Register protocol */
150   proto_rua = proto_register_protocol(PNAME, PSNAME, PFNAME);
151   /* Register fields and subtrees */
152   proto_register_field_array(proto_rua, hf, array_length(hf));
153   proto_register_subtree_array(ett, array_length(ett));
154
155   /* Register dissector */
156   register_dissector("rua", dissect_rua, proto_rua);
157
158   /* Register dissector tables */
159   rua_ies_dissector_table = register_dissector_table("rua.ies", "RUA-PROTOCOL-IES", FT_UINT32, BASE_DEC);
160   rua_extension_dissector_table = register_dissector_table("rua.extension", "RUA-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
161   rua_proc_imsg_dissector_table = register_dissector_table("rua.proc.imsg", "RUA-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
162   rua_proc_sout_dissector_table = register_dissector_table("rua.proc.sout", "RUA-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
163   rua_proc_uout_dissector_table = register_dissector_table("rua.proc.uout", "RUA-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
164
165   rua_module = prefs_register_protocol(proto_rua, proto_reg_handoff_rua);
166   prefs_register_uint_preference(rua_module, "port", "RUA SCTP Port", "Set the port for RUA messages (Default of 29169)", 10, &global_sctp_port);
167
168 }
169
170
171 /*--- proto_reg_handoff_rua ---------------------------------------*/
172 void
173 proto_reg_handoff_rua(void)
174 {
175         static gboolean initialized = FALSE;
176         static dissector_handle_t rua_handle;
177         static guint sctp_port;
178
179         if (!initialized) {
180                 rua_handle = find_dissector("rua");
181                 ranap_handle = find_dissector("ranap");
182                 dissector_add_uint("sctp.ppi", RUA_PAYLOAD_PROTOCOL_ID, rua_handle);
183                 initialized = TRUE;
184 #include "packet-rua-dis-tab.c"
185
186         } else {
187                 dissector_delete_uint("sctp.port", sctp_port, rua_handle);
188         }
189         /* Set our port number for future use */
190         sctp_port = global_sctp_port;
191         dissector_add_uint("sctp.port", sctp_port, rua_handle);
192 }