Corrected "old-style function definition".
[obnox/wireshark/wip.git] / asn1 / q932 / packet-q932-template.c
1 /* packet-q932.c
2  * Routines for Q.932 packet dissection
3  * 2007  Tomas Kukosa
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
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <epan/packet.h>
31 #include <epan/strutil.h>
32 #include <epan/asn1.h>
33
34 #include "packet-ber.h"
35 #include "packet-q932.h"
36
37 #define PNAME  "Q.932"
38 #define PSNAME "Q932"
39 #define PFNAME "q932"
40
41 /* Initialize the protocol and registered fields */
42 static int proto_q932 = -1;
43 static int hf_q932_ie_type = -1;
44 static int hf_q932_ie_len = -1;
45 static int hf_q932_ie_data = -1;
46 static int hf_q932_pp = -1;
47 static int hf_q932_nd = -1;
48 #include "packet-q932-hf.c"
49
50 /* Initialize the subtree pointers */
51 static gint ett_q932 = -1;
52 static gint ett_q932_ie = -1;
53 #include "packet-q932-ett.c"
54
55 /* Preferences */
56
57 /* ROSE context */
58 static rose_ctx_t q932_rose_ctx;
59
60 /* Subdissectors */
61 static dissector_handle_t q932_ros_handle; 
62
63 #define Q932_IE_EXTENDED_FACILITY   0x0D
64 #define Q932_IE_FACILITY            0x1C
65 #define Q932_IE_NOTIFICATION_INDICATOR  0x27
66 #define Q932_IE_INFORMATION_REQUEST 0x32
67 #define Q932_IE_FEATURE_ACTIVATION  0x38
68 #define Q932_IE_FEATURE_INDICATION  0x39
69 #define Q932_IE_SERVICE_PROFILE_ID  0x3A
70 #define Q932_IE_ENDPOINT_IDENTIFIER 0x3B
71 static const value_string q932_str_ie_type[] = {
72   { Q932_IE_EXTENDED_FACILITY  , "Extended facility" },
73   { Q932_IE_FACILITY           , "Facility" },
74   { Q932_IE_NOTIFICATION_INDICATOR, "Notification indicator" },
75   { Q932_IE_INFORMATION_REQUEST, "Information request" },
76   { Q932_IE_FEATURE_ACTIVATION , "Feature activation" },
77   { Q932_IE_FEATURE_INDICATION , "Feature indication" },
78   { Q932_IE_SERVICE_PROFILE_ID , "Service profile identification" },
79   { Q932_IE_ENDPOINT_IDENTIFIER, "Endpoint identifier" },
80   { 0, NULL}
81 };
82
83 static const value_string str_pp[] = {
84   { 0x11  , "Remote Operations Protocol" },
85   { 0x12  , "CMIP Protocol" },
86   { 0x13  , "ACSE Protocol" },
87   { 0x1F  , "Networking extensions" },
88   { 0, NULL}
89 };
90
91 static const value_string str_nd[] = {
92   { 0x00  , "User suspended" },
93   { 0x01  , "User resume" },
94   { 0x02  , "Bearer service change" },
95   { 0x04  , "Call completion delay" },
96   { 0x03  , "Discriminator for extension to ASN.1 encoded component" },
97   { 0x40  , "Discriminator for extension to ASN.1 encoded component for ISO" },
98   { 0x42  , "Conference established" },
99   { 0x43  , "Conference disconnected" },
100   { 0x44  , "Other party added" },
101   { 0x45  , "Isolated" },
102   { 0x46  , "Reattached" },
103   { 0x47  , "Other party isolated" },
104   { 0x48  , "Other party reattached" },
105   { 0x49  , "Other party split" },
106   { 0x4A  , "Other party disconnected" },
107   { 0x4B  , "Conference floating" },
108   { 0x4C  , "Conference disconnected, pre-emption" },
109   { 0x4F  , "Conference floating, served user pre-empted" },
110   { 0x60  , "Call is a waiting call" },
111   { 0x68  , "Diversion activated" },
112   { 0x69  , "call transferred, alerting" },
113   { 0x6A  , "call transferred, answered" },
114   { 0x6E  , "reverse charging (whole call)" },
115   { 0x6F  , "reverse charging (for the rest of the call)" },
116   { 0x74  , "service profile update" },
117   { 0x79  , "Remote hold" },
118   { 0x7A  , "Remote retrieval" },
119   { 0x7B  , "Call is diverting" },
120   { 0, NULL}
121 };
122
123 #include "packet-q932-fn.c"
124
125 /*--- dissect_q932_facility_ie -------------------------------------------------------*/
126 /*static*/ void
127 dissect_q932_facility_ie(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int length) {
128   gint8 class;
129   gboolean pc;
130   gint32 tag;
131   guint32 len;
132   int hoffset, eoffset;
133   int ie_end;
134   tvbuff_t *next_tvb;
135
136   ie_end = offset + length;
137   proto_tree_add_item(tree, hf_q932_pp, tvb, offset, 1, FALSE);
138   offset++;
139   while (offset < ie_end) {
140     hoffset = offset;
141     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
142     offset = get_ber_length(tvb, offset, &len, NULL);
143     eoffset = offset + len;
144     next_tvb =  tvb_new_subset(tvb, hoffset, eoffset - hoffset, eoffset - hoffset);
145     switch (class) {
146       case BER_CLASS_CON:
147         switch (tag) {
148           case 10 :  /* Network Facility Extension */
149             dissect_NetworkFacilityExtension_PDU(next_tvb, pinfo, tree);
150             break;
151           case 18 :  /* Network Protocol Profile */
152             dissect_NetworkProtocolProfile_PDU(next_tvb, pinfo, tree);
153             break;
154           case 11 :  /* Interpretation Component */
155             dissect_InterpretationComponent_PDU(next_tvb, pinfo, tree);
156             break;
157           /* ROSE APDU */
158           case  1 :  /* invoke */
159           case  2 :  /* returnResult */
160           case  3 :  /* returnError */
161           case  4 :  /* reject */
162             q932_rose_ctx.apdu_depth = 1;
163             pinfo->private_data = &q932_rose_ctx;
164             call_dissector(q932_ros_handle, next_tvb, pinfo, tree);
165             break;
166           /* DSE APDU */
167           case 12 :  /* begin */
168           case 14 :  /* end */
169           case 15 :  /* continue */
170           case 17 :  /* abort */
171             offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
172             offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
173             proto_tree_add_text(tree, tvb, offset, len, "DSE APDU (not supported)");
174             break;
175           default:
176             offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
177             offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
178             proto_tree_add_text(tree, tvb, offset, len, "Unknown Component");
179         }
180         break;
181       case BER_CLASS_APP:
182         switch (tag) {
183           /* ACSE APDU */
184           case  0 :  /* aarq */
185           case  1 :  /* aare */
186           case  2 :  /* rlrq */
187           case  3 :  /* rlre */
188           case  4 :  /* abrt */
189             offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
190             offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
191             proto_tree_add_text(tree, tvb, offset, len, "ACSE APDU (not supported)");
192             break;
193           default:
194             offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
195             offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
196             proto_tree_add_text(tree, tvb, offset, len, "Unknown Component");
197         }
198         break;
199       default:
200         offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
201         offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
202         proto_tree_add_text(tree, tvb, offset, len, "Unknown Component");
203     }
204     offset = eoffset;
205   }
206 }
207
208 /*--- dissect_q932_ni_ie -------------------------------------------------------*/
209 static void
210 dissect_q932_ni_ie(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int length) {
211   int remain = length;
212   guint8 octet = 0;
213   guint32 value = 0;
214
215   while ((remain > 0) && !(octet & 0x80)) {
216     octet = tvb_get_guint8(tvb, offset++);
217     remain--;
218     value <<= 7;
219     value |= octet & 0x7F;
220   }
221   proto_tree_add_uint(tree, hf_q932_nd, tvb, offset - (length - remain), length - remain, value);
222
223   if (remain > 0) {
224     proto_tree_add_text(tree, tvb, offset - remain, remain, "ASN.1 Encoded Data Structure(NOT IMPLEMENTED): %s", tvb_bytes_to_str(tvb, offset - remain, remain));
225   }
226 }
227
228 /*--- dissect_q932_ie -------------------------------------------------------*/
229 static void
230 dissect_q932_ie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
231   gint offset;
232   proto_item *ti, *ti_ie;
233   proto_tree *ie_tree;
234   guint8 ie_type, ie_len;
235
236   offset = 0;
237
238   ti = proto_tree_add_item(tree, proto_q932, tvb, offset, -1, FALSE);
239   PROTO_ITEM_SET_HIDDEN(ti);
240
241   ie_type = tvb_get_guint8(tvb, offset);
242   ie_len = tvb_get_guint8(tvb, offset + 1);
243
244   ti_ie = proto_tree_add_text(tree, tvb, offset, -1, "%s",
245             val_to_str(ie_type, VALS(q932_str_ie_type), "unknown (0x%02X)"));
246   ie_tree = proto_item_add_subtree(ti_ie, ett_q932_ie); 
247   proto_tree_add_item(ie_tree, hf_q932_ie_type, tvb, offset, 1, FALSE);
248   proto_tree_add_item(ie_tree, hf_q932_ie_len, tvb, offset + 1, 1, FALSE);
249   offset += 2;
250   if (tvb_length_remaining(tvb, offset) <= 0)
251     return;
252   switch (ie_type) {
253     case Q932_IE_FACILITY :
254       dissect_q932_facility_ie(tvb, offset, pinfo, ie_tree, ie_len);
255       break;
256     case Q932_IE_NOTIFICATION_INDICATOR :
257       dissect_q932_ni_ie(tvb, offset, pinfo, ie_tree, ie_len);
258       break;
259     default:
260       if (ie_len > 0) {
261         if (tree) proto_tree_add_item(ie_tree, hf_q932_ie_data, tvb, offset, ie_len, FALSE);
262       }
263   }
264 }
265
266 /*--- dissect_q932_apdu -----------------------------------------------------*/
267 static void
268 dissect_q932_apdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
269   call_dissector(q932_ros_handle, tvb, pinfo, tree);
270 }
271
272 /*--- proto_register_q932 ---------------------------------------------------*/
273 void proto_register_q932(void) {
274
275   /* List of fields */
276   static hf_register_info hf[] = {
277     { &hf_q932_ie_type, { "Type", "q932.ie.type",
278                           FT_UINT8, BASE_HEX, VALS(q932_str_ie_type), 0x0,
279                           "Information Element Type", HFILL }},
280     { &hf_q932_ie_len,  { "Length", "q932.ie.len",
281                           FT_UINT8, BASE_DEC, NULL, 0x0,
282                           "Information Element Length", HFILL }},
283     { &hf_q932_ie_data, { "Data", "q932.ie.data",
284                           FT_BYTES, BASE_NONE, NULL, 0x0,
285                           NULL, HFILL }},
286     { &hf_q932_pp,      { "Protocol profile", "q932.pp",
287                           FT_UINT8, BASE_HEX, VALS(str_pp), 0x1F,
288                           NULL, HFILL }},
289     { &hf_q932_nd,      { "Notification description", "q932.nd",
290                           FT_UINT8, BASE_HEX, VALS(str_nd), 0x0,
291                           NULL, HFILL }},
292 #include "packet-q932-hfarr.c"
293   };
294
295   /* List of subtrees */
296   static gint *ett[] = {
297     &ett_q932,
298     &ett_q932_ie,
299 #include "packet-q932-ettarr.c"
300   };
301
302   /* Register protocol and dissector */
303   proto_q932 = proto_register_protocol(PNAME, PSNAME, PFNAME);
304   register_dissector("q932.apdu", dissect_q932_apdu, proto_q932);
305
306   /* Register fields and subtrees */
307   proto_register_field_array(proto_q932, hf, array_length(hf));
308   proto_register_subtree_array(ett, array_length(ett));
309
310   rose_ctx_init(&q932_rose_ctx);
311
312   /* Register dissector tables */
313   q932_rose_ctx.arg_global_dissector_table = register_dissector_table("q932.ros.global.arg", "Q.932 Operation Argument (global opcode)", FT_STRING, BASE_NONE);
314   q932_rose_ctx.res_global_dissector_table = register_dissector_table("q932.ros.global.res", "Q.932 Operation Result (global opcode)", FT_STRING, BASE_NONE);
315   q932_rose_ctx.arg_local_dissector_table = register_dissector_table("q932.ros.local.arg", "Q.932 Operation Argument (local opcode)", FT_UINT32, BASE_HEX); 
316   q932_rose_ctx.res_local_dissector_table = register_dissector_table("q932.ros.local.res", "Q.932 Operation Result (local opcode)", FT_UINT32, BASE_HEX); 
317   q932_rose_ctx.err_global_dissector_table = register_dissector_table("q932.ros.global.err", "Q.932 Error (global opcode)", FT_STRING, BASE_NONE);
318   q932_rose_ctx.err_local_dissector_table = register_dissector_table("q932.ros.local.err", "Q.932 Error (local opcode)", FT_UINT32, BASE_HEX); 
319 }
320
321 /*--- proto_reg_handoff_q932 ------------------------------------------------*/
322 void proto_reg_handoff_q932(void) {
323   dissector_handle_t q932_ie_handle;
324
325   q932_ie_handle = create_dissector_handle(dissect_q932_ie, proto_q932);
326   /* Facility */
327   dissector_add_uint("q931.ie", (0x00 << 8) | Q932_IE_FACILITY, q932_ie_handle); 
328   /* Notification indicator */
329   dissector_add_uint("q931.ie", (0x00 << 8) | Q932_IE_NOTIFICATION_INDICATOR, q932_ie_handle); 
330
331   q932_ros_handle = find_dissector("q932.ros");
332 }
333
334 /*---------------------------------------------------------------------------*/