2 * Routines for Ethernet loopback/Configuration Test Protocol dissection
6 * http://stuff.mit.edu/people/jhawk/ctp.html
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <epan/packet.h>
33 #include <epan/etypes.h>
35 static int proto_loop
= -1;
36 static int hf_loop_skipcount
= -1;
37 static int hf_loop_function
= -1;
38 static int hf_loop_receipt_number
= -1;
39 static int hf_loop_forwarding_address
= -1;
41 static gint ett_loop
= -1;
43 static dissector_handle_t data_handle
;
46 #define FUNC_FORWARD_DATA 2
48 static const value_string function_vals
[] = {
49 { FUNC_REPLY
, "Reply" },
50 { FUNC_FORWARD_DATA
, "Forward Data" },
55 dissect_loop(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
57 proto_tree
*loop_tree
= NULL
;
62 gboolean set_info
= TRUE
;
63 gboolean more_function
;
66 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "LOOP");
67 col_clear(pinfo
->cinfo
, COL_INFO
);
70 ti
= proto_tree_add_item(tree
, proto_loop
, tvb
, offset
, -1, ENC_NA
);
71 loop_tree
= proto_item_add_subtree(ti
, ett_loop
);
73 proto_tree_add_item(loop_tree
, hf_loop_skipcount
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
75 skip_offset
= 2 + tvb_get_letohs(tvb
, offset
);
79 function
= tvb_get_letohs(tvb
, offset
);
80 if (offset
== skip_offset
) {
81 col_add_str(pinfo
->cinfo
, COL_INFO
,
82 val_to_str(function
, function_vals
, "Unknown function (%u)"));
84 proto_tree_add_text(loop_tree
, tvb
, offset
, 2, "Relevant function:");
88 proto_tree_add_uint(loop_tree
, hf_loop_function
, tvb
, offset
, 2, function
);
94 proto_tree_add_item(loop_tree
, hf_loop_receipt_number
, tvb
, offset
, 2,
97 more_function
= FALSE
;
100 case FUNC_FORWARD_DATA
:
102 proto_tree_add_item(loop_tree
, hf_loop_forwarding_address
, tvb
, offset
,
105 more_function
= TRUE
;
109 more_function
= FALSE
;
112 } while (more_function
);
115 col_set_str(pinfo
->cinfo
, COL_INFO
, "No valid function found");
118 if (tvb_length_remaining(tvb
, offset
) > 0)
120 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
121 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
126 proto_register_loop(void)
128 static hf_register_info hf
[] = {
129 { &hf_loop_skipcount
,
130 { "skipCount", "loop.skipcount",
131 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
135 { "Function", "loop.function",
136 FT_UINT16
, BASE_DEC
, VALS(function_vals
), 0x0,
139 { &hf_loop_receipt_number
,
140 { "Receipt number", "loop.receipt_number",
141 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
144 { &hf_loop_forwarding_address
,
145 { "Forwarding address", "loop.forwarding_address",
146 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
149 static gint
*ett
[] = {
153 proto_loop
= proto_register_protocol("Configuration Test Protocol (loopback)",
155 proto_register_field_array(proto_loop
, hf
, array_length(hf
));
156 proto_register_subtree_array(ett
, array_length(ett
));
160 proto_reg_handoff_loop(void)
162 dissector_handle_t loop_handle
;
164 loop_handle
= create_dissector_handle(dissect_loop
, proto_loop
);
166 dissector_add_uint("ethertype", ETHERTYPE_LOOP
, loop_handle
);
168 data_handle
= find_dissector("data");