2 * Routines for arcnet dissection
3 * Copyright 2001-2002, Peter Fales <ethereal@fales-lorenz.net>
5 * $Id: packet-arcnet.c,v 1.11 2003/12/19 19:09:49 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
36 #include <epan/packet.h>
37 #include "packet-arcnet.h"
38 #include "arcnet_pids.h"
39 #include "packet-ip.h"
41 /* Initialize the protocol and registered fields */
42 static int proto_arcnet = -1;
43 static int hf_arcnet_src = -1;
44 static int hf_arcnet_dst = -1;
45 static int hf_arcnet_offset = -1;
46 static int hf_arcnet_protID = -1;
47 static int hf_arcnet_exception_flag = -1;
48 static int hf_arcnet_split_flag = -1;
49 static int hf_arcnet_sequence = -1;
51 /* Initialize the subtree pointers */
52 static gint ett_arcnet = -1;
54 static dissector_table_t arcnet_dissector_table;
55 static dissector_handle_t data_handle;
58 capture_arcnet (const guchar *pd, int len, packet_counts *ld,
59 gboolean has_offset, gboolean has_exception)
61 int offset = has_offset ? 4 : 2;
63 if (!BYTES_ARE_IN_FRAME(offset, len, 1)) {
70 case ARCNET_PROTO_IP_1051:
71 /* No fragmentation stuff in the header */
72 capture_ip(pd, offset + 1, len, ld);
75 case ARCNET_PROTO_IP_1201:
77 * There's fragmentation stuff in the header.
79 * XXX - on at least some versions of NetBSD, it appears that we
80 * might we get ARCNET frames, not reassembled packets; we should
81 * perhaps bump "ld->other" for all but the first frame of a packet.
83 * XXX - but on FreeBSD it appears that we get reassembled packets
84 * on input (but apparently we get frames on output - or maybe
85 * we get the packet *and* all its frames!); how to tell the
86 * difference? It looks from the FreeBSD reassembly code as if
87 * the reassembled packet arrives with the header for the first
88 * frame. It also looks as if, on output, we first get the
89 * full packet, with a header containing none of the fragmentation
90 * stuff, and then get the frames.
92 * On Linux, we get only reassembled packets, and the exception
93 * frame stuff is hidden - there's a split flag and sequence
94 * number, but it appears that it will never have the exception
97 * XXX - what about OpenBSD? And, for that matter, what about
98 * Windows? (I suspect Windows supplies reassembled frames,
99 * as WinPcap, like PF_PACKET sockets, taps into the networking
100 * stack just as other protocols do.)
103 if (!BYTES_ARE_IN_FRAME(offset, len, 1)) {
107 if (has_exception && pd[offset] == 0xff) {
108 /* This is an exception packet. The flag value there is the
109 "this is an exception flag" packet; the next two bytes
110 after it are padding, and another copy of the packet
111 type appears after the padding. */
114 capture_ip(pd, offset + 3, len, ld);
117 case ARCNET_PROTO_ARP_1051:
118 case ARCNET_PROTO_ARP_1201:
120 * XXX - do we have to worry about fragmentation for ARP?
125 case ARCNET_PROTO_IPX:
136 dissect_arcnet_common (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
137 gboolean has_offset, gboolean has_exception)
140 guint8 dst, src, protID, split_flag;
142 proto_item *ti = NULL;
143 proto_tree *arcnet_tree = NULL;
145 if (check_col (pinfo->cinfo, COL_PROTOCOL))
146 col_set_str (pinfo->cinfo, COL_PROTOCOL, "ARCNET");
148 if (check_col (pinfo->cinfo, COL_INFO))
149 col_set_str (pinfo->cinfo, COL_INFO, "ARCNET");
151 src = tvb_get_guint8 (tvb, 0);
152 dst = tvb_get_guint8 (tvb, 1);
153 SET_ADDRESS(&pinfo->dl_src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
154 SET_ADDRESS(&pinfo->src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
155 SET_ADDRESS(&pinfo->dl_dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
156 SET_ADDRESS(&pinfo->dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
161 proto_tree_add_item (tree, proto_arcnet, tvb, 0, -1, FALSE);
163 arcnet_tree = proto_item_add_subtree (ti, ett_arcnet);
165 proto_tree_add_uint (tree, hf_arcnet_src, tvb, offset, 1, src);
170 proto_tree_add_uint (tree, hf_arcnet_dst, tvb, offset, 1, dst);
175 proto_tree_add_item (tree, hf_arcnet_offset, tvb, offset, 2, FALSE);
179 protID = tvb_get_guint8 (tvb, offset);
181 proto_tree_add_uint (tree, hf_arcnet_protID, tvb, offset, 1, protID);
186 case ARCNET_PROTO_IP_1051:
187 case ARCNET_PROTO_ARP_1051:
188 case ARCNET_PROTO_DIAGNOSE:
189 case ARCNET_PROTO_BACNET: /* XXX - no fragmentation? */
190 /* No fragmentation stuff in the header */
195 * Show the fragmentation stuff - flag and sequence ID.
197 * XXX - on at least some versions of NetBSD, it appears that
198 * we might get ARCNET frames, not reassembled packets; if so,
199 * we should reassemble them.
201 * XXX - but on FreeBSD it appears that we get reassembled packets
202 * on input (but apparently we get frames on output - or maybe
203 * we get the packet *and* all its frames!); how to tell the
204 * difference? It looks from the FreeBSD reassembly code as if
205 * the reassembled packet arrives with the header for the first
206 * frame. It also looks as if, on output, we first get the
207 * full packet, with a header containing none of the fragmentation
208 * stuff, and then get the frames.
210 * On Linux, we get only reassembled packets, and the exception
211 * frame stuff is hidden - there's a split flag and sequence
212 * number, but it appears that it will never have the exception
215 * XXX - what about OpenBSD? And, for that matter, what about
216 * Windows? (I suspect Windows supplies reassembled frames,
217 * as WinPcap, like PF_PACKET sockets, taps into the networking
218 * stack just as other protocols do.)
220 split_flag = tvb_get_guint8 (tvb, offset);
221 if (has_exception && split_flag == 0xff) {
222 /* This is an exception packet. The flag value there is the
223 "this is an exception flag" packet; the next two bytes
224 after it are padding. */
226 proto_tree_add_uint (tree, hf_arcnet_exception_flag, tvb, offset, 1,
232 proto_tree_add_text (tree, tvb, offset, 2, "Padding");
235 /* Another copy of the packet type appears after the padding. */
237 proto_tree_add_item (tree, hf_arcnet_protID, tvb, offset, 1, FALSE);
240 /* And after that comes the real split flag. */
241 split_flag = tvb_get_guint8 (tvb, offset);
244 proto_tree_add_uint (tree, hf_arcnet_split_flag, tvb, offset, 1,
250 proto_tree_add_item (tree, hf_arcnet_sequence, tvb, offset, 2, FALSE);
256 /* Set the length of the ARCNET header protocol tree item. */
258 proto_item_set_len(ti, offset);
260 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
262 if (!dissector_try_port (arcnet_dissector_table, protID,
263 next_tvb, pinfo, tree))
265 if (check_col (pinfo->cinfo, COL_PROTOCOL))
267 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protID);
269 call_dissector (data_handle, next_tvb, pinfo, tree);
275 * BSD-style ARCNET headers - they don't have the offset field from the
276 * ARCNET hardware packet, but we might get an exception frame header.
279 dissect_arcnet (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
281 dissect_arcnet_common (tvb, pinfo, tree, FALSE, TRUE);
285 * Linux-style ARCNET headers - they *do* have the offset field from the
286 * ARCNET hardware packet, but we should never see an exception frame
290 dissect_arcnet_linux (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
292 dissect_arcnet_common (tvb, pinfo, tree, TRUE, FALSE);
295 static const value_string arcnet_prot_id_vals[] = {
296 {ARCNET_PROTO_IP_1051, "RFC 1051 IP"},
297 {ARCNET_PROTO_ARP_1051, "RFC 1051 ARP"},
298 {ARCNET_PROTO_IP_1201, "RFC 1201 IP"},
299 {ARCNET_PROTO_ARP_1201, "RFC 1201 ARP"},
300 {ARCNET_PROTO_RARP_1201, "RFC 1201 RARP"},
301 {ARCNET_PROTO_IPX, "IPX"},
302 {ARCNET_PROTO_NOVELL_EC, "Novell of some sort"},
303 {ARCNET_PROTO_IPv6, "IPv6"},
304 {ARCNET_PROTO_ETHERNET, "Encapsulated Ethernet"},
305 {ARCNET_PROTO_DATAPOINT_BOOT, "Datapoint boot"},
306 {ARCNET_PROTO_DATAPOINT_MOUNT, "Datapoint mount"},
307 {ARCNET_PROTO_POWERLAN_BEACON, "PowerLAN beacon"},
308 {ARCNET_PROTO_POWERLAN_BEACON2, "PowerLAN beacon2"},
309 {ARCNET_PROTO_APPLETALK, "Appletalk"},
310 {ARCNET_PROTO_BANYAN, "Banyan VINES"},
311 {ARCNET_PROTO_DIAGNOSE, "Diagnose"},
312 {ARCNET_PROTO_BACNET, "BACnet"},
317 proto_register_arcnet (void)
320 /* Setup list of header fields See Section 1.6.1 for details*/
321 static hf_register_info hf[] = {
323 {"Source", "arcnet.src",
324 FT_UINT8, BASE_HEX, NULL, 0,
328 {"Dest", "arcnet.dst",
329 FT_UINT8, BASE_HEX, NULL, 0,
333 {"Offset", "arcnet.offset",
334 FT_BYTES, BASE_NONE, NULL, 0,
338 {"Protocol ID", "arcnet.protID",
339 FT_UINT8, BASE_HEX, VALS(arcnet_prot_id_vals), 0,
342 {&hf_arcnet_split_flag,
343 {"Split Flag", "arcnet.split_flag",
344 FT_UINT8, BASE_DEC, NULL, 0,
347 {&hf_arcnet_exception_flag,
348 {"Exception Flag", "arcnet.exception_flag",
349 FT_UINT8, BASE_HEX, NULL, 0,
350 "Exception flag", HFILL}
352 {&hf_arcnet_sequence,
353 {"Sequence", "arcnet.sequence",
354 FT_UINT16, BASE_DEC, NULL, 0,
355 "Sequence number", HFILL}
359 /* Setup protocol subtree array */
360 static gint *ett[] = {
364 arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id",
365 "ARCNET Protocol ID",
368 /* Register the protocol name and description */
369 proto_arcnet = proto_register_protocol ("ARCNET", "ARCNET", "arcnet");
371 /* Required function calls to register the header fields and subtrees used */
372 proto_register_field_array (proto_arcnet, hf, array_length (hf));
373 proto_register_subtree_array (ett, array_length (ett));
378 proto_reg_handoff_arcnet (void)
380 dissector_handle_t arcnet_handle, arcnet_linux_handle;
382 arcnet_handle = create_dissector_handle (dissect_arcnet, proto_arcnet);
383 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET, arcnet_handle);
385 arcnet_linux_handle = create_dissector_handle (dissect_arcnet_linux,
387 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, arcnet_linux_handle);
388 data_handle = find_dissector ("data");