2 * Routines for FC Common Transport Protocol (used by GS3 services)
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/to_str.h>
32 #include <epan/etypes.h>
33 #include <epan/conversation.h>
34 #include "packet-scsi.h"
35 #include "packet-fc.h"
36 #include "packet-fcct.h"
38 /* Initialize the protocol and registered fields */
39 static int proto_fcct
= -1;
40 static int hf_fcct_revision
= -1;
41 static int hf_fcct_inid
= -1;
42 static int hf_fcct_gstype
= -1;
43 static int hf_fcct_gssubtype
= -1;
44 static int hf_fcct_options
= -1;
45 static int hf_fcct_server
= -1; /* derived field */
47 /* Extended preamble fields */
49 static int hf_fcct_ext_said
= -1;
50 static int hf_fcct_ext_tid
= -1;
51 static int hf_fcct_ext_reqname
= -1;
52 static int hf_fcct_ext_tstamp
= -1;
53 static int hf_fcct_ext_authblk
= -1;
56 /* Initialize the subtree pointers */
57 static gint ett_fcct
= -1;
58 static gint ett_fcct_ext
= -1; /* for the extended header */
60 const value_string fc_ct_rjt_code_vals
[] = {
61 {FCCT_RJT_INVCMDCODE
, "Invalid Cmd Code"},
62 {FCCT_RJT_INVVERSION
, "Invalid Version Level"},
63 {FCCT_RJT_LOGICALERR
, "Logical Error"},
64 {FCCT_RJT_INVSIZE
, "Invalid CT_IU Size"},
65 {FCCT_RJT_LOGICALBSY
, "Logical Busy"},
66 {FCCT_RJT_PROTOERR
, "Protocol Error"},
67 {FCCT_RJT_GENFAIL
, "Unable to Perform Cmd"},
68 {FCCT_RJT_CMDNOTSUPP
, "Cmd Not Supported"},
72 const value_string fc_ct_gstype_vals
[] = {
73 {FCCT_GSTYPE_KEYSVC
, "Key Service"},
74 {FCCT_GSTYPE_ALIASSVC
, "Alias Service"},
75 {FCCT_GSTYPE_MGMTSVC
, "Management Service"},
76 {FCCT_GSTYPE_TIMESVC
, "Time Service"},
77 {FCCT_GSTYPE_DIRSVC
, "Directory Service"},
78 {FCCT_GSTYPE_FCTLR
, "Fabric Controller"},
79 {FCCT_GSTYPE_VENDOR
, "Vendor-Specific"},
83 const value_string fc_ct_gsserver_vals
[] = {
84 {FCCT_GSRVR_DNS
, "dNS"},
85 {FCCT_GSRVR_IP
, "IP"},
86 {FCCT_GSRVR_FCS
, "Fabric Config Server"},
87 {FCCT_GSRVR_UNS
, "Unzoned Name Server"},
88 {FCCT_GSRVR_FZS
, "Fabric Zone Server"},
89 {FCCT_GSRVR_TS
, "Time Server"},
90 {FCCT_GSRVR_KS
, "Key Server"},
91 {FCCT_GSRVR_AS
, "Alias Server"},
92 {FCCT_GSRVR_FCTLR
, "Fabric Controller"},
96 static dissector_table_t fcct_gserver_table
;
97 static dissector_handle_t data_handle
;
100 get_gs_server (guint8 gstype
, guint8 gssubtype
)
103 case FCCT_GSTYPE_KEYSVC
:
104 return FCCT_GSRVR_KS
;
105 case FCCT_GSTYPE_ALIASSVC
:
106 if (gssubtype
== FCCT_GSSUBTYPE_AS
)
107 return FCCT_GSRVR_AS
;
108 return FCCT_GSRVR_UNKNOWN
;
109 case FCCT_GSTYPE_MGMTSVC
:
110 if (gssubtype
== FCCT_GSSUBTYPE_FCS
)
111 return FCCT_GSRVR_FCS
;
112 else if (gssubtype
== FCCT_GSSUBTYPE_UNS
)
113 return FCCT_GSRVR_UNS
;
114 else if (gssubtype
== FCCT_GSSUBTYPE_FZS
)
115 return FCCT_GSRVR_FZS
;
116 else return FCCT_GSRVR_UNKNOWN
;
117 case FCCT_GSTYPE_TIMESVC
:
118 if (gssubtype
== FCCT_GSSUBTYPE_TS
)
119 return FCCT_GSRVR_TS
;
120 return FCCT_GSRVR_UNKNOWN
;
121 case FCCT_GSTYPE_DIRSVC
:
122 if (gssubtype
== FCCT_GSSUBTYPE_DNS
)
123 return FCCT_GSRVR_DNS
;
124 else if (gssubtype
== FCCT_GSSUBTYPE_IP
)
125 return FCCT_GSRVR_IP
;
126 return FCCT_GSRVR_UNKNOWN
;
127 case FCCT_GSRVR_FCTLR
:
128 if (gssubtype
== FCCT_GSSUBTYPE_FCTLR
)
129 return (FCCT_GSRVR_FCTLR
);
130 else return (FCCT_GSRVR_UNKNOWN
);
132 return FCCT_GSRVR_UNKNOWN
;
136 /* Code to actually dissect the packets */
138 dissect_fcct (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
141 /* Set up structures needed to add the protocol subtree and manage it */
143 proto_tree
*fcct_tree
;
148 fc_ct_preamble cthdr
;
150 /* Make entries in Protocol column and Info column on summary display */
151 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FC_CT");
154 cthdr.revision = tvb_get_guint8 (tvb, offset++);
155 cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
158 cthdr.gstype = tvb_get_guint8 (tvb, offset++);
159 cthdr.options = tvb_get_guint8 (tvb, offset++);
161 tvb_memcpy (tvb
, (guint8
*)&cthdr
, offset
, FCCT_PRMBL_SIZE
);
162 cthdr
.revision
= tvb_get_guint8 (tvb
, offset
++);
163 cthdr
.in_id
= tvb_get_ntoh24 (tvb
, offset
);
164 cthdr
.opcode
= g_ntohs (cthdr
.opcode
);
165 cthdr
.maxres_size
= g_ntohs (cthdr
.maxres_size
);
167 if (cthdr
.opcode
< FCCT_MSG_REQ_MAX
) {
168 col_append_str (pinfo
->cinfo
, COL_INFO
, " Request");
170 else if (cthdr
.opcode
== FCCT_MSG_ACC
) {
171 col_append_str (pinfo
->cinfo
, COL_INFO
, " Accept");
173 else if (cthdr
.opcode
== FCCT_MSG_RJT
) {
174 col_append_fstr (pinfo
->cinfo
, COL_INFO
, " Reject (%s)",
175 val_to_str (cthdr
.rjt_code
, fc_ct_rjt_code_vals
, "0x%x"));
178 col_append_str (pinfo
->cinfo
, COL_INFO
, " Reserved");
182 in_id
= g_htonl (in_id
) >> 8;
184 /* Determine server */
185 server
= get_gs_server (cthdr
.gstype
, cthdr
.gssubtype
);
189 ti
= proto_tree_add_protocol_format (tree
, proto_fcct
, tvb
, 0, FCCT_PRMBL_SIZE
,
191 fcct_tree
= proto_item_add_subtree (ti
, ett_fcct
);
193 proto_tree_add_item (fcct_tree
, hf_fcct_revision
, tvb
, offset
++,
194 sizeof (guint8
), ENC_BIG_ENDIAN
);
195 proto_tree_add_string (fcct_tree
, hf_fcct_inid
, tvb
, offset
, 3,
196 fc_to_str ((guint8
*)&in_id
));
197 offset
+= 3; /* sizeof FC address */
199 proto_tree_add_item (fcct_tree
, hf_fcct_gstype
, tvb
, offset
++,
200 sizeof (guint8
), ENC_BIG_ENDIAN
);
201 proto_tree_add_item (fcct_tree
, hf_fcct_gssubtype
, tvb
, offset
,
202 sizeof (guint8
), ENC_BIG_ENDIAN
);
203 proto_tree_add_uint (fcct_tree
, hf_fcct_server
, tvb
, offset
++, 1,
205 proto_tree_add_item (fcct_tree
, hf_fcct_options
, tvb
, offset
++,
206 sizeof (guint8
), ENC_BIG_ENDIAN
);
209 /* We do not change the starting offset for the next protocol in the
210 * chain since the fc_ct header is common to the sub-protocols.
212 next_tvb
= tvb_new_subset_remaining (tvb
, 0);
213 if (!dissector_try_uint (fcct_gserver_table
, server
, next_tvb
, pinfo
,
215 call_dissector (data_handle
, next_tvb
, pinfo
, tree
);
219 /* Register the protocol with Wireshark */
221 /* this format is require because a script is used to build the C function
222 that calls all the protocol registration.
226 proto_register_fcct(void)
229 /* Setup list of header fields See Section 1.6.1 for details*/
230 static hf_register_info hf
[] = {
232 {"Revision", "fcct.revision", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
234 {"IN_ID", "fcct.in_id", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
236 {"GS Type", "fcct.gstype", FT_UINT8
, BASE_HEX
, VALS(fc_ct_gstype_vals
),
238 { &hf_fcct_gssubtype
,
239 {"GS Subtype", "fcct.gssubtype", FT_UINT8
, BASE_HEX
, NULL
, 0x0,
242 {"Server", "fcct.server", FT_UINT8
, BASE_HEX
,
243 VALS (fc_ct_gsserver_vals
), 0x0,
244 "Derived from GS Type & Subtype fields", HFILL
}},
246 {"Options", "fcct.options", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
,
250 {"Auth SAID", "fcct.ext_said", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
,
253 {"Transaction ID", "fcct.ext_tid", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
,
255 { &hf_fcct_ext_reqname
,
256 {"Requestor Port Name", "fcct.ext_reqnm", FT_BYTES
, BASE_NONE
, NULL
,
258 { &hf_fcct_ext_tstamp
,
259 {"Timestamp", "fcct.ext_tstamp", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
,
261 { &hf_fcct_ext_authblk
,
262 {"Auth Hash Blk", "fcct.ext_authblk", FT_BYTES
, BASE_NONE
, NULL
, 0x0,
267 /* Setup protocol subtree array */
268 static gint
*ett
[] = {
273 /* Register the protocol name and description */
274 proto_fcct
= proto_register_protocol("Fibre Channel Common Transport", "FC_CT", "fcct");
276 /* Required function calls to register the header fields and subtrees used */
277 proto_register_field_array(proto_fcct
, hf
, array_length(hf
));
278 proto_register_subtree_array(ett
, array_length(ett
));
280 fcct_gserver_table
= register_dissector_table ("fcct.server",
285 /* If this dissector uses sub-dissector registration add a registration routine.
286 This format is required because a script is used to find these routines and
287 create the code that calls these routines.
290 proto_reg_handoff_fcct (void)
292 dissector_handle_t fcct_handle
;
294 fcct_handle
= create_dissector_handle (dissect_fcct
, proto_fcct
);
295 dissector_add_uint("fc.ftype", FC_FTYPE_FCCT
, fcct_handle
);
297 data_handle
= find_dissector ("data");