2 * Routines for laplink dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
35 #include <epan/strutil.h>
37 #include "packet-tcp.h"
38 #include <epan/prefs.h>
40 #define TCP_PORT_LAPLINK 1547
41 #define UDP_PORT_LAPLINK 1547
43 /* Initialize the protocol and registered fields */
44 static int proto_laplink = -1;
45 static int hf_laplink_udp_ident = -1;
46 static int hf_laplink_udp_name = -1;
47 static int hf_laplink_tcp_ident = -1;
48 static int hf_laplink_tcp_length = -1;
49 static int hf_laplink_tcp_data = -1;
51 /* Initialize the subtree pointers */
52 static gint ett_laplink = -1;
54 static const value_string laplink_udp_magic[] = {
55 { 0x0f010000, "Name Solicitation" },
56 { 0xf0000200, "Name Reply" },
60 static const value_string laplink_tcp_magic[] = {
61 { 0xff08c000, "Unknown TCP query - connection?" },
62 { 0xff08c200, "Unknown TCP query - connection?" },
63 { 0xff0bc000, "Unknown TCP query - connection?" },
64 { 0xff0bc200, "Unknown TCP query - connection?" },
65 { 0xff10c000, "Unknown TCP response - connection?" },
66 { 0xff10c200, "Unknown TCP response - connection?" },
67 { 0xff11c000, "Unknown TCP query/response - directory list or file transfer?" },
68 { 0xff11c200, "Unknown TCP query - directory list or file request?" },
69 { 0xff13c000, "Unknown TCP response - connection?" },
70 { 0xff13c200, "Unknown TCP response - connection?" },
71 { 0xff14c000, "Unknown TCP response - directory list or file transfer?" },
75 static gboolean laplink_desegment = TRUE;
77 /* Code to actually dissect the packets - UDP */
79 dissect_laplink_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
83 proto_tree *laplink_tree;
85 const gchar *udp_ident_string;
88 * Make sure the identifier is reasonable.
90 if (!tvb_bytes_exist(tvb, offset, 4))
91 return 0; /* not enough bytes to check */
92 udp_ident = tvb_get_ntohl(tvb, offset);
93 udp_ident_string = match_strval(udp_ident, laplink_udp_magic);
94 if (udp_ident_string == NULL)
95 return 0; /* unknown */
97 /* Make entries in Protocol column and Info column on summary display */
98 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
100 if (check_col(pinfo->cinfo, COL_INFO))
101 col_add_str(pinfo->cinfo, COL_INFO, udp_ident_string);
104 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, ENC_NA);
105 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
107 proto_tree_add_uint(laplink_tree, hf_laplink_udp_ident, tvb, offset, 4, udp_ident);
110 proto_tree_add_item(laplink_tree, hf_laplink_udp_name, tvb, offset, -1, ENC_ASCII|ENC_NA);
112 return tvb_length(tvb);
115 /* Code to actually dissect the packets - TCP aspects*/
117 dissect_laplink_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
122 proto_tree *laplink_tree;
125 /* Make entries in Protocol column and Info column on summary display */
126 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
128 tcp_ident = tvb_get_ntohl(tvb, offset);
129 if (check_col(pinfo->cinfo, COL_INFO)) {
130 col_add_str(pinfo->cinfo, COL_INFO,
131 val_to_str(tcp_ident, laplink_tcp_magic, "TCP TBA (%u)"));
135 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, ENC_NA);
138 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
140 proto_tree_add_item(laplink_tree, hf_laplink_tcp_ident, tvb, offset, 4, ENC_BIG_ENDIAN);
143 length = tvb_get_ntohs(tvb, offset);
144 proto_tree_add_item(laplink_tree, hf_laplink_tcp_length, tvb, offset, 2, ENC_BIG_ENDIAN);
147 proto_tree_add_item(laplink_tree, hf_laplink_tcp_data, tvb, offset, length, ENC_NA);
149 /* Continue adding tree items to process the packet here */
153 /* If this protocol has a sub-dissector call it here, see section 1.8 */
157 get_laplink_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
161 * The length doesn't include the length or ident fields; add those in.
163 plen = (tvb_get_ntohs(tvb, offset+4) + 2 + 4);
168 dissect_laplink_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
170 tcp_dissect_pdus(tvb, pinfo, tree, laplink_desegment,
171 6, get_laplink_pdu_len,
172 dissect_laplink_tcp_pdu);
176 /* Register the protocol with Wireshark */
179 proto_register_laplink(void)
182 /* Setup list of header fields See Section 1.6.1 for details*/
183 static hf_register_info hf[] = {
184 { &hf_laplink_udp_ident,
185 { "UDP Ident", "laplink.udp_ident",
186 FT_UINT32, BASE_HEX, VALS(laplink_udp_magic), 0x0,
187 "Unknown magic", HFILL }
189 { &hf_laplink_udp_name,
190 { "UDP Name", "laplink.udp_name",
191 FT_STRINGZ, BASE_NONE, NULL, 0x0,
192 "Machine name", HFILL }
194 { &hf_laplink_tcp_ident,
195 { "TCP Ident", "laplink.tcp_ident",
196 FT_UINT32, BASE_HEX, VALS(laplink_tcp_magic), 0x0,
197 "Unknown magic", HFILL }
199 { &hf_laplink_tcp_length,
200 { "TCP Data payload length", "laplink.tcp_length",
201 FT_UINT16, BASE_DEC, NULL, 0x0,
202 "Length of remaining payload", HFILL }
204 { &hf_laplink_tcp_data,
205 { "Unknown TCP data", "laplink.tcp_data",
206 FT_BYTES, BASE_NONE, NULL, 0x0,
211 /* Setup protocol subtree array */
212 static gint *ett[] = {
216 module_t *laplink_module;
218 /* Register the protocol name and description */
219 proto_laplink = proto_register_protocol("Laplink",
220 "Laplink", "laplink");
222 /* Required function calls to register the header fields and subtrees used */
223 proto_register_field_array(proto_laplink, hf, array_length(hf));
224 proto_register_subtree_array(ett, array_length(ett));
226 laplink_module = prefs_register_protocol(proto_laplink, NULL);
227 prefs_register_bool_preference(laplink_module, "desegment_laplink_over_tcp",
228 "Reassemble Laplink over TCP messages spanning multiple TCP segments",
229 "Whether the Laplink dissector should reassemble messages spanning multiple TCP segments."
230 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
235 /* If this dissector uses sub-dissector registration add a registration routine.
236 This format is required because a script is used to find these routines and
237 create the code that calls these routines.
240 proto_reg_handoff_laplink(void)
242 dissector_handle_t laplink_udp_handle;
243 dissector_handle_t laplink_tcp_handle;
245 laplink_tcp_handle = create_dissector_handle(dissect_laplink_tcp,
247 dissector_add_uint("tcp.port", TCP_PORT_LAPLINK, laplink_tcp_handle);
249 laplink_udp_handle = new_create_dissector_handle(dissect_laplink_udp,
251 dissector_add_uint("udp.port", UDP_PORT_LAPLINK, laplink_udp_handle);