#include <epan/conversation.h> and/or #include <epan/emem.h> not req'd ...
[obnox/wireshark/wip.git] / asn1 / inap / packet-inap-template.c
1 /* packet-inap-template.c
2  * Routines for INAP
3  * Copyright 2004, Tim Endean <endeant@hotmail.com>
4  * Built from the gsm-map dissector Copyright 2004, Anders Broman <anders.broman@ericsson.com>
5  *
6  * $Id$
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  * References: ETSI 300 374
25  * ITU Q.1218
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/prefs.h>
35 #include <epan/oids.h>
36 #include "epan/expert.h"
37 #include <epan/asn1.h>
38
39 #include <stdio.h>
40 #include <string.h>
41
42 #include "packet-ber.h"
43 #include "packet-inap.h"
44 #include "packet-q931.h"
45 #include "packet-e164.h"
46 #include "packet-isup.h"
47 #include "packet-tcap.h"
48
49 #define PNAME  "Intelligent Network Application Protocol"
50 #define PSNAME "INAP"
51 #define PFNAME "inap"
52
53 /* Initialize the protocol and registered fields */
54 int proto_inap = -1;
55
56 /* include constants */
57 #include "packet-inap-val.h"
58
59 #include "packet-inap-hf.c"
60
61 #define MAX_SSN 254
62 static range_t *global_ssn_range;
63
64 static dissector_handle_t       inap_handle;
65
66 /* Global variables */
67 static guint32 opcode=0;
68 static guint32 errorCode=0;
69
70 static int inap_opcode_type;
71 #define INAP_OPCODE_INVOKE        1
72 #define INAP_OPCODE_RETURN_RESULT 2
73 #define INAP_OPCODE_RETURN_ERROR  3
74 #define INAP_OPCODE_REJECT        4
75
76 /* Initialize the subtree pointers */
77 static gint ett_inap = -1;
78 static gint ett_inapisup_parameter = -1;
79 #include "packet-inap-ett.c"
80
81 #include "packet-inap-table.c"
82
83 const value_string inap_general_problem_strings[] = {
84 {0,"General Problem Unrecognized Component"},
85 {1,"General Problem Mistyped Component"},
86 {3,"General Problem Badly Structured Component"},
87 {0, NULL}
88 };
89
90 /* Forvard declarations */
91 static int dissect_invokeData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
92 static int dissect_returnResultData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
93 static int dissect_returnErrorData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx);
94
95 #include "packet-inap-fn.c"
96 /*
97 TC-Invokable OPERATION ::=
98   {activateServiceFiltering | activityTest | analysedInformation |
99    analyseInformation | applyCharging | applyChargingReport |
100    assistRequestInstructions | callGap | callInformationReport |
101    callInformationRequest | cancel | cancelStatusReportRequest |
102    collectedInformation | collectInformation | connect | connectToResource |
103    continue | disconnectForwardConnection | establishTemporaryConnection |
104    eventNotificationCharging | eventReportBCSM | furnishChargingInformation |
105    holdCallInNetwork | initialDP | initiateCallAttempt | oAnswer |
106    oCalledPartyBusy | oDisconnect | oMidCall | oNoAnswer |
107    originationAttemptAuthorized | releaseCall | requestCurrentStatusReport |
108    requestEveryStatusChangeReport | requestFirstStatusMatchReport |
109    requestNotificationChargingEvent | requestReportBCSMEvent | resetTimer |
110    routeSelectFailure | selectFacility | selectRoute | sendChargingInformation
111    | serviceFilteringResponse | statusReport | tAnswer | tBusy | tDisconnect |
112    termAttemptAuthorized | tMidCall | tNoAnswer | playAnnouncement |
113    promptAndCollectUserInformation}
114 */
115
116 #include "packet-inap-table2.c"
117
118
119 static guint8 inap_pdu_type = 0;
120 static guint8 inap_pdu_size = 0;
121
122
123 static void
124 dissect_inap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
125 {
126     proto_item          *item=NULL;
127     proto_tree          *tree=NULL;
128         int                             offset = 0;
129         asn1_ctx_t asn1_ctx;
130         asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
131
132     if (check_col(pinfo->cinfo, COL_PROTOCOL))
133     {
134         col_set_str(pinfo->cinfo, COL_PROTOCOL, "INAP");
135     }
136
137     /* create display subtree for the protocol */
138     if(parent_tree){
139        item = proto_tree_add_item(parent_tree, proto_inap, tvb, 0, -1, FALSE);
140        tree = proto_item_add_subtree(item, ett_inap);
141     }
142         inap_pdu_type = tvb_get_guint8(tvb, offset)&0x0f;
143         /* Get the length and add 2 */
144         inap_pdu_size = tvb_get_guint8(tvb, offset+1)+2;
145         opcode = 0;
146     offset = dissect_inap_ROS(TRUE, tvb, offset, &asn1_ctx, tree, -1);
147
148
149 }
150
151 /*--- proto_reg_handoff_inap ---------------------------------------*/
152 static void range_delete_callback(guint32 ssn)
153 {
154     if (ssn) {
155         delete_itu_tcap_subdissector(ssn, inap_handle);
156     }
157 }
158
159 static void range_add_callback(guint32 ssn)
160 {
161     if (ssn) {
162         add_itu_tcap_subdissector(ssn, inap_handle);
163     }
164 }
165
166 void proto_reg_handoff_inap(void) {
167
168     static gboolean inap_prefs_initialized = FALSE;
169     static range_t *ssn_range;
170
171     if (!inap_prefs_initialized) {
172             inap_prefs_initialized = TRUE;
173             inap_handle = find_dissector("inap");
174             oid_add_from_string("Core-INAP-CS1-Codes","0.4.0.1.1.0.3.0");
175     }
176     else {
177             range_foreach(ssn_range, range_delete_callback);
178             g_free(ssn_range);
179     }
180
181     ssn_range = range_copy(global_ssn_range);
182
183     range_foreach(ssn_range, range_add_callback);
184
185 }
186
187
188 void proto_register_inap(void) {
189         module_t *inap_module;
190   /* List of fields */
191   static hf_register_info hf[] = {
192
193
194
195 #include "packet-inap-hfarr.c"
196   };
197
198
199
200
201
202
203   /* List of subtrees */
204   static gint *ett[] = {
205     &ett_inap,
206         &ett_inapisup_parameter,
207 #include "packet-inap-ettarr.c"
208   };
209
210   /* Register protocol */
211   proto_inap = proto_register_protocol(PNAME, PSNAME, PFNAME);
212   register_dissector("inap", dissect_inap, proto_inap);
213   /* Register fields and subtrees */
214   proto_register_field_array(proto_inap, hf, array_length(hf));
215   proto_register_subtree_array(ett, array_length(ett));
216
217   /* Set default SSNs */
218   range_convert_str(&global_ssn_range, "106,241", MAX_SSN);
219
220   inap_module = prefs_register_protocol(proto_inap, proto_reg_handoff_inap);
221
222   prefs_register_obsolete_preference(inap_module, "tcap.itu_ssn");
223
224   prefs_register_obsolete_preference(inap_module, "tcap.itu_ssn1");
225
226   prefs_register_range_preference(inap_module, "ssn", "TCAP SSNs",
227                                   "TCAP Subsystem numbers used for INAP",
228                                   &global_ssn_range, MAX_SSN);
229 }
230
231
232