f8f761b794b6f7a32895dc170fabf83524285a36
[obnox/wireshark/wip.git] / asn1 / nbap / packet-nbap-template.c
1 /* packet-nbap-template.c
2  * Routines for UMTS Node B Application Part(NBAP) packet dissection
3  * Copyright 2005, 2009 Anders Broman <anders.broman@ericsson.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.433 version 6.6.0 Release 6
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35 #include <epan/sctpppids.h>
36 #include <epan/asn1.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 Iub interface NBAP signalling"
46 #define PSNAME "NBAP"
47 #define PFNAME "nbap"
48
49 #include "packet-nbap-val.h"
50
51 /* Initialize the protocol and registered fields */
52 static int proto_nbap = -1;
53 static int hf_nbap_transportLayerAddress_ipv4 = -1;
54 static int hf_nbap_transportLayerAddress_ipv6 = -1;
55
56 #include "packet-nbap-hf.c"
57
58 /* Initialize the subtree pointers */
59 static int ett_nbap = -1;
60 static int ett_nbap_TransportLayerAddress = -1;
61
62 #include "packet-nbap-ett.c"
63
64 /* Global variables */
65 static guint32 ProcedureCode;
66 static guint32 ProtocolIE_ID;
67 static guint32 ddMode;
68 static const gchar *ProcedureID;
69
70 /* Dissector tables */
71 static dissector_table_t nbap_ies_dissector_table;
72 static dissector_table_t nbap_extension_dissector_table;
73 static dissector_table_t nbap_proc_imsg_dissector_table;
74 static dissector_table_t nbap_proc_sout_dissector_table;
75 static dissector_table_t nbap_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
83 #include "packet-nbap-fn.c"
84
85 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
86 {
87   return (dissector_try_uint_new(nbap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
88 }
89
90 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
91 {
92   return (dissector_try_uint_new(nbap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
93 }
94
95 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 {
97   if (!ProcedureID) return 0;
98   return (dissector_try_string(nbap_proc_imsg_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
99 }
100
101 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
102 {
103   if (!ProcedureID) return 0;
104   return (dissector_try_string(nbap_proc_sout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
105 }
106
107 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
108 {
109   if (!ProcedureID) return 0;
110   return (dissector_try_string(nbap_proc_uout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
111 }
112
113 static void
114 dissect_nbap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
115 {
116         proto_item      *nbap_item = NULL;
117         proto_tree      *nbap_tree = NULL;
118
119         /* make entry in the Protocol column on summary display */
120         col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBAP");
121
122         /* create the nbap protocol tree */
123         nbap_item = proto_tree_add_item(tree, proto_nbap, tvb, 0, -1, FALSE);
124         nbap_tree = proto_item_add_subtree(nbap_item, ett_nbap);
125         
126         dissect_NBAP_PDU_PDU(tvb, pinfo, nbap_tree);
127 }
128
129 /*--- proto_register_nbap -------------------------------------------*/
130 void proto_register_nbap(void) {
131
132   /* List of fields */
133
134   static hf_register_info hf[] = {
135     { &hf_nbap_transportLayerAddress_ipv4,
136       { "transportLayerAddress IPv4", "nbap.transportLayerAddress_ipv4",
137         FT_IPv4, BASE_NONE, NULL, 0,
138         NULL, HFILL }},
139     { &hf_nbap_transportLayerAddress_ipv6,
140       { "transportLayerAddress IPv6", "nbap.transportLayerAddress_ipv6",
141         FT_IPv6, BASE_NONE, NULL, 0,
142         NULL, HFILL }},
143
144 #include "packet-nbap-hfarr.c"
145   };
146
147   /* List of subtrees */
148   static gint *ett[] = {
149                   &ett_nbap,
150                   &ett_nbap_TransportLayerAddress,
151 #include "packet-nbap-ettarr.c"
152   };
153
154
155   /* Register protocol */
156   proto_nbap = proto_register_protocol(PNAME, PSNAME, PFNAME);
157   /* Register fields and subtrees */
158   proto_register_field_array(proto_nbap, hf, array_length(hf));
159   proto_register_subtree_array(ett, array_length(ett));
160  
161   /* Register dissector */
162   register_dissector("nbap", dissect_nbap, proto_nbap);
163
164   /* Register dissector tables */
165   nbap_ies_dissector_table = register_dissector_table("nbap.ies", "NBAP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
166   nbap_extension_dissector_table = register_dissector_table("nbap.extension", "NBAP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
167   nbap_proc_imsg_dissector_table = register_dissector_table("nbap.proc.imsg", "NBAP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_STRING, BASE_NONE);
168   nbap_proc_sout_dissector_table = register_dissector_table("nbap.proc.sout", "NBAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_STRING, BASE_NONE);
169   nbap_proc_uout_dissector_table = register_dissector_table("nbap.proc.uout", "NBAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_STRING, BASE_NONE);
170
171 }
172
173
174 /*--- proto_reg_handoff_nbap ---------------------------------------*/
175 void
176 proto_reg_handoff_nbap(void)
177 {
178         dissector_handle_t nbap_handle;
179
180         nbap_handle = find_dissector("nbap");
181         dissector_add_uint("sctp.ppi", NBAP_PAYLOAD_PROTOCOL_ID, nbap_handle);
182         dissector_add_handle("sctp.port", nbap_handle);  /* for "decode-as" */
183
184 #include "packet-nbap-dis-tab.c"
185 }
186
187