2 * Routines for xyplex packet dissection
4 * Copyright 2002 Randy McEoin <rmceoin@pe.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-tftp.c
12 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/packet.h>
18 #include <epan/conversation.h>
20 void proto_register_xyplex(void);
21 void proto_reg_handoff_xyplex(void);
23 static int proto_xyplex
;
24 static int hf_xyplex_type
;
25 static int hf_xyplex_pad
;
26 static int hf_xyplex_server_port
;
27 static int hf_xyplex_return_port
;
28 static int hf_xyplex_reserved
;
29 static int hf_xyplex_reply
;
30 static int hf_xyplex_data
;
32 static int ett_xyplex
;
34 static dissector_handle_t xyplex_handle
;
36 #define UDP_PORT_XYPLEX 173
38 #define XYPLEX_REG_OK 0x00
39 #define XYPLEX_REG_QUEFULL 0x05
41 static const value_string xyplex_reg_vals
[] = {
42 { XYPLEX_REG_OK
, "OK" },
43 { XYPLEX_REG_QUEFULL
, "Queue Full" },
48 dissect_xyplex(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
50 proto_tree
*xyplex_tree
;
52 conversation_t
*conversation
;
62 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "XYPLEX");
64 ti
= proto_tree_add_item(tree
, proto_xyplex
, tvb
, offset
, -1, ENC_NA
);
65 xyplex_tree
= proto_item_add_subtree(ti
, ett_xyplex
);
67 if (pinfo
->destport
== UDP_PORT_XYPLEX
) {
68 /* This is a registration request from a Unix server
69 * to the Xyplex server. The server_port indicates
70 * which Xyplex serial port is desired. The
71 * return_port tells the Xyplex server what TCP port
72 * to open to the Unix server.
74 prototype
= tvb_get_uint8(tvb
, offset
);
75 padding
= tvb_get_uint8(tvb
, offset
+1);
76 server_port
= tvb_get_ntohs(tvb
, offset
+2);
77 return_port
= tvb_get_ntohs(tvb
, offset
+4);
78 reserved
= tvb_get_ntohs(tvb
, offset
+6);
79 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
80 "Registration Request: %d Return: %d",
81 server_port
, return_port
);
84 proto_tree_add_uint(xyplex_tree
, hf_xyplex_type
, tvb
,
85 offset
, 1, prototype
);
86 proto_tree_add_uint(xyplex_tree
, hf_xyplex_pad
, tvb
,
87 offset
+1, 1, padding
);
88 proto_tree_add_uint(xyplex_tree
, hf_xyplex_server_port
, tvb
,
89 offset
+2, 2, server_port
);
90 proto_tree_add_uint(xyplex_tree
, hf_xyplex_return_port
, tvb
,
91 offset
+4, 2, return_port
);
92 proto_tree_add_uint(xyplex_tree
, hf_xyplex_reserved
, tvb
,
93 offset
+6, 2, reserved
);
97 /* Look for all future TCP conversations between the
98 * requesting server and the Xyplex host using the
101 conversation
= find_conversation(pinfo
->num
, &pinfo
->src
, &pinfo
->dst
,
102 CONVERSATION_TCP
, return_port
, 0, NO_PORT_B
);
103 if (conversation
== NULL
) {
104 conversation
= conversation_new(pinfo
->num
, &pinfo
->src
, &pinfo
->dst
,
105 CONVERSATION_TCP
, return_port
, 0, NO_PORT2
);
106 conversation_set_dissector(conversation
, xyplex_handle
);
111 if (pinfo
->srcport
== UDP_PORT_XYPLEX
) {
112 prototype
= tvb_get_uint8(tvb
, offset
);
113 padding
= tvb_get_uint8(tvb
, offset
+1);
114 reply
= tvb_get_ntohs(tvb
, offset
+2);
115 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Registration Reply: %s",
116 val_to_str(reply
, xyplex_reg_vals
, "Unknown (0x%02x)"));
119 proto_tree_add_uint(xyplex_tree
, hf_xyplex_type
, tvb
,
120 offset
, 1, prototype
);
121 proto_tree_add_uint(xyplex_tree
, hf_xyplex_pad
, tvb
,
122 offset
+1, 1, padding
);
123 proto_tree_add_uint(xyplex_tree
, hf_xyplex_reply
, tvb
,
131 * This must be the TCP data stream. This will just be
132 * the raw data being transferred from the remote server
133 * and the Xyplex serial port.
135 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%d > %d Data",
136 pinfo
->srcport
, pinfo
->destport
);
138 proto_tree_add_item(xyplex_tree
, hf_xyplex_data
, tvb
, offset
, -1, ENC_NA
);
140 return tvb_reported_length_remaining(tvb
, offset
);
145 proto_register_xyplex(void)
147 static hf_register_info hf
[] = {
149 { "Type", "xyplex.type",
150 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
151 "Protocol type", HFILL
}},
154 { "Pad", "xyplex.pad",
155 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
158 { &hf_xyplex_server_port
,
159 { "Server Port", "xyplex.server_port",
160 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
163 { &hf_xyplex_return_port
,
164 { "Return Port", "xyplex.return_port",
165 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
168 { &hf_xyplex_reserved
,
169 { "Reserved field", "xyplex.reserved",
170 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
174 { "Registration Reply", "xyplex.reply",
175 FT_UINT16
, BASE_DEC
, VALS(xyplex_reg_vals
), 0x0,
179 { "Data", "xyplex.data",
180 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
184 static int *ett
[] = {
188 proto_xyplex
= proto_register_protocol("Xyplex", "XYPLEX", "xyplex");
189 proto_register_field_array(proto_xyplex
, hf
, array_length(hf
));
190 proto_register_subtree_array(ett
, array_length(ett
));
191 xyplex_handle
= register_dissector("xyplex", dissect_xyplex
, proto_xyplex
);
195 proto_reg_handoff_xyplex(void)
197 dissector_add_uint_with_preference("udp.port", UDP_PORT_XYPLEX
, xyplex_handle
);
201 * Editor modelines - https://www.wireshark.org/tools/modelines.html
206 * indent-tabs-mode: nil
209 * ex: set shiftwidth=2 tabstop=8 expandtab:
210 * :indentSize=2:tabSize=8:noTabs=true: