2 * Routines for Fibre Channel Decoding (FC Header, Link Ctl & Basic Link Svc)
3 * Copyright 2001, Dinesh G Dutt <ddutt@cisco.com>
4 * Copyright 2003 Ronnie Sahlberg, exchange first/last matching and
5 * tap listener and misc updates
7 * $Id: packet-fc.c,v 1.10 2003/06/25 10:21:44 sahlberg Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * 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.
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
47 #ifdef NEED_SNPRINTF_H
48 # include "snprintf.h"
51 #include <epan/packet.h>
53 #include "reassemble.h"
55 #include "packet-fc.h"
56 #include "packet-fclctl.h"
57 #include "packet-fcbls.h"
60 #define FC_HEADER_SIZE 24
61 #define FC_RCTL_EISL 0x50
62 #define MDSHDR_TRAILER_SIZE 6
64 /* Size of various fields in FC header in bytes */
65 #define FC_RCTL_SIZE 1
67 #define FC_CSCTL_SIZE 1
69 #define FC_TYPE_SIZE 1
70 #define FC_FCTL_SIZE 3
71 #define FC_SEQID_SIZE 1
72 #define FC_DFCTL_SIZE 1
73 #define FC_SEQCNT_SIZE 2
74 #define FC_OXID_SIZE 2
75 #define FC_RXID_SIZE 2
76 #define FC_PARAM_SIZE 4
78 /* Initialize the protocol and registered fields */
79 static int proto_fc = -1;
80 static int hf_fc_time = -1;
81 static int hf_fc_exchange_first_frame = -1;
82 static int hf_fc_exchange_last_frame = -1;
83 static int hf_fc_rctl = -1;
84 static int hf_fc_did = -1;
85 static int hf_fc_csctl = -1;
86 static int hf_fc_sid = -1;
87 static int hf_fc_id = -1;
88 static int hf_fc_type = -1;
89 static int hf_fc_fctl = -1;
90 static int hf_fc_fctl_exchange_responder = -1;
91 static int hf_fc_fctl_seq_recipient = -1;
92 static int hf_fc_fctl_exchange_first = -1;
93 static int hf_fc_fctl_exchange_last = -1;
94 static int hf_fc_fctl_seq_last = -1;
95 static int hf_fc_fctl_priority = -1;
96 static int hf_fc_fctl_transfer_seq_initiative = -1;
97 static int hf_fc_fctl_rexmitted_seq = -1;
98 static int hf_fc_fctl_rel_offset = -1;
99 static int hf_fc_fctl_abts_ack = -1;
100 static int hf_fc_fctl_abts_not_ack = -1;
101 static int hf_fc_fctl_last_data_frame = -1;
102 static int hf_fc_fctl_ack_0_1 = -1;
103 static int hf_fc_seqid = -1;
104 static int hf_fc_dfctl = -1;
105 static int hf_fc_seqcnt = -1;
106 static int hf_fc_oxid = -1;
107 static int hf_fc_rxid = -1;
108 static int hf_fc_param = -1;
109 static int hf_fc_ftype = -1; /* Derived field, non-existent in FC hdr */
110 static int hf_fc_reassembled = -1;
112 /* Network_Header fields */
113 static int hf_fc_nh_da = -1;
114 static int hf_fc_nh_sa = -1;
116 /* For Basic Link Svc */
117 static int hf_fc_bls_seqid_vld = -1;
118 static int hf_fc_bls_lastvld_seqid = -1;
119 static int hf_fc_bls_oxid = -1;
120 static int hf_fc_bls_rxid = -1;
121 static int hf_fc_bls_lowseqcnt = -1;
122 static int hf_fc_bls_hiseqcnt = -1;
123 static int hf_fc_bls_rjtcode = -1;
124 static int hf_fc_bls_rjtdetail = -1;
125 static int hf_fc_bls_vendor = -1;
128 /* Initialize the subtree pointers */
129 static gint ett_fc = -1;
130 static gint ett_fctl = -1;
131 static gint ett_fcbls = -1;
133 static dissector_table_t fcftype_dissector_table;
134 static dissector_handle_t data_handle;
136 static int fc_tap = -1;
138 /* Reassembly stuff */
139 static gboolean fc_reassemble = TRUE;
140 static guint32 fc_max_frame_size = 1024;
141 static GHashTable *fc_fragment_table = NULL;
144 static GHashTable *fc_exchange_unmatched = NULL;
145 static GHashTable *fc_exchange_matched = NULL;
146 static GMemChunk *fc_exchange_vals = NULL;
147 static guint32 fc_exchange_init_count = 200;
150 fc_exchange_hash_unmatched(gconstpointer v)
152 const fc_exchange_data *fced=(const fc_exchange_data *)v;
157 fc_exchange_equal_unmatched(gconstpointer v1, gconstpointer v2)
159 const fc_exchange_data *fced1=(const fc_exchange_data *)v1;
160 const fc_exchange_data *fced2=(const fc_exchange_data *)v2;
162 /* oxid must match */
163 if(fced1->oxid!=fced2->oxid){
166 /* compare s_id, d_id and treat the fc address
167 s_id==00.00.00 as a wildcard matching anything */
168 if( (fced1->s_id!=0) && (fced1->s_id!=fced2->s_id) ){
171 if(fced1->d_id!=fced2->d_id){
179 fc_exchange_hash_matched(gconstpointer v)
181 const fc_exchange_data *fced=(const fc_exchange_data *)v;
186 fc_exchange_equal_matched(gconstpointer v1, gconstpointer v2)
188 const fc_exchange_data *fced1=(const fc_exchange_data *)v1;
189 const fc_exchange_data *fced2=(const fc_exchange_data *)v2;
190 guint32 fef1, fef2, lef1, lef2;
192 /* oxid must match */
193 if(fced1->oxid!=fced2->oxid){
196 fef1=fced1->first_exchange_frame;
197 fef2=fced2->first_exchange_frame;
198 lef1=fced1->last_exchange_frame;
199 lef2=fced2->last_exchange_frame;
216 fc_exchange_init_protocol(void)
218 if(fc_exchange_vals){
219 g_mem_chunk_destroy(fc_exchange_vals);
220 fc_exchange_vals=NULL;
222 if(fc_exchange_unmatched){
223 g_hash_table_destroy(fc_exchange_unmatched);
224 fc_exchange_unmatched=NULL;
226 if(fc_exchange_matched){
227 g_hash_table_destroy(fc_exchange_matched);
228 fc_exchange_matched=NULL;
231 fc_exchange_unmatched=g_hash_table_new(fc_exchange_hash_unmatched, fc_exchange_equal_unmatched);
232 fc_exchange_matched=g_hash_table_new(fc_exchange_hash_matched, fc_exchange_equal_matched);
233 fc_exchange_vals=g_mem_chunk_new("fc_exchange_vals", sizeof(fc_exchange_data), fc_exchange_init_count*sizeof(fc_exchange_data), G_ALLOC_AND_FREE);
241 const value_string fc_fc4_val[] = {
242 {FC_TYPE_ELS , "Ext Link Svc"},
243 {FC_TYPE_LLCSNAP , "LLC_SNAP"},
244 {FC_TYPE_IP , "IP/FC"},
245 {FC_TYPE_SCSI , "FCP"},
246 {FC_TYPE_FCCT , "FC_CT"},
247 {FC_TYPE_SWILS , "SW_ILS"},
249 {FC_TYPE_SNMP , "SNMP"},
253 static const value_string fc_ftype_vals [] = {
254 {FC_FTYPE_UNDEF , "Unknown frame"},
255 {FC_FTYPE_SWILS, "SW_ILS"},
256 {FC_FTYPE_IP , "IP/FC"},
257 {FC_FTYPE_SCSI , "FCP"},
258 {FC_FTYPE_BLS , "Basic Link Svc"},
259 {FC_FTYPE_ELS , "ELS"},
260 {FC_FTYPE_FCCT , "FC_CT"},
261 {FC_FTYPE_LINKDATA, "Link Data"},
262 {FC_FTYPE_VDO, "Video Data"},
263 {FC_FTYPE_LINKCTL, "Link Ctl"},
267 static const value_string fc_wka_vals[] = {
268 {FC_WKA_MULTICAST, "Multicast Server"},
269 {FC_WKA_CLKSYNC, "Clock Sync Server"},
270 {FC_WKA_KEYDIST, "Key Distribution Server"},
271 {FC_WKA_ALIAS, "Alias Server"},
272 {FC_WKA_QOSF, "QoS Facilitator"},
273 {FC_WKA_MGMT, "Management Server"},
274 {FC_WKA_TIME, "Time Server"},
275 {FC_WKA_DNS, "Directory Server"},
276 {FC_WKA_FABRIC_CTRLR, "Fabric Ctlr"},
277 {FC_WKA_FPORT, "F_Port Server"},
278 {FC_WKA_BCAST, "Broadcast ID"},
282 static const value_string fc_iu_val[] = {
283 {FC_IU_UNCATEGORIZED , "Uncategorized Data"},
284 {FC_IU_SOLICITED_DATA , "Solicited Data"},
285 {FC_IU_UNSOLICITED_CTL , "Unsolicited Control"},
286 {FC_IU_SOLICITED_CTL , "Solicited Control"},
287 {FC_IU_UNSOLICITED_DATA, "Solicited Data"},
288 {FC_IU_DATA_DESCRIPTOR , "Data Descriptor"},
289 {FC_IU_UNSOLICITED_CMD , "Unsolicited Command"},
290 {FC_IU_CMD_STATUS , "Command Status"},
295 static void fc_defragment_init(void)
297 fragment_table_init(&fc_fragment_table);
302 fctl_to_str (const guint8 *fctl, gchar *str, gboolean is_ack)
310 if (fctl[0] & 0x80) {
311 strcpy (str, "Exchange Responder, ");
315 strcpy (str, "Exchange Originator, ");
319 if (fctl[0] & 0x40) {
320 strcpy (&str[stroff], "Seq Recipient, ");
324 strcpy (&str[stroff], "Seq Initiator, ");
328 if (fctl[0] & 0x20) {
329 strcpy (&str[stroff], "Exchg First, ");
333 if (fctl[0] & 0x10) {
334 strcpy (&str[stroff], "Exchg Last, ");
339 strcpy (&str[stroff], "Seq Last, ");
344 strcpy (&str[stroff], "Priority, ");
348 strcpy (&str[stroff], "CS_CTL, ");
353 strcpy (&str[stroff], "Transfer Seq Initiative, ");
357 if (fctl[1] & 0x30) {
358 strcpy (&str[stroff], "ACK_0 Reqd, ");
361 else if (fctl[1] & 0x10) {
362 strcpy (&str[stroff], "ACK_1 Reqd, ");
367 strcpy (&str[stroff], "Rexmitted Seq, ");
371 tmp = fctl[2] & 0xC0;
374 strcpy (&str[stroff], "Last Data Frame - No Info, ");
378 strcpy (&str[stroff], "Last Data Frame - Seq Imm, ");
382 strcpy (&str[stroff], "Last Data Frame - Seq Soon, ");
386 strcpy (&str[stroff], "Last Data Frame - Seq Delyd, ");
391 tmp = fctl[2] & 0x30;
395 strcpy (&str[stroff], "ABTS - Cont, ");
399 strcpy (&str[stroff], "ABTS - Abort/MS, ");
405 strcpy (&str[stroff], "ABTS - AbortABTS - Abort, ");
409 strcpy (&str[stroff], "ABTS - Abort/SS, ");
415 strcpy (&str[stroff], "ABTS - Stop, ");
419 strcpy (&str[stroff], "ABTS - Process/IB, ");
425 strcpy (&str[stroff], "ABTS - Imm Seq Retx, ");
429 strcpy (&str[stroff], "ABTS - Discard/MS/Imm Retx, ");
436 strcpy (&str[stroff], "Rel Offset = 1");
443 /* BA_ACC & BA_RJT are decoded in this file itself instead of a traditional
444 * dedicated file and dissector format because the dissector would require some
445 * fields of the FC_HDR such as param in some cases, type in some others, the
446 * lower 4 bits of r_ctl in some other cases etc. So, we decode BLS & Link Ctl
447 * in this file itself.
450 dissect_fc_ba_acc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
452 /* Set up structures needed to add the protocol subtree and manage it */
454 proto_tree *acc_tree;
457 /* Make entries in Protocol column and Info column on summary display */
458 if (check_col(pinfo->cinfo, COL_PROTOCOL))
459 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BLS");
461 if (check_col(pinfo->cinfo, COL_INFO))
462 col_set_str(pinfo->cinfo, COL_INFO, "BA_ACC");
465 ti = proto_tree_add_text (tree, tvb, 0, tvb_length (tvb), "Basic Link Svc");
466 acc_tree = proto_item_add_subtree (ti, ett_fcbls);
468 proto_tree_add_item (acc_tree, hf_fc_bls_seqid_vld, tvb, offset++, 1, FALSE);
469 proto_tree_add_item (acc_tree, hf_fc_bls_lastvld_seqid, tvb, offset++, 1, FALSE);
470 offset += 2; /* Skip reserved field */
471 proto_tree_add_item (acc_tree, hf_fc_bls_oxid, tvb, offset, 2, FALSE);
473 proto_tree_add_item (acc_tree, hf_fc_bls_rxid, tvb, offset, 2, FALSE);
475 proto_tree_add_item (acc_tree, hf_fc_bls_lowseqcnt, tvb, offset, 2, FALSE);
477 proto_tree_add_item (acc_tree, hf_fc_bls_hiseqcnt, tvb, offset, 2, FALSE);
482 dissect_fc_ba_rjt (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
484 /* Set up structures needed to add the protocol subtree and manage it */
486 proto_tree *rjt_tree;
489 /* Make entries in Protocol column and Info column on summary display */
490 if (check_col(pinfo->cinfo, COL_PROTOCOL))
491 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BLS");
493 if (check_col(pinfo->cinfo, COL_INFO))
494 col_set_str(pinfo->cinfo, COL_INFO, "BA_RJT");
497 ti = proto_tree_add_text (tree, tvb, 0, tvb_length (tvb), "Basic Link Svc");
498 rjt_tree = proto_item_add_subtree (ti, ett_fcbls);
500 proto_tree_add_item (rjt_tree, hf_fc_bls_rjtcode, tvb, offset+1, 1, FALSE);
501 proto_tree_add_item (rjt_tree, hf_fc_bls_rjtdetail, tvb, offset+2, 1, FALSE);
502 proto_tree_add_item (rjt_tree, hf_fc_bls_vendor, tvb, offset+3, 1, FALSE);
507 fc_get_ftype (guint8 r_ctl, guint8 type)
509 /* A simple attempt to determine the upper level protocol based on the
510 * r_ctl & type fields.
512 switch (r_ctl & 0xF0) {
513 case FC_RCTL_DEV_DATA:
516 if ((r_ctl == 0x2) || (r_ctl == 0x3))
517 return FC_FTYPE_SWILS;
519 return FC_FTYPE_UNDEF;
523 return FC_FTYPE_SCSI;
525 return FC_FTYPE_FCCT;
527 return FC_FTYPE_UNDEF;
531 if (((r_ctl & 0x0F) == 0x2) || ((r_ctl & 0x0F) == 0x3))
534 return FC_FTYPE_UNDEF;
536 case FC_RCTL_LINK_DATA:
537 return FC_FTYPE_LINKDATA;
546 return FC_FTYPE_UNDEF;
548 case FC_RCTL_LINK_CTL:
549 return FC_FTYPE_LINKCTL;
552 return FC_FTYPE_UNDEF;
557 static const value_string abts_ack_vals[] = {
558 {0x000000, "ABTS - Cont"},
559 {0x000010, "ABTS - Abort"},
560 {0x000020, "ABTS - Stop"},
561 {0x000030, "ABTS - Imm Seq Retx"},
564 static const value_string abts_not_ack_vals[] = {
565 {0x000000, "ABTS - Abort/MS"},
566 {0x000010, "ABTS - Abort/SS"},
567 {0x000020, "ABTS - Process/IB"},
568 {0x000030, "ABTS - Discard/MS/Imm Retx"},
571 static const value_string last_data_frame_vals[] = {
572 {0x000000, "Last Data Frame - No Info"},
573 {0x004000, "Last Data Frame - Seq Imm"},
574 {0x008000, "Last Data Frame - Seq Soon"},
575 {0x00c000, "Last Data Frame - Seq Delyd"},
578 static const value_string ack_0_1_vals[] = {
579 {0x003000, "ACK_0 Required"},
580 {0x002000, "ACK_0 Required"},
581 {0x001000, "ACK_1 Required"},
582 {0x000000, "no ack required"},
585 static const true_false_string tfs_fc_fctl_exchange_responder = {
586 "Exchange Responder",
587 "Exchange Originator"
589 static const true_false_string tfs_fc_fctl_seq_recipient = {
593 static const true_false_string tfs_fc_fctl_exchange_first = {
597 static const true_false_string tfs_fc_fctl_exchange_last = {
601 static const true_false_string tfs_fc_fctl_seq_last = {
605 static const true_false_string tfs_fc_fctl_priority = {
609 static const true_false_string tfs_fc_fctl_transfer_seq_initiative = {
610 "Transfer Seq Initiative",
611 "NOT transfer seq initiative"
613 static const true_false_string tfs_fc_fctl_rexmitted_seq = {
614 "Retransmitted Sequence",
615 "NOT retransmitted sequence"
617 static const true_false_string tfs_fc_fctl_rel_offset = {
625 /* code to dissect the F_CTL bitmask */
627 dissect_fc_fctl(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gboolean is_ack, guint32 fctl)
633 item=proto_tree_add_uint(parent_tree, hf_fc_fctl, tvb, offset, 3, fctl);
634 tree=proto_item_add_subtree(item, ett_fctl);
637 proto_tree_add_boolean(tree, hf_fc_fctl_exchange_responder, tvb, offset, 3, fctl);
639 proto_tree_add_boolean(tree, hf_fc_fctl_seq_recipient, tvb, offset, 3, fctl);
641 proto_tree_add_boolean(tree, hf_fc_fctl_exchange_first, tvb, offset, 3, fctl);
643 proto_tree_add_boolean(tree, hf_fc_fctl_exchange_last, tvb, offset, 3, fctl);
645 proto_tree_add_boolean(tree, hf_fc_fctl_seq_last, tvb, offset, 3, fctl);
647 proto_tree_add_boolean(tree, hf_fc_fctl_priority, tvb, offset, 3, fctl);
649 proto_tree_add_boolean(tree, hf_fc_fctl_transfer_seq_initiative, tvb, offset, 3, fctl);
651 proto_tree_add_uint(tree, hf_fc_fctl_last_data_frame, tvb, offset, 3, fctl);
653 proto_tree_add_uint(tree, hf_fc_fctl_ack_0_1, tvb, offset, 3, fctl);
656 proto_tree_add_boolean(tree, hf_fc_fctl_rexmitted_seq, tvb, offset, 3, fctl);
659 proto_tree_add_uint(tree, hf_fc_fctl_abts_ack, tvb, offset, 3, fctl);
661 proto_tree_add_uint(tree, hf_fc_fctl_abts_ack, tvb, offset, 3, fctl);
664 proto_tree_add_boolean(tree, hf_fc_fctl_rel_offset, tvb, offset, 3, fctl);
666 fctl_to_str( ((guint8 *)&fctl)+1, str, is_ack);
667 proto_item_append_text(item, " %s", str);
671 /* Code to actually dissect the packets */
673 dissect_fc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
675 /* Set up structures needed to add the protocol subtree and manage it */
677 proto_tree *fc_tree = NULL;
679 int offset = 0, next_offset;
680 gboolean is_lastframe_inseq;
681 gboolean is_exchg_resp = 0;
682 fragment_data *fcfrag_head;
692 fc_exchange_data *fc_ex=NULL;
696 /* Make entries in Protocol column and Info column on summary display */
697 if (check_col(pinfo->cinfo, COL_PROTOCOL))
698 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FC");
700 fchdr.r_ctl = tvb_get_guint8 (tvb, offset);
702 /* If the R_CTL is the EISL field, skip the first 8 bytes to retrieve the
703 * real FC header. EISL is Cisco-proprietary and is not decoded.
705 if (fchdr.r_ctl == FC_RCTL_EISL) {
707 fchdr.r_ctl = tvb_get_guint8 (tvb, offset);
710 fchdr.d_id=tvb_get_letoh24(tvb, offset+1);
711 fchdr.s_id=tvb_get_letoh24(tvb, offset+5);
712 fchdr.cs_ctl = tvb_get_guint8 (tvb, offset+4);
713 fchdr.type = tvb_get_guint8 (tvb, offset+8);
714 fchdr.fctl=tvb_get_ntoh24(tvb,offset+9);
715 fchdr.seqcnt = tvb_get_ntohs (tvb, offset+14);
716 fchdr.oxid=tvb_get_ntohs(tvb,offset+16);
717 fchdr.rxid=tvb_get_ntohs(tvb,offset+18);
718 param = tvb_get_ntohl (tvb, offset+20);
720 SET_ADDRESS (&pinfo->dst, AT_FC, 3, tvb_get_ptr(tvb,offset+1,3));
721 SET_ADDRESS (&pinfo->src, AT_FC, 3, tvb_get_ptr(tvb,offset+5,3));
722 pinfo->oxid = fchdr.oxid;
723 pinfo->rxid = fchdr.rxid;
724 pinfo->ptype = PT_EXCHG;
725 pinfo->r_ctl = fchdr.r_ctl;
727 is_ack = ((fchdr.r_ctl == 0xC0) || (fchdr.r_ctl == 0xC1));
729 ftype = fc_get_ftype (fchdr.r_ctl, fchdr.type);
731 if (check_col (pinfo->cinfo, COL_INFO)) {
732 col_add_str (pinfo->cinfo, COL_INFO, match_strval (ftype, fc_ftype_vals));
734 if (ftype == FC_FTYPE_LINKCTL)
735 col_append_fstr (pinfo->cinfo, COL_INFO, ", %s",
736 match_strval ((fchdr.r_ctl & 0x0F),
740 /* In the interest of speed, if "tree" is NULL, don't do any work not
741 necessary to generate protocol tree items. */
743 ti = proto_tree_add_protocol_format (tree, proto_fc, tvb, offset,
744 FC_HEADER_SIZE, "Fibre Channel");
745 fc_tree = proto_item_add_subtree (ti, ett_fc);
748 /* match first exchange with last exchange */
749 if(fchdr.fctl&FC_FCTL_EXCHANGE_FIRST){
750 if(!pinfo->fd->flags.visited){
751 fc_exchange_data fced, *old_fced;
752 /* first check if we already have seen this exchange and it
753 is still open/unmatched.
755 fced.oxid=fchdr.oxid;
756 fced.s_id=fchdr.s_id;
757 fced.d_id=fchdr.d_id;
758 old_fced=g_hash_table_lookup(fc_exchange_unmatched, &fced);
760 g_hash_table_remove(fc_exchange_unmatched, old_fced);
762 old_fced=g_mem_chunk_alloc(fc_exchange_vals);
763 old_fced->oxid=fchdr.oxid;
764 old_fced->s_id=fchdr.s_id;
765 old_fced->d_id=fchdr.d_id;
766 old_fced->first_exchange_frame=pinfo->fd->num;
767 old_fced->fc_time.nsecs = pinfo->fd->abs_usecs*1000;
768 old_fced->fc_time.secs = pinfo->fd->abs_secs;
769 g_hash_table_insert(fc_exchange_unmatched, old_fced, old_fced);
771 fc_exchange_data fced, *old_fced;
772 fced.oxid=fchdr.oxid;
773 fced.first_exchange_frame=pinfo->fd->num;
774 fced.last_exchange_frame=0;
775 old_fced=g_hash_table_lookup(fc_exchange_matched, &fced);
781 if(fchdr.fctl&FC_FCTL_EXCHANGE_LAST){
782 if(!pinfo->fd->flags.visited){
783 fc_exchange_data fced, *old_fced;
785 fced.oxid=fchdr.oxid;
786 fced.s_id=fchdr.d_id;
787 fced.d_id=fchdr.s_id;
788 old_fced=g_hash_table_lookup(fc_exchange_unmatched, &fced);
790 g_hash_table_remove(fc_exchange_unmatched, old_fced);
791 old_fced->last_exchange_frame=pinfo->fd->num;
792 g_hash_table_insert(fc_exchange_matched, old_fced, old_fced);
795 fc_exchange_data fced, *old_fced;
796 fced.oxid=fchdr.oxid;
797 fced.first_exchange_frame=0;
798 fced.last_exchange_frame=pinfo->fd->num;
799 old_fced=g_hash_table_lookup(fc_exchange_matched, &fced);
806 if(fchdr.fctl&FC_FCTL_EXCHANGE_FIRST){
807 proto_tree_add_uint(fc_tree, hf_fc_exchange_last_frame, tvb, 0, 0, fc_ex->last_exchange_frame);
809 if(fchdr.fctl&FC_FCTL_EXCHANGE_LAST){
811 proto_tree_add_uint(fc_tree, hf_fc_exchange_first_frame, tvb, 0, 0, fc_ex->first_exchange_frame);
812 delta_time.secs = pinfo->fd->abs_secs - fc_ex->fc_time.secs;
813 delta_time.nsecs = pinfo->fd->abs_usecs*1000 - fc_ex->fc_time.nsecs;
814 if (delta_time.nsecs<0){
815 delta_time.nsecs+=1000000000;
818 proto_tree_add_time(ti, hf_fc_time, tvb, 0, 0, &delta_time);
823 if (ftype == FC_FTYPE_LINKCTL) {
824 /* the lower 4 bits of R_CTL indicate the type of link ctl frame */
825 proto_tree_add_uint_format (fc_tree, hf_fc_rctl, tvb, offset,
826 FC_RCTL_SIZE, fchdr.r_ctl,
829 val_to_str ((fchdr.r_ctl & 0x0F),
830 fc_lctl_proto_val, "0x%x"));
831 } else if (ftype == FC_FTYPE_BLS) {
832 /* the lower 4 bits of R_CTL indicate the type of BLS frame */
833 proto_tree_add_uint_format (fc_tree, hf_fc_rctl, tvb, offset,
834 FC_RCTL_SIZE, fchdr.r_ctl,
837 val_to_str ((fchdr.r_ctl & 0x0F),
838 fc_bls_proto_val, "0x%x"));
840 proto_tree_add_item (fc_tree, hf_fc_rctl, tvb, offset, 1, FALSE);
843 proto_tree_add_uint_hidden (fc_tree, hf_fc_ftype, tvb, offset, 1,
846 proto_tree_add_string (fc_tree, hf_fc_did, tvb, offset+1, 3,
847 fc32_to_str (fchdr.d_id));
848 proto_tree_add_string_hidden (fc_tree, hf_fc_id, tvb, offset+1, 3,
849 fc32_to_str (fchdr.d_id));
851 proto_tree_add_uint (fc_tree, hf_fc_csctl, tvb, offset+4, 1, fchdr.cs_ctl);
853 proto_tree_add_string (fc_tree, hf_fc_sid, tvb, offset+5, 3,
854 fc32_to_str (fchdr.s_id));
855 proto_tree_add_string_hidden (fc_tree, hf_fc_id, tvb, offset+5, 3,
856 fc32_to_str (fchdr.s_id));
858 if (ftype == FC_FTYPE_LINKCTL) {
859 if (((fchdr.r_ctl & 0x0F) == FC_LCTL_FBSYB) ||
860 ((fchdr.r_ctl & 0x0F) == FC_LCTL_FBSYL)) {
861 /* for F_BSY frames, the upper 4 bits of the type field specify the
862 * reason for the BSY.
864 proto_tree_add_uint_format (fc_tree, hf_fc_type, tvb,
865 offset+8, FC_TYPE_SIZE,
866 fchdr.type,"Type: 0x%x(%s)", fchdr.type,
867 fclctl_get_typestr (fchdr.r_ctl & 0x0F,
870 proto_tree_add_item (fc_tree, hf_fc_type, tvb, offset+8, 1, FALSE);
873 proto_tree_add_item (fc_tree, hf_fc_type, tvb, offset+8, 1, FALSE);
877 dissect_fc_fctl(pinfo, fc_tree, tvb, offset+9, is_ack, fchdr.fctl);
880 proto_tree_add_item (fc_tree, hf_fc_seqid, tvb, offset+12, 1, FALSE);
882 df_ctl = tvb_get_guint8(tvb, offset+13);
884 proto_tree_add_uint (fc_tree, hf_fc_dfctl, tvb, offset+13, 1, df_ctl);
885 proto_tree_add_uint (fc_tree, hf_fc_seqcnt, tvb, offset+14, 2, fchdr.seqcnt);
886 proto_tree_add_uint (fc_tree, hf_fc_oxid, tvb, offset+16, 2, fchdr.oxid);
887 proto_tree_add_uint (fc_tree, hf_fc_rxid, tvb, offset+18, 2, fchdr.rxid);
889 if (ftype == FC_FTYPE_LINKCTL) {
890 if (((fchdr.r_ctl & 0x0F) == FC_LCTL_FRJT) ||
891 ((fchdr.r_ctl & 0x0F) == FC_LCTL_PRJT) ||
892 ((fchdr.r_ctl & 0x0F) == FC_LCTL_PBSY)) {
893 /* In all these cases of Link Ctl frame, the parameter field
894 * encodes the detailed error message
896 proto_tree_add_uint_format (fc_tree, hf_fc_param, tvb,
898 "Parameter: 0x%x(%s)", param,
899 fclctl_get_paramstr ((fchdr.r_ctl & 0x0F),
902 proto_tree_add_item (fc_tree, hf_fc_param, tvb, offset+20, 4, FALSE);
904 } else if (ftype == FC_FTYPE_BLS) {
905 if ((fchdr.r_ctl & 0x0F) == FC_BLS_ABTS) {
906 proto_tree_add_uint_format (fc_tree, hf_fc_param, tvb,
908 "Parameter: 0x%x(%s)", param,
909 ((param & 0x0F) == 1 ? "Abort Sequence" :
912 proto_tree_add_item (fc_tree, hf_fc_param, tvb, offset+20,
916 proto_tree_add_item (fc_tree, hf_fc_param, tvb, offset+20, 4, FALSE);
919 /* Skip the Frame_Header */
920 next_offset = offset + FC_HEADER_SIZE;
922 /* Network_Header present? */
923 if (df_ctl & FC_DFCTL_NH) {
924 /* Yes - dissect it. */
926 proto_tree_add_string (fc_tree, hf_fc_nh_da, tvb, next_offset, 8,
927 fcwwn_to_str (tvb_get_ptr (tvb, offset, 8)));
928 proto_tree_add_string (fc_tree, hf_fc_nh_sa, tvb, offset+8, 8,
929 fcwwn_to_str (tvb_get_ptr (tvb, offset+8, 8)));
934 /* XXX - handle Association_Header and Device_Header here */
936 if (ftype == FC_FTYPE_LINKCTL) {
937 /* ACK_1 frames and other LINK_CTL frames echo the last seq bit if the
938 * packet they're ack'ing did not have it set. So, we'll incorrectly
939 * flag them as being fragmented when they're not. This fixes the
942 is_lastframe_inseq = TRUE;
944 is_lastframe_inseq = fchdr.fctl & FC_FCTL_SEQ_LAST;
945 /* XXX is this right? offset 20, shouldnt it be offset 9? */
946 is_exchg_resp = ((tvb_get_guint8 (tvb, offset+20) & 0x80) == 0x80);
949 frag_size = tvb_reported_length (tvb)-FC_HEADER_SIZE;
951 /* If there is an MDS header, we need to subtract the MDS trailer size */
952 if ((pinfo->ethertype == ETHERTYPE_UNK) || (pinfo->ethertype == ETHERTYPE_FCFT)) {
953 frag_size -= MDSHDR_TRAILER_SIZE;
954 } else if (pinfo->ethertype == ETHERTYPE_BRDWALK) {
955 frag_size -= 8; /* 4 byte of FC CRC +
956 4 bytes of error+EOF = 8 bytes */
959 if (!is_lastframe_inseq) {
960 /* Show this only as a fragmented FC frame */
961 if (check_col (pinfo->cinfo, COL_INFO)) {
962 col_append_str (pinfo->cinfo, COL_INFO, " (Fragmented)");
966 /* If this is a fragment, attempt to check if fully reassembled frame is
967 * present, if we're configured to reassemble.
969 if ((ftype != FC_FTYPE_LINKCTL) && (ftype != FC_FTYPE_BLS) &&
970 (!is_lastframe_inseq || fchdr.seqcnt) && fc_reassemble &&
971 tvb_bytes_exist(tvb, FC_HEADER_SIZE, frag_size)) {
972 /* Add this to the list of fragments */
973 frag_id = (pinfo->oxid << 16) | is_exchg_resp;
975 /* We assume that all frames are of the same max size */
976 fcfrag_head = fragment_add (tvb, FC_HEADER_SIZE, pinfo, frag_id,
978 fchdr.seqcnt * fc_max_frame_size,
980 !is_lastframe_inseq);
983 next_tvb = tvb_new_real_data (fcfrag_head->data,
984 fcfrag_head->datalen,
985 fcfrag_head->datalen);
986 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
988 /* Add the defragmented data to the data source list. */
989 add_new_data_source(pinfo, next_tvb, "Reassembled FC");
992 proto_tree_add_boolean_hidden (fc_tree, hf_fc_reassembled,
993 tvb, offset+9, 1, 1);
997 proto_tree_add_boolean_hidden (fc_tree, hf_fc_reassembled,
998 tvb, offset+9, 1, 0);
1000 next_tvb = tvb_new_subset (tvb, next_offset, -1, -1);
1001 call_dissector (data_handle, next_tvb, pinfo, tree);
1006 proto_tree_add_boolean_hidden (fc_tree, hf_fc_reassembled,
1007 tvb, offset+9, 1, 0);
1009 next_tvb = tvb_new_subset (tvb, next_offset, -1, -1);
1012 if ((ftype != FC_FTYPE_LINKCTL) && (ftype != FC_FTYPE_BLS)) {
1013 if (!dissector_try_port (fcftype_dissector_table, ftype, next_tvb,
1015 call_dissector (data_handle, next_tvb, pinfo, tree);
1017 } else if (ftype == FC_FTYPE_BLS) {
1018 if ((fchdr.r_ctl & 0x0F) == FC_BLS_BAACC) {
1019 dissect_fc_ba_acc (next_tvb, pinfo, tree);
1020 } else if ((fchdr.r_ctl & 0x0F) == FC_BLS_BARJT) {
1021 dissect_fc_ba_rjt (next_tvb, pinfo, tree);
1025 tap_queue_packet(fc_tap, pinfo, &fchdr);
1029 /* Register the protocol with Ethereal */
1031 /* this format is require because a script is used to build the C function
1032 that calls all the protocol registration.
1036 proto_register_fc(void)
1039 /* Setup list of header fields See Section 1.6.1 for details*/
1040 static hf_register_info hf[] = {
1042 { "R_CTL", "fc.r_ctl", FT_UINT8, BASE_HEX, NULL, 0x0,
1045 {"Frame type", "fc.ftype", FT_UINT8, BASE_HEX, VALS(fc_ftype_vals),
1046 0x0, "Derived Type", HFILL}},
1048 { "Dest Addr", "fc.d_id", FT_STRING, BASE_HEX, NULL, 0x0,
1049 "Destination Address", HFILL}},
1051 {"CS_CTL", "fc.cs_ctl", FT_UINT8, BASE_HEX, NULL, 0x0,
1054 {"Src Addr", "fc.s_id", FT_STRING, BASE_HEX, NULL, 0x0,
1055 "Source Address", HFILL}},
1057 {"Addr", "fc.id", FT_STRING, BASE_HEX, NULL, 0x0,
1058 "Source or Destination Address", HFILL}},
1060 {"Type", "fc.type", FT_UINT8, BASE_HEX, VALS (fc_fc4_val), 0x0,
1063 {"F_CTL", "fc.f_ctl", FT_UINT24, BASE_HEX, NULL, 0x0, "", HFILL}},
1065 {"SEQ_ID", "fc.seq_id", FT_UINT8, BASE_HEX, NULL, 0x0,
1066 "Sequence ID", HFILL}},
1068 {"DF_CTL", "fc.df_ctl", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL}},
1070 {"SEQ_CNT", "fc.seq_cnt", FT_UINT16, BASE_DEC, NULL, 0x0,
1071 "Sequence Count", HFILL}},
1073 {"OX_ID", "fc.ox_id", FT_UINT16, BASE_HEX, NULL, 0x0, "Originator ID",
1076 {"RX_ID", "fc.rx_id", FT_UINT16, BASE_HEX, NULL, 0x0, "Receiver ID",
1079 {"Parameter", "fc.parameter", FT_UINT32, BASE_HEX, NULL, 0x0, "Parameter",
1082 { &hf_fc_reassembled,
1083 {"Reassembled Frame", "fc.reassembled", FT_BOOLEAN, BASE_HEX, NULL,
1086 {"Network DA", "fc.nethdr.da", FT_STRING, BASE_HEX, NULL,
1089 {"Network SA", "fc.nethdr.sa", FT_STRING, BASE_HEX, NULL,
1092 /* Basic Link Svc field definitions */
1093 { &hf_fc_bls_seqid_vld,
1094 {"SEQID Valid", "fc.bls_seqidvld", FT_UINT8, BASE_HEX,
1095 VALS (fc_bls_seqid_val), 0x0, "", HFILL}},
1096 { &hf_fc_bls_lastvld_seqid,
1097 {"Last Valid SEQID", "fc.bls_lastseqid", FT_UINT8, BASE_HEX, NULL,
1100 {"OXID", "fc.bls_oxid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL}},
1102 {"RXID", "fc.bls_rxid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL}},
1103 { &hf_fc_bls_lowseqcnt,
1104 {"Low SEQCNT", "fc.bls_lseqcnt", FT_UINT16, BASE_HEX, NULL, 0x0, "",
1106 { &hf_fc_bls_hiseqcnt,
1107 {"High SEQCNT", "fc.bls_hseqcnt", FT_UINT16, BASE_HEX, NULL, 0x0, "",
1109 { &hf_fc_bls_rjtcode,
1110 {"Reason", "fc.bls_reason", FT_UINT8, BASE_HEX, VALS(fc_bls_barjt_val),
1112 { &hf_fc_bls_rjtdetail,
1113 {"Reason Explanantion", "fc.bls_rjtdetail", FT_UINT8, BASE_HEX,
1114 VALS (fc_bls_barjt_det_val), 0x0, "", HFILL}},
1115 { &hf_fc_bls_vendor,
1116 {"Vendor Unique Reason", "fc.bls_vnduniq", FT_UINT8, BASE_HEX, NULL,
1118 { &hf_fc_fctl_exchange_responder,
1119 {"ExgRpd", "fc.fctl.exchange_responder", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_exchange_responder),
1120 FC_FCTL_EXCHANGE_RESPONDER, "Exchange Responder?", HFILL}},
1121 { &hf_fc_fctl_seq_recipient,
1122 {"SeqRec", "fc.fctl.seq_recipient", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_seq_recipient),
1123 FC_FCTL_SEQ_RECIPIENT, "Seq Recipient?", HFILL}},
1124 { &hf_fc_fctl_exchange_first,
1125 {"ExgFst", "fc.fctl.exchange_first", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_exchange_first),
1126 FC_FCTL_EXCHANGE_FIRST, "First Exchange?", HFILL}},
1127 { &hf_fc_fctl_exchange_last,
1128 {"ExgLst", "fc.fctl.exchange_last", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_exchange_last),
1129 FC_FCTL_EXCHANGE_LAST, "Last Exchange?", HFILL}},
1130 { &hf_fc_fctl_seq_last,
1131 {"SeqLst", "fc.fctl.seq_last", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_seq_last),
1132 FC_FCTL_SEQ_LAST, "Last Sequence?", HFILL}},
1133 { &hf_fc_fctl_priority,
1134 {"Pri", "fc.fctl.priority", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_priority),
1135 FC_FCTL_PRIORITY, "Priority", HFILL}},
1136 { &hf_fc_fctl_transfer_seq_initiative,
1137 {"TSI", "fc.fctl.transfer_seq_initiative", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_transfer_seq_initiative),
1138 FC_FCTL_TRANSFER_SEQ_INITIATIVE, "Transfer Seq Initiative", HFILL}},
1139 { &hf_fc_fctl_rexmitted_seq,
1140 {"RetSeq", "fc.fctl.rexmitted_seq", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_rexmitted_seq),
1141 FC_FCTL_REXMITTED_SEQ, "Retransmitted Sequence", HFILL}},
1142 { &hf_fc_fctl_rel_offset,
1143 {"RelOff", "fc.fctl.rel_offset", FT_BOOLEAN, 24, TFS(&tfs_fc_fctl_rel_offset),
1144 FC_FCTL_REL_OFFSET, "rel offset", HFILL}},
1145 { &hf_fc_fctl_last_data_frame,
1146 {"LDF", "fc.fctl.last_data_frame", FT_UINT24, BASE_HEX, VALS(last_data_frame_vals),
1147 FC_FCTL_LAST_DATA_FRAME_MASK, "Last Data Frame?", HFILL}},
1148 { &hf_fc_fctl_ack_0_1,
1149 {"A01", "fc.fctl.ack_0_1", FT_UINT24, BASE_HEX, VALS(ack_0_1_vals),
1150 FC_FCTL_ACK_0_1_MASK, "Ack 0/1 value", HFILL}},
1151 { &hf_fc_fctl_abts_ack,
1152 {"AA", "fc.fctl.abts_ack", FT_UINT24, BASE_HEX, VALS(abts_ack_vals),
1153 FC_FCTL_ABTS_MASK, "ABTS ACK values", HFILL}},
1154 { &hf_fc_fctl_abts_not_ack,
1155 {"AnA", "fc.fctl.abts_not_ack", FT_UINT24, BASE_HEX, VALS(abts_not_ack_vals),
1156 FC_FCTL_ABTS_MASK, "ABTS not ACK vals", HFILL}},
1157 { &hf_fc_exchange_first_frame,
1158 { "Exchange First In", "fc.exchange_first_frame", FT_FRAMENUM, BASE_NONE, NULL,
1159 0, "The first frame of this exchange is in this frame", HFILL }},
1160 { &hf_fc_exchange_last_frame,
1161 { "Exchange Last In", "fc.exchange_last_frame", FT_FRAMENUM, BASE_NONE, NULL,
1162 0, "The last frame of this exchange is in this frame", HFILL }},
1164 { "Time from Exchange First", "fc.time", FT_RELATIVE_TIME, BASE_NONE, NULL,
1165 0, "Time since the first frame of the Exchange", HFILL }},
1168 /* Setup protocol subtree array */
1169 static gint *ett[] = {
1175 module_t *fc_module;
1177 /* Register the protocol name and description */
1178 proto_fc = proto_register_protocol ("Fibre Channel", "FC", "fc");
1179 register_dissector ("fc", dissect_fc, proto_fc);
1180 fc_tap = register_tap("fc");
1182 /* Required function calls to register the header fields and subtrees used */
1183 proto_register_field_array(proto_fc, hf, array_length(hf));
1184 proto_register_subtree_array(ett, array_length(ett));
1186 fcftype_dissector_table = register_dissector_table ("fc.ftype",
1188 FT_UINT8, BASE_HEX);
1190 /* Register preferences */
1191 fc_module = prefs_register_protocol (proto_fc, NULL);
1192 prefs_register_bool_preference (fc_module,
1194 "Reassemble multi-frame sequences",
1195 "If enabled, reassembly of multi-frame "
1196 "sequences is done",
1198 prefs_register_uint_preference (fc_module,
1199 "max_frame_size", "Max FC Frame Size",
1200 "This is the size of non-last frames in a "
1201 "multi-frame sequence", 10,
1202 &fc_max_frame_size);
1204 register_init_routine(fc_defragment_init);
1205 register_init_routine (fc_exchange_init_protocol);
1209 /* If this dissector uses sub-dissector registration add a registration routine.
1210 This format is required because a script is used to find these routines and
1211 create the code that calls these routines.
1214 proto_reg_handoff_fc (void)
1216 dissector_handle_t fc_handle;
1218 fc_handle = create_dissector_handle (dissect_fc, proto_fc);
1220 data_handle = find_dissector("data");