87dd5ec600830e1c5a6295f1bd4ad4c0a0e31e33
[obnox/wireshark/wip.git] / asn1 / rnsap / packet-rnsap-template.c
1 /* packet-rnsap.c
2  * Routines for dissecting Universal Mobile Telecommunications System (UMTS);
3  * UTRAN Iur interface Radio Network Subsystem
4  * Application Part (RNSAP) signalling
5  * (3GPP TS 25.423 version 6.7.0 Release 6) packet dissection
6  * Copyright 2005 - 2006, Anders Broman <anders.broman@ericsson.com>
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  *
28  * Ref: 3GPP TS 25.423 version 6.7.0 Release 6
29  */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <glib.h>
36 #include <epan/packet.h>
37
38 #include <string.h>
39
40 #include <epan/asn1.h>
41
42 #include "packet-per.h"
43
44 #ifdef _MSC_VER
45 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
46 #pragma warning(disable:4146)
47 #endif
48
49 #define PNAME  "UTRAN Iur interface Radio Network Subsystem Application Part"
50 #define PSNAME "RNSAP"
51 #define PFNAME "rnsap"
52
53 #define SCCP_SSN_RNSAP 143
54
55 #include "packet-rnsap-val.h"
56
57 static dissector_handle_t rrc_dl_dcch_handle = NULL;
58
59 /* Initialize the protocol and registered fields */
60 static int proto_rnsap = -1;
61
62 #include "packet-rnsap-hf.c"
63
64 /* Initialize the subtree pointers */
65 static int ett_rnsap = -1;
66
67 #include "packet-rnsap-ett.c"
68
69 /* Global variables */
70 static guint32 ProcedureCode;
71 static guint32 ProtocolIE_ID;
72 static guint32 ddMode;
73 static const gchar *ProcedureID;
74
75 /* Dissector tables */
76 static dissector_table_t rnsap_ies_dissector_table;
77 static dissector_table_t rnsap_extension_dissector_table;
78 static dissector_table_t rnsap_proc_imsg_dissector_table;
79 static dissector_table_t rnsap_proc_sout_dissector_table;
80 static dissector_table_t rnsap_proc_uout_dissector_table;
81
82 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
83 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
84 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
85 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
86 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
87
88 #include "packet-rnsap-fn.c"
89
90 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
91 {
92   return (dissector_try_port(rnsap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? 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_port(rnsap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
98 }
99
100 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
101 {
102   if (!ProcedureID) return 0;
103   return (dissector_try_string(rnsap_proc_imsg_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
104 }
105
106 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
107 {
108   if (!ProcedureID) return 0;
109   return (dissector_try_string(rnsap_proc_sout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
110 }
111
112 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
113 {
114   if (!ProcedureID) return 0;
115   return (dissector_try_string(rnsap_proc_uout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
116 }
117
118 static void
119 dissect_rnsap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
120 {
121         proto_item      *rnsap_item = NULL;
122         proto_tree      *rnsap_tree = NULL;
123
124         /* make entry in the Protocol column on summary display */
125         col_set_str(pinfo->cinfo, COL_PROTOCOL, "RNSAP");
126
127         /* create the rnsap protocol tree */
128         rnsap_item = proto_tree_add_item(tree, proto_rnsap, tvb, 0, -1, FALSE);
129         rnsap_tree = proto_item_add_subtree(rnsap_item, ett_rnsap);
130         
131         dissect_RNSAP_PDU_PDU(tvb, pinfo, rnsap_tree);
132 }
133
134 /*--- proto_register_rnsap -------------------------------------------*/
135 void proto_register_rnsap(void) {
136
137   /* List of fields */
138
139   static hf_register_info hf[] = {
140 #include "packet-rnsap-hfarr.c"
141   };
142
143   /* List of subtrees */
144   static gint *ett[] = {
145                   &ett_rnsap,
146 #include "packet-rnsap-ettarr.c"
147   };
148
149
150   /* Register protocol */
151   proto_rnsap = proto_register_protocol(PNAME, PSNAME, PFNAME);
152   /* Register fields and subtrees */
153   proto_register_field_array(proto_rnsap, hf, array_length(hf));
154   proto_register_subtree_array(ett, array_length(ett));
155  
156   /* Register dissector */
157   register_dissector("rnsap", dissect_rnsap, proto_rnsap);
158
159   /* Register dissector tables */
160   rnsap_ies_dissector_table = register_dissector_table("rnsap.ies", "RNSAP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
161   rnsap_extension_dissector_table = register_dissector_table("rnsap.extension", "RNSAP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
162   rnsap_proc_imsg_dissector_table = register_dissector_table("rnsap.proc.imsg", "RNSAP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_STRING, BASE_NONE);
163   rnsap_proc_sout_dissector_table = register_dissector_table("rnsap.proc.sout", "RNSAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_STRING, BASE_NONE);
164   rnsap_proc_uout_dissector_table = register_dissector_table("rnsap.proc.uout", "RNSAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_STRING, BASE_NONE);
165
166 }
167
168
169 /*--- proto_reg_handoff_rnsap ---------------------------------------*/
170 void
171 proto_reg_handoff_rnsap(void)
172 {
173         dissector_handle_t rnsap_handle;
174
175         rnsap_handle = find_dissector("rnsap");
176         rrc_dl_dcch_handle = find_dissector("rrc.dl.dcch");
177
178         dissector_add("sccp.ssn", SCCP_SSN_RNSAP, rnsap_handle);
179         /* Add heuristic dissector
180          * Perhaps we want a preference whether the heuristic dissector
181          * is or isn't enabled
182          */
183         /*heur_dissector_add("sccp", dissect_sccp_rnsap_heur, proto_rnsap); */
184
185 #include "packet-rnsap-dis-tab.c"
186 }
187
188