2 * Routines for arcnet dissection
3 * Copyright 2001-2002, Peter Fales <ethereal@fales-lorenz.net>
5 * $Id: packet-arcnet.c,v 1.5 2003/01/23 06:57:37 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_split_flag = -1;
48 static int hf_arcnet_sequence = -1;
50 /* Initialize the subtree pointers */
51 static gint ett_arcnet = -1;
53 static dissector_table_t arcnet_dissector_table;
54 static dissector_handle_t data_handle;
57 capture_arcnet (const guchar *pd, int len, packet_counts *ld,
60 int offset = has_offset ? 2 : 4;
62 if (!BYTES_ARE_IN_FRAME(offset, len, 1)) {
69 case ARCNET_PROTO_IP_1051:
70 /* No fragmentation stuff in the header */
71 capture_ip(pd, offset + 1, len, ld);
74 case ARCNET_PROTO_IP_1201:
75 /* There's fragmentation stuff in the header */
76 capture_ip(pd, offset + 4, len, ld);
79 case ARCNET_PROTO_ARP_1051:
80 case ARCNET_PROTO_ARP_1201:
91 dissect_arcnet_common (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
95 guint8 dst, src, protID;
97 proto_item *ti = NULL;
98 proto_tree *arcnet_tree = NULL;
100 if (check_col (pinfo->cinfo, COL_PROTOCOL))
101 col_set_str (pinfo->cinfo, COL_PROTOCOL, "ARCNET");
103 if (check_col (pinfo->cinfo, COL_INFO))
104 col_set_str (pinfo->cinfo, COL_INFO, "ARCNET");
106 src = tvb_get_guint8 (tvb, 0);
107 dst = tvb_get_guint8 (tvb, 1);
108 SET_ADDRESS(&pinfo->dl_src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
109 SET_ADDRESS(&pinfo->src, AT_ARCNET, 1, tvb_get_ptr(tvb, 0, 1));
110 SET_ADDRESS(&pinfo->dl_dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
111 SET_ADDRESS(&pinfo->dst, AT_ARCNET, 1, tvb_get_ptr(tvb, 1, 1));
116 proto_tree_add_item (tree, proto_arcnet, tvb, 0, -1, FALSE);
118 arcnet_tree = proto_item_add_subtree (ti, ett_arcnet);
120 proto_tree_add_uint (tree, hf_arcnet_src, tvb, offset, 1, src);
125 proto_tree_add_uint (tree, hf_arcnet_dst, tvb, offset, 1, dst);
130 proto_tree_add_item (tree, hf_arcnet_offset, tvb, offset, 2, FALSE);
134 protID = tvb_get_guint8 (tvb, offset);
136 proto_tree_add_uint (tree, hf_arcnet_protID, tvb, offset, 1, protID);
141 case ARCNET_PROTO_IP_1051:
142 case ARCNET_PROTO_ARP_1051:
143 case ARCNET_PROTO_DIAGNOSE:
144 /* No fragmentation stuff in the header */
148 /* Show the fragmentation stuff - flag and sequence ID */
150 proto_tree_add_item (tree, hf_arcnet_split_flag, tvb, offset, 1, FALSE);
151 proto_tree_add_item (tree, hf_arcnet_sequence, tvb, offset, 2, FALSE);
157 /* Set the length of the ARCNET header protocol tree item. */
159 proto_item_set_len(ti, offset);
161 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
163 if (!dissector_try_port (arcnet_dissector_table, protID,
164 next_tvb, pinfo, tree))
166 if (check_col (pinfo->cinfo, COL_PROTOCOL))
168 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protID);
170 call_dissector (data_handle, next_tvb, pinfo, tree);
176 * BSD-style ARCNET headers - they don't have the offset field from the
177 * ARCNET hardware packet.
180 dissect_arcnet (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
182 dissect_arcnet_common (tvb, pinfo, tree, FALSE);
186 * Linux-style ARCNET headers - they *do* have the offset field from the
187 * ARCNET hardware packet.
190 dissect_arcnet_linux (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
192 dissect_arcnet_common (tvb, pinfo, tree, TRUE);
195 static const value_string arcnet_prot_id_vals[] = {
196 {ARCNET_PROTO_IP_1051, "RFC 1051 IP"},
197 {ARCNET_PROTO_ARP_1051, "RFC 1051 ARP"},
198 {ARCNET_PROTO_IP_1201, "RFC 1201 IP"},
199 {ARCNET_PROTO_ARP_1201, "RFC 1201 ARP"},
200 {ARCNET_PROTO_RARP_1201, "RFC 1201 RARP"},
201 {ARCNET_PROTO_IPX, "IPX"},
202 {ARCNET_PROTO_NOVELL_EC, "Novell of some sort"},
203 {ARCNET_PROTO_IPv6, "IPv6"},
204 {ARCNET_PROTO_ETHERNET, "Encapsulated Ethernet"},
205 {ARCNET_PROTO_DATAPOINT_BOOT, "Datapoint boot"},
206 {ARCNET_PROTO_DATAPOINT_MOUNT, "Datapoint mount"},
207 {ARCNET_PROTO_POWERLAN_BEACON, "PowerLAN beacon"},
208 {ARCNET_PROTO_POWERLAN_BEACON2, "PowerLAN beacon2"},
209 {ARCNET_PROTO_APPLETALK, "Appletalk"},
210 {ARCNET_PROTO_BANYAN, "Banyan VINES"},
211 {ARCNET_PROTO_DIAGNOSE, "Diagnose"},
216 proto_register_arcnet (void)
219 /* Setup list of header fields See Section 1.6.1 for details*/
220 static hf_register_info hf[] = {
222 {"Source", "arcnet.src",
223 FT_UINT8, BASE_HEX, NULL, 0,
227 {"Dest", "arcnet.dst",
228 FT_UINT8, BASE_HEX, NULL, 0,
232 {"Offset", "arcnet.offset",
233 FT_BYTES, BASE_NONE, NULL, 0,
237 {"Protocol ID", "arcnet.protID",
238 FT_UINT8, BASE_HEX, VALS(arcnet_prot_id_vals), 0,
241 {&hf_arcnet_split_flag,
242 {"Split Flag", "arcnet.split_flag",
243 FT_UINT8, BASE_DEC, NULL, 0,
246 {&hf_arcnet_sequence,
247 {"Sequence", "arcnet.sequence",
248 FT_UINT16, BASE_DEC, NULL, 0,
249 "Sequence number", HFILL}
253 /* Setup protocol subtree array */
254 static gint *ett[] = {
258 arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id",
259 "ARCNET Protocol ID",
262 /* Register the protocol name and description */
263 proto_arcnet = proto_register_protocol ("ARCNET", "ARCNET", "arcnet");
265 /* Required function calls to register the header fields and subtrees used */
266 proto_register_field_array (proto_arcnet, hf, array_length (hf));
267 proto_register_subtree_array (ett, array_length (ett));
272 proto_reg_handoff_arcnet (void)
274 dissector_handle_t arcnet_handle, arcnet_linux_handle;
276 arcnet_handle = create_dissector_handle (dissect_arcnet, proto_arcnet);
277 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET, arcnet_handle);
279 arcnet_linux_handle = create_dissector_handle (dissect_arcnet_linux,
281 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, arcnet_linux_handle);
282 data_handle = find_dissector ("data");