2 * Routines for Interlink protocol packet disassembly
3 * By Uwe Girlich <uwe.girlich@philosys.de>
4 * Copyright 2010 Uwe Girlich
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
17 void proto_register_interlink(void);
18 void proto_reg_handoff_interlink(void);
21 * No public information available.
24 static int proto_interlink = -1;
26 static int hf_interlink_id = -1;
27 static int hf_interlink_version = -1;
28 static int hf_interlink_cmd = -1;
29 static int hf_interlink_seq = -1;
30 static int hf_interlink_flags = -1;
31 static int hf_interlink_flags_req_ack = -1;
32 static int hf_interlink_flags_inc_ack_port = -1;
33 static int hf_interlink_block_type = -1;
34 static int hf_interlink_block_version = -1;
35 static int hf_interlink_block_length = -1;
37 static gint ett_interlink = -1;
38 static gint ett_interlink_header = -1;
39 static gint ett_interlink_flags = -1;
40 static gint ett_interlink_block = -1;
42 static dissector_handle_t data_handle;
43 static dissector_table_t subdissector_table;
44 static dissector_handle_t interlink_handle;
46 static const true_false_string flags_set_notset = {
50 static const value_string names_cmd[] = {
58 dissect_interlink(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
63 proto_tree *ilh_tree = NULL;
64 proto_tree *ilb_tree = NULL;
67 guint16 type_version = 0;
68 dissector_handle_t handle;
71 col_set_str(pinfo->cinfo, COL_PROTOCOL, "INTERLINK");
72 col_clear(pinfo->cinfo, COL_INFO);
74 il_item = proto_tree_add_item(tree, proto_interlink,
76 il_tree = proto_item_add_subtree(il_item, ett_interlink);
78 ilh_tree = proto_tree_add_subtree(il_tree, tvb, 0, 12, ett_interlink_header, NULL, "Interlink Header");
81 proto_tree_add_item(ilh_tree, hf_interlink_id, tvb, offset, 4, ENC_ASCII|ENC_NA);
83 proto_tree_add_item(ilh_tree, hf_interlink_version, tvb, offset, 2, ENC_LITTLE_ENDIAN);
85 proto_tree_add_item(ilh_tree, hf_interlink_cmd, tvb, offset, 2, ENC_LITTLE_ENDIAN);
87 proto_tree_add_item(ilh_tree, hf_interlink_seq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
94 static const int * flags[] = {
95 &hf_interlink_flags_req_ack,
96 &hf_interlink_flags_inc_ack_port,
100 proto_tree_add_bitmask(ilh_tree, tvb, offset, hf_interlink_flags, ett_interlink_flags, flags, ENC_LITTLE_ENDIAN);
105 ilb_tree = proto_tree_add_subtree(il_tree, tvb, offset, 4, ett_interlink_block, NULL, "Block Header");
107 ilb_type = tvb_get_guint8(tvb, offset);
108 ilb_version = tvb_get_guint8(tvb, offset + 1);
109 type_version = ilb_type << 8 | ilb_version;
110 col_append_fstr(pinfo->cinfo, COL_INFO, "Type: %d, Version: %d",
111 ilb_type, ilb_version);
114 proto_tree_add_item(ilb_tree, hf_interlink_block_type, tvb, offset, 1, ENC_BIG_ENDIAN);
116 proto_tree_add_item(ilb_tree, hf_interlink_block_version, tvb, offset, 1, ENC_BIG_ENDIAN);
118 proto_tree_add_item(ilb_tree, hf_interlink_block_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
124 /* Generate a new tvb for the rest. */
125 next_tvb = tvb_new_subset_remaining(tvb, offset);
127 /* Probably a sub-dissector exists for this type/version combination. */
128 handle = dissector_get_uint_handle(subdissector_table, type_version);
130 /* Without a proper sub-dissector, we use "data". */
131 if (handle == NULL) handle = data_handle;
133 /* Call the sub-dissector. */
134 call_dissector(handle, next_tvb, pinfo, tree);
136 return tvb_captured_length(tvb);
141 dissect_interlink_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
143 if (!tvb_bytes_exist(tvb, 0, 4)) {
147 tvb_get_guint8(tvb,0) != 'I' ||
148 tvb_get_guint8(tvb,1) != 'L' ||
149 tvb_get_guint8(tvb,2) != 'N' ||
150 tvb_get_guint8(tvb,3) != 'K'
154 dissect_interlink(tvb, pinfo, tree, data);
160 proto_register_interlink(void)
162 static hf_register_info hf[] = {
163 { &hf_interlink_id, {
164 "Magic ID", "interlink.id", FT_STRING,
165 BASE_NONE, NULL, 0, NULL, HFILL }},
166 { &hf_interlink_version, {
167 "Version", "interlink.version", FT_UINT16,
168 BASE_DEC, NULL, 0, NULL, HFILL }},
169 { &hf_interlink_cmd, {
170 "Command", "interlink.cmd", FT_UINT16,
171 BASE_DEC, VALS(names_cmd), 0, NULL, HFILL }},
172 { &hf_interlink_seq, {
173 "Sequence", "interlink.seq", FT_UINT16,
174 BASE_DEC, NULL, 0, NULL, HFILL }},
175 { &hf_interlink_flags, {
176 "Flags", "interlink.flags", FT_UINT16,
177 BASE_HEX, NULL, 0, NULL, HFILL }},
178 { &hf_interlink_flags_req_ack, {
179 "REQ_ACK", "interlink.flags.req_ack", FT_BOOLEAN,
180 16, TFS(&flags_set_notset), 0x01, NULL, HFILL }},
181 { &hf_interlink_flags_inc_ack_port, {
182 "INC_ACK_PORT", "interlink.flags.inc_ack_port", FT_BOOLEAN,
183 16, TFS(&flags_set_notset), 0x02, NULL, HFILL }},
184 { &hf_interlink_block_type, {
185 "Type", "interlink.type", FT_UINT8,
186 BASE_DEC, NULL, 0, NULL, HFILL }},
187 { &hf_interlink_block_version, {
188 "Version", "interlink.block_version", FT_UINT8,
189 BASE_DEC, NULL, 0, NULL, HFILL }},
190 { &hf_interlink_block_length, {
191 "Length", "interlink.length", FT_UINT16,
192 BASE_DEC, NULL, 0, NULL, HFILL }},
195 static gint *ett[] = {
197 &ett_interlink_header,
198 &ett_interlink_flags,
199 &ett_interlink_block,
202 proto_interlink = proto_register_protocol("Interlink Protocol",
205 proto_register_field_array(proto_interlink, hf, array_length(hf));
206 proto_register_subtree_array(ett, array_length(ett));
207 interlink_handle = register_dissector("interlink", dissect_interlink, proto_interlink);
209 /* Probably someone will write sub-dissectors. You can never know. */
210 subdissector_table = register_dissector_table("interlink.type_version",
211 "Interlink type_version", proto_interlink, FT_UINT16, BASE_HEX);
216 proto_reg_handoff_interlink(void)
218 /* Allow "Decode As" with any UDP packet. */
219 dissector_add_for_decode_as_with_preference("udp.port", interlink_handle);
221 /* Add our heuristic packet finder. */
222 heur_dissector_add("udp", dissect_interlink_heur, "Interlink over UDP", "interlink_udp", proto_interlink, HEURISTIC_ENABLE);
224 data_handle = find_dissector("data");
228 * Editor modelines - http://www.wireshark.org/tools/modelines.html
233 * indent-tabs-mode: t
236 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
237 * :indentSize=8:tabSize=8:noTabs=false: