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