From Didier Gautheron:
[obnox/wireshark/wip.git] / 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  * $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/conversation.h>
34 #include <epan/oids.h>
35 #include <epan/asn1.h>
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "packet-ber.h"
41 #include "packet-acse.h"
42 #include "packet-ros.h"
43
44 #include "packet-x509if.h"
45 #include "packet-x509af.h"
46 #include "packet-x509sat.h"
47 #include "packet-crmf.h"
48
49 #include "packet-dsp.h"
50 #include "packet-disp.h"
51 #include "packet-dap.h"
52 #include <epan/strutil.h>
53
54 /* we don't have a separate dissector for X519 - 
55    most of DAP is defined in X511 */
56 #define PNAME  "X.519 Directory Access Protocol"
57 #define PSNAME "DAP"
58 #define PFNAME "dap"
59
60 static guint global_dap_tcp_port = 102;
61 static dissector_handle_t tpkt_handle;
62 void prefs_register_dap(void); /* forward declaration for use in preferences registration */
63
64
65 /* Initialize the protocol and registered fields */
66 int proto_dap = -1;
67
68
69 #include "packet-dap-hf.c"
70
71 /* Initialize the subtree pointers */
72 static gint ett_dap = -1;
73 #include "packet-dap-ett.c"
74
75 #include "packet-dap-val.h"
76
77 #include "packet-dap-table.c"   /* operation and error codes */
78
79 #include "packet-dap-fn.c"
80
81 #include "packet-dap-table11.c" /* operation argument/result dissectors */
82 #include "packet-dap-table21.c" /* error dissector */
83
84 static const ros_info_t dap_ros_info = {
85   "DAP",
86   &proto_dap,
87   &ett_dap,
88   dap_opr_code_string_vals,
89   dap_opr_tab,
90   dap_err_code_string_vals,
91   dap_err_tab
92 };
93
94
95 /*--- proto_register_dap -------------------------------------------*/
96 void proto_register_dap(void) {
97
98   /* List of fields */
99   static hf_register_info hf[] =
100   {
101 #include "packet-dap-hfarr.c"
102   };
103
104   /* List of subtrees */
105   static gint *ett[] = {
106     &ett_dap,
107 #include "packet-dap-ettarr.c"
108   };
109   module_t *dap_module;
110
111   /* Register protocol */
112   proto_dap = proto_register_protocol(PNAME, PSNAME, PFNAME);
113
114   /* Register fields and subtrees */
115   proto_register_field_array(proto_dap, hf, array_length(hf));
116   proto_register_subtree_array(ett, array_length(ett));
117
118   /* Register our configuration options for DAP, particularly our port */
119
120   dap_module = prefs_register_protocol_subtree("OSI/X.500", proto_dap, prefs_register_dap);
121
122   prefs_register_uint_preference(dap_module, "tcp.port", "DAP TCP Port",
123                                  "Set the port for DAP operations (if other"
124                                  " than the default of 102)",
125                                  10, &global_dap_tcp_port);
126
127 }
128
129
130 /*--- proto_reg_handoff_dap --- */
131 void proto_reg_handoff_dap(void) {
132
133   /* #include "packet-dap-dis-tab.c" */
134
135   /* APPLICATION CONTEXT */
136
137   oid_add_from_string("id-ac-directory-access","2.5.3.1");
138
139   /* ABSTRACT SYNTAXES */
140     
141   /* Register DAP with ROS (with no use of RTSE) */
142   register_ros_protocol_info("2.5.9.1", &dap_ros_info, 0, "id-as-directory-access", FALSE); 
143
144   /* remember the tpkt handler for change in preferences */
145   tpkt_handle = find_dissector("tpkt");
146
147   /* AttributeValueAssertions */
148   x509if_register_fmt(hf_dap_equality, "=");
149   x509if_register_fmt(hf_dap_greaterOrEqual, ">=");
150   x509if_register_fmt(hf_dap_lessOrEqual, "<=");
151   x509if_register_fmt(hf_dap_approximateMatch, "=~");
152   /* AttributeTypes */
153   x509if_register_fmt(hf_dap_present, "= *");
154
155 }
156
157
158 void prefs_register_dap(void) {
159   static guint tcp_port = 0;
160
161   /* de-register the old port */
162   /* port 102 is registered by TPKT - don't undo this! */
163   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
164     dissector_delete("tcp.port", tcp_port, tpkt_handle);
165
166   /* Set our port number for future use */
167   tcp_port = global_dap_tcp_port;
168
169   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
170     dissector_add("tcp.port", global_dap_tcp_port, tpkt_handle);
171
172 }