2 * Routines for FDDI packet disassembly
4 * Laurent Deniel <deniel@worldnet.fr>
6 * $Id: packet-fddi.c,v 1.45 2001/01/03 10:34:41 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
41 #include "packet-fddi.h"
42 #include "packet-llc.h"
45 static int proto_fddi = -1;
46 static int hf_fddi_fc = -1;
47 static int hf_fddi_dst = -1;
48 static int hf_fddi_src = -1;
49 static int hf_fddi_addr = -1;
51 static gint ett_fddi = -1;
53 /* FDDI Frame Control values */
55 #define FDDI_FC_VOID 0x00 /* Void frame */
56 #define FDDI_FC_NRT 0x80 /* Nonrestricted token */
57 #define FDDI_FC_RT 0xc0 /* Restricted token */
58 #define FDDI_FC_MAC 0xc0 /* MAC frame */
59 #define FDDI_FC_SMT 0x40 /* SMT frame */
60 #define FDDI_FC_SMT_INFO 0x41 /* SMT Info */
61 #define FDDI_FC_SMT_NSA 0x4F /* SMT Next station adrs */
62 #define FDDI_FC_SMT_MIN FDDI_FC_SMT_INFO
63 #define FDDI_FC_SMT_MAX FDDI_FC_SMT_NSA
64 #define FDDI_FC_MAC_MIN 0xc1
65 #define FDDI_FC_MAC_BEACON 0xc2 /* MAC Beacon frame */
66 #define FDDI_FC_MAC_CLAIM 0xc3 /* MAC Claim frame */
67 #define FDDI_FC_MAC_MAX 0xcf
68 #define FDDI_FC_LLC_ASYNC 0x50 /* Async. LLC frame */
69 #define FDDI_FC_LLC_ASYNC_MIN FDDI_FC_LLC_ASYNC
70 #define FDDI_FC_LLC_ASYNC_DEF 0x54
71 #define FDDI_FC_LLC_ASYNC_MAX 0x5f
72 #define FDDI_FC_LLC_SYNC 0xd0 /* Sync. LLC frame */
73 #define FDDI_FC_LLC_SYNC_MIN FDDI_FC_LLC_SYNC
74 #define FDDI_FC_LLC_SYNC_MAX 0xd7
75 #define FDDI_FC_IMP_ASYNC 0x60 /* Implementor Async. */
76 #define FDDI_FC_IMP_ASYNC_MIN FDDI_FC_IMP_ASYNC
77 #define FDDI_FC_IMP_ASYNC_MAX 0x6f
78 #define FDDI_FC_IMP_SYNC 0xe0 /* Implementor Synch. */
80 #define FDDI_FC_CLFF 0xF0 /* Class/Length/Format bits */
81 #define FDDI_FC_ZZZZ 0x0F /* Control bits */
84 * Async frame ZZZZ bits:
86 #define FDDI_FC_ASYNC_R 0x08 /* Reserved */
87 #define FDDI_FC_ASYNC_PRI 0x07 /* Priority */
89 #define FDDI_HEADER_SIZE 13
94 #define FDDI_P_DHOST 1
95 #define FDDI_P_SHOST 7
97 static dissector_handle_t llc_handle;
100 swap_mac_addr(u_char *swapped_addr, const u_char *orig_addr)
104 for (i = 0; i < 6; i++) {
105 swapped_addr[i] = BIT_SWAP(orig_addr[i]);
111 capture_fddi(const u_char *pd, packet_counts *ld)
115 if (!BYTES_ARE_IN_FRAME(0, FDDI_HEADER_SIZE)) {
119 offset = FDDI_HEADER_SIZE;
121 fc = (int) pd[FDDI_P_FC];
125 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
127 case FDDI_FC_LLC_ASYNC + 0 :
128 case FDDI_FC_LLC_ASYNC + 1 :
129 case FDDI_FC_LLC_ASYNC + 2 :
130 case FDDI_FC_LLC_ASYNC + 3 :
131 case FDDI_FC_LLC_ASYNC + 4 :
132 case FDDI_FC_LLC_ASYNC + 5 :
133 case FDDI_FC_LLC_ASYNC + 6 :
134 case FDDI_FC_LLC_ASYNC + 7 :
135 case FDDI_FC_LLC_ASYNC + 8 :
136 case FDDI_FC_LLC_ASYNC + 9 :
137 case FDDI_FC_LLC_ASYNC + 10 :
138 case FDDI_FC_LLC_ASYNC + 11 :
139 case FDDI_FC_LLC_ASYNC + 12 :
140 case FDDI_FC_LLC_ASYNC + 13 :
141 case FDDI_FC_LLC_ASYNC + 14 :
142 case FDDI_FC_LLC_ASYNC + 15 :
143 capture_llc(pd, offset, ld);
154 fddifc_to_str(int fc)
156 static gchar strbuf[128+1];
160 case FDDI_FC_VOID: /* Void frame */
163 case FDDI_FC_NRT: /* Nonrestricted token */
164 return "Nonrestricted token";
166 case FDDI_FC_RT: /* Restricted token */
167 return "Restricted token";
169 case FDDI_FC_SMT_INFO: /* SMT Info */
172 case FDDI_FC_SMT_NSA: /* SMT Next station adrs */
173 return "SMT Next station address";
175 case FDDI_FC_MAC_BEACON: /* MAC Beacon frame */
178 case FDDI_FC_MAC_CLAIM: /* MAC Claim frame */
179 return "MAC claim token";
182 switch (fc & FDDI_FC_CLFF) {
185 sprintf(strbuf, "MAC frame, control %x", fc & FDDI_FC_ZZZZ);
189 sprintf(strbuf, "SMT frame, control %x", fc & FDDI_FC_ZZZZ);
192 case FDDI_FC_LLC_ASYNC:
193 if (fc & FDDI_FC_ASYNC_R)
194 sprintf(strbuf, "Async LLC frame, control %x", fc & FDDI_FC_ZZZZ);
196 sprintf(strbuf, "Async LLC frame, priority %d",
197 fc & FDDI_FC_ASYNC_PRI);
200 case FDDI_FC_LLC_SYNC:
201 if (fc & FDDI_FC_ZZZZ) {
202 sprintf(strbuf, "Sync LLC frame, control %x", fc & FDDI_FC_ZZZZ);
205 return "Sync LLC frame";
207 case FDDI_FC_IMP_ASYNC:
208 sprintf(strbuf, "Implementor async frame, control %x",
212 case FDDI_FC_IMP_SYNC:
213 sprintf(strbuf, "Implementor sync frame, control %x",
219 return "Unknown frame type";
226 dissect_fddi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
230 proto_tree *fh_tree = NULL;
233 static u_char src[6], dst[6];
234 u_char src_swapped[6], dst_swapped[6];
237 CHECK_DISPLAY_AS_DATA(proto_fddi, tvb, pinfo, tree);
239 pinfo->current_proto = "FDDI";
240 if (check_col(pinfo->fd, COL_PROTOCOL))
241 col_set_str(pinfo->fd, COL_PROTOCOL, "FDDI");
243 fc = (int) tvb_get_guint8(tvb, FDDI_P_FC);
244 fc_str = fddifc_to_str(fc);
246 if (check_col(pinfo->fd, COL_INFO))
247 col_add_str(pinfo->fd, COL_INFO, fc_str);
250 ti = proto_tree_add_protocol_format(tree, proto_fddi, tvb, 0, FDDI_HEADER_SIZE,
251 "Fiber Distributed Data Interface, %s", fc_str);
252 fh_tree = proto_item_add_subtree(ti, ett_fddi);
253 proto_tree_add_uint(fh_tree, hf_fddi_fc, tvb, FDDI_P_FC, 1, fc);
256 /* Extract the destination address, possibly bit-swapping it. */
258 swap_mac_addr(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
260 memcpy(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6), sizeof dst);
261 swap_mac_addr(dst_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
263 /* XXX - copy them to some buffer associated with "pi", rather than
264 just making "dst" static? */
265 SET_ADDRESS(&pi.dl_dst, AT_ETHER, 6, &dst[0]);
266 SET_ADDRESS(&pi.dst, AT_ETHER, 6, &dst[0]);
269 proto_tree_add_ether(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst);
270 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst);
272 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
273 proto_tree_add_ether_hidden(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst_swapped);
274 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst_swapped);
277 /* Extract the source address, possibly bit-swapping it. */
279 swap_mac_addr(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
281 memcpy(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6), sizeof src);
282 swap_mac_addr(src_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
284 /* XXX - copy them to some buffer associated with "pi", rather than
285 just making "src" static? */
286 SET_ADDRESS(&pi.dl_src, AT_ETHER, 6, &src[0]);
287 SET_ADDRESS(&pi.src, AT_ETHER, 6, &src[0]);
290 proto_tree_add_ether(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src);
291 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src);
293 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
294 proto_tree_add_ether_hidden(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src_swapped);
295 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src_swapped);
298 next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE, -1, -1);
302 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
304 case FDDI_FC_LLC_ASYNC + 0 :
305 case FDDI_FC_LLC_ASYNC + 1 :
306 case FDDI_FC_LLC_ASYNC + 2 :
307 case FDDI_FC_LLC_ASYNC + 3 :
308 case FDDI_FC_LLC_ASYNC + 4 :
309 case FDDI_FC_LLC_ASYNC + 5 :
310 case FDDI_FC_LLC_ASYNC + 6 :
311 case FDDI_FC_LLC_ASYNC + 7 :
312 case FDDI_FC_LLC_ASYNC + 8 :
313 case FDDI_FC_LLC_ASYNC + 9 :
314 case FDDI_FC_LLC_ASYNC + 10 :
315 case FDDI_FC_LLC_ASYNC + 11 :
316 case FDDI_FC_LLC_ASYNC + 12 :
317 case FDDI_FC_LLC_ASYNC + 13 :
318 case FDDI_FC_LLC_ASYNC + 14 :
319 case FDDI_FC_LLC_ASYNC + 15 :
320 call_dissector(llc_handle, next_tvb, pinfo, tree);
324 dissect_data(next_tvb, 0, pinfo, tree);
332 dissect_fddi_bitswapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
334 dissect_fddi(tvb, pinfo, tree, TRUE);
338 dissect_fddi_not_bitswapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
340 dissect_fddi(tvb, pinfo, tree, FALSE);
344 proto_register_fddi(void)
346 static hf_register_info hf[] = {
349 * XXX - we want this guy to have his own private formatting
350 * routine, using "fc_to_str()"; if "fc_to_str()" returns
351 * NULL, just show the hex value, else show the string.
354 { "Frame Control", "fddi.fc", FT_UINT8, BASE_HEX, NULL, 0x0,
358 { "Destination", "fddi.dst", FT_ETHER, BASE_NONE, NULL, 0x0,
359 "Destination Hardware Address" }},
362 { "Source", "fddi.src", FT_ETHER, BASE_NONE, NULL, 0x0,
366 { "Source or Destination Address", "fddi.addr", FT_ETHER, BASE_NONE, NULL, 0x0,
367 "Source or Destination Hardware Address" }},
370 static gint *ett[] = {
374 proto_fddi = proto_register_protocol("Fiber Distributed Data Interface",
376 proto_register_field_array(proto_fddi, hf, array_length(hf));
377 proto_register_subtree_array(ett, array_length(ett));
381 proto_reg_handoff_fddi(void)
384 * Get a handle for the LLC dissector.
386 llc_handle = find_dissector("llc");
388 dissector_add("wtap_encap", WTAP_ENCAP_FDDI, dissect_fddi_not_bitswapped);
389 dissector_add("wtap_encap", WTAP_ENCAP_FDDI_BITSWAPPED, dissect_fddi_bitswapped);