2 * Routines for FDDI packet disassembly
4 * ANSI Standard X3T9.5/88-139, Rev 4.0
6 * ISO Standards 9314-N (N = 1 for PHY, N = 2 for MAC, N = 6 for SMT, etc.)
8 * Laurent Deniel <laurent.deniel@free.fr>
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include <epan/packet.h>
36 #include <epan/bitswap.h>
37 #include <epan/prefs.h>
38 #include "packet-fddi.h"
39 #include "packet-llc.h"
42 #include <epan/addr_resolv.h>
44 static int proto_fddi
= -1;
45 static int hf_fddi_fc
= -1;
46 static int hf_fddi_fc_clf
= -1;
47 static int hf_fddi_fc_prio
= -1;
48 static int hf_fddi_fc_smt_subtype
= -1;
49 static int hf_fddi_fc_mac_subtype
= -1;
50 static int hf_fddi_dst
= -1;
51 static int hf_fddi_src
= -1;
52 static int hf_fddi_addr
= -1;
54 static gint ett_fddi
= -1;
55 static gint ett_fddi_fc
= -1;
57 static int fddi_tap
= -1;
59 static gboolean fddi_padding
= FALSE
;
61 #define FDDI_PADDING ((fddi_padding) ? 3 : 0)
63 /* FDDI Frame Control values */
65 #define FDDI_FC_VOID 0x00 /* Void frame */
66 #define FDDI_FC_NRT 0x80 /* Nonrestricted token */
67 #define FDDI_FC_RT 0xc0 /* Restricted token */
68 #define FDDI_FC_MAC 0xc0 /* MAC frame */
69 #define FDDI_FC_SMT 0x40 /* SMT frame */
70 #define FDDI_FC_SMT_INFO 0x41 /* SMT Info */
71 #define FDDI_FC_SMT_NSA 0x4F /* SMT Next station adrs */
72 #define FDDI_FC_SMT_MIN FDDI_FC_SMT_INFO
73 #define FDDI_FC_SMT_MAX FDDI_FC_SMT_NSA
74 #define FDDI_FC_MAC_MIN 0xc1
75 #define FDDI_FC_MAC_BEACON 0xc2 /* MAC Beacon frame */
76 #define FDDI_FC_MAC_CLAIM 0xc3 /* MAC Claim frame */
77 #define FDDI_FC_MAC_MAX 0xcf
78 #define FDDI_FC_LLC_ASYNC 0x50 /* Async. LLC frame */
79 #define FDDI_FC_LLC_ASYNC_MIN FDDI_FC_LLC_ASYNC
80 #define FDDI_FC_LLC_ASYNC_DEF 0x54
81 #define FDDI_FC_LLC_ASYNC_MAX 0x5f
82 #define FDDI_FC_LLC_SYNC 0xd0 /* Sync. LLC frame */
83 #define FDDI_FC_LLC_SYNC_MIN FDDI_FC_LLC_SYNC
84 #define FDDI_FC_LLC_SYNC_MAX 0xd7
85 #define FDDI_FC_IMP_ASYNC 0x60 /* Implementor Async. */
86 #define FDDI_FC_IMP_ASYNC_MIN FDDI_FC_IMP_ASYNC
87 #define FDDI_FC_IMP_ASYNC_MAX 0x6f
88 #define FDDI_FC_IMP_SYNC 0xe0 /* Implementor Synch. */
90 #define FDDI_FC_CLFF 0xF0 /* Class/Length/Format bits */
91 #define FDDI_FC_ZZZZ 0x0F /* Control bits */
94 * Async frame ZZZZ bits:
96 #define FDDI_FC_ASYNC_R 0x08 /* Reserved */
97 #define FDDI_FC_ASYNC_PRI 0x07 /* Priority */
99 #define CLFF_BITS(fc) (((fc) & FDDI_FC_CLFF) >> 4)
100 #define ZZZZ_BITS(fc) ((fc) & FDDI_FC_ZZZZ)
102 static const value_string clf_vals
[] = {
103 { CLFF_BITS(FDDI_FC_VOID
), "Void" },
104 { CLFF_BITS(FDDI_FC_SMT
), "SMT" },
105 { CLFF_BITS(FDDI_FC_LLC_ASYNC
), "Async LLC" },
106 { CLFF_BITS(FDDI_FC_IMP_ASYNC
), "Implementor Async" },
107 { CLFF_BITS(FDDI_FC_NRT
), "Nonrestricted Token" },
108 { CLFF_BITS(FDDI_FC_MAC
), "MAC" },
109 { CLFF_BITS(FDDI_FC_LLC_SYNC
), "Sync LLC" },
110 { CLFF_BITS(FDDI_FC_IMP_SYNC
), "Implementor Sync" },
114 static const value_string smt_subtype_vals
[] = {
115 { ZZZZ_BITS(FDDI_FC_SMT_INFO
), "Info" },
116 { ZZZZ_BITS(FDDI_FC_SMT_NSA
), "Next Station Address" },
120 static const value_string mac_subtype_vals
[] = {
121 { ZZZZ_BITS(FDDI_FC_MAC_BEACON
), "Beacon" },
122 { ZZZZ_BITS(FDDI_FC_MAC_CLAIM
), "Claim" },
126 #define FDDI_HEADER_SIZE 13
128 /* field positions */
131 #define FDDI_P_DHOST 1
132 #define FDDI_P_SHOST 7
134 static dissector_handle_t llc_handle
;
135 static dissector_handle_t data_handle
;
138 swap_mac_addr(guint8
*swapped_addr
, tvbuff_t
*tvb
, gint offset
)
142 for (i
= 0; i
< 6; i
++) {
143 swapped_addr
[i
] = BIT_SWAP(tvb_get_guint8(tvb
, offset
+i
));
149 capture_fddi(const guchar
*pd
, int len
, packet_counts
*ld
)
153 if (!BYTES_ARE_IN_FRAME(0, len
, FDDI_HEADER_SIZE
+ FDDI_PADDING
)) {
157 offset
= FDDI_PADDING
+ FDDI_HEADER_SIZE
;
159 fc
= (int) pd
[FDDI_P_FC
+FDDI_PADDING
];
163 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
165 case FDDI_FC_LLC_ASYNC
+ 0 :
166 case FDDI_FC_LLC_ASYNC
+ 1 :
167 case FDDI_FC_LLC_ASYNC
+ 2 :
168 case FDDI_FC_LLC_ASYNC
+ 3 :
169 case FDDI_FC_LLC_ASYNC
+ 4 :
170 case FDDI_FC_LLC_ASYNC
+ 5 :
171 case FDDI_FC_LLC_ASYNC
+ 6 :
172 case FDDI_FC_LLC_ASYNC
+ 7 :
173 case FDDI_FC_LLC_ASYNC
+ 8 :
174 case FDDI_FC_LLC_ASYNC
+ 9 :
175 case FDDI_FC_LLC_ASYNC
+ 10 :
176 case FDDI_FC_LLC_ASYNC
+ 11 :
177 case FDDI_FC_LLC_ASYNC
+ 12 :
178 case FDDI_FC_LLC_ASYNC
+ 13 :
179 case FDDI_FC_LLC_ASYNC
+ 14 :
180 case FDDI_FC_LLC_ASYNC
+ 15 :
181 capture_llc(pd
, offset
, len
, ld
);
192 fddifc_to_str(int fc
)
194 static gchar strbuf
[128+1];
198 case FDDI_FC_VOID
: /* Void frame */
201 case FDDI_FC_NRT
: /* Nonrestricted token */
202 return "Nonrestricted token";
204 case FDDI_FC_RT
: /* Restricted token */
205 return "Restricted token";
207 case FDDI_FC_SMT_INFO
: /* SMT Info */
210 case FDDI_FC_SMT_NSA
: /* SMT Next station adrs */
211 return "SMT Next station address";
213 case FDDI_FC_MAC_BEACON
: /* MAC Beacon frame */
216 case FDDI_FC_MAC_CLAIM
: /* MAC Claim frame */
217 return "MAC claim token";
220 switch (fc
& FDDI_FC_CLFF
) {
223 g_snprintf(strbuf
, sizeof(strbuf
), "MAC frame, control %x", fc
& FDDI_FC_ZZZZ
);
227 g_snprintf(strbuf
, sizeof(strbuf
), "SMT frame, control %x", fc
& FDDI_FC_ZZZZ
);
230 case FDDI_FC_LLC_ASYNC
:
231 if (fc
& FDDI_FC_ASYNC_R
)
232 g_snprintf(strbuf
, sizeof(strbuf
), "Async LLC frame, control %x", fc
& FDDI_FC_ZZZZ
);
234 g_snprintf(strbuf
, sizeof(strbuf
), "Async LLC frame, priority %d",
235 fc
& FDDI_FC_ASYNC_PRI
);
238 case FDDI_FC_LLC_SYNC
:
239 if (fc
& FDDI_FC_ZZZZ
) {
240 g_snprintf(strbuf
, sizeof(strbuf
), "Sync LLC frame, control %x", fc
& FDDI_FC_ZZZZ
);
243 return "Sync LLC frame";
245 case FDDI_FC_IMP_ASYNC
:
246 g_snprintf(strbuf
, sizeof(strbuf
), "Implementor async frame, control %x",
250 case FDDI_FC_IMP_SYNC
:
251 g_snprintf(strbuf
, sizeof(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
;
267 proto_item
*ti
, *hidden_item
;
270 static guchar src
[6], dst
[6]; /* has to be static due to SET_ADDRESS */
271 guchar src_swapped
[6], dst_swapped
[6];
273 static fddi_hdr fddihdrs
[4];
274 static int fddihdr_num
= 0;
278 if (fddihdr_num
>= 4) {
281 fddihdr
= &fddihdrs
[fddihdr_num
];
283 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FDDI");
285 fddihdr
->fc
= tvb_get_guint8(tvb
, FDDI_P_FC
+ FDDI_PADDING
);
286 fc_str
= fddifc_to_str(fddihdr
->fc
);
288 col_add_str(pinfo
->cinfo
, COL_INFO
, fc_str
);
291 ti
= proto_tree_add_protocol_format(tree
, proto_fddi
, tvb
, 0, FDDI_HEADER_SIZE
+FDDI_PADDING
,
292 "Fiber Distributed Data Interface, %s", fc_str
);
293 fh_tree
= proto_item_add_subtree(ti
, ett_fddi
);
294 ti
= proto_tree_add_uint_format_value(fh_tree
, hf_fddi_fc
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
,
295 "0x%02x (%s)", fddihdr
->fc
, fc_str
);
296 fc_tree
= proto_item_add_subtree(ti
, ett_fddi_fc
);
297 proto_tree_add_uint(fc_tree
, hf_fddi_fc_clf
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
298 switch ((fddihdr
->fc
) & FDDI_FC_CLFF
) {
301 proto_tree_add_uint(fc_tree
, hf_fddi_fc_smt_subtype
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
305 if (fddihdr
->fc
!= FDDI_FC_RT
)
306 proto_tree_add_uint(fc_tree
, hf_fddi_fc_mac_subtype
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
309 case FDDI_FC_LLC_ASYNC
:
310 if (!((fddihdr
->fc
) & FDDI_FC_ASYNC_R
))
311 proto_tree_add_uint(fc_tree
, hf_fddi_fc_prio
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
316 /* Extract the destination address, possibly bit-swapping it. */
318 swap_mac_addr(dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
);
320 tvb_memcpy(tvb
, dst
, FDDI_P_DHOST
+ FDDI_PADDING
, sizeof(dst
));
321 swap_mac_addr(dst_swapped
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
);
323 /* XXX - copy them to some buffer associated with "pi", rather than
324 just making "dst" static? */
325 SET_ADDRESS(&pinfo
->dl_dst
, AT_ETHER
, 6, &dst
[0]);
326 SET_ADDRESS(&pinfo
->dst
, AT_ETHER
, 6, &dst
[0]);
327 SET_ADDRESS(&fddihdr
->dst
, AT_ETHER
, 6, &dst
[0]);
330 proto_tree_add_ether(fh_tree
, hf_fddi_dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst
);
331 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst
);
332 PROTO_ITEM_SET_HIDDEN(hidden_item
);
334 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
335 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst_swapped
);
336 PROTO_ITEM_SET_HIDDEN(hidden_item
);
337 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst_swapped
);
338 PROTO_ITEM_SET_HIDDEN(hidden_item
);
341 /* Extract the source address, possibly bit-swapping it. */
343 swap_mac_addr(src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
);
345 tvb_memcpy(tvb
, src
, FDDI_P_SHOST
+ FDDI_PADDING
, sizeof(src
));
346 swap_mac_addr(src_swapped
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
);
348 /* XXX - copy them to some buffer associated with "pi", rather than
349 just making "src" static? */
350 SET_ADDRESS(&pinfo
->dl_src
, AT_ETHER
, 6, &src
[0]);
351 SET_ADDRESS(&pinfo
->src
, AT_ETHER
, 6, &src
[0]);
352 SET_ADDRESS(&fddihdr
->src
, AT_ETHER
, 6, &src
[0]);
355 proto_tree_add_ether(fh_tree
, hf_fddi_src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src
);
356 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src
);
357 PROTO_ITEM_SET_HIDDEN(hidden_item
);
359 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
360 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src_swapped
);
361 PROTO_ITEM_SET_HIDDEN(hidden_item
);
362 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src_swapped
);
363 PROTO_ITEM_SET_HIDDEN(hidden_item
);
366 next_tvb
= tvb_new_subset_remaining(tvb
, FDDI_HEADER_SIZE
+ FDDI_PADDING
);
369 tap_queue_packet(fddi_tap
, pinfo
, fddihdr
);
371 switch (fddihdr
->fc
) {
373 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
375 case FDDI_FC_LLC_ASYNC
+ 0 :
376 case FDDI_FC_LLC_ASYNC
+ 1 :
377 case FDDI_FC_LLC_ASYNC
+ 2 :
378 case FDDI_FC_LLC_ASYNC
+ 3 :
379 case FDDI_FC_LLC_ASYNC
+ 4 :
380 case FDDI_FC_LLC_ASYNC
+ 5 :
381 case FDDI_FC_LLC_ASYNC
+ 6 :
382 case FDDI_FC_LLC_ASYNC
+ 7 :
383 case FDDI_FC_LLC_ASYNC
+ 8 :
384 case FDDI_FC_LLC_ASYNC
+ 9 :
385 case FDDI_FC_LLC_ASYNC
+ 10 :
386 case FDDI_FC_LLC_ASYNC
+ 11 :
387 case FDDI_FC_LLC_ASYNC
+ 12 :
388 case FDDI_FC_LLC_ASYNC
+ 13 :
389 case FDDI_FC_LLC_ASYNC
+ 14 :
390 case FDDI_FC_LLC_ASYNC
+ 15 :
391 call_dissector(llc_handle
, next_tvb
, pinfo
, tree
);
395 call_dissector(data_handle
,next_tvb
, pinfo
, tree
);
403 dissect_fddi_bitswapped(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
405 dissect_fddi(tvb
, pinfo
, tree
, TRUE
);
409 dissect_fddi_not_bitswapped(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
411 dissect_fddi(tvb
, pinfo
, tree
, FALSE
);
415 proto_register_fddi(void)
417 static hf_register_info hf
[] = {
420 * XXX - we want this guy to have his own private formatting
421 * routine, using "fc_to_str()"; if "fc_to_str()" returns
422 * NULL, just show the hex value, else show the string.
425 { "Frame Control", "fddi.fc", FT_UINT8
, BASE_HEX
, NULL
, 0x0,
429 { "Class/Length/Format", "fddi.fc.clf", FT_UINT8
, BASE_HEX
, VALS(clf_vals
), FDDI_FC_CLFF
,
433 { "Priority", "fddi.fc.prio", FT_UINT8
, BASE_DEC
, NULL
, FDDI_FC_ASYNC_PRI
,
436 { &hf_fddi_fc_smt_subtype
,
437 { "SMT Subtype", "fddi.fc.smt_subtype", FT_UINT8
, BASE_DEC
, VALS(smt_subtype_vals
), FDDI_FC_ZZZZ
,
440 { &hf_fddi_fc_mac_subtype
,
441 { "MAC Subtype", "fddi.fc.mac_subtype", FT_UINT8
, BASE_DEC
, VALS(mac_subtype_vals
), FDDI_FC_ZZZZ
,
445 { "Destination", "fddi.dst", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
446 "Destination Hardware Address", HFILL
}},
449 { "Source", "fddi.src", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
453 { "Source or Destination Address", "fddi.addr", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
454 "Source or Destination Hardware Address", HFILL
}},
457 static gint
*ett
[] = {
462 module_t
*fddi_module
;
464 proto_fddi
= proto_register_protocol("Fiber Distributed Data Interface",
466 proto_register_field_array(proto_fddi
, hf
, array_length(hf
));
467 proto_register_subtree_array(ett
, array_length(ett
));
470 * Called from various dissectors for encapsulated FDDI frames.
471 * We assume the MAC addresses in them aren't bitswapped.
473 register_dissector("fddi", dissect_fddi_not_bitswapped
, proto_fddi
);
475 fddi_module
= prefs_register_protocol(proto_fddi
, NULL
);
476 prefs_register_bool_preference(fddi_module
, "padding",
477 "Add 3-byte padding to all FDDI packets",
478 "Whether the FDDI dissector should add 3-byte padding to all "
479 "captured FDDI packets (useful with e.g. Tru64 UNIX tcpdump)",
482 fddi_tap
= register_tap("fddi");
486 proto_reg_handoff_fddi(void)
488 dissector_handle_t fddi_handle
, fddi_bitswapped_handle
;
491 * Get a handle for the LLC dissector.
493 llc_handle
= find_dissector("llc");
494 data_handle
= find_dissector("data");
496 fddi_handle
= find_dissector("fddi");
497 dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI
, fddi_handle
);
498 fddi_bitswapped_handle
=
499 create_dissector_handle(dissect_fddi_bitswapped
, proto_fddi
);
500 dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI_BITSWAPPED
,
501 fddi_bitswapped_handle
);