For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / asn1 / lcsap / packet-lcsap-template.c
1 /* packet-lcsap.c
2  * Routines for LCS-AP packet dissembly.
3  *
4  * Copyright (c) 2011 by Spenser Sheng <spenser.sheng@ericsson.com>
5  *
6  * $Id: packet-lcsap.c 28770 2011-06-18 21:30:42Z stig  Spenser Sheng$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1999 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  * References:
26  * ETSI TS 129 171 V9.2.0 (2010-10)
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <epan/packet.h>
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <epan/strutil.h>
40 #include <epan/asn1.h>
41 #include <epan/prefs.h>
42 #include <epan/sctpppids.h>
43
44 #include "packet-ber.h"
45 #include "packet-per.h"
46 #include "packet-e212.h"
47 #include "packet-sccp.h"
48
49 #ifdef _MSC_VER
50 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
51 #pragma warning(disable:4146)
52 #endif
53
54 #define PNAME  "LCS Application Protocol"
55 #define PSNAME "LCSAP"
56 #define PFNAME "lcsap"
57
58 #define SCTP_PORT_LCSAP 9082
59 #include "packet-lcsap-val.h"
60 /* Strcture to hold ProcedureCode */
61 struct pro_code {
62         guint8 code;
63 } _pro_code;
64
65 /* Initialize the protocol and registered fields */
66 static int proto_lcsap  =   -1;
67 #include "packet-lcsap-hf.c"
68
69 /* Initialize the subtree pointers */
70 static int ett_lcsap = -1;
71
72 #include "packet-lcsap-ett.c"
73
74 /* Global variables */
75 static guint32 ProcedureCode;
76 static guint32 ProtocolIE_ID;
77 static guint32 ProtocolExtensionID;
78 static guint gbl_lcsapSctpPort=SCTP_PORT_LCSAP;
79
80 /* Dissector tables */
81 static dissector_table_t lcsap_ies_dissector_table;
82
83 static dissector_table_t lcsap_extension_dissector_table;
84 static dissector_table_t lcsap_proc_imsg_dissector_table;
85 static dissector_table_t lcsap_proc_sout_dissector_table;
86 static dissector_table_t lcsap_proc_uout_dissector_table;
87
88 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
89
90 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
91 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
92 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
93 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
94
95 #include "packet-lcsap-fn.c"
96
97 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
98 {
99   return (dissector_try_uint(lcsap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
100 }
101
102
103 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
104 {
105   return (dissector_try_uint(lcsap_extension_dissector_table, ProtocolExtensionID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
106 }
107
108 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
109 {
110   return (dissector_try_uint(lcsap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
111 }
112
113 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
114 {
115   return (dissector_try_uint(lcsap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
116 }
117
118 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
119 {
120   return (dissector_try_uint(lcsap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
121 }
122
123
124 static void
125 dissect_lcsap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
126 {
127         proto_item      *lcsap_item = NULL;
128         proto_tree      *lcsap_tree = NULL;
129
130         /* make entry in the Protocol column on summary display */
131         if (check_col(pinfo->cinfo, COL_PROTOCOL))
132                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LCSAP");
133
134         /* create the lcsap protocol tree */
135         lcsap_item = proto_tree_add_item(tree, proto_lcsap, tvb, 0, -1, ENC_NA);
136         lcsap_tree = proto_item_add_subtree(lcsap_item, ett_lcsap);
137
138         dissect_LCS_AP_PDU_PDU(tvb, pinfo, lcsap_tree);
139 }
140
141 /*--- proto_reg_handoff_lcsap ---------------------------------------*/
142 void
143 proto_reg_handoff_lcsap(void)
144 {
145         static gboolean Initialized=FALSE;
146         static dissector_handle_t lcsap_handle;
147         static guint SctpPort;
148
149         if (!Initialized) {
150                 lcsap_handle = find_dissector("lcsap");
151
152                 dissector_add_handle("sctp.port", lcsap_handle);   /* for "decode-as"  */
153                 dissector_add_uint("sctp.ppi", LCS_AP_PAYLOAD_PROTOCOL_ID,   lcsap_handle);
154                 Initialized=TRUE;
155 #include "packet-lcsap-dis-tab.c"
156         } else {
157                 if (SctpPort != 0) {
158                         dissector_delete_uint("sctp.port", SctpPort, lcsap_handle);
159                 }
160         }
161
162         SctpPort=gbl_lcsapSctpPort;
163         if (SctpPort != 0) {
164                 dissector_add_uint("sctp.port", SctpPort, lcsap_handle);
165         }
166 }
167
168 /*--- proto_register_lcsap -------------------------------------------*/
169 void proto_register_lcsap(void) {
170
171   /* List of fields */
172   static hf_register_info hf[] = {
173 #include "packet-lcsap-hfarr.c"
174   };
175
176   /* List of subtrees */
177   static gint *ett[] = {
178                   &ett_lcsap,
179 #include "packet-lcsap-ettarr.c"
180  };
181
182   module_t *lcsap_module;
183
184   /* Register protocol */
185   proto_lcsap = proto_register_protocol(PNAME, PSNAME, PFNAME);
186
187   /* Register fields and subtrees */
188   proto_register_field_array(proto_lcsap, hf, array_length(hf));
189   proto_register_subtree_array(ett, array_length(ett));
190   register_dissector("lcsap", dissect_lcsap, proto_lcsap);
191
192   /* Register dissector tables */
193   lcsap_ies_dissector_table = register_dissector_table("lcsap.ies", "LCS-AP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
194
195
196   lcsap_extension_dissector_table = register_dissector_table("lcsap.extension", "LCS-AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
197   lcsap_proc_imsg_dissector_table = register_dissector_table("lcsap.proc.imsg", "LCS-AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
198   lcsap_proc_sout_dissector_table = register_dissector_table("lcsap.proc.sout", "LCS-AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
199   lcsap_proc_uout_dissector_table = register_dissector_table("lcsap.proc.uout", "LCS-AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
200
201   /* Register configuration options for ports */
202   lcsap_module = prefs_register_protocol(proto_lcsap, proto_reg_handoff_lcsap);
203
204   prefs_register_uint_preference(lcsap_module, "sctp.port",
205                                  "LCSAP SCTP Port",
206                                  "Set the SCTP port for LCSAP messages",
207                                  10,
208                                  &gbl_lcsapSctpPort);
209
210 }
211
212