2 * Routines for FDDI packet disassembly
4 * Laurent Deniel <laurent.deniel@free.fr>
6 * $Id: packet-fddi.c,v 1.62 2003/08/29 10:59:09 sahlberg Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/bitswap.h>
35 #include <epan/packet.h>
37 #include "packet-fddi.h"
38 #include "packet-llc.h"
41 #include <epan/resolv.h>
43 static int proto_fddi = -1;
44 static int hf_fddi_fc = -1;
45 static int hf_fddi_fc_clf = -1;
46 static int hf_fddi_fc_prio = -1;
47 static int hf_fddi_fc_smt_subtype = -1;
48 static int hf_fddi_fc_mac_subtype = -1;
49 static int hf_fddi_dst = -1;
50 static int hf_fddi_src = -1;
51 static int hf_fddi_addr = -1;
53 static gint ett_fddi = -1;
54 static gint ett_fddi_fc = -1;
56 static int fddi_tap = -1;
58 static gboolean fddi_padding = FALSE;
60 #define FDDI_PADDING ((fddi_padding) ? 3 : 0)
62 /* FDDI Frame Control values */
64 #define FDDI_FC_VOID 0x00 /* Void frame */
65 #define FDDI_FC_NRT 0x80 /* Nonrestricted token */
66 #define FDDI_FC_RT 0xc0 /* Restricted token */
67 #define FDDI_FC_MAC 0xc0 /* MAC frame */
68 #define FDDI_FC_SMT 0x40 /* SMT frame */
69 #define FDDI_FC_SMT_INFO 0x41 /* SMT Info */
70 #define FDDI_FC_SMT_NSA 0x4F /* SMT Next station adrs */
71 #define FDDI_FC_SMT_MIN FDDI_FC_SMT_INFO
72 #define FDDI_FC_SMT_MAX FDDI_FC_SMT_NSA
73 #define FDDI_FC_MAC_MIN 0xc1
74 #define FDDI_FC_MAC_BEACON 0xc2 /* MAC Beacon frame */
75 #define FDDI_FC_MAC_CLAIM 0xc3 /* MAC Claim frame */
76 #define FDDI_FC_MAC_MAX 0xcf
77 #define FDDI_FC_LLC_ASYNC 0x50 /* Async. LLC frame */
78 #define FDDI_FC_LLC_ASYNC_MIN FDDI_FC_LLC_ASYNC
79 #define FDDI_FC_LLC_ASYNC_DEF 0x54
80 #define FDDI_FC_LLC_ASYNC_MAX 0x5f
81 #define FDDI_FC_LLC_SYNC 0xd0 /* Sync. LLC frame */
82 #define FDDI_FC_LLC_SYNC_MIN FDDI_FC_LLC_SYNC
83 #define FDDI_FC_LLC_SYNC_MAX 0xd7
84 #define FDDI_FC_IMP_ASYNC 0x60 /* Implementor Async. */
85 #define FDDI_FC_IMP_ASYNC_MIN FDDI_FC_IMP_ASYNC
86 #define FDDI_FC_IMP_ASYNC_MAX 0x6f
87 #define FDDI_FC_IMP_SYNC 0xe0 /* Implementor Synch. */
89 #define FDDI_FC_CLFF 0xF0 /* Class/Length/Format bits */
90 #define FDDI_FC_ZZZZ 0x0F /* Control bits */
93 * Async frame ZZZZ bits:
95 #define FDDI_FC_ASYNC_R 0x08 /* Reserved */
96 #define FDDI_FC_ASYNC_PRI 0x07 /* Priority */
98 #define CLFF_BITS(fc) (((fc) & FDDI_FC_CLFF) >> 4)
99 #define ZZZZ_BITS(fc) ((fc) & FDDI_FC_ZZZZ)
101 static const value_string clf_vals[] = {
102 { CLFF_BITS(FDDI_FC_VOID), "Void" },
103 { CLFF_BITS(FDDI_FC_SMT), "SMT" },
104 { CLFF_BITS(FDDI_FC_LLC_ASYNC), "Async LLC" },
105 { CLFF_BITS(FDDI_FC_IMP_ASYNC), "Implementor Async" },
106 { CLFF_BITS(FDDI_FC_NRT), "Nonrestricted Token" },
107 { CLFF_BITS(FDDI_FC_MAC), "MAC" },
108 { CLFF_BITS(FDDI_FC_LLC_SYNC), "Sync LLC" },
109 { CLFF_BITS(FDDI_FC_IMP_SYNC), "Implementor Sync" },
113 static const value_string smt_subtype_vals[] = {
114 { ZZZZ_BITS(FDDI_FC_SMT_INFO), "Info" },
115 { ZZZZ_BITS(FDDI_FC_SMT_NSA), "Next Station Address" },
119 static const value_string mac_subtype_vals[] = {
120 { ZZZZ_BITS(FDDI_FC_MAC_BEACON), "Beacon" },
121 { ZZZZ_BITS(FDDI_FC_MAC_CLAIM), "Claim" },
125 #define FDDI_HEADER_SIZE 13
127 /* field positions */
130 #define FDDI_P_DHOST 1
131 #define FDDI_P_SHOST 7
133 static dissector_handle_t llc_handle;
134 static dissector_handle_t data_handle;
137 swap_mac_addr(guint8 *swapped_addr, const guint8 *orig_addr)
141 for (i = 0; i < 6; i++) {
142 swapped_addr[i] = BIT_SWAP(orig_addr[i]);
148 capture_fddi(const guchar *pd, int len, packet_counts *ld)
152 if (!BYTES_ARE_IN_FRAME(0, len, FDDI_HEADER_SIZE + FDDI_PADDING)) {
156 offset = FDDI_PADDING + FDDI_HEADER_SIZE;
158 fc = (int) pd[FDDI_P_FC+FDDI_PADDING];
162 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
164 case FDDI_FC_LLC_ASYNC + 0 :
165 case FDDI_FC_LLC_ASYNC + 1 :
166 case FDDI_FC_LLC_ASYNC + 2 :
167 case FDDI_FC_LLC_ASYNC + 3 :
168 case FDDI_FC_LLC_ASYNC + 4 :
169 case FDDI_FC_LLC_ASYNC + 5 :
170 case FDDI_FC_LLC_ASYNC + 6 :
171 case FDDI_FC_LLC_ASYNC + 7 :
172 case FDDI_FC_LLC_ASYNC + 8 :
173 case FDDI_FC_LLC_ASYNC + 9 :
174 case FDDI_FC_LLC_ASYNC + 10 :
175 case FDDI_FC_LLC_ASYNC + 11 :
176 case FDDI_FC_LLC_ASYNC + 12 :
177 case FDDI_FC_LLC_ASYNC + 13 :
178 case FDDI_FC_LLC_ASYNC + 14 :
179 case FDDI_FC_LLC_ASYNC + 15 :
180 capture_llc(pd, offset, len, ld);
191 fddifc_to_str(int fc)
193 static gchar strbuf[128+1];
197 case FDDI_FC_VOID: /* Void frame */
200 case FDDI_FC_NRT: /* Nonrestricted token */
201 return "Nonrestricted token";
203 case FDDI_FC_RT: /* Restricted token */
204 return "Restricted token";
206 case FDDI_FC_SMT_INFO: /* SMT Info */
209 case FDDI_FC_SMT_NSA: /* SMT Next station adrs */
210 return "SMT Next station address";
212 case FDDI_FC_MAC_BEACON: /* MAC Beacon frame */
215 case FDDI_FC_MAC_CLAIM: /* MAC Claim frame */
216 return "MAC claim token";
219 switch (fc & FDDI_FC_CLFF) {
222 sprintf(strbuf, "MAC frame, control %x", fc & FDDI_FC_ZZZZ);
226 sprintf(strbuf, "SMT frame, control %x", fc & FDDI_FC_ZZZZ);
229 case FDDI_FC_LLC_ASYNC:
230 if (fc & FDDI_FC_ASYNC_R)
231 sprintf(strbuf, "Async LLC frame, control %x", fc & FDDI_FC_ZZZZ);
233 sprintf(strbuf, "Async LLC frame, priority %d",
234 fc & FDDI_FC_ASYNC_PRI);
237 case FDDI_FC_LLC_SYNC:
238 if (fc & FDDI_FC_ZZZZ) {
239 sprintf(strbuf, "Sync LLC frame, control %x", fc & FDDI_FC_ZZZZ);
242 return "Sync LLC frame";
244 case FDDI_FC_IMP_ASYNC:
245 sprintf(strbuf, "Implementor async frame, control %x",
249 case FDDI_FC_IMP_SYNC:
250 sprintf(strbuf, "Implementor sync frame, control %x",
256 return "Unknown frame type";
263 dissect_fddi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
266 proto_tree *fh_tree = NULL;
270 static guchar src[6], dst[6];
271 guchar src_swapped[6], dst_swapped[6];
273 static fddi_hdr fddihdrs[4];
274 static int fddihdr_num=0;
281 fddihdr=&fddihdrs[fddihdr_num];
283 if (check_col(pinfo->cinfo, COL_PROTOCOL))
284 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FDDI");
286 fddihdr->fc = tvb_get_guint8(tvb, FDDI_P_FC + FDDI_PADDING);
287 fc_str = fddifc_to_str(fddihdr->fc);
289 if (check_col(pinfo->cinfo, COL_INFO))
290 col_add_str(pinfo->cinfo, COL_INFO, fc_str);
293 ti = proto_tree_add_protocol_format(tree, proto_fddi, tvb, 0, FDDI_HEADER_SIZE+FDDI_PADDING,
294 "Fiber Distributed Data Interface, %s", fc_str);
295 fh_tree = proto_item_add_subtree(ti, ett_fddi);
296 ti = proto_tree_add_uint_format(fh_tree, hf_fddi_fc, tvb, FDDI_P_FC + FDDI_PADDING, 1, fddihdr->fc,
297 "Frame Control: 0x%02x (%s)", fddihdr->fc, fc_str);
298 fc_tree = proto_item_add_subtree(ti, ett_fddi_fc);
299 proto_tree_add_uint(fc_tree, hf_fddi_fc_clf, tvb, FDDI_P_FC + FDDI_PADDING, 1, fddihdr->fc);
300 switch ((fddihdr->fc) & FDDI_FC_CLFF) {
303 proto_tree_add_uint(fc_tree, hf_fddi_fc_smt_subtype, tvb, FDDI_P_FC + FDDI_PADDING, 1, fddihdr->fc);
307 if (fddihdr->fc != FDDI_FC_RT)
308 proto_tree_add_uint(fc_tree, hf_fddi_fc_mac_subtype, tvb, FDDI_P_FC + FDDI_PADDING, 1, fddihdr->fc);
311 case FDDI_FC_LLC_ASYNC:
312 if (!((fddihdr->fc) & FDDI_FC_ASYNC_R))
313 proto_tree_add_uint(fc_tree, hf_fddi_fc_prio, tvb, FDDI_P_FC + FDDI_PADDING, 1, fddihdr->fc);
318 /* Extract the destination address, possibly bit-swapping it. */
320 swap_mac_addr(dst, tvb_get_ptr(tvb, FDDI_P_DHOST + FDDI_PADDING, 6));
322 memcpy(dst, tvb_get_ptr(tvb, FDDI_P_DHOST + FDDI_PADDING, 6), sizeof dst);
323 swap_mac_addr(dst_swapped, tvb_get_ptr(tvb, FDDI_P_DHOST + FDDI_PADDING, 6));
325 /* XXX - copy them to some buffer associated with "pi", rather than
326 just making "dst" static? */
327 SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, &dst[0]);
328 SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, &dst[0]);
329 SET_ADDRESS(&fddihdr->dst, AT_ETHER, 6, &dst[0]);
332 proto_tree_add_ether(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST + FDDI_PADDING, 6, dst);
333 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST + FDDI_PADDING, 6, dst);
335 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
336 proto_tree_add_ether_hidden(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST + FDDI_PADDING, 6, dst_swapped);
337 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST + FDDI_PADDING, 6, dst_swapped);
340 /* Extract the source address, possibly bit-swapping it. */
342 swap_mac_addr(src, tvb_get_ptr(tvb, FDDI_P_SHOST + FDDI_PADDING, 6));
344 memcpy(src, tvb_get_ptr(tvb, FDDI_P_SHOST + FDDI_PADDING, 6), sizeof src);
345 swap_mac_addr(src_swapped, tvb_get_ptr(tvb, FDDI_P_SHOST + FDDI_PADDING, 6));
347 /* XXX - copy them to some buffer associated with "pi", rather than
348 just making "src" static? */
349 SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, &src[0]);
350 SET_ADDRESS(&pinfo->src, AT_ETHER, 6, &src[0]);
351 SET_ADDRESS(&fddihdr->src, AT_ETHER, 6, &src[0]);
354 proto_tree_add_ether(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST + FDDI_PADDING, 6, src);
355 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST + FDDI_PADDING, 6, src);
357 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
358 proto_tree_add_ether_hidden(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST + FDDI_PADDING, 6, src_swapped);
359 proto_tree_add_ether_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST + FDDI_PADDING, 6, src_swapped);
362 next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE + FDDI_PADDING, -1, -1);
365 tap_queue_packet(fddi_tap, pinfo, fddihdr);
367 switch (fddihdr->fc) {
369 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
371 case FDDI_FC_LLC_ASYNC + 0 :
372 case FDDI_FC_LLC_ASYNC + 1 :
373 case FDDI_FC_LLC_ASYNC + 2 :
374 case FDDI_FC_LLC_ASYNC + 3 :
375 case FDDI_FC_LLC_ASYNC + 4 :
376 case FDDI_FC_LLC_ASYNC + 5 :
377 case FDDI_FC_LLC_ASYNC + 6 :
378 case FDDI_FC_LLC_ASYNC + 7 :
379 case FDDI_FC_LLC_ASYNC + 8 :
380 case FDDI_FC_LLC_ASYNC + 9 :
381 case FDDI_FC_LLC_ASYNC + 10 :
382 case FDDI_FC_LLC_ASYNC + 11 :
383 case FDDI_FC_LLC_ASYNC + 12 :
384 case FDDI_FC_LLC_ASYNC + 13 :
385 case FDDI_FC_LLC_ASYNC + 14 :
386 case FDDI_FC_LLC_ASYNC + 15 :
387 call_dissector(llc_handle, next_tvb, pinfo, tree);
391 call_dissector(data_handle,next_tvb, pinfo, tree);
399 dissect_fddi_bitswapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
401 dissect_fddi(tvb, pinfo, tree, TRUE);
405 dissect_fddi_not_bitswapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
407 dissect_fddi(tvb, pinfo, tree, FALSE);
411 proto_register_fddi(void)
413 static hf_register_info hf[] = {
416 * XXX - we want this guy to have his own private formatting
417 * routine, using "fc_to_str()"; if "fc_to_str()" returns
418 * NULL, just show the hex value, else show the string.
421 { "Frame Control", "fddi.fc", FT_UINT8, BASE_HEX, NULL, 0x0,
425 { "Class/Length/Format", "fddi.fc.clf", FT_UINT8, BASE_HEX, VALS(clf_vals), FDDI_FC_CLFF,
429 { "Priority", "fddi.fc.prio", FT_UINT8, BASE_DEC, NULL, FDDI_FC_ASYNC_PRI,
432 { &hf_fddi_fc_smt_subtype,
433 { "SMT Subtype", "fddi.fc.smt_subtype", FT_UINT8, BASE_DEC, VALS(smt_subtype_vals), FDDI_FC_ZZZZ,
436 { &hf_fddi_fc_mac_subtype,
437 { "MAC Subtype", "fddi.fc.mac_subtype", FT_UINT8, BASE_DEC, VALS(mac_subtype_vals), FDDI_FC_ZZZZ,
441 { "Destination", "fddi.dst", FT_ETHER, BASE_NONE, NULL, 0x0,
442 "Destination Hardware Address", HFILL }},
445 { "Source", "fddi.src", FT_ETHER, BASE_NONE, NULL, 0x0,
449 { "Source or Destination Address", "fddi.addr", FT_ETHER, BASE_NONE, NULL, 0x0,
450 "Source or Destination Hardware Address", HFILL }},
453 static gint *ett[] = {
458 module_t *fddi_module;
460 proto_fddi = proto_register_protocol("Fiber Distributed Data Interface",
462 proto_register_field_array(proto_fddi, hf, array_length(hf));
463 proto_register_subtree_array(ett, array_length(ett));
466 * Called from various dissectors for encapsulated FDDI frames.
467 * We assume the MAC addresses in them aren't bitswapped.
469 register_dissector("fddi", dissect_fddi_not_bitswapped, proto_fddi);
471 fddi_module = prefs_register_protocol(proto_fddi, NULL);
472 prefs_register_bool_preference(fddi_module, "padding",
473 "Add 3-byte padding to all FDDI packets",
474 "Whether the FDDI dissector should add 3-byte padding to all "
475 "captured FDDI packets (useful with e.g. Tru64 UNIX tcpdump)",
478 fddi_tap = register_tap("fddi");
482 proto_reg_handoff_fddi(void)
484 dissector_handle_t fddi_handle, fddi_bitswapped_handle;
487 * Get a handle for the LLC dissector.
489 llc_handle = find_dissector("llc");
490 data_handle = find_dissector("data");
492 fddi_handle = find_dissector("fddi");
493 dissector_add("wtap_encap", WTAP_ENCAP_FDDI, fddi_handle);
494 fddi_bitswapped_handle =
495 create_dissector_handle(dissect_fddi_bitswapped, proto_fddi);
496 dissector_add("wtap_encap", WTAP_ENCAP_FDDI_BITSWAPPED,
497 fddi_bitswapped_handle);