3 * Top-most dissector. Decides dissector based on Wiretap Encapsulation Type.
5 * $Id: packet-frame.c,v 1.36 2003/03/03 23:29:57 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 2000 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.
31 #include <epan/packet.h>
32 #include <epan/timestamp.h>
33 #include <epan/tvbuff.h>
34 #include "packet-frame.h"
38 static int proto_frame = -1;
39 static int hf_frame_arrival_time = -1;
40 static int hf_frame_time_delta = -1;
41 static int hf_frame_time_relative = -1;
42 static int hf_frame_number = -1;
43 static int hf_frame_packet_len = -1;
44 static int hf_frame_capture_len = -1;
45 static int hf_frame_p2p_dir = -1;
46 static int hf_frame_file_off = -1;
47 static int hf_frame_marked = -1;
49 static int proto_short = -1;
50 int proto_malformed = -1;
51 static int proto_unreassembled = -1;
53 static gint ett_frame = -1;
55 static int frame_tap = -1;
57 static dissector_handle_t data_handle;
58 static dissector_handle_t docsis_handle;
61 static gboolean show_file_off = FALSE;
62 static gboolean force_docsis_encap;
64 static const value_string p2p_dirs[] = {
65 { P2P_DIR_SENT, "Sent" },
66 { P2P_DIR_RECV, "Received" },
70 static dissector_table_t wtap_encap_dissector_table;
73 dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
80 pinfo->current_proto = "Frame";
82 if (pinfo->pseudo_header != NULL) {
83 switch (pinfo->fd->lnk_t) {
85 case WTAP_ENCAP_WFLEET_HDLC:
86 case WTAP_ENCAP_CHDLC:
87 case WTAP_ENCAP_PPP_WITH_PHDR:
89 pinfo->p2p_dir = pinfo->pseudo_header->p2p.sent ?
90 P2P_DIR_SENT : P2P_DIR_RECV;
94 case WTAP_ENCAP_FRELAY_WITH_PHDR:
96 (pinfo->pseudo_header->x25.flags & FROM_DCE) ?
97 P2P_DIR_RECV : P2P_DIR_SENT;
100 case WTAP_ENCAP_ISDN:
101 pinfo->p2p_dir = pinfo->pseudo_header->isdn.uton ?
102 P2P_DIR_SENT : P2P_DIR_RECV;
107 if ((force_docsis_encap) && (docsis_handle)) {
109 * XXX - setting it here makes it impossible to
110 * turn the "Treat all frames as DOCSIS frames"
113 * The TCP Graph code currently uses "fd->lnk_t";
114 * it should eventually just get the information
115 * it needs from a full-blown dissection, so that
116 * can handle any link-layer type.
118 pinfo->fd->lnk_t = WTAP_ENCAP_DOCSIS;
121 /* Put in frame header information. */
124 cap_len = tvb_length(tvb);
125 pkt_len = tvb_reported_length(tvb);
127 ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, -1,
128 "Frame %u (%u bytes on wire, %u bytes captured)", pinfo->fd->num, pkt_len, cap_len);
130 fh_tree = proto_item_add_subtree(ti, ett_frame);
132 proto_tree_add_boolean_hidden(fh_tree, hf_frame_marked, tvb, 0, 0,pinfo->fd->flags.marked);
134 ts.secs = pinfo->fd->abs_secs;
135 ts.nsecs = pinfo->fd->abs_usecs*1000;
137 proto_tree_add_time(fh_tree, hf_frame_arrival_time, tvb,
140 ts.secs = pinfo->fd->del_secs;
141 ts.nsecs = pinfo->fd->del_usecs*1000;
143 proto_tree_add_time(fh_tree, hf_frame_time_delta, tvb,
146 ts.secs = pinfo->fd->rel_secs;
147 ts.nsecs = pinfo->fd->rel_usecs*1000;
149 proto_tree_add_time(fh_tree, hf_frame_time_relative, tvb,
152 proto_tree_add_uint(fh_tree, hf_frame_number, tvb,
153 0, 0, pinfo->fd->num);
155 proto_tree_add_uint_format(fh_tree, hf_frame_packet_len, tvb,
156 0, 0, pkt_len, "Packet Length: %d byte%s", pkt_len,
157 plurality(pkt_len, "", "s"));
159 proto_tree_add_uint_format(fh_tree, hf_frame_capture_len, tvb,
160 0, 0, cap_len, "Capture Length: %d byte%s", cap_len,
161 plurality(cap_len, "", "s"));
163 /* Check for existences of P2P pseudo header */
164 if (pinfo->p2p_dir != P2P_DIR_UNKNOWN) {
165 proto_tree_add_uint(fh_tree, hf_frame_p2p_dir, tvb,
166 0, 0, pinfo->p2p_dir);
170 proto_tree_add_int_format(fh_tree, hf_frame_file_off, tvb,
171 0, 0, pinfo->fd->file_off,
172 "File Offset: %ld (0x%lx)",
173 pinfo->fd->file_off, pinfo->fd->file_off);
179 if (!dissector_try_port(wtap_encap_dissector_table, pinfo->fd->lnk_t,
182 if (check_col(pinfo->cinfo, COL_PROTOCOL))
183 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
184 if (check_col(pinfo->cinfo, COL_INFO))
185 col_add_fstr(pinfo->cinfo, COL_INFO, "WTAP_ENCAP = %u",
187 call_dissector(data_handle,tvb, pinfo, tree);
191 if (check_col(pinfo->cinfo, COL_INFO))
192 col_append_str(pinfo->cinfo, COL_INFO, "[Short Frame]");
193 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
194 "[Short Frame: %s]", pinfo->current_proto);
196 CATCH(ReportedBoundsError) {
197 show_reported_bounds_error(tvb, pinfo, tree);
201 tap_queue_packet(frame_tap, pinfo, NULL);
205 show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
207 if (pinfo->fragmented) {
209 * We were dissecting an unreassembled fragmented
210 * packet when the exception was thrown, so the
211 * problem isn't that the dissector expected
212 * something but it wasn't in the packet, the
213 * problem is that the dissector expected something
214 * but it wasn't in the fragment we dissected.
216 if (check_col(pinfo->cinfo, COL_INFO))
217 col_append_fstr(pinfo->cinfo, COL_INFO,
218 "[Unreassembled Packet%s]",
219 pinfo->noreassembly_reason);
220 proto_tree_add_protocol_format(tree, proto_unreassembled,
221 tvb, 0, 0, "[Unreassembled Packet%s: %s]",
222 pinfo->noreassembly_reason, pinfo->current_proto);
224 if (check_col(pinfo->cinfo, COL_INFO))
225 col_append_str(pinfo->cinfo, COL_INFO,
226 "[Malformed Packet]");
227 proto_tree_add_protocol_format(tree, proto_malformed,
228 tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
233 proto_register_frame(void)
235 static hf_register_info hf[] = {
236 { &hf_frame_arrival_time,
237 { "Arrival Time", "frame.time", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
240 { &hf_frame_time_delta,
241 { "Time delta from previous packet", "frame.time_delta", FT_RELATIVE_TIME, BASE_NONE, NULL,
245 { &hf_frame_time_relative,
246 { "Time relative to first packet", "frame.time_relative", FT_RELATIVE_TIME, BASE_NONE, NULL,
251 { "Frame Number", "frame.number", FT_UINT32, BASE_DEC, NULL, 0x0,
254 { &hf_frame_packet_len,
255 { "Total Frame Length", "frame.pkt_len", FT_UINT32, BASE_DEC, NULL, 0x0,
258 { &hf_frame_capture_len,
259 { "Capture Frame Length", "frame.cap_len", FT_UINT32, BASE_DEC, NULL, 0x0,
263 { "Point-to-Point Direction", "frame.p2p_dir", FT_UINT8, BASE_DEC, VALS(p2p_dirs), 0x0,
266 { &hf_frame_file_off,
267 { "File Offset", "frame.file_off", FT_INT32, BASE_DEC, NULL, 0x0,
271 { "Frame is marked", "frame.marked", FT_BOOLEAN, 8, NULL, 0x0,
272 "Frame is marked in the GUI", HFILL }},
274 static gint *ett[] = {
277 module_t *frame_module;
279 wtap_encap_dissector_table = register_dissector_table("wtap_encap",
280 "Wiretap encapsulation type", FT_UINT32, BASE_DEC);
282 proto_frame = proto_register_protocol("Frame", "Frame", "frame");
283 proto_register_field_array(proto_frame, hf, array_length(hf));
284 proto_register_subtree_array(ett, array_length(ett));
285 register_dissector("frame",dissect_frame,proto_frame);
287 /* You can't disable dissection of "Frame", as that would be
288 tantamount to not doing any dissection whatsoever. */
289 proto_set_cant_disable(proto_frame);
291 proto_short = proto_register_protocol("Short Frame", "Short frame", "short");
292 proto_malformed = proto_register_protocol("Malformed Packet",
293 "Malformed packet", "malformed");
294 proto_unreassembled = proto_register_protocol(
295 "Unreassembled Fragmented Packet",
296 "Unreassembled fragmented packet", "unreassembled");
298 /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
299 Packet" aren't really protocols, they're error indications;
300 disabling them makes no sense. */
301 proto_set_cant_disable(proto_short);
302 proto_set_cant_disable(proto_malformed);
303 proto_set_cant_disable(proto_unreassembled);
305 /* Our preferences */
306 frame_module = prefs_register_protocol(proto_frame, NULL);
307 prefs_register_bool_preference(frame_module, "show_file_off",
308 "Show File Offset", "Show File Offset", &show_file_off);
309 prefs_register_bool_preference(frame_module, "force_docsis_encap",
310 "Treat all frames as DOCSIS frames", "Treat all frames as DOCSIS Frames", &force_docsis_encap);
312 frame_tap=register_tap("frame");
316 proto_reg_handoff_frame(void)
318 data_handle = find_dissector("data");
319 docsis_handle = find_dissector("docsis");