2 * Routines for xyplex packet dissection
4 * Copyright 2002 Randy McEoin <rmceoin@pe.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-tftp.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <epan/packet.h>
33 #include <epan/conversation.h>
35 static int proto_xyplex
= -1;
36 static int hf_xyplex_type
= -1;
37 static int hf_xyplex_pad
= -1;
38 static int hf_xyplex_server_port
= -1;
39 static int hf_xyplex_return_port
= -1;
40 static int hf_xyplex_reserved
= -1;
41 static int hf_xyplex_reply
= -1;
43 static gint ett_xyplex
= -1;
45 static dissector_handle_t xyplex_handle
;
47 #define UDP_PORT_XYPLEX 173
49 #define XYPLEX_REG_OK 0x00
50 #define XYPLEX_REG_QUEFULL 0x05
52 static const value_string xyplex_reg_vals
[] = {
53 { XYPLEX_REG_OK
, "OK" },
54 { XYPLEX_REG_QUEFULL
, "Queue Full" },
59 dissect_xyplex(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
61 proto_tree
*xyplex_tree
= NULL
;
63 conversation_t
*conversation
;
73 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "XYPLEX");
76 ti
= proto_tree_add_item(tree
, proto_xyplex
, tvb
, offset
, -1, ENC_NA
);
77 xyplex_tree
= proto_item_add_subtree(ti
, ett_xyplex
);
80 if (pinfo
->destport
== UDP_PORT_XYPLEX
) {
81 /* This is a registration request from a Unix server
82 * to the Xyplex server. The server_port indicates
83 * which Xyplex serial port is desired. The
84 * return_port tells the Xyplex server what TCP port
85 * to open to the Unix server.
87 prototype
= tvb_get_guint8(tvb
, offset
);
88 padding
= tvb_get_guint8(tvb
, offset
+1);
89 server_port
= tvb_get_ntohs(tvb
, offset
+2);
90 return_port
= tvb_get_ntohs(tvb
, offset
+4);
91 reserved
= tvb_get_ntohs(tvb
, offset
+6);
92 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
93 "Registration Request: %d Return: %d",
94 server_port
, return_port
);
97 proto_tree_add_uint(xyplex_tree
, hf_xyplex_type
, tvb
,
98 offset
, 1, prototype
);
99 proto_tree_add_uint(xyplex_tree
, hf_xyplex_pad
, tvb
,
100 offset
+1, 1, padding
);
101 proto_tree_add_uint(xyplex_tree
, hf_xyplex_server_port
, tvb
,
102 offset
+2, 2, server_port
);
103 proto_tree_add_uint(xyplex_tree
, hf_xyplex_return_port
, tvb
,
104 offset
+4, 2, return_port
);
105 proto_tree_add_uint(xyplex_tree
, hf_xyplex_reserved
, tvb
,
106 offset
+6, 2, reserved
);
110 /* Look for all future TCP conversations between the
111 * requestiong server and the Xyplex host using the
114 conversation
= find_conversation(pinfo
->fd
->num
, &pinfo
->src
, &pinfo
->dst
,
115 PT_TCP
, return_port
, 0, NO_PORT_B
);
116 if (conversation
== NULL
) {
117 conversation
= conversation_new(pinfo
->fd
->num
, &pinfo
->src
, &pinfo
->dst
,
118 PT_TCP
, return_port
, 0, NO_PORT2
);
119 conversation_set_dissector(conversation
, xyplex_handle
);
124 if (pinfo
->srcport
== UDP_PORT_XYPLEX
) {
125 prototype
= tvb_get_guint8(tvb
, offset
);
126 padding
= tvb_get_guint8(tvb
, offset
+1);
127 reply
= tvb_get_ntohs(tvb
, offset
+2);
128 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Registration Reply: %s",
129 val_to_str(reply
, xyplex_reg_vals
, "Unknown (0x%02x)"));
132 proto_tree_add_uint(xyplex_tree
, hf_xyplex_type
, tvb
,
133 offset
, 1, prototype
);
134 proto_tree_add_uint(xyplex_tree
, hf_xyplex_pad
, tvb
,
135 offset
+1, 1, padding
);
136 proto_tree_add_uint(xyplex_tree
, hf_xyplex_reply
, tvb
,
144 * This must be the TCP data stream. This will just be
145 * the raw data being transfered from the remote server
146 * and the Xyplex serial port.
148 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%d > %d Data",
149 pinfo
->srcport
, pinfo
->destport
);
151 proto_tree_add_text(xyplex_tree
, tvb
, offset
, -1,
152 "Data (%d bytes)", tvb_reported_length_remaining(tvb
, offset
));
154 return tvb_reported_length_remaining(tvb
, offset
);
159 proto_register_xyplex(void)
161 static hf_register_info hf
[] = {
163 { "Type", "xyplex.type",
164 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
165 "Protocol type", HFILL
}},
168 { "Pad", "xyplex.pad",
169 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
172 { &hf_xyplex_server_port
,
173 { "Server Port", "xyplex.server_port",
174 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
177 { &hf_xyplex_return_port
,
178 { "Return Port", "xyplex.return_port",
179 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
182 { &hf_xyplex_reserved
,
183 { "Reserved field", "xyplex.reserved",
184 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
188 { "Registration Reply", "xyplex.reply",
189 FT_UINT16
, BASE_DEC
, VALS(xyplex_reg_vals
), 0x0,
193 static gint
*ett
[] = {
197 proto_xyplex
= proto_register_protocol("Xyplex", "XYPLEX", "xyplex");
198 proto_register_field_array(proto_xyplex
, hf
, array_length(hf
));
199 proto_register_subtree_array(ett
, array_length(ett
));
203 proto_reg_handoff_xyplex(void)
205 xyplex_handle
= new_create_dissector_handle(dissect_xyplex
, proto_xyplex
);
206 dissector_add_uint("udp.port", UDP_PORT_XYPLEX
, xyplex_handle
);