update to netlogon to show DsrGetDcNameEx2() Client account name, domain name and...
[obnox/wireshark/wip.git] / packet-tuxedo.c
1 /* packet-tuxedo.c
2  * Routines for BEA Tuxedo ATMI protocol
3  *
4  * metatech <metatech@flashmail.com>
5  *
6  * $Id: packet-tuxedo.c,v 1.1 2004/04/20 05:07:23 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/conversation.h>
34
35 static int proto_tuxedo = -1;
36 static int hf_tuxedo_magic = -1;
37 static int hf_tuxedo_opcode = -1;
38
39 static gint ett_tuxedo = -1;
40
41 static dissector_handle_t tuxedo_handle;
42
43 #define TUXEDO_MAGIC           0x91039858
44 #define TUXEDO_SMAGIC          0x73903842
45
46 #define TUXEDO_ATMI_CALL                 1
47 #define TUXEDO_ATMI_REPLY                2
48 #define TUXEDO_ATMI_FAILURE              3
49 #define TUXEDO_ATMI_CONNECT              4
50 #define TUXEDO_ATMI_DATA                 5
51 #define TUXEDO_ATMI_DISCON               6
52 #define TUXEDO_ATMI_PREPARE              7
53 #define TUXEDO_ATMI_READY                8
54 #define TUXEDO_ATMI_COMMIT               9
55 #define TUXEDO_ATMI_DONE                10
56 #define TUXEDO_ATMI_COMPLETE            11
57 #define TUXEDO_ATMI_ROLLBACK            12
58 #define TUXEDO_ATMI_HEURISTIC           13
59 #define TUXEDO_ATMI_PRE_NW_ACALL1       14
60 #define TUXEDO_ATMI_PRE_NW_ACALL1_RPLY  15
61 #define TUXEDO_ATMI_PRE_NW_ACALL2       16
62 #define TUXEDO_ATMI_PRE_NW_ACALL2_RPLY  17
63 #define TUXEDO_ATMI_PRE_NW_ACALL3       18
64 #define TUXEDO_ATMI_PRE_NW_ACALL3_RPLY  19
65 #define TUXEDO_ATMI_PRE_NW_LLE          20
66 #define TUXEDO_ATMI_PRE_NW_LLE_RPLY     21
67 #define TUXEDO_ATMI_SEC_EXCHG_RQST      22
68 #define TUXEDO_ATMI_SEC_EXCHG_RPLY      23
69 #define TUXEDO_ATMI_SEC_NW_ACALL3       24
70 #define TUXEDO_ATMI_SEC_NW_ACALL3_RPLY  25
71
72
73 static const value_string tuxedo_opcode_vals[] = {
74   { TUXEDO_ATMI_CALL,                 "CALL" },
75   { TUXEDO_ATMI_REPLY,                "REPLY" },
76   { TUXEDO_ATMI_FAILURE,              "FAILURE" },
77   { TUXEDO_ATMI_CONNECT,              "CONNECT" },
78   { TUXEDO_ATMI_DATA,                 "DATA" },
79   { TUXEDO_ATMI_DISCON,               "DISCON" },
80   { TUXEDO_ATMI_PREPARE,              "PREPARE" },
81   { TUXEDO_ATMI_READY,                "READY" },
82   { TUXEDO_ATMI_COMMIT,               "COMMIT" },
83   { TUXEDO_ATMI_DONE,                 "DONE" },
84   { TUXEDO_ATMI_COMPLETE,             "COMPLETE" },
85   { TUXEDO_ATMI_ROLLBACK,             "ROLLBACK" },
86   { TUXEDO_ATMI_HEURISTIC,            "HEURISTIC" },
87   { TUXEDO_ATMI_PRE_NW_ACALL1,        "ACALL1" },
88   { TUXEDO_ATMI_PRE_NW_ACALL1_RPLY,   "ACALL1_REPLY" },
89   { TUXEDO_ATMI_PRE_NW_ACALL2,        "ACALL2" },
90   { TUXEDO_ATMI_PRE_NW_ACALL2_RPLY,   "ACALL2_REPLY" },
91   { TUXEDO_ATMI_PRE_NW_ACALL3,        "ACALL3" },
92   { TUXEDO_ATMI_PRE_NW_ACALL3_RPLY,   "ACALL3_REPLY" },
93   { TUXEDO_ATMI_PRE_NW_LLE,           "LLE" },
94   { TUXEDO_ATMI_PRE_NW_LLE_RPLY,      "LLE_REPLY" },
95   { TUXEDO_ATMI_SEC_EXCHG_RQST,       "SEC_EXCHANGE" },
96   { TUXEDO_ATMI_SEC_EXCHG_RPLY,       "SEC_EXCHANGE_REPLY" },
97   { TUXEDO_ATMI_SEC_NW_ACALL3,        "SEC_ACALL3" },
98   { TUXEDO_ATMI_SEC_NW_ACALL3_RPLY,   "SEC_ACALL3_REPLY" },
99   { 0,          NULL }
100 };
101
102
103 static void
104 dissect_tuxedo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
105 {
106         proto_tree      *tuxedoroot_tree = NULL;
107         proto_item      *ti;
108         guint32 magic;
109         guint32 opcode;
110         
111         if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "TUXEDO");           
112         
113         if (tvb_length(tvb) >= 8)
114         {
115                 magic = tvb_get_ntohl(tvb, 0);
116                 if (magic == TUXEDO_MAGIC || magic == TUXEDO_SMAGIC)
117                 {
118                         opcode = tvb_get_ntohl(tvb, 4);
119
120                         if (check_col(pinfo->cinfo, COL_INFO)) 
121                         {                                       
122                                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str(opcode, tuxedo_opcode_vals, "Unknown (0x%02x)"));         
123                         }
124
125                         if (tree)
126                         {
127                                 ti = proto_tree_add_item(tree, proto_tuxedo, tvb, 0, -1, FALSE);
128                                 tuxedoroot_tree = proto_item_add_subtree(ti, ett_tuxedo);
129
130                                 proto_tree_add_item(tuxedoroot_tree, hf_tuxedo_magic, tvb, 0, 4, FALSE);                
131                                 proto_tree_add_item(tuxedoroot_tree, hf_tuxedo_opcode, tvb, 4, 4, FALSE);
132                         }
133                 }
134                 else
135                 {
136                         /* This packet is a continuation */
137                         if (check_col(pinfo->cinfo, COL_INFO)) col_set_str(pinfo->cinfo, COL_INFO, "Continuation");             
138                         if (tree)
139                         {
140                                 ti = proto_tree_add_item(tree, proto_tuxedo, tvb, 0, -1, FALSE);
141                         }
142                 }
143         }
144 }
145
146 static gboolean
147 dissect_tuxedo_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
148 {
149         if (tvb_length(tvb) >= 8)
150         {
151                 guint32 magic;
152                 magic = tvb_get_ntohl(tvb, 0);
153                 if (magic == TUXEDO_MAGIC || magic == TUXEDO_SMAGIC) 
154                 {
155                         /* Register this dissector for this conversation */
156                         conversation_t  *conversation = NULL;
157                         conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
158                         if (conversation == NULL) 
159                         {
160                                 conversation = conversation_new(&pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
161                         }
162                         conversation_set_dissector(conversation, tuxedo_handle);
163
164                         dissect_tuxedo(tvb, pinfo, tree);
165                         return TRUE;
166                 }
167         }
168         return FALSE;
169 }
170
171 void
172 proto_register_tuxedo(void)
173 {
174   static hf_register_info hf[] = {
175    { &hf_tuxedo_magic,
176       { "Magic", "tuxedo.magic", FT_UINT32, BASE_HEX, NULL, 0x0, "TUXEDO magic", HFILL }},
177
178    { &hf_tuxedo_opcode,
179       { "Opcode", "tuxedo.opcode", FT_UINT32, BASE_HEX, VALS(tuxedo_opcode_vals), 0x0, "TUXEDO opcode", HFILL }}
180
181   };
182   static gint *ett[] = {
183     &ett_tuxedo,
184   };
185
186   proto_tuxedo = proto_register_protocol("BEA Tuxedo", "TUXEDO", "tuxedo");
187   proto_register_field_array(proto_tuxedo, hf, array_length(hf));
188   proto_register_subtree_array(ett, array_length(ett));
189
190   tuxedo_handle = create_dissector_handle(dissect_tuxedo, proto_tuxedo);
191
192 }
193
194 void
195 proto_reg_handoff_tuxedo(void)
196 {
197         heur_dissector_add("tcp", dissect_tuxedo_heur, proto_tuxedo);
198         dissector_add_handle("tcp.port", tuxedo_handle);
199 }