2 * Routines for arcnet dissection
3 * Copyright 2001-2002, Peter Fales <ethereal@fales-lorenz.net>
5 * $Id: packet-arcnet.c,v 1.6 2003/01/23 07:55:28 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,
61 int offset = has_offset ? 2 : 4;
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:
76 /* There's fragmentation stuff in the header */
78 if (!BYTES_ARE_IN_FRAME(offset, len, 1)) {
82 if (pd[offset] == 0xff) {
83 /* This is an exception packet. The flag value there is the
84 "this is an exception flag" packet; the next two bytes
85 after it are padding, and another copy of the packet
86 type appears after the padding. */
89 capture_ip(pd, offset + 3, len, ld);
92 case ARCNET_PROTO_ARP_1051:
93 case ARCNET_PROTO_ARP_1201:
104 dissect_arcnet_common (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
108 guint8 dst, src, protID, split_flag;
110 proto_item *ti = NULL;
111 proto_tree *arcnet_tree = NULL;
113 if (check_col (pinfo->cinfo, COL_PROTOCOL))
114 col_set_str (pinfo->cinfo, COL_PROTOCOL, "ARCNET");
116 if (check_col (pinfo->cinfo, COL_INFO))
117 col_set_str (pinfo->cinfo, COL_INFO, "ARCNET");
119 src = tvb_get_guint8 (tvb, 0);
120 dst = tvb_get_guint8 (tvb, 1);
121 SET_ADDRESS(&pinfo->dl_src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
122 SET_ADDRESS(&pinfo->src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
123 SET_ADDRESS(&pinfo->dl_dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
124 SET_ADDRESS(&pinfo->dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
129 proto_tree_add_item (tree, proto_arcnet, tvb, 0, -1, FALSE);
131 arcnet_tree = proto_item_add_subtree (ti, ett_arcnet);
133 proto_tree_add_uint (tree, hf_arcnet_src, tvb, offset, 1, src);
138 proto_tree_add_uint (tree, hf_arcnet_dst, tvb, offset, 1, dst);
143 proto_tree_add_item (tree, hf_arcnet_offset, tvb, offset, 2, FALSE);
147 protID = tvb_get_guint8 (tvb, offset);
149 proto_tree_add_uint (tree, hf_arcnet_protID, tvb, offset, 1, protID);
154 case ARCNET_PROTO_IP_1051:
155 case ARCNET_PROTO_ARP_1051:
156 case ARCNET_PROTO_DIAGNOSE:
157 /* No fragmentation stuff in the header */
161 /* Show the fragmentation stuff - flag and sequence ID */
162 split_flag = tvb_get_guint8 (tvb, offset);
163 if (split_flag == 0xff) {
164 /* This is an exception packet. The flag value there is the
165 "this is an exception flag" packet; the next two bytes
166 after it are padding. */
168 proto_tree_add_uint (tree, hf_arcnet_exception_flag, tvb, offset, 1,
174 proto_tree_add_text (tree, tvb, offset, 2, "Padding");
177 /* Another copy of the packet type appears after the padding. */
179 proto_tree_add_item (tree, hf_arcnet_protID, tvb, offset, 1, FALSE);
182 /* And after that comes the real split flag. */
183 split_flag = tvb_get_guint8 (tvb, offset);
186 proto_tree_add_uint (tree, hf_arcnet_split_flag, tvb, offset, 1,
192 proto_tree_add_item (tree, hf_arcnet_sequence, tvb, offset, 2, FALSE);
198 /* Set the length of the ARCNET header protocol tree item. */
200 proto_item_set_len(ti, offset);
202 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
204 if (!dissector_try_port (arcnet_dissector_table, protID,
205 next_tvb, pinfo, tree))
207 if (check_col (pinfo->cinfo, COL_PROTOCOL))
209 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protID);
211 call_dissector (data_handle, next_tvb, pinfo, tree);
217 * BSD-style ARCNET headers - they don't have the offset field from the
218 * ARCNET hardware packet.
221 dissect_arcnet (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
223 dissect_arcnet_common (tvb, pinfo, tree, FALSE);
227 * Linux-style ARCNET headers - they *do* have the offset field from the
228 * ARCNET hardware packet.
231 dissect_arcnet_linux (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
233 dissect_arcnet_common (tvb, pinfo, tree, TRUE);
236 static const value_string arcnet_prot_id_vals[] = {
237 {ARCNET_PROTO_IP_1051, "RFC 1051 IP"},
238 {ARCNET_PROTO_ARP_1051, "RFC 1051 ARP"},
239 {ARCNET_PROTO_IP_1201, "RFC 1201 IP"},
240 {ARCNET_PROTO_ARP_1201, "RFC 1201 ARP"},
241 {ARCNET_PROTO_RARP_1201, "RFC 1201 RARP"},
242 {ARCNET_PROTO_IPX, "IPX"},
243 {ARCNET_PROTO_NOVELL_EC, "Novell of some sort"},
244 {ARCNET_PROTO_IPv6, "IPv6"},
245 {ARCNET_PROTO_ETHERNET, "Encapsulated Ethernet"},
246 {ARCNET_PROTO_DATAPOINT_BOOT, "Datapoint boot"},
247 {ARCNET_PROTO_DATAPOINT_MOUNT, "Datapoint mount"},
248 {ARCNET_PROTO_POWERLAN_BEACON, "PowerLAN beacon"},
249 {ARCNET_PROTO_POWERLAN_BEACON2, "PowerLAN beacon2"},
250 {ARCNET_PROTO_APPLETALK, "Appletalk"},
251 {ARCNET_PROTO_BANYAN, "Banyan VINES"},
252 {ARCNET_PROTO_DIAGNOSE, "Diagnose"},
257 proto_register_arcnet (void)
260 /* Setup list of header fields See Section 1.6.1 for details*/
261 static hf_register_info hf[] = {
263 {"Source", "arcnet.src",
264 FT_UINT8, BASE_HEX, NULL, 0,
268 {"Dest", "arcnet.dst",
269 FT_UINT8, BASE_HEX, NULL, 0,
273 {"Offset", "arcnet.offset",
274 FT_BYTES, BASE_NONE, NULL, 0,
278 {"Protocol ID", "arcnet.protID",
279 FT_UINT8, BASE_HEX, VALS(arcnet_prot_id_vals), 0,
282 {&hf_arcnet_split_flag,
283 {"Split Flag", "arcnet.split_flag",
284 FT_UINT8, BASE_DEC, NULL, 0,
287 {&hf_arcnet_exception_flag,
288 {"Exception Flag", "arcnet.exception_flag",
289 FT_UINT8, BASE_HEX, NULL, 0,
290 "Exception flag", HFILL}
292 {&hf_arcnet_sequence,
293 {"Sequence", "arcnet.sequence",
294 FT_UINT16, BASE_DEC, NULL, 0,
295 "Sequence number", HFILL}
299 /* Setup protocol subtree array */
300 static gint *ett[] = {
304 arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id",
305 "ARCNET Protocol ID",
308 /* Register the protocol name and description */
309 proto_arcnet = proto_register_protocol ("ARCNET", "ARCNET", "arcnet");
311 /* Required function calls to register the header fields and subtrees used */
312 proto_register_field_array (proto_arcnet, hf, array_length (hf));
313 proto_register_subtree_array (ett, array_length (ett));
318 proto_reg_handoff_arcnet (void)
320 dissector_handle_t arcnet_handle, arcnet_linux_handle;
322 arcnet_handle = create_dissector_handle (dissect_arcnet, proto_arcnet);
323 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET, arcnet_handle);
325 arcnet_linux_handle = create_dissector_handle (dissect_arcnet_linux,
327 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, arcnet_linux_handle);
328 data_handle = find_dissector ("data");