2 * Routines for laplink dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
16 #include "packet-tcp.h"
17 #include <epan/prefs.h>
19 void proto_register_laplink(void);
20 void proto_reg_handoff_laplink(void);
22 static dissector_handle_t laplink_udp_handle
;
23 static dissector_handle_t laplink_tcp_handle
;
25 #define TCP_PORT_LAPLINK 1547
26 #define UDP_PORT_LAPLINK 1547
28 /* Initialize the protocol and registered fields */
29 static int proto_laplink
;
30 static int hf_laplink_udp_ident
;
31 static int hf_laplink_udp_name
;
32 static int hf_laplink_tcp_ident
;
33 static int hf_laplink_tcp_length
;
34 static int hf_laplink_tcp_data
;
36 /* Initialize the subtree pointers */
37 static int ett_laplink
;
39 static const value_string laplink_udp_magic
[] = {
40 { 0x0f010000, "Name Solicitation" },
41 { 0xf0000200, "Name Reply" },
45 static const value_string laplink_tcp_magic
[] = {
46 { 0xff08c000, "Unknown TCP query - connection?" },
47 { 0xff08c200, "Unknown TCP query - connection?" },
48 { 0xff0bc000, "Unknown TCP query - connection?" },
49 { 0xff0bc200, "Unknown TCP query - connection?" },
50 { 0xff10c000, "Unknown TCP response - connection?" },
51 { 0xff10c200, "Unknown TCP response - connection?" },
52 { 0xff11c000, "Unknown TCP query/response - directory list or file transfer?" },
53 { 0xff11c200, "Unknown TCP query - directory list or file request?" },
54 { 0xff13c000, "Unknown TCP response - connection?" },
55 { 0xff13c200, "Unknown TCP response - connection?" },
56 { 0xff14c000, "Unknown TCP response - directory list or file transfer?" },
60 static bool laplink_desegment
= true;
62 /* Code to actually dissect the packets - UDP */
64 dissect_laplink_udp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
68 proto_tree
*laplink_tree
;
70 const char *udp_ident_string
;
73 * Make sure the identifier is reasonable.
75 if (!tvb_bytes_exist(tvb
, offset
, 4))
76 return 0; /* not enough bytes to check */
77 udp_ident
= tvb_get_ntohl(tvb
, offset
);
78 udp_ident_string
= try_val_to_str(udp_ident
, laplink_udp_magic
);
79 if (udp_ident_string
== NULL
)
80 return 0; /* unknown */
82 /* Make entries in Protocol column and Info column on summary display */
83 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Laplink");
85 col_add_str(pinfo
->cinfo
, COL_INFO
, udp_ident_string
);
88 ti
= proto_tree_add_item(tree
, proto_laplink
, tvb
, 0, -1, ENC_NA
);
89 laplink_tree
= proto_item_add_subtree(ti
, ett_laplink
);
91 proto_tree_add_uint(laplink_tree
, hf_laplink_udp_ident
, tvb
, offset
, 4, udp_ident
);
94 proto_tree_add_item(laplink_tree
, hf_laplink_udp_name
, tvb
, offset
, -1, ENC_ASCII
);
96 return tvb_captured_length(tvb
);
99 /* Code to actually dissect the packets - TCP aspects*/
101 dissect_laplink_tcp_pdu(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
106 proto_tree
*laplink_tree
;
109 /* Make entries in Protocol column and Info column on summary display */
110 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Laplink");
112 tcp_ident
= tvb_get_ntohl(tvb
, offset
);
113 col_add_str(pinfo
->cinfo
, COL_INFO
,
114 val_to_str(tcp_ident
, laplink_tcp_magic
, "TCP TBA (%u)"));
117 ti
= proto_tree_add_item(tree
, proto_laplink
, tvb
, 0, -1, ENC_NA
);
120 laplink_tree
= proto_item_add_subtree(ti
, ett_laplink
);
122 proto_tree_add_item(laplink_tree
, hf_laplink_tcp_ident
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
125 length
= tvb_get_ntohs(tvb
, offset
);
126 proto_tree_add_item(laplink_tree
, hf_laplink_tcp_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
129 proto_tree_add_item(laplink_tree
, hf_laplink_tcp_data
, tvb
, offset
, length
, ENC_NA
);
131 /* Continue adding tree items to process the packet here */
135 return tvb_captured_length(tvb
);
136 /* If this protocol has a sub-dissector call it here, see section 1.8 */
140 get_laplink_pdu_len(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
, void *data _U_
)
144 * The length doesn't include the length or ident fields; add those in.
146 plen
= (tvb_get_ntohs(tvb
, offset
+4) + 2 + 4);
151 dissect_laplink_tcp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
153 tcp_dissect_pdus(tvb
, pinfo
, tree
, laplink_desegment
,
154 6, get_laplink_pdu_len
,
155 dissect_laplink_tcp_pdu
, data
);
156 return tvb_captured_length(tvb
);
160 /* Register the protocol with Wireshark */
163 proto_register_laplink(void)
166 /* Setup list of header fields See Section 1.6.1 for details*/
167 static hf_register_info hf
[] = {
168 { &hf_laplink_udp_ident
,
169 { "UDP Ident", "laplink.udp_ident",
170 FT_UINT32
, BASE_HEX
, VALS(laplink_udp_magic
), 0x0,
171 "Unknown magic", HFILL
}
173 { &hf_laplink_udp_name
,
174 { "UDP Name", "laplink.udp_name",
175 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
176 "Machine name", HFILL
}
178 { &hf_laplink_tcp_ident
,
179 { "TCP Ident", "laplink.tcp_ident",
180 FT_UINT32
, BASE_HEX
, VALS(laplink_tcp_magic
), 0x0,
181 "Unknown magic", HFILL
}
183 { &hf_laplink_tcp_length
,
184 { "TCP Data payload length", "laplink.tcp_length",
185 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
186 "Length of remaining payload", HFILL
}
188 { &hf_laplink_tcp_data
,
189 { "Unknown TCP data", "laplink.tcp_data",
190 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
195 /* Setup protocol subtree array */
196 static int *ett
[] = {
200 module_t
*laplink_module
;
202 /* Register the protocol name and description */
203 proto_laplink
= proto_register_protocol("Laplink", "Laplink", "laplink");
205 /* Required function calls to register the header fields and subtrees used */
206 proto_register_field_array(proto_laplink
, hf
, array_length(hf
));
207 proto_register_subtree_array(ett
, array_length(ett
));
209 laplink_module
= prefs_register_protocol(proto_laplink
, NULL
);
210 prefs_register_bool_preference(laplink_module
, "desegment_laplink_over_tcp",
211 "Reassemble Laplink over TCP messages spanning multiple TCP segments",
212 "Whether the Laplink dissector should reassemble messages spanning multiple TCP segments."
213 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
216 laplink_tcp_handle
= register_dissector("laplink.tcp", dissect_laplink_tcp
, proto_laplink
);
217 laplink_udp_handle
= register_dissector("laplink.udp", dissect_laplink_udp
, proto_laplink
);
221 /* If this dissector uses sub-dissector registration add a registration routine.
222 This format is required because a script is used to find these routines and
223 create the code that calls these routines.
226 proto_reg_handoff_laplink(void)
228 dissector_add_uint_with_preference("tcp.port", TCP_PORT_LAPLINK
, laplink_tcp_handle
);
229 dissector_add_uint_with_preference("udp.port", UDP_PORT_LAPLINK
, laplink_udp_handle
);
233 * Editor modelines - https://www.wireshark.org/tools/modelines.html
238 * indent-tabs-mode: t
241 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
242 * :indentSize=8:tabSize=8:noTabs=false: