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>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <epan/packet.h>
20 #include <wsutil/bitswap.h>
21 #include <epan/prefs.h>
22 #include <epan/conversation_table.h>
23 #include <epan/capture_dissectors.h>
24 #include "packet-llc.h"
25 #include "packet-sflow.h"
27 #include <epan/addr_resolv.h>
29 void proto_register_fddi(void);
30 void proto_reg_handoff_fddi(void);
32 static int proto_fddi
;
33 static int hf_fddi_fc
;
34 static int hf_fddi_fc_clf
;
35 static int hf_fddi_fc_prio
;
36 static int hf_fddi_fc_smt_subtype
;
37 static int hf_fddi_fc_mac_subtype
;
38 static int hf_fddi_dst
;
39 static int hf_fddi_src
;
40 static int hf_fddi_addr
;
43 static int ett_fddi_fc
;
47 static dissector_handle_t fddi_handle
, fddi_bitswapped_handle
;
49 static capture_dissector_handle_t llc_cap_handle
;
51 static bool fddi_padding
;
53 #define FDDI_PADDING ((fddi_padding) ? 3 : 0)
55 /* FDDI Frame Control values */
57 #define FDDI_FC_VOID 0x00 /* Void frame */
58 #define FDDI_FC_NRT 0x80 /* Nonrestricted token */
59 #define FDDI_FC_RT 0xc0 /* Restricted token */
60 #define FDDI_FC_MAC 0xc0 /* MAC frame */
61 #define FDDI_FC_SMT 0x40 /* SMT frame */
62 #define FDDI_FC_SMT_INFO 0x41 /* SMT Info */
63 #define FDDI_FC_SMT_NSA 0x4F /* SMT Next station adrs */
64 #define FDDI_FC_SMT_MIN FDDI_FC_SMT_INFO
65 #define FDDI_FC_SMT_MAX FDDI_FC_SMT_NSA
66 #define FDDI_FC_MAC_MIN 0xc1
67 #define FDDI_FC_MAC_BEACON 0xc2 /* MAC Beacon frame */
68 #define FDDI_FC_MAC_CLAIM 0xc3 /* MAC Claim frame */
69 #define FDDI_FC_MAC_MAX 0xcf
70 #define FDDI_FC_LLC_ASYNC 0x50 /* Async. LLC frame */
71 #define FDDI_FC_LLC_ASYNC_MIN FDDI_FC_LLC_ASYNC
72 #define FDDI_FC_LLC_ASYNC_DEF 0x54
73 #define FDDI_FC_LLC_ASYNC_MAX 0x5f
74 #define FDDI_FC_LLC_SYNC 0xd0 /* Sync. LLC frame */
75 #define FDDI_FC_LLC_SYNC_MIN FDDI_FC_LLC_SYNC
76 #define FDDI_FC_LLC_SYNC_MAX 0xd7
77 #define FDDI_FC_IMP_ASYNC 0x60 /* Implementor Async. */
78 #define FDDI_FC_IMP_ASYNC_MIN FDDI_FC_IMP_ASYNC
79 #define FDDI_FC_IMP_ASYNC_MAX 0x6f
80 #define FDDI_FC_IMP_SYNC 0xe0 /* Implementor Synch. */
82 #define FDDI_FC_CLFF 0xF0 /* Class/Length/Format bits */
83 #define FDDI_FC_ZZZZ 0x0F /* Control bits */
86 * Async frame ZZZZ bits:
88 #define FDDI_FC_ASYNC_R 0x08 /* Reserved */
89 #define FDDI_FC_ASYNC_PRI 0x07 /* Priority */
91 #define CLFF_BITS(fc) (((fc) & FDDI_FC_CLFF) >> 4)
92 #define ZZZZ_BITS(fc) ((fc) & FDDI_FC_ZZZZ)
94 static const value_string clf_vals
[] = {
95 { CLFF_BITS(FDDI_FC_VOID
), "Void" },
96 { CLFF_BITS(FDDI_FC_SMT
), "SMT" },
97 { CLFF_BITS(FDDI_FC_LLC_ASYNC
), "Async LLC" },
98 { CLFF_BITS(FDDI_FC_IMP_ASYNC
), "Implementor Async" },
99 { CLFF_BITS(FDDI_FC_NRT
), "Nonrestricted Token" },
100 { CLFF_BITS(FDDI_FC_MAC
), "MAC" },
101 { CLFF_BITS(FDDI_FC_LLC_SYNC
), "Sync LLC" },
102 { CLFF_BITS(FDDI_FC_IMP_SYNC
), "Implementor Sync" },
106 static const value_string smt_subtype_vals
[] = {
107 { ZZZZ_BITS(FDDI_FC_SMT_INFO
), "Info" },
108 { ZZZZ_BITS(FDDI_FC_SMT_NSA
), "Next Station Address" },
112 static const value_string mac_subtype_vals
[] = {
113 { ZZZZ_BITS(FDDI_FC_MAC_BEACON
), "Beacon" },
114 { ZZZZ_BITS(FDDI_FC_MAC_CLAIM
), "Claim" },
118 typedef struct _fddi_hdr
{
124 #define FDDI_HEADER_SIZE 13
126 /* field positions */
129 #define FDDI_P_DHOST 1
130 #define FDDI_P_SHOST 7
132 static dissector_handle_t llc_handle
;
135 swap_mac_addr(uint8_t *swapped_addr
, tvbuff_t
*tvb
, int offset
)
137 tvb_memcpy(tvb
, swapped_addr
, offset
, 6);
138 bitswap_buf_inplace(swapped_addr
, 6);
141 static const char* fddi_conv_get_filter_type(conv_item_t
* conv
, conv_filter_type_e filter
)
143 if ((filter
== CONV_FT_SRC_ADDRESS
) && (conv
->src_address
.type
== AT_ETHER
))
146 if ((filter
== CONV_FT_DST_ADDRESS
) && (conv
->dst_address
.type
== AT_ETHER
))
149 if ((filter
== CONV_FT_ANY_ADDRESS
) && (conv
->src_address
.type
== AT_ETHER
))
152 return CONV_FILTER_INVALID
;
155 static ct_dissector_info_t fddi_ct_dissector_info
= {&fddi_conv_get_filter_type
};
157 static tap_packet_status
158 fddi_conversation_packet(void *pct
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *vip
, tap_flags_t flags
)
160 conv_hash_t
*hash
= (conv_hash_t
*) pct
;
162 const fddi_hdr
*ehdr
=(const fddi_hdr
*)vip
;
164 add_conversation_table_data(hash
, &ehdr
->src
, &ehdr
->dst
, 0, 0, 1, pinfo
->fd
->pkt_len
, &pinfo
->rel_ts
, &pinfo
->abs_ts
, &fddi_ct_dissector_info
, CONVERSATION_NONE
);
166 return TAP_PACKET_REDRAW
;
169 static const char* fddi_endpoint_get_filter_type(endpoint_item_t
* endpoint
, conv_filter_type_e filter
)
171 if ((filter
== CONV_FT_ANY_ADDRESS
) && (endpoint
->myaddress
.type
== AT_ETHER
))
174 return CONV_FILTER_INVALID
;
177 static et_dissector_info_t fddi_endpoint_dissector_info
= {&fddi_endpoint_get_filter_type
};
179 static tap_packet_status
180 fddi_endpoint_packet(void *pit
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *vip
, tap_flags_t flags
)
182 conv_hash_t
*hash
= (conv_hash_t
*) pit
;
184 const fddi_hdr
*ehdr
=(const fddi_hdr
*)vip
;
186 /* Take two "add" passes per packet, adding for each direction, ensures that all
187 packets are counted properly (even if address is sending to itself)
188 XXX - this could probably be done more efficiently inside endpoint_table */
189 add_endpoint_table_data(hash
, &ehdr
->src
, 0, true, 1, pinfo
->fd
->pkt_len
, &fddi_endpoint_dissector_info
, ENDPOINT_NONE
);
190 add_endpoint_table_data(hash
, &ehdr
->dst
, 0, false, 1, pinfo
->fd
->pkt_len
, &fddi_endpoint_dissector_info
, ENDPOINT_NONE
);
192 return TAP_PACKET_REDRAW
;
196 capture_fddi(const unsigned char *pd
, int offset
, int len
, capture_packet_info_t
*cpinfo
, const union wtap_pseudo_header
*pseudo_header
)
200 if (!BYTES_ARE_IN_FRAME(0, len
, FDDI_HEADER_SIZE
+ FDDI_PADDING
))
203 offset
= FDDI_PADDING
+ FDDI_HEADER_SIZE
;
205 fc
= (int) pd
[FDDI_P_FC
+FDDI_PADDING
];
209 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
211 case FDDI_FC_LLC_ASYNC
+ 0 :
212 case FDDI_FC_LLC_ASYNC
+ 1 :
213 case FDDI_FC_LLC_ASYNC
+ 2 :
214 case FDDI_FC_LLC_ASYNC
+ 3 :
215 case FDDI_FC_LLC_ASYNC
+ 4 :
216 case FDDI_FC_LLC_ASYNC
+ 5 :
217 case FDDI_FC_LLC_ASYNC
+ 6 :
218 case FDDI_FC_LLC_ASYNC
+ 7 :
219 case FDDI_FC_LLC_ASYNC
+ 8 :
220 case FDDI_FC_LLC_ASYNC
+ 9 :
221 case FDDI_FC_LLC_ASYNC
+ 10 :
222 case FDDI_FC_LLC_ASYNC
+ 11 :
223 case FDDI_FC_LLC_ASYNC
+ 12 :
224 case FDDI_FC_LLC_ASYNC
+ 13 :
225 case FDDI_FC_LLC_ASYNC
+ 14 :
226 case FDDI_FC_LLC_ASYNC
+ 15 :
227 return call_capture_dissector(llc_cap_handle
, pd
, offset
, len
, cpinfo
, pseudo_header
);
234 fddifc_to_str(int fc
)
236 static char strbuf
[128+1];
240 case FDDI_FC_VOID
: /* Void frame */
243 case FDDI_FC_NRT
: /* Nonrestricted token */
244 return "Nonrestricted token";
246 case FDDI_FC_RT
: /* Restricted token */
247 return "Restricted token";
249 case FDDI_FC_SMT_INFO
: /* SMT Info */
252 case FDDI_FC_SMT_NSA
: /* SMT Next station adrs */
253 return "SMT Next station address";
255 case FDDI_FC_MAC_BEACON
: /* MAC Beacon frame */
258 case FDDI_FC_MAC_CLAIM
: /* MAC Claim frame */
259 return "MAC claim token";
262 switch (fc
& FDDI_FC_CLFF
) {
265 snprintf(strbuf
, sizeof(strbuf
), "MAC frame, control %x", fc
& FDDI_FC_ZZZZ
);
269 snprintf(strbuf
, sizeof(strbuf
), "SMT frame, control %x", fc
& FDDI_FC_ZZZZ
);
272 case FDDI_FC_LLC_ASYNC
:
273 if (fc
& FDDI_FC_ASYNC_R
)
274 snprintf(strbuf
, sizeof(strbuf
), "Async LLC frame, control %x", fc
& FDDI_FC_ZZZZ
);
276 snprintf(strbuf
, sizeof(strbuf
), "Async LLC frame, priority %d",
277 fc
& FDDI_FC_ASYNC_PRI
);
280 case FDDI_FC_LLC_SYNC
:
281 if (fc
& FDDI_FC_ZZZZ
) {
282 snprintf(strbuf
, sizeof(strbuf
), "Sync LLC frame, control %x", fc
& FDDI_FC_ZZZZ
);
285 return "Sync LLC frame";
287 case FDDI_FC_IMP_ASYNC
:
288 snprintf(strbuf
, sizeof(strbuf
), "Implementor async frame, control %x",
292 case FDDI_FC_IMP_SYNC
:
293 snprintf(strbuf
, sizeof(strbuf
), "Implementor sync frame, control %x",
298 return "Unknown frame type";
305 dissect_fddi(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
308 proto_tree
*fh_tree
= NULL
;
309 proto_item
*ti
, *hidden_item
;
312 unsigned char *src
= (unsigned char*)wmem_alloc(pinfo
->pool
, 6), *dst
= (unsigned char*)wmem_alloc(pinfo
->pool
, 6);
313 unsigned char src_swapped
[6], dst_swapped
[6];
315 static fddi_hdr fddihdrs
[4];
316 static int fddihdr_num
= 0;
320 if (fddihdr_num
>= 4) {
323 fddihdr
= &fddihdrs
[fddihdr_num
];
325 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FDDI");
327 fddihdr
->fc
= tvb_get_uint8(tvb
, FDDI_P_FC
+ FDDI_PADDING
);
328 fc_str
= fddifc_to_str(fddihdr
->fc
);
330 col_add_str(pinfo
->cinfo
, COL_INFO
, fc_str
);
333 ti
= proto_tree_add_protocol_format(tree
, proto_fddi
, tvb
, 0, FDDI_HEADER_SIZE
+FDDI_PADDING
,
334 "Fiber Distributed Data Interface, %s", fc_str
);
335 fh_tree
= proto_item_add_subtree(ti
, ett_fddi
);
336 ti
= proto_tree_add_uint_format_value(fh_tree
, hf_fddi_fc
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
,
337 "0x%02x (%s)", fddihdr
->fc
, fc_str
);
338 fc_tree
= proto_item_add_subtree(ti
, ett_fddi_fc
);
339 proto_tree_add_uint(fc_tree
, hf_fddi_fc_clf
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
340 switch ((fddihdr
->fc
) & FDDI_FC_CLFF
) {
343 proto_tree_add_uint(fc_tree
, hf_fddi_fc_smt_subtype
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
347 if (fddihdr
->fc
!= FDDI_FC_RT
)
348 proto_tree_add_uint(fc_tree
, hf_fddi_fc_mac_subtype
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
351 case FDDI_FC_LLC_ASYNC
:
352 if (!((fddihdr
->fc
) & FDDI_FC_ASYNC_R
))
353 proto_tree_add_uint(fc_tree
, hf_fddi_fc_prio
, tvb
, FDDI_P_FC
+ FDDI_PADDING
, 1, fddihdr
->fc
);
358 /* Extract the destination address, possibly bit-swapping it. */
360 swap_mac_addr(dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
);
362 tvb_memcpy(tvb
, dst
, FDDI_P_DHOST
+ FDDI_PADDING
, 6);
363 swap_mac_addr(dst_swapped
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
);
365 set_address(&pinfo
->dl_dst
, AT_ETHER
, 6, dst
);
366 copy_address_shallow(&pinfo
->dst
, &pinfo
->dl_dst
);
367 copy_address_shallow(&fddihdr
->dst
, &pinfo
->dl_dst
);
370 proto_tree_add_ether(fh_tree
, hf_fddi_dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst
);
371 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst
);
372 proto_item_set_hidden(hidden_item
);
374 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
375 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_dst
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst_swapped
);
376 proto_item_set_hidden(hidden_item
);
377 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_DHOST
+ FDDI_PADDING
, 6, dst_swapped
);
378 proto_item_set_hidden(hidden_item
);
381 /* Extract the source address, possibly bit-swapping it. */
383 swap_mac_addr(src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
);
385 tvb_memcpy(tvb
, src
, FDDI_P_SHOST
+ FDDI_PADDING
, 6);
386 swap_mac_addr(src_swapped
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
);
388 set_address(&pinfo
->dl_src
, AT_ETHER
, 6, src
);
389 copy_address_shallow(&pinfo
->src
, &pinfo
->dl_src
);
390 copy_address_shallow(&fddihdr
->src
, &pinfo
->dl_src
);
393 proto_tree_add_ether(fh_tree
, hf_fddi_src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src
);
394 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src
);
395 proto_item_set_hidden(hidden_item
);
397 /* hide some bit-swapped mac address fields in the proto_tree, just in case */
398 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_src
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src_swapped
);
399 proto_item_set_hidden(hidden_item
);
400 hidden_item
= proto_tree_add_ether(fh_tree
, hf_fddi_addr
, tvb
, FDDI_P_SHOST
+ FDDI_PADDING
, 6, src_swapped
);
401 proto_item_set_hidden(hidden_item
);
404 next_tvb
= tvb_new_subset_remaining(tvb
, FDDI_HEADER_SIZE
+ FDDI_PADDING
);
407 tap_queue_packet(fddi_tap
, pinfo
, fddihdr
);
409 switch (fddihdr
->fc
) {
411 /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
413 case FDDI_FC_LLC_ASYNC
+ 0 :
414 case FDDI_FC_LLC_ASYNC
+ 1 :
415 case FDDI_FC_LLC_ASYNC
+ 2 :
416 case FDDI_FC_LLC_ASYNC
+ 3 :
417 case FDDI_FC_LLC_ASYNC
+ 4 :
418 case FDDI_FC_LLC_ASYNC
+ 5 :
419 case FDDI_FC_LLC_ASYNC
+ 6 :
420 case FDDI_FC_LLC_ASYNC
+ 7 :
421 case FDDI_FC_LLC_ASYNC
+ 8 :
422 case FDDI_FC_LLC_ASYNC
+ 9 :
423 case FDDI_FC_LLC_ASYNC
+ 10 :
424 case FDDI_FC_LLC_ASYNC
+ 11 :
425 case FDDI_FC_LLC_ASYNC
+ 12 :
426 case FDDI_FC_LLC_ASYNC
+ 13 :
427 case FDDI_FC_LLC_ASYNC
+ 14 :
428 case FDDI_FC_LLC_ASYNC
+ 15 :
429 call_dissector(llc_handle
, next_tvb
, pinfo
, tree
);
433 call_data_dissector(next_tvb
, pinfo
, tree
);
441 dissect_fddi_bitswapped(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
443 dissect_fddi(tvb
, pinfo
, tree
, true);
444 return tvb_captured_length(tvb
);
448 dissect_fddi_not_bitswapped(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
450 dissect_fddi(tvb
, pinfo
, tree
, false);
451 return tvb_captured_length(tvb
);
455 proto_register_fddi(void)
457 static hf_register_info hf
[] = {
460 { "Frame Control", "fddi.fc", FT_UINT8
, BASE_HEX
, NULL
, 0x0,
464 { "Class/Length/Format", "fddi.fc.clf", FT_UINT8
, BASE_HEX
, VALS(clf_vals
), FDDI_FC_CLFF
,
468 { "Priority", "fddi.fc.prio", FT_UINT8
, BASE_DEC
, NULL
, FDDI_FC_ASYNC_PRI
,
471 { &hf_fddi_fc_smt_subtype
,
472 { "SMT Subtype", "fddi.fc.smt_subtype", FT_UINT8
, BASE_DEC
, VALS(smt_subtype_vals
), FDDI_FC_ZZZZ
,
475 { &hf_fddi_fc_mac_subtype
,
476 { "MAC Subtype", "fddi.fc.mac_subtype", FT_UINT8
, BASE_DEC
, VALS(mac_subtype_vals
), FDDI_FC_ZZZZ
,
480 { "Destination", "fddi.dst", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
481 "Destination Hardware Address", HFILL
}},
484 { "Source", "fddi.src", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
488 { "Source or Destination Address", "fddi.addr", FT_ETHER
, BASE_NONE
, NULL
, 0x0,
489 "Source or Destination Hardware Address", HFILL
}},
492 static int *ett
[] = {
497 module_t
*fddi_module
;
499 proto_fddi
= proto_register_protocol("Fiber Distributed Data Interface",
501 proto_register_field_array(proto_fddi
, hf
, array_length(hf
));
502 proto_register_subtree_array(ett
, array_length(ett
));
505 * Called from various dissectors for encapsulated FDDI frames.
506 * We assume the MAC addresses in them aren't bitswapped.
508 fddi_handle
= register_dissector("fddi", dissect_fddi_not_bitswapped
, proto_fddi
);
511 * Here, we assume they are bitswapped.
513 fddi_bitswapped_handle
= register_dissector("fddi_bitswapped", dissect_fddi_bitswapped
, proto_fddi
);
515 fddi_module
= prefs_register_protocol(proto_fddi
, NULL
);
516 prefs_register_bool_preference(fddi_module
, "padding",
517 "Add 3-byte padding to all FDDI packets",
518 "Whether the FDDI dissector should add 3-byte padding to all "
519 "captured FDDI packets (useful with e.g. Tru64 UNIX tcpdump)",
522 fddi_tap
= register_tap("fddi");
523 register_conversation_table(proto_fddi
, true, fddi_conversation_packet
, fddi_endpoint_packet
);
527 proto_reg_handoff_fddi(void)
529 capture_dissector_handle_t fddi_cap_handle
;
532 * Get a handle for the LLC dissector.
534 llc_handle
= find_dissector_add_dependency("llc", proto_fddi
);
536 dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI
, fddi_handle
);
537 dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI_BITSWAPPED
,
538 fddi_bitswapped_handle
);
539 dissector_add_uint("sflow_245.header_protocol", SFLOW_245_HEADER_FDDI
,
542 fddi_cap_handle
= create_capture_dissector_handle(capture_fddi
, proto_fddi
);
543 capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI
, fddi_cap_handle
);
544 capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_FDDI_BITSWAPPED
, fddi_cap_handle
);
546 llc_cap_handle
= find_capture_dissector("llc");
550 * Editor modelines - https://www.wireshark.org/tools/modelines.html
555 * indent-tabs-mode: nil
558 * ex: set shiftwidth=2 tabstop=8 expandtab:
559 * :indentSize=2:tabSize=8:noTabs=true: