c5592bce1fe5a6267ab59d8914f655274ace714c
[metze/wireshark/wip.git] / epan / dissectors / asn1 / dap / packet-dap-template.c
1 /* packet-dap.c
2  * Routines for X.511 (X.500 Directory Asbtract Service) and X.519 DAP  packet dissection
3  * Graeme Lunt 2005
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <epan/packet.h>
27 #include <epan/prefs.h>
28 #include <epan/expert.h>
29 #include <epan/oids.h>
30 #include <epan/asn1.h>
31
32 #include "packet-ber.h"
33 #include "packet-acse.h"
34 #include "packet-ros.h"
35 #include "packet-idmp.h"
36
37 #include "packet-x509if.h"
38 #include "packet-x509af.h"
39 #include "packet-x509sat.h"
40 #include "packet-crmf.h"
41
42 #include "packet-dsp.h"
43 #include "packet-disp.h"
44 #include "packet-dap.h"
45 #include <epan/strutil.h>
46
47 /* we don't have a separate dissector for X519 -
48    most of DAP is defined in X511 */
49 #define PNAME  "X.519 Directory Access Protocol"
50 #define PSNAME "DAP"
51 #define PFNAME "dap"
52
53 void proto_register_dap(void);
54 void proto_reg_handoff_dap(void);
55
56 static guint global_dap_tcp_port = 102;
57 static dissector_handle_t tpkt_handle;
58 static void prefs_register_dap(void); /* forward declaration for use in preferences registration */
59
60
61 /* Initialize the protocol and registered fields */
62 static int proto_dap = -1;
63
64
65 #include "packet-dap-hf.c"
66
67 /* Initialize the subtree pointers */
68 static gint ett_dap = -1;
69 #include "packet-dap-ett.c"
70
71 static expert_field ei_dap_anonymous = EI_INIT;
72
73 #include "packet-dap-val.h"
74
75 #include "packet-dap-table.c"   /* operation and error codes */
76
77 #include "packet-dap-fn.c"
78
79 #include "packet-dap-table11.c" /* operation argument/result dissectors */
80 #include "packet-dap-table21.c" /* error dissector */
81
82 static const ros_info_t dap_ros_info = {
83   "DAP",
84   &proto_dap,
85   &ett_dap,
86   dap_opr_code_string_vals,
87   dap_opr_tab,
88   dap_err_code_string_vals,
89   dap_err_tab
90 };
91
92
93 /*--- proto_register_dap -------------------------------------------*/
94 void proto_register_dap(void) {
95
96   /* List of fields */
97   static hf_register_info hf[] =
98   {
99 #include "packet-dap-hfarr.c"
100   };
101
102   /* List of subtrees */
103   static gint *ett[] = {
104     &ett_dap,
105 #include "packet-dap-ettarr.c"
106   };
107
108   static ei_register_info ei[] = {
109     { &ei_dap_anonymous, { "dap.anonymous", PI_PROTOCOL, PI_NOTE, "Anonymous", EXPFILL }},
110   };
111
112   module_t *dap_module;
113   expert_module_t* expert_dap;
114
115   /* Register protocol */
116   proto_dap = proto_register_protocol(PNAME, PSNAME, PFNAME);
117
118   /* Register fields and subtrees */
119   proto_register_field_array(proto_dap, hf, array_length(hf));
120   proto_register_subtree_array(ett, array_length(ett));
121   expert_dap = expert_register_protocol(proto_dap);
122   expert_register_field_array(expert_dap, ei, array_length(ei));
123
124   /* Register our configuration options for DAP, particularly our port */
125
126   dap_module = prefs_register_protocol_subtree("OSI/X.500", proto_dap, prefs_register_dap);
127
128   prefs_register_uint_preference(dap_module, "tcp.port", "DAP TCP Port",
129                                  "Set the port for DAP operations (if other"
130                                  " than the default of 102)",
131                                  10, &global_dap_tcp_port);
132
133 }
134
135
136 /*--- proto_reg_handoff_dap --- */
137 void proto_reg_handoff_dap(void) {
138
139   /* #include "packet-dap-dis-tab.c" */
140
141   /* APPLICATION CONTEXT */
142
143   oid_add_from_string("id-ac-directory-access","2.5.3.1");
144
145   /* ABSTRACT SYNTAXES */
146
147   /* Register DAP with ROS (with no use of RTSE) */
148   register_ros_protocol_info("2.5.9.1", &dap_ros_info, 0, "id-as-directory-access", FALSE);
149
150   register_idmp_protocol_info("2.5.33.0", &dap_ros_info, 0, "dap-ip");
151
152   /* remember the tpkt handler for change in preferences */
153   tpkt_handle = find_dissector("tpkt");
154
155   /* AttributeValueAssertions */
156   x509if_register_fmt(hf_dap_equality, "=");
157   x509if_register_fmt(hf_dap_greaterOrEqual, ">=");
158   x509if_register_fmt(hf_dap_lessOrEqual, "<=");
159   x509if_register_fmt(hf_dap_approximateMatch, "=~");
160   /* AttributeTypes */
161   x509if_register_fmt(hf_dap_present, "= *");
162
163 }
164
165
166 static void
167 prefs_register_dap(void)
168 {
169   static guint tcp_port = 0;
170
171   /* de-register the old port */
172   /* port 102 is registered by TPKT - don't undo this! */
173   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
174     dissector_delete_uint("tcp.port", tcp_port, tpkt_handle);
175
176   /* Set our port number for future use */
177   tcp_port = global_dap_tcp_port;
178
179   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
180     dissector_add_uint("tcp.port", global_dap_tcp_port, tpkt_handle);
181
182 }