From Graeme Lunt
[obnox/wireshark/wip.git] / epan / dissectors / packet-rtse.c
1 /* Do not modify this file.                                                   */
2 /* It is created automatically by the ASN.1 to Ethereal dissector compiler    */
3 /* .\packet-rtse.c                                                            */
4 /* ../../tools/asn2eth.py -X -b -e -p rtse -c rtse.cnf -s packet-rtse-template rtse.asn */
5
6 /* Input file: packet-rtse-template.c */
7
8 /* packet-rtse_asn1.c
9  * Routines for RTSE packet dissection
10  * Graeme Lunt 2005
11  *
12  * $Id$
13  *
14  * Ethereal - Network traffic analyzer
15  * By Gerald Combs <gerald@ethereal.com>
16  * Copyright 1998 Gerald Combs
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free Software Foundation; either version 2
21  * of the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <glib.h>
38 #include <epan/packet.h>
39 #include <epan/conversation.h>
40
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "packet-ber.h"
45 #include "packet-pres.h"
46 #include "packet-acse.h"
47 #include "packet-ros.h"
48 #include "packet-rtse.h"
49
50 #define PNAME  "X.228 OSI Reliable Transfer Service"
51 #define PSNAME "RTSE"
52 #define PFNAME "rtse"
53
54 /* Initialize the protocol and registered fields */
55 int proto_rtse = -1;
56
57 static struct SESSION_DATA_STRUCTURE* session = NULL;
58
59 static char object_identifier_id[MAX_OID_STR_LEN];
60 /* indirect_reference, used to pick up the signalling so we know what
61    kind of data is transferred in SES_DATA_TRANSFER_PDUs */
62 static guint32 indir_ref=0;
63 static guint32 app_proto=0;
64
65 static proto_tree *top_tree=NULL;
66
67 static int dissect_rtse_EXTERNAL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_);
68
69
70
71 /*--- Included file: packet-rtse-hf.c ---*/
72
73 static int hf_rtse_rtorq_apdu = -1;               /* RTORQapdu */
74 static int hf_rtse_rtoac_apdu = -1;               /* RTOACapdu */
75 static int hf_rtse_rtorj_apdu = -1;               /* RTORJapdu */
76 static int hf_rtse_rttp_apdu = -1;                /* RTTPapdu */
77 static int hf_rtse_rttr_apdu = -1;                /* RTTRapdu */
78 static int hf_rtse_rtab_apdu = -1;                /* RTABapdu */
79 static int hf_rtse_checkpointSize = -1;           /* INTEGER */
80 static int hf_rtse_windowSize = -1;               /* INTEGER */
81 static int hf_rtse_dialogueMode = -1;             /* T_dialogueMode */
82 static int hf_rtse_connectionDataRQ = -1;         /* ConnectionData */
83 static int hf_rtse_applicationProtocol = -1;      /* T_applicationProtocol */
84 static int hf_rtse_connectionDataAC = -1;         /* ConnectionData */
85 static int hf_rtse_refuseReason = -1;             /* RefuseReason */
86 static int hf_rtse_userDataRJ = -1;               /* T_userDataRJ */
87 static int hf_rtse_abortReason = -1;              /* AbortReason */
88 static int hf_rtse_reflectedParameter = -1;       /* BIT_STRING */
89 static int hf_rtse_userdataAB = -1;               /* T_userdataAB */
90 static int hf_rtse_open = -1;                     /* T_open */
91 static int hf_rtse_recover = -1;                  /* SessionConnectionIdentifier */
92 static int hf_rtse_callingSSuserReference = -1;   /* CallingSSuserReference */
93 static int hf_rtse_commonReference = -1;          /* CommonReference */
94 static int hf_rtse_additionalReferenceInformation = -1;  /* AdditionalReferenceInformation */
95 static int hf_rtse_t61String = -1;                /* T61String */
96 static int hf_rtse_octetString = -1;              /* OCTET_STRING */
97 static int hf_rtse_direct_reference = -1;         /* OBJECT_IDENTIFIER */
98 static int hf_rtse_indirect_reference = -1;       /* T_indirect_reference */
99 static int hf_rtse_data_value_descriptor = -1;    /* ObjectDescriptor */
100 static int hf_rtse_encoding = -1;                 /* T_encoding */
101 static int hf_rtse_single_ASN1_type = -1;         /* T_single_ASN1_type */
102 static int hf_rtse_octet_aligned = -1;            /* OCTET_STRING */
103 static int hf_rtse_arbitrary = -1;                /* BIT_STRING */
104
105 /*--- End of included file: packet-rtse-hf.c ---*/
106
107
108 /* Initialize the subtree pointers */
109 static gint ett_rtse = -1;
110
111 /*--- Included file: packet-rtse-ett.c ---*/
112
113 static gint ett_rtse_RTSE_apdus = -1;
114 static gint ett_rtse_RTORQapdu = -1;
115 static gint ett_rtse_RTOACapdu = -1;
116 static gint ett_rtse_RTORJapdu = -1;
117 static gint ett_rtse_RTABapdu = -1;
118 static gint ett_rtse_ConnectionData = -1;
119 static gint ett_rtse_SessionConnectionIdentifier = -1;
120 static gint ett_rtse_CallingSSuserReference = -1;
121 static gint ett_rtse_EXTERNAL = -1;
122 static gint ett_rtse_T_encoding = -1;
123
124 /*--- End of included file: packet-rtse-ett.c ---*/
125
126
127
128 static dissector_table_t rtse_oid_dissector_table=NULL;
129 static GHashTable *oid_table=NULL;
130 static gint ett_rtse_unknown = -1;
131
132 void
133 register_rtse_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto _U_, const char *name)
134 {
135         dissector_add_string("rtse.oid", oid, dissector);
136         g_hash_table_insert(oid_table, (gpointer)oid, (gpointer)name);
137 }
138
139 static int
140 call_rtse_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
141 {
142         tvbuff_t *next_tvb;
143
144         next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), tvb_reported_length_remaining(tvb, offset));
145         if(!dissector_try_string(rtse_oid_dissector_table, oid, next_tvb, pinfo, tree)){
146                 proto_item *item=NULL;
147                 proto_tree *next_tree=NULL;
148
149                 item=proto_tree_add_text(tree, next_tvb, 0, tvb_length_remaining(tvb, offset), "RTSE: Dissector for OID:%s not implemented. Contact Ethereal developers if you want this supported", oid);
150                 if(item){
151                         next_tree=proto_item_add_subtree(item, ett_rtse_unknown);
152                 }
153                 dissect_unknown_ber(pinfo, next_tvb, offset, next_tree);
154         }
155
156         /*XXX until we change the #.REGISTER signature for _PDU()s 
157          * into new_dissector_t   we have to do this kludge with
158          * manually step past the content in the ANY type.
159          */
160         offset+=tvb_length_remaining(tvb, offset);
161
162         return offset;
163 }
164
165
166 /*--- Included file: packet-rtse-fn.c ---*/
167
168 /*--- Fields for imported types ---*/
169
170
171
172
173 static int
174 dissect_rtse_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
175   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
176                                   NULL);
177
178   return offset;
179 }
180 static int dissect_checkpointSize_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
181   return dissect_rtse_INTEGER(TRUE, tvb, offset, pinfo, tree, hf_rtse_checkpointSize);
182 }
183 static int dissect_windowSize_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
184   return dissect_rtse_INTEGER(TRUE, tvb, offset, pinfo, tree, hf_rtse_windowSize);
185 }
186
187
188 static const value_string rtse_T_dialogueMode_vals[] = {
189   {   0, "monologue" },
190   {   1, "twa" },
191   { 0, NULL }
192 };
193
194
195 static int
196 dissect_rtse_T_dialogueMode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
197   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
198                                   NULL);
199
200   return offset;
201 }
202 static int dissect_dialogueMode_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
203   return dissect_rtse_T_dialogueMode(TRUE, tvb, offset, pinfo, tree, hf_rtse_dialogueMode);
204 }
205
206
207
208 static int
209 dissect_rtse_T_open(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
210
211         char *oid = NULL;
212
213         switch(app_proto)  {
214         case 1:         /* mts-transfer-protocol-1984 */
215                 oid = "applicationProtocol.1";
216                 break;
217         case 12:        /* mts-transfer-protocol */
218                 oid = "applicationProtocol.12";
219                 break;
220         default:
221                 if(session && session->pres_ctx_id)
222                         oid = find_oid_by_pres_ctx_id(pinfo, session->pres_ctx_id);
223                 break;
224         }
225         
226         if(!oid) /* XXX: problem here is we haven't decoded the applicationProtocol yet - so we make assumptions! */
227                 oid = "applicationProtocol.12";
228
229         if(oid) {
230
231                 offset = call_rtse_oid_callback(oid, tvb, offset, pinfo, top_tree ? top_tree : tree);
232         }
233
234         /* else XXX: need to flag we can't find the presentation context */
235
236
237   return offset;
238 }
239 static int dissect_open(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
240   return dissect_rtse_T_open(FALSE, tvb, offset, pinfo, tree, hf_rtse_open);
241 }
242
243
244
245 static int
246 dissect_rtse_T61String(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
247   offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_TeletexString,
248                                             pinfo, tree, tvb, offset, hf_index,
249                                             NULL);
250
251   return offset;
252 }
253 static int dissect_t61String(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
254   return dissect_rtse_T61String(FALSE, tvb, offset, pinfo, tree, hf_rtse_t61String);
255 }
256
257
258
259 static int
260 dissect_rtse_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
261   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
262                                        NULL);
263
264   return offset;
265 }
266 static int dissect_octetString(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
267   return dissect_rtse_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_rtse_octetString);
268 }
269 static int dissect_octet_aligned_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
270   return dissect_rtse_OCTET_STRING(TRUE, tvb, offset, pinfo, tree, hf_rtse_octet_aligned);
271 }
272
273
274 static const value_string rtse_CallingSSuserReference_vals[] = {
275   {   0, "t61String" },
276   {   1, "octetString" },
277   { 0, NULL }
278 };
279
280 static const ber_choice_t CallingSSuserReference_choice[] = {
281   {   0, BER_CLASS_UNI, BER_UNI_TAG_TeletexString, BER_FLAGS_NOOWNTAG, dissect_t61String },
282   {   1, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_octetString },
283   { 0, 0, 0, 0, NULL }
284 };
285
286 static int
287 dissect_rtse_CallingSSuserReference(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
288   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
289                                  CallingSSuserReference_choice, hf_index, ett_rtse_CallingSSuserReference,
290                                  NULL);
291
292   return offset;
293 }
294 static int dissect_callingSSuserReference(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
295   return dissect_rtse_CallingSSuserReference(FALSE, tvb, offset, pinfo, tree, hf_rtse_callingSSuserReference);
296 }
297
298
299
300 static int
301 dissect_rtse_CommonReference(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
302   offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_UTCTime,
303                                             pinfo, tree, tvb, offset, hf_index,
304                                             NULL);
305
306   return offset;
307 }
308 static int dissect_commonReference(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
309   return dissect_rtse_CommonReference(FALSE, tvb, offset, pinfo, tree, hf_rtse_commonReference);
310 }
311
312
313
314 static int
315 dissect_rtse_AdditionalReferenceInformation(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
316   offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_TeletexString,
317                                             pinfo, tree, tvb, offset, hf_index,
318                                             NULL);
319
320   return offset;
321 }
322 static int dissect_additionalReferenceInformation_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
323   return dissect_rtse_AdditionalReferenceInformation(TRUE, tvb, offset, pinfo, tree, hf_rtse_additionalReferenceInformation);
324 }
325
326
327 static const ber_sequence_t SessionConnectionIdentifier_sequence[] = {
328   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_callingSSuserReference },
329   { BER_CLASS_UNI, BER_UNI_TAG_UTCTime, BER_FLAGS_NOOWNTAG, dissect_commonReference },
330   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_additionalReferenceInformation_impl },
331   { 0, 0, 0, NULL }
332 };
333
334 static int
335 dissect_rtse_SessionConnectionIdentifier(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
336   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
337                                    SessionConnectionIdentifier_sequence, hf_index, ett_rtse_SessionConnectionIdentifier);
338
339   return offset;
340 }
341 static int dissect_recover_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
342   return dissect_rtse_SessionConnectionIdentifier(TRUE, tvb, offset, pinfo, tree, hf_rtse_recover);
343 }
344
345
346 static const value_string rtse_ConnectionData_vals[] = {
347   {   0, "open" },
348   {   1, "recover" },
349   { 0, NULL }
350 };
351
352 static const ber_choice_t ConnectionData_choice[] = {
353   {   0, BER_CLASS_CON, 0, 0, dissect_open },
354   {   1, BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_recover_impl },
355   { 0, 0, 0, 0, NULL }
356 };
357
358 static int
359 dissect_rtse_ConnectionData(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
360   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
361                                  ConnectionData_choice, hf_index, ett_rtse_ConnectionData,
362                                  NULL);
363
364   return offset;
365 }
366 static int dissect_connectionDataRQ(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
367   return dissect_rtse_ConnectionData(FALSE, tvb, offset, pinfo, tree, hf_rtse_connectionDataRQ);
368 }
369 static int dissect_connectionDataAC(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
370   return dissect_rtse_ConnectionData(FALSE, tvb, offset, pinfo, tree, hf_rtse_connectionDataAC);
371 }
372
373
374 static const value_string rtse_T_applicationProtocol_vals[] = {
375   {  12, "mts-transfer-protocol" },
376   {   1, "mts-transfer-protocol-1984" },
377   { 0, NULL }
378 };
379
380
381 static int
382 dissect_rtse_T_applicationProtocol(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
383
384   offset = dissect_ber_integer(TRUE, pinfo, tree, tvb, offset, hf_index, &app_proto);
385
386
387   return offset;
388 }
389 static int dissect_applicationProtocol_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
390   return dissect_rtse_T_applicationProtocol(TRUE, tvb, offset, pinfo, tree, hf_rtse_applicationProtocol);
391 }
392
393
394 static const ber_sequence_t RTORQapdu_set[] = {
395   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_checkpointSize_impl },
396   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_windowSize_impl },
397   { BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_dialogueMode_impl },
398   { BER_CLASS_CON, 3, BER_FLAGS_NOTCHKTAG, dissect_connectionDataRQ },
399   { BER_CLASS_CON, 4, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_applicationProtocol_impl },
400   { 0, 0, 0, NULL }
401 };
402
403 int
404 dissect_rtse_RTORQapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
405
406   if(session  = (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data))
407         session->ros_op = (ROS_OP_BIND | ROS_OP_ARGUMENT);
408
409   offset = dissect_ber_set(implicit_tag, pinfo, tree, tvb, offset,
410                               RTORQapdu_set, hf_index, ett_rtse_RTORQapdu);
411
412
413
414   return offset;
415 }
416 static int dissect_rtorq_apdu_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
417   return dissect_rtse_RTORQapdu(TRUE, tvb, offset, pinfo, tree, hf_rtse_rtorq_apdu);
418 }
419
420
421 static const ber_sequence_t RTOACapdu_set[] = {
422   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_checkpointSize_impl },
423   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_windowSize_impl },
424   { BER_CLASS_CON, 2, BER_FLAGS_NOTCHKTAG, dissect_connectionDataAC },
425   { 0, 0, 0, NULL }
426 };
427
428 int
429 dissect_rtse_RTOACapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
430
431   if(session  = (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data))
432         session->ros_op = (ROS_OP_BIND | ROS_OP_RESULT);
433
434   offset = dissect_ber_set(implicit_tag, pinfo, tree, tvb, offset,
435                               RTOACapdu_set, hf_index, ett_rtse_RTOACapdu);
436
437
438
439   return offset;
440 }
441 static int dissect_rtoac_apdu_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
442   return dissect_rtse_RTOACapdu(TRUE, tvb, offset, pinfo, tree, hf_rtse_rtoac_apdu);
443 }
444
445
446 static const value_string rtse_RefuseReason_vals[] = {
447   {   0, "rtsBusy" },
448   {   1, "cannotRecover" },
449   {   2, "validationFailure" },
450   {   3, "unacceptableDialogueMode" },
451   { 0, NULL }
452 };
453
454
455 static int
456 dissect_rtse_RefuseReason(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
457   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
458                                   NULL);
459
460   return offset;
461 }
462 static int dissect_refuseReason_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
463   return dissect_rtse_RefuseReason(TRUE, tvb, offset, pinfo, tree, hf_rtse_refuseReason);
464 }
465
466
467
468 static int
469 dissect_rtse_T_userDataRJ(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
470 /*XXX not implemented yet */
471
472
473   return offset;
474 }
475 static int dissect_userDataRJ(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
476   return dissect_rtse_T_userDataRJ(FALSE, tvb, offset, pinfo, tree, hf_rtse_userDataRJ);
477 }
478
479
480 static const ber_sequence_t RTORJapdu_set[] = {
481   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_refuseReason_impl },
482   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL, dissect_userDataRJ },
483   { 0, 0, 0, NULL }
484 };
485
486 int
487 dissect_rtse_RTORJapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
488   offset = dissect_ber_set(implicit_tag, pinfo, tree, tvb, offset,
489                               RTORJapdu_set, hf_index, ett_rtse_RTORJapdu);
490
491   return offset;
492 }
493 static int dissect_rtorj_apdu_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
494   return dissect_rtse_RTORJapdu(TRUE, tvb, offset, pinfo, tree, hf_rtse_rtorj_apdu);
495 }
496
497
498
499 static int
500 dissect_rtse_RTTPapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
501   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
502                                   NULL);
503
504   return offset;
505 }
506 static int dissect_rttp_apdu(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
507   return dissect_rtse_RTTPapdu(FALSE, tvb, offset, pinfo, tree, hf_rtse_rttp_apdu);
508 }
509
510
511
512 static int
513 dissect_rtse_RTTRapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
514         tvbuff_t *next_tvb = NULL;
515
516         offset = dissect_ber_octet_string(FALSE, pinfo, tree, tvb, offset, hf_index, &next_tvb);
517
518         if(next_tvb) {
519
520                 /* XXX: we should check is this is an EXTERNAL first */
521
522                 /* ROS won't do this for us */
523                 if(session)
524                         session->ros_op = (ROS_OP_INVOKE | ROS_OP_ARGUMENT);
525
526                 offset = dissect_rtse_EXTERNAL(FALSE, next_tvb, 0, pinfo, tree, -1);
527
528         }
529
530
531   return offset;
532 }
533 static int dissect_rttr_apdu(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
534   return dissect_rtse_RTTRapdu(FALSE, tvb, offset, pinfo, tree, hf_rtse_rttr_apdu);
535 }
536
537
538 static const value_string rtse_AbortReason_vals[] = {
539   {   0, "localSystemProblem" },
540   {   1, "invalidParameter" },
541   {   2, "unrecognizedActivity" },
542   {   3, "temporaryProblem" },
543   {   4, "protocolError" },
544   {   5, "permanentProblem" },
545   {   6, "userError" },
546   {   7, "transferCompleted" },
547   { 0, NULL }
548 };
549
550
551 static int
552 dissect_rtse_AbortReason(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
553   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
554                                   NULL);
555
556   return offset;
557 }
558 static int dissect_abortReason_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
559   return dissect_rtse_AbortReason(TRUE, tvb, offset, pinfo, tree, hf_rtse_abortReason);
560 }
561
562
563
564 static int
565 dissect_rtse_BIT_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
566   offset = dissect_ber_bitstring(implicit_tag, pinfo, tree, tvb, offset,
567                                     NULL, hf_index, -1,
568                                     NULL);
569
570   return offset;
571 }
572 static int dissect_reflectedParameter_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
573   return dissect_rtse_BIT_STRING(TRUE, tvb, offset, pinfo, tree, hf_rtse_reflectedParameter);
574 }
575 static int dissect_arbitrary_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
576   return dissect_rtse_BIT_STRING(TRUE, tvb, offset, pinfo, tree, hf_rtse_arbitrary);
577 }
578
579
580
581 static int
582 dissect_rtse_T_userdataAB(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
583 /*XXX not implemented yet */
584
585
586   return offset;
587 }
588 static int dissect_userdataAB(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
589   return dissect_rtse_T_userdataAB(FALSE, tvb, offset, pinfo, tree, hf_rtse_userdataAB);
590 }
591
592
593 static const ber_sequence_t RTABapdu_set[] = {
594   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_abortReason_impl },
595   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_reflectedParameter_impl },
596   { BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL, dissect_userdataAB },
597   { 0, 0, 0, NULL }
598 };
599
600 int
601 dissect_rtse_RTABapdu(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
602   offset = dissect_ber_set(implicit_tag, pinfo, tree, tvb, offset,
603                               RTABapdu_set, hf_index, ett_rtse_RTABapdu);
604
605   return offset;
606 }
607 static int dissect_rtab_apdu_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
608   return dissect_rtse_RTABapdu(TRUE, tvb, offset, pinfo, tree, hf_rtse_rtab_apdu);
609 }
610
611
612 static const value_string rtse_RTSE_apdus_vals[] = {
613   {   0, "rtorq-apdu" },
614   {   1, "rtoac-apdu" },
615   {   2, "rtorj-apdu" },
616   {   3, "rttp-apdu" },
617   {   4, "rttr-apdu" },
618   {   5, "rtab-apdu" },
619   { 0, NULL }
620 };
621
622 static const ber_choice_t RTSE_apdus_choice[] = {
623   {   0, BER_CLASS_CON, 16, BER_FLAGS_IMPLTAG, dissect_rtorq_apdu_impl },
624   {   1, BER_CLASS_CON, 17, BER_FLAGS_IMPLTAG, dissect_rtoac_apdu_impl },
625   {   2, BER_CLASS_CON, 18, BER_FLAGS_IMPLTAG, dissect_rtorj_apdu_impl },
626   {   3, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_rttp_apdu },
627   {   4, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_rttr_apdu },
628   {   5, BER_CLASS_CON, 22, BER_FLAGS_IMPLTAG, dissect_rtab_apdu_impl },
629   { 0, 0, 0, 0, NULL }
630 };
631
632 static int
633 dissect_rtse_RTSE_apdus(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
634   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
635                                  RTSE_apdus_choice, hf_index, ett_rtse_RTSE_apdus,
636                                  NULL);
637
638   return offset;
639 }
640
641
642
643 static int
644 dissect_rtse_OBJECT_IDENTIFIER(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
645   offset = dissect_ber_object_identifier(implicit_tag, pinfo, tree, tvb, offset, hf_index,
646                                             NULL);
647
648   return offset;
649 }
650 static int dissect_direct_reference(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
651   return dissect_rtse_OBJECT_IDENTIFIER(FALSE, tvb, offset, pinfo, tree, hf_rtse_direct_reference);
652 }
653
654
655
656 static int
657 dissect_rtse_T_indirect_reference(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
658   char *oid;
659
660   offset = dissect_ber_integer(FALSE, pinfo, tree, tvb, offset,
661                 hf_rtse_indirect_reference,
662                 &indir_ref);
663
664   /* look up the indirect reference */
665   if(oid = find_oid_by_pres_ctx_id(pinfo, indir_ref)) {
666     strcpy(object_identifier_id, oid);
667   }
668         
669
670
671   return offset;
672 }
673 static int dissect_indirect_reference(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
674   return dissect_rtse_T_indirect_reference(FALSE, tvb, offset, pinfo, tree, hf_rtse_indirect_reference);
675 }
676
677
678
679 static int
680 dissect_rtse_ObjectDescriptor(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
681   offset = dissect_ber_restricted_string(implicit_tag, BER_UNI_TAG_ObjectDescriptor,
682                                             pinfo, tree, tvb, offset, hf_index,
683                                             NULL);
684
685   return offset;
686 }
687 static int dissect_data_value_descriptor(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
688   return dissect_rtse_ObjectDescriptor(FALSE, tvb, offset, pinfo, tree, hf_rtse_data_value_descriptor);
689 }
690
691
692
693 static int
694 dissect_rtse_T_single_ASN1_type(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
695   offset=call_rtse_oid_callback(object_identifier_id, tvb, offset, pinfo, top_tree);
696
697
698
699   return offset;
700 }
701 static int dissect_single_ASN1_type(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
702   return dissect_rtse_T_single_ASN1_type(FALSE, tvb, offset, pinfo, tree, hf_rtse_single_ASN1_type);
703 }
704
705
706 static const value_string rtse_T_encoding_vals[] = {
707   {   0, "single-ASN1-type" },
708   {   1, "octet-aligned" },
709   {   2, "arbitrary" },
710   { 0, NULL }
711 };
712
713 static const ber_choice_t T_encoding_choice[] = {
714   {   0, BER_CLASS_CON, 0, 0, dissect_single_ASN1_type },
715   {   1, BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_octet_aligned_impl },
716   {   2, BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_arbitrary_impl },
717   { 0, 0, 0, 0, NULL }
718 };
719
720 static int
721 dissect_rtse_T_encoding(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
722   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
723                                  T_encoding_choice, hf_index, ett_rtse_T_encoding,
724                                  NULL);
725
726   return offset;
727 }
728 static int dissect_encoding(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
729   return dissect_rtse_T_encoding(FALSE, tvb, offset, pinfo, tree, hf_rtse_encoding);
730 }
731
732
733 static const ber_sequence_t EXTERNAL_sequence[] = {
734   { BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_direct_reference },
735   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_indirect_reference },
736   { BER_CLASS_UNI, BER_UNI_TAG_ObjectDescriptor, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_data_value_descriptor },
737   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_encoding },
738   { 0, 0, 0, NULL }
739 };
740
741 static int
742 dissect_rtse_EXTERNAL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
743   gint8 class;
744   gboolean pc, ind_field;
745   gint32 tag;
746   guint32 len1;
747
748   /* XXX  asn2eth can not yet handle tagged assignment so for the
749    * time being  just remove this tag manually inside the EXTERNAL
750    * dissector.
751    */
752    offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
753    offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
754    offset = dissect_ber_sequence(TRUE, pinfo, tree, tvb, offset,
755                                 EXTERNAL_sequence, hf_index, ett_rtse_EXTERNAL);
756
757
758   return offset;
759 }
760
761
762 /*--- End of included file: packet-rtse-fn.c ---*/
763
764
765 /*
766 * Dissect RTSE PDUs inside a PPDU.
767 */
768 static void
769 dissect_rtse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
770 {
771         int offset = 0;
772         int old_offset;
773         proto_item *item=NULL;
774         proto_tree *tree=NULL;
775
776         /* save parent_tree so subdissectors can create new top nodes */
777         top_tree=parent_tree;
778
779         /* do we have application context from the acse dissector?  */
780         if( !pinfo->private_data ){
781                 if(parent_tree){
782                         proto_tree_add_text(parent_tree, tvb, offset, -1,
783                                 "Internal error:can't get application context from ACSE dissector.");
784                 } 
785                 return  ;
786         } else {
787                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
788
789         }
790
791         if(parent_tree){
792                 item = proto_tree_add_item(parent_tree, proto_rtse, tvb, 0, -1, FALSE);
793                 tree = proto_item_add_subtree(item, ett_rtse);
794         }
795         if (check_col(pinfo->cinfo, COL_PROTOCOL))
796                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSE");
797         if (check_col(pinfo->cinfo, COL_INFO))
798                 col_clear(pinfo->cinfo, COL_INFO);
799
800         while (tvb_reported_length_remaining(tvb, offset) > 0){
801                 old_offset=offset;
802                 offset=dissect_rtse_RTSE_apdus(FALSE, tvb, offset, pinfo , tree, -1);
803                 if(offset == old_offset){
804                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte RTSE PDU");
805                         offset = tvb_length(tvb);
806                         break;
807                 }
808         }
809
810         top_tree = NULL;
811 }
812
813
814 /*--- proto_register_rtse -------------------------------------------*/
815 void proto_register_rtse(void) {
816
817   /* List of fields */
818   static hf_register_info hf[] =
819   {
820
821 /*--- Included file: packet-rtse-hfarr.c ---*/
822
823     { &hf_rtse_rtorq_apdu,
824       { "rtorq-apdu", "rtse.rtorq_apdu",
825         FT_NONE, BASE_NONE, NULL, 0,
826         "RTSE-apdus/rtorq-apdu", HFILL }},
827     { &hf_rtse_rtoac_apdu,
828       { "rtoac-apdu", "rtse.rtoac_apdu",
829         FT_NONE, BASE_NONE, NULL, 0,
830         "RTSE-apdus/rtoac-apdu", HFILL }},
831     { &hf_rtse_rtorj_apdu,
832       { "rtorj-apdu", "rtse.rtorj_apdu",
833         FT_NONE, BASE_NONE, NULL, 0,
834         "RTSE-apdus/rtorj-apdu", HFILL }},
835     { &hf_rtse_rttp_apdu,
836       { "rttp-apdu", "rtse.rttp_apdu",
837         FT_INT32, BASE_DEC, NULL, 0,
838         "RTSE-apdus/rttp-apdu", HFILL }},
839     { &hf_rtse_rttr_apdu,
840       { "rttr-apdu", "rtse.rttr_apdu",
841         FT_BYTES, BASE_HEX, NULL, 0,
842         "RTSE-apdus/rttr-apdu", HFILL }},
843     { &hf_rtse_rtab_apdu,
844       { "rtab-apdu", "rtse.rtab_apdu",
845         FT_NONE, BASE_NONE, NULL, 0,
846         "RTSE-apdus/rtab-apdu", HFILL }},
847     { &hf_rtse_checkpointSize,
848       { "checkpointSize", "rtse.checkpointSize",
849         FT_INT32, BASE_DEC, NULL, 0,
850         "", HFILL }},
851     { &hf_rtse_windowSize,
852       { "windowSize", "rtse.windowSize",
853         FT_INT32, BASE_DEC, NULL, 0,
854         "", HFILL }},
855     { &hf_rtse_dialogueMode,
856       { "dialogueMode", "rtse.dialogueMode",
857         FT_INT32, BASE_DEC, VALS(rtse_T_dialogueMode_vals), 0,
858         "RTORQapdu/dialogueMode", HFILL }},
859     { &hf_rtse_connectionDataRQ,
860       { "connectionDataRQ", "rtse.connectionDataRQ",
861         FT_UINT32, BASE_DEC, VALS(rtse_ConnectionData_vals), 0,
862         "RTORQapdu/connectionDataRQ", HFILL }},
863     { &hf_rtse_applicationProtocol,
864       { "applicationProtocol", "rtse.applicationProtocol",
865         FT_INT32, BASE_DEC, VALS(rtse_T_applicationProtocol_vals), 0,
866         "RTORQapdu/applicationProtocol", HFILL }},
867     { &hf_rtse_connectionDataAC,
868       { "connectionDataAC", "rtse.connectionDataAC",
869         FT_UINT32, BASE_DEC, VALS(rtse_ConnectionData_vals), 0,
870         "RTOACapdu/connectionDataAC", HFILL }},
871     { &hf_rtse_refuseReason,
872       { "refuseReason", "rtse.refuseReason",
873         FT_INT32, BASE_DEC, VALS(rtse_RefuseReason_vals), 0,
874         "RTORJapdu/refuseReason", HFILL }},
875     { &hf_rtse_userDataRJ,
876       { "userDataRJ", "rtse.userDataRJ",
877         FT_NONE, BASE_NONE, NULL, 0,
878         "RTORJapdu/userDataRJ", HFILL }},
879     { &hf_rtse_abortReason,
880       { "abortReason", "rtse.abortReason",
881         FT_INT32, BASE_DEC, VALS(rtse_AbortReason_vals), 0,
882         "RTABapdu/abortReason", HFILL }},
883     { &hf_rtse_reflectedParameter,
884       { "reflectedParameter", "rtse.reflectedParameter",
885         FT_BYTES, BASE_HEX, NULL, 0,
886         "RTABapdu/reflectedParameter", HFILL }},
887     { &hf_rtse_userdataAB,
888       { "userdataAB", "rtse.userdataAB",
889         FT_NONE, BASE_NONE, NULL, 0,
890         "RTABapdu/userdataAB", HFILL }},
891     { &hf_rtse_open,
892       { "open", "rtse.open",
893         FT_NONE, BASE_NONE, NULL, 0,
894         "ConnectionData/open", HFILL }},
895     { &hf_rtse_recover,
896       { "recover", "rtse.recover",
897         FT_NONE, BASE_NONE, NULL, 0,
898         "ConnectionData/recover", HFILL }},
899     { &hf_rtse_callingSSuserReference,
900       { "callingSSuserReference", "rtse.callingSSuserReference",
901         FT_UINT32, BASE_DEC, VALS(rtse_CallingSSuserReference_vals), 0,
902         "SessionConnectionIdentifier/callingSSuserReference", HFILL }},
903     { &hf_rtse_commonReference,
904       { "commonReference", "rtse.commonReference",
905         FT_STRING, BASE_NONE, NULL, 0,
906         "SessionConnectionIdentifier/commonReference", HFILL }},
907     { &hf_rtse_additionalReferenceInformation,
908       { "additionalReferenceInformation", "rtse.additionalReferenceInformation",
909         FT_STRING, BASE_NONE, NULL, 0,
910         "SessionConnectionIdentifier/additionalReferenceInformation", HFILL }},
911     { &hf_rtse_t61String,
912       { "t61String", "rtse.t61String",
913         FT_STRING, BASE_NONE, NULL, 0,
914         "CallingSSuserReference/t61String", HFILL }},
915     { &hf_rtse_octetString,
916       { "octetString", "rtse.octetString",
917         FT_BYTES, BASE_HEX, NULL, 0,
918         "CallingSSuserReference/octetString", HFILL }},
919     { &hf_rtse_direct_reference,
920       { "direct-reference", "rtse.direct_reference",
921         FT_STRING, BASE_NONE, NULL, 0,
922         "EXTERNAL/direct-reference", HFILL }},
923     { &hf_rtse_indirect_reference,
924       { "indirect-reference", "rtse.indirect_reference",
925         FT_INT32, BASE_DEC, NULL, 0,
926         "EXTERNAL/indirect-reference", HFILL }},
927     { &hf_rtse_data_value_descriptor,
928       { "data-value-descriptor", "rtse.data_value_descriptor",
929         FT_STRING, BASE_NONE, NULL, 0,
930         "EXTERNAL/data-value-descriptor", HFILL }},
931     { &hf_rtse_encoding,
932       { "encoding", "rtse.encoding",
933         FT_UINT32, BASE_DEC, VALS(rtse_T_encoding_vals), 0,
934         "EXTERNAL/encoding", HFILL }},
935     { &hf_rtse_single_ASN1_type,
936       { "single-ASN1-type", "rtse.single_ASN1_type",
937         FT_NONE, BASE_NONE, NULL, 0,
938         "EXTERNAL/encoding/single-ASN1-type", HFILL }},
939     { &hf_rtse_octet_aligned,
940       { "octet-aligned", "rtse.octet_aligned",
941         FT_BYTES, BASE_HEX, NULL, 0,
942         "EXTERNAL/encoding/octet-aligned", HFILL }},
943     { &hf_rtse_arbitrary,
944       { "arbitrary", "rtse.arbitrary",
945         FT_BYTES, BASE_HEX, NULL, 0,
946         "EXTERNAL/encoding/arbitrary", HFILL }},
947
948 /*--- End of included file: packet-rtse-hfarr.c ---*/
949
950   };
951
952   /* List of subtrees */
953   static gint *ett[] = {
954     &ett_rtse,
955     &ett_rtse_unknown,
956
957 /*--- Included file: packet-rtse-ettarr.c ---*/
958
959     &ett_rtse_RTSE_apdus,
960     &ett_rtse_RTORQapdu,
961     &ett_rtse_RTOACapdu,
962     &ett_rtse_RTORJapdu,
963     &ett_rtse_RTABapdu,
964     &ett_rtse_ConnectionData,
965     &ett_rtse_SessionConnectionIdentifier,
966     &ett_rtse_CallingSSuserReference,
967     &ett_rtse_EXTERNAL,
968     &ett_rtse_T_encoding,
969
970 /*--- End of included file: packet-rtse-ettarr.c ---*/
971
972   };
973
974   /* Register protocol */
975   proto_rtse = proto_register_protocol(PNAME, PSNAME, PFNAME);
976   register_dissector("rtse", dissect_rtse, proto_rtse);
977   /* Register fields and subtrees */
978   proto_register_field_array(proto_rtse, hf, array_length(hf));
979   proto_register_subtree_array(ett, array_length(ett));
980
981   rtse_oid_dissector_table = register_dissector_table("rtse.oid", "RTSE OID Dissectors", FT_STRING, BASE_NONE);
982   oid_table=g_hash_table_new(g_str_hash, g_str_equal);
983
984 }
985
986
987 /*--- proto_reg_handoff_rtse --- */
988 void proto_reg_handoff_rtse(void) {
989 }