name change
[obnox/wireshark/wip.git] / asn1 / x411 / packet-x411-template.c
1 /* packet-x411.c
2  * Routines for X.411 (X.400 Message Transfer)  packet dissection
3  * Graeme Lunt 2005
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 <glib.h>
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "packet-ber.h"
38 #include "packet-acse.h"
39 #include "packet-ros.h"
40 #include "packet-rtse.h"
41
42 #include "packet-x509af.h"
43 #include "packet-x509ce.h"
44 #include "packet-x509if.h"
45 #include "packet-x509sat.h"
46
47 #include "packet-x411.h"
48 #include <epan/emem.h>
49 #include <epan/strutil.h>
50
51 #define PNAME  "X.411 Message Transfer Service"
52 #define PSNAME "X411"
53 #define PFNAME "x411"
54
55 /* Initialize the protocol and registered fields */
56 int proto_x411 = -1;
57
58 static struct SESSION_DATA_STRUCTURE* session = NULL;
59 static int extension_id = -1; /* integer extension id */
60 static const char *object_identifier_id; /* extensions identifier */
61 static const char *content_type_id; /* content type identifier */
62
63 #define MAX_ORA_STR_LEN     256
64 static char *oraddress = NULL;
65 static gboolean doing_address=FALSE;
66 static proto_item *address_item;
67
68 static proto_tree *top_tree=NULL;
69
70 static int
71 call_x411_oid_callback(char *base_oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
72
73 #include "packet-x411-hf.c"
74
75 /* Initialize the subtree pointers */
76 static gint ett_x411 = -1;
77 #include "packet-x411-ett.c"
78
79 #include "packet-x411-fn.c"
80
81 static int
82 call_x411_oid_callback(char *base_oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
83 {
84   const char *name = NULL;
85   char extension_oid[BER_MAX_OID_STR_LEN];
86
87   sprintf(extension_oid, "%s.%d", base_oid, extension_id);      
88
89   name = get_ber_oid_name(extension_oid);
90   proto_item_append_text(tree, " (%s)", name ? name : extension_oid); 
91
92   return call_ber_oid_callback(extension_oid, tvb, offset, pinfo, tree);
93
94 }
95
96
97 /*
98  * Dissect X411 MTS APDU
99  */
100 int 
101 dissect_x411_mts_apdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
102 {
103         proto_item *item=NULL;
104         proto_tree *tree=NULL;
105
106         /* save parent_tree so subdissectors can create new top nodes */
107         top_tree=parent_tree;
108
109         if(parent_tree){
110                 item = proto_tree_add_item(parent_tree, proto_x411, tvb, 0, -1, FALSE);
111                 tree = proto_item_add_subtree(item, ett_x411);
112         }
113
114         if (check_col(pinfo->cinfo, COL_PROTOCOL))
115                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "P1");
116         if (check_col(pinfo->cinfo, COL_INFO))
117                 col_set_str(pinfo->cinfo, COL_INFO, "Transfer");
118
119         return dissect_x411_MTS_APDU (FALSE, tvb, 0, pinfo, tree, hf_x411_MTS_APDU_PDU);
120 }
121
122 /*
123 * Dissect X411 PDUs inside a PPDU.
124 */
125 static void
126 dissect_x411(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
127 {
128         int offset = 0;
129         int old_offset;
130         proto_item *item=NULL;
131         proto_tree *tree=NULL;
132         int (*x411_dissector)(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) = NULL;
133         char *x411_op_name;
134         int hf_x411_index;
135
136         /* save parent_tree so subdissectors can create new top nodes */
137         top_tree=parent_tree;
138
139         /* do we have operation information from the ROS dissector?  */
140         if( !pinfo->private_data ){
141                 if(parent_tree){
142                         proto_tree_add_text(parent_tree, tvb, offset, -1,
143                                 "Internal error: can't get operation information from ROS dissector.");
144                 } 
145                 return  ;
146         } else {
147                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
148         }
149
150         if(parent_tree){
151                 item = proto_tree_add_item(parent_tree, proto_x411, tvb, 0, -1, FALSE);
152                 tree = proto_item_add_subtree(item, ett_x411);
153         }
154         if (check_col(pinfo->cinfo, COL_PROTOCOL))
155                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "P1");
156         if (check_col(pinfo->cinfo, COL_INFO))
157                 col_clear(pinfo->cinfo, COL_INFO);
158
159         switch(session->ros_op & ROS_OP_MASK) {
160         case (ROS_OP_BIND | ROS_OP_ARGUMENT):   /*  BindInvoke */
161           x411_dissector = dissect_x411_MTABindArgument;
162           x411_op_name = "Bind-Argument";
163           hf_x411_index = hf_x411_MTABindArgument_PDU;
164           break;
165         case (ROS_OP_BIND | ROS_OP_RESULT):     /*  BindResult */
166           x411_dissector = dissect_x411_MTABindResult;
167           x411_op_name = "Bind-Result";
168           hf_x411_index = hf_x411_MTABindResult_PDU;
169           break;
170         case (ROS_OP_BIND | ROS_OP_ERROR):      /*  BindError */
171           x411_dissector = dissect_x411_MTABindError;
172           x411_op_name = "Bind-Error";
173           hf_x411_index = hf_x411_MTABindError_PDU;
174           break;
175         case (ROS_OP_INVOKE | ROS_OP_ARGUMENT): /*  Invoke Argument */
176           x411_dissector = dissect_x411_MTS_APDU;
177           x411_op_name = "Transfer";
178           hf_x411_index = hf_x411_MTS_APDU_PDU;
179           break;
180         default:
181           proto_tree_add_text(tree, tvb, offset, -1,"Unsupported X411 PDU");
182           return;
183         }
184
185         if (check_col(pinfo->cinfo, COL_INFO))
186           col_add_str(pinfo->cinfo, COL_INFO, x411_op_name);
187
188         while (tvb_reported_length_remaining(tvb, offset) > 0){
189                 old_offset=offset;
190                 offset=(*x411_dissector)(FALSE, tvb, offset, pinfo , tree, hf_x411_index);
191                 if(offset == old_offset){
192                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte X411 PDU");
193                         offset = tvb_length(tvb);
194                         break;
195                 }
196         }
197 }
198
199
200 /*--- proto_register_x411 -------------------------------------------*/
201 void proto_register_x411(void) {
202
203   /* List of fields */
204   static hf_register_info hf[] =
205   {
206 #include "packet-x411-hfarr.c"
207   };
208
209   /* List of subtrees */
210   static gint *ett[] = {
211     &ett_x411,
212 #include "packet-x411-ettarr.c"
213   };
214
215   /* Register protocol */
216   proto_x411 = proto_register_protocol(PNAME, PSNAME, PFNAME);
217   register_dissector("x411", dissect_x411, proto_x411);
218   /* Register fields and subtrees */
219   proto_register_field_array(proto_x411, hf, array_length(hf));
220   proto_register_subtree_array(ett, array_length(ett));
221
222 }
223
224
225 /*--- proto_reg_handoff_x411 --- */
226 void proto_reg_handoff_x411(void) {
227   dissector_handle_t handle = NULL;
228
229 #include "packet-x411-dis-tab.c"
230
231   /* APPLICATION CONTEXT */
232
233   register_ber_oid_name("2.6.0.1.6", "id-ac-mts-transfer");
234
235   /* ABSTRACT SYNTAXES */
236
237   if((handle = find_dissector("x411")) != NULL) {
238     register_rtse_oid_dissector_handle("2.6.0.2.12", handle, 0, "id-as-mta-rtse", TRUE); 
239     register_rtse_oid_dissector_handle("2.6.0.2.7", handle, 0, "id-as-mtse", FALSE);
240
241     register_rtse_oid_dissector_handle("applicationProtocol.1", handle, 0, "mts-transfer-protocol-1984", FALSE);
242     register_rtse_oid_dissector_handle("applicationProtocol.12", handle, 0, "mta-transfer-protocol", FALSE);
243   }
244
245
246 }