#include <epan/conversation.h> and/or #include <epan/emem.h> not req'd ...
[obnox/wireshark/wip.git] / asn1 / p7 / packet-p7-template.c
1 /* packet-p7.c
2  * Routines for X.413 (P7) packet dissection
3  * Graeme Lunt 2007
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/prefs.h>
33 #include <epan/oids.h>
34 #include <epan/asn1.h>
35
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "packet-ber.h"
40 #include "packet-acse.h"
41 #include "packet-ros.h"
42 #include "packet-rtse.h"
43
44 #include "packet-x411.h"
45 #include <epan/strutil.h>
46
47 #define PNAME  "X.413 Message Store Service"
48 #define PSNAME "P7"
49 #define PFNAME "p7"
50
51 static guint global_p7_tcp_port = 102;
52 static dissector_handle_t tpkt_handle;
53 static const char *object_identifier_id = NULL; /* attribute identifier */
54 static int seqno = 0;
55
56 void prefs_register_p7(void); /* forward declaration for use in preferences registration */
57
58
59 /* Initialize the protocol and registered fields */
60 int proto_p7 = -1;
61
62 #include "packet-p7-hf.c"
63
64 /* Initialize the subtree pointers */
65 static gint ett_p7 = -1;
66 #include "packet-p7-ett.c"
67
68 #include "packet-p7-val.h"
69
70 #include "packet-p7-table.c"   /* operation and error codes */
71
72 #include "packet-p7-fn.c"
73
74 #include "packet-p7-table11.c" /* operation argument/result dissectors */
75 #include "packet-p7-table21.c" /* error dissector */
76
77 static const ros_info_t p7_ros_info = {
78   "P7",
79   &proto_p7,
80   &ett_p7,
81   p7_opr_code_string_vals,
82   p7_opr_tab,
83   p7_err_code_string_vals,
84   p7_err_tab
85 };
86
87
88 /*--- proto_register_p7 -------------------------------------------*/
89 void proto_register_p7(void) {
90
91   /* List of fields */
92   static hf_register_info hf[] =
93   {
94 #include "packet-p7-hfarr.c"
95   };
96
97   /* List of subtrees */
98   static gint *ett[] = {
99     &ett_p7,
100 #include "packet-p7-ettarr.c"
101   };
102   module_t *p7_module;
103
104   /* Register protocol */
105   proto_p7 = proto_register_protocol(PNAME, PSNAME, PFNAME);
106
107   /* Register fields and subtrees */
108   proto_register_field_array(proto_p7, hf, array_length(hf));
109   proto_register_subtree_array(ett, array_length(ett));
110
111   /* Register our configuration options for P7, particularly our port */
112
113   p7_module = prefs_register_protocol_subtree("OSI/X.400", proto_p7, prefs_register_p7);
114
115   prefs_register_uint_preference(p7_module, "tcp.port", "P7 TCP Port",
116                                  "Set the port for P7 operations (if other"
117                                  " than the default of 102)",
118                                  10, &global_p7_tcp_port);
119
120 }
121
122
123 /*--- proto_reg_handoff_p7 --- */
124 void proto_reg_handoff_p7(void) {
125
126   #include "packet-p7-dis-tab.c"
127
128   /* APPLICATION CONTEXT */
129
130   oid_add_from_string("id-ac-ms-access","2.6.0.1.11");
131   oid_add_from_string("id-ac-ms-reliable-access","2.6.0.1.12");
132
133   /* ABSTRACT SYNTAXES */
134
135   /* Register P7 with ROS (with no use of RTSE) */
136   register_ros_protocol_info("2.6.0.2.9", &p7_ros_info, 0, "id-as-ms", FALSE); 
137   register_ros_protocol_info("2.6.0.2.5", &p7_ros_info, 0, "id-as-mrse", FALSE); 
138   register_ros_protocol_info("2.6.0.2.1", &p7_ros_info, 0, "id-as-msse", FALSE); 
139
140   /* remember the tpkt handler for change in preferences */
141   tpkt_handle = find_dissector("tpkt");
142 }
143
144
145 void prefs_register_p7(void) {
146   static guint tcp_port = 0;
147
148   /* de-register the old port */
149   /* port 102 is registered by TPKT - don't undo this! */
150   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
151     dissector_delete("tcp.port", tcp_port, tpkt_handle);
152
153   /* Set our port number for future use */
154   tcp_port = global_p7_tcp_port;
155
156   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
157     dissector_add("tcp.port", global_p7_tcp_port, tpkt_handle);
158
159 }