Move /asn1 to /epan/dissectors
[metze/wireshark/wip.git] / epan / dissectors / asn1 / m3ap / packet-m3ap-template.c
1 /* packet-m3ap.c
2  * Routines for M3 Application Protocol packet dissection
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Reference: 3GPP TS 36.444 v11.0.0
23  */
24
25 #include "config.h"
26
27 #include <epan/packet.h>
28
29 #include <epan/strutil.h>
30 #include <epan/asn1.h>
31 #include <epan/sctpppids.h>
32 #include <epan/expert.h>
33
34 #include "packet-ber.h"
35 #include "packet-per.h"
36 #include "packet-e212.h"
37 #include "packet-gtpv2.h"
38 #include "packet-ntp.h"
39
40 #define PNAME  "M3 Application Protocol"
41 #define PSNAME "M3AP"
42 #define PFNAME "m3ap"
43
44 void proto_register_m3ap(void);
45 void proto_reg_handoff_m3ap(void);
46
47 /* M3AP uses port 36444 as recommended by IANA. */
48 #define M3AP_PORT 36444
49 static dissector_handle_t m3ap_handle=NULL;
50
51 #include "packet-m3ap-val.h"
52
53 /* Initialize the protocol and registered fields */
54 static int proto_m3ap = -1;
55
56 static int hf_m3ap_Absolute_Time_ofMBMS_Data_value = -1;
57 static int hf_m3ap_IPAddress_v4 = -1;
58 static int hf_m3ap_IPAddress_v6 = -1;
59
60 #include "packet-m3ap-hf.c"
61
62 /* Initialize the subtree pointers */
63 static int ett_m3ap = -1;
64
65 #include "packet-m3ap-ett.c"
66
67 static expert_field ei_m3ap_invalid_ip_address_len = EI_INIT;
68
69 enum{
70   INITIATING_MESSAGE,
71   SUCCESSFUL_OUTCOME,
72   UNSUCCESSFUL_OUTCOME
73 };
74
75 /* Global variables */
76 static guint32 ProcedureCode;
77 static guint32 ProtocolIE_ID;
78 /*static guint32 ProtocolExtensionID; */
79 static int global_m3ap_port = M3AP_PORT;
80 static guint32 message_type;
81
82 /* Dissector tables */
83 static dissector_table_t m3ap_ies_dissector_table;
84 static dissector_table_t m3ap_extension_dissector_table;
85 static dissector_table_t m3ap_proc_imsg_dissector_table;
86 static dissector_table_t m3ap_proc_sout_dissector_table;
87 static dissector_table_t m3ap_proc_uout_dissector_table;
88
89 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
90 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
91 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
92 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
93 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
94
95 #include "packet-m3ap-fn.c"
96
97 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
98 {
99   return (dissector_try_uint(m3ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
100 }
101
102 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
103 {
104   return (dissector_try_uint(m3ap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
105 }
106
107 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
108 {
109   return (dissector_try_uint(m3ap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
110 }
111
112 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
113 {
114   return (dissector_try_uint(m3ap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
115 }
116
117 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
118 {
119   return (dissector_try_uint(m3ap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
120 }
121
122
123 static int
124 dissect_m3ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
125 {
126   proto_item      *m3ap_item = NULL;
127   proto_tree      *m3ap_tree = NULL;
128
129   /* make entry in the Protocol column on summary display */
130   col_set_str(pinfo->cinfo, COL_PROTOCOL, PNAME);
131
132   /* create the m3ap protocol tree */
133   if (tree) {
134     m3ap_item = proto_tree_add_item(tree, proto_m3ap, tvb, 0, -1, ENC_NA);
135     m3ap_tree = proto_item_add_subtree(m3ap_item, ett_m3ap);
136
137     dissect_M3AP_PDU_PDU(tvb, pinfo, m3ap_tree, NULL);
138   }
139   return tvb_captured_length(tvb);
140 }
141 /*--- proto_register_m3ap -------------------------------------------*/
142 void proto_register_m3ap(void) {
143
144   /* List of fields */
145   static hf_register_info hf[] = {
146     { &hf_m3ap_Absolute_Time_ofMBMS_Data_value,
147       { "Absolute-Time-ofMBMS-Data-value", "m3ap.Absolute_Time_ofMBMS_Data_value",
148          FT_STRING, BASE_NONE, NULL, 0,
149          NULL, HFILL }
150     },
151     { &hf_m3ap_IPAddress_v4,
152       { "IPAddress", "m3ap.IPAddress_v4",
153          FT_IPv4, BASE_NONE, NULL, 0,
154          NULL, HFILL }
155     },
156     { &hf_m3ap_IPAddress_v6,
157       { "IPAddress", "m3ap.IPAddress_v6",
158          FT_IPv6, BASE_NONE, NULL, 0,
159          NULL, HFILL }
160     },
161
162 #include "packet-m3ap-hfarr.c"
163   };
164
165   /* List of subtrees */
166   static gint *ett[] = {
167                   &ett_m3ap,
168 #include "packet-m3ap-ettarr.c"
169   };
170
171   expert_module_t* expert_m3ap;
172
173   static ei_register_info ei[] = {
174      { &ei_m3ap_invalid_ip_address_len, { "m3ap.invalid_ip_address_len", PI_MALFORMED, PI_ERROR, "Invalid IP address length", EXPFILL }}
175   };
176
177   /* Register protocol */
178   proto_m3ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
179   /* Register fields and subtrees */
180   proto_register_field_array(proto_m3ap, hf, array_length(hf));
181   proto_register_subtree_array(ett, array_length(ett));
182   expert_m3ap = expert_register_protocol(proto_m3ap);
183   expert_register_field_array(expert_m3ap, ei, array_length(ei));
184
185   /* Register dissector tables */
186   m3ap_ies_dissector_table = register_dissector_table("m3ap.ies", "M3AP-PROTOCOL-IES", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
187   m3ap_extension_dissector_table = register_dissector_table("m3ap.extension", "M3AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
188   m3ap_proc_imsg_dissector_table = register_dissector_table("m3ap.proc.imsg", "M3AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
189   m3ap_proc_sout_dissector_table = register_dissector_table("m3ap.proc.sout", "M3AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
190   m3ap_proc_uout_dissector_table = register_dissector_table("m3ap.proc.uout", "M3AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
191 }
192
193
194 /*--- proto_reg_handoff_m3ap ---------------------------------------*/
195 void
196 proto_reg_handoff_m3ap(void)
197 {
198   static gboolean inited = FALSE;
199   static guint SctpPort;
200
201   if( !inited ) {
202     m3ap_handle = create_dissector_handle(dissect_m3ap, proto_m3ap);
203     dissector_add_uint("sctp.ppi", PROTO_3GPP_M3AP_PROTOCOL_ID, m3ap_handle);
204     inited = TRUE;
205 #include "packet-m3ap-dis-tab.c"
206     dissector_add_uint("m3ap.extension", 17, create_dissector_handle(dissect_AllocationAndRetentionPriority_PDU, proto_m3ap));
207   }
208   else {
209     if (SctpPort != 0) {
210       dissector_delete_uint("sctp.port", SctpPort, m3ap_handle);
211     }
212   }
213
214   SctpPort = global_m3ap_port;
215   if (SctpPort != 0) {
216     dissector_add_uint("sctp.port", SctpPort, m3ap_handle);
217   }
218 }