Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-xyplex.c
blobbdf4ac72f5862ae026b5b659fcc0013257a6fe1b
1 /* packet-xyplex.c
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
15 #include "config.h"
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" },
44 { 0, NULL }
47 static int
48 dissect_xyplex(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
50 proto_tree *xyplex_tree;
51 proto_item *ti;
52 conversation_t *conversation;
53 int offset = 0;
55 uint8_t prototype;
56 uint8_t padding;
57 uint16_t server_port;
58 uint16_t return_port;
59 uint16_t reserved;
60 uint16_t reply;
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);
83 if (tree) {
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);
95 offset += 8;
97 /* Look for all future TCP conversations between the
98 * requesting server and the Xyplex host using the
99 * return_port.
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);
108 return offset;
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)"));
118 if (tree) {
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,
124 offset+2, 2, reply);
126 offset += 4;
127 return offset;
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);
144 void
145 proto_register_xyplex(void)
147 static hf_register_info hf[] = {
148 { &hf_xyplex_type,
149 { "Type", "xyplex.type",
150 FT_UINT8, BASE_DEC, NULL, 0x0,
151 "Protocol type", HFILL }},
153 { &hf_xyplex_pad,
154 { "Pad", "xyplex.pad",
155 FT_UINT8, BASE_DEC, NULL, 0x0,
156 "Padding", HFILL }},
158 { &hf_xyplex_server_port,
159 { "Server Port", "xyplex.server_port",
160 FT_UINT16, BASE_DEC, NULL, 0x0,
161 NULL, HFILL }},
163 { &hf_xyplex_return_port,
164 { "Return Port", "xyplex.return_port",
165 FT_UINT16, BASE_DEC, NULL, 0x0,
166 NULL, HFILL }},
168 { &hf_xyplex_reserved,
169 { "Reserved field", "xyplex.reserved",
170 FT_UINT16, BASE_DEC, NULL, 0x0,
171 NULL, HFILL }},
173 { &hf_xyplex_reply,
174 { "Registration Reply", "xyplex.reply",
175 FT_UINT16, BASE_DEC, VALS(xyplex_reg_vals), 0x0,
176 NULL, HFILL }},
178 { &hf_xyplex_data,
179 { "Data", "xyplex.data",
180 FT_BYTES, BASE_NONE, NULL, 0x0,
181 NULL, HFILL }},
184 static int *ett[] = {
185 &ett_xyplex,
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);
194 void
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
203 * Local Variables:
204 * c-basic-offset: 2
205 * tab-width: 8
206 * indent-tabs-mode: nil
207 * End:
209 * ex: set shiftwidth=2 tabstop=8 expandtab:
210 * :indentSize=2:tabSize=8:noTabs=true: