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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
44 #include <epan/packet.h>
45 #include <epan/etypes.h>
46 #include <epan/conversation.h>
47 #include "packet-fc.h"
48 #include "packet-fcct.h"
50 /* Initialize the protocol and registered fields */
51 static int proto_fcct = -1;
52 static int hf_fcct_revision = -1;
53 static int hf_fcct_inid = -1;
54 static int hf_fcct_gstype = -1;
55 static int hf_fcct_gssubtype = -1;
56 static int hf_fcct_options = -1;
57 static int hf_fcct_server = -1; /* derived field */
59 /* Extended preamble fields */
60 static int hf_fcct_ext_said = -1;
61 static int hf_fcct_ext_tid = -1;
62 static int hf_fcct_ext_reqname = -1;
63 static int hf_fcct_ext_tstamp = -1;
64 static int hf_fcct_ext_authblk = -1;
66 /* Initialize the subtree pointers */
67 static gint ett_fcct = -1;
68 static gint ett_fcct_ext = -1; /* for the extended header */
70 const value_string fc_ct_rjt_code_vals [] = {
71 {FCCT_RJT_INVCMDCODE, "Invalid Cmd Code"},
72 {FCCT_RJT_INVVERSION, "Invalid Version Level"},
73 {FCCT_RJT_LOGICALERR, "Logical Error"},
74 {FCCT_RJT_INVSIZE, "Invalid CT_IU Size"},
75 {FCCT_RJT_LOGICALBSY, "Logical Busy"},
76 {FCCT_RJT_PROTOERR, "Protocol Error"},
77 {FCCT_RJT_GENFAIL, "Unable to Perform Cmd"},
78 {FCCT_RJT_CMDNOTSUPP, "Cmd Not Supported"},
82 const value_string fc_ct_gstype_vals[] = {
83 {FCCT_GSTYPE_KEYSVC, "Key Service"},
84 {FCCT_GSTYPE_ALIASSVC, "Alias Service"},
85 {FCCT_GSTYPE_MGMTSVC, "Management Service"},
86 {FCCT_GSTYPE_TIMESVC, "Time Service"},
87 {FCCT_GSTYPE_DIRSVC, "Directory Service"},
88 {FCCT_GSTYPE_FCTLR, "Fabric Controller"},
89 {FCCT_GSTYPE_VENDOR, "Vendor-Specific"},
93 const value_string fc_ct_gsserver_vals[] = {
94 {FCCT_GSRVR_DNS, "dNS"},
95 {FCCT_GSRVR_IP, "IP"},
96 {FCCT_GSRVR_FCS, "Fabric Config Server"},
97 {FCCT_GSRVR_UNS, "Unzoned Name Server"},
98 {FCCT_GSRVR_FZS, "Fabric Zone Server"},
99 {FCCT_GSRVR_TS, "Time Server"},
100 {FCCT_GSRVR_KS, "Key Server"},
101 {FCCT_GSRVR_AS, "Alias Server"},
102 {FCCT_GSRVR_FCTLR, "Fabric Controller"},
106 static dissector_table_t fcct_gserver_table;
107 static dissector_handle_t data_handle;
110 get_gs_server (guint8 gstype, guint8 gssubtype)
113 case FCCT_GSTYPE_KEYSVC:
114 return FCCT_GSRVR_KS;
115 case FCCT_GSTYPE_ALIASSVC:
116 if (gssubtype == FCCT_GSSUBTYPE_AS)
117 return FCCT_GSRVR_AS;
118 return FCCT_GSRVR_UNKNOWN;
119 case FCCT_GSTYPE_MGMTSVC:
120 if (gssubtype == FCCT_GSSUBTYPE_FCS)
121 return FCCT_GSRVR_FCS;
122 else if (gssubtype == FCCT_GSSUBTYPE_UNS)
123 return FCCT_GSRVR_UNS;
124 else if (gssubtype == FCCT_GSSUBTYPE_FZS)
125 return FCCT_GSRVR_FZS;
126 else return FCCT_GSRVR_UNKNOWN;
127 case FCCT_GSTYPE_TIMESVC:
128 if (gssubtype == FCCT_GSSUBTYPE_TS)
129 return FCCT_GSRVR_TS;
130 return FCCT_GSRVR_UNKNOWN;
131 case FCCT_GSTYPE_DIRSVC:
132 if (gssubtype == FCCT_GSSUBTYPE_DNS)
133 return FCCT_GSRVR_DNS;
134 else if (gssubtype == FCCT_GSSUBTYPE_IP)
135 return FCCT_GSRVR_IP;
136 return FCCT_GSRVR_UNKNOWN;
137 case FCCT_GSRVR_FCTLR:
138 if (gssubtype == FCCT_GSSUBTYPE_FCTLR)
139 return (FCCT_GSRVR_FCTLR);
140 else return (FCCT_GSRVR_UNKNOWN);
142 return FCCT_GSRVR_UNKNOWN;
146 /* Code to actually dissect the packets */
148 dissect_fcct (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
151 /* Set up structures needed to add the protocol subtree and manage it */
153 proto_tree *fcct_tree;
158 fc_ct_preamble cthdr;
160 /* Make entries in Protocol column and Info column on summary display */
161 if (check_col(pinfo->cinfo, COL_PROTOCOL))
162 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FC_CT");
165 cthdr.revision = tvb_get_guint8 (tvb, offset++);
166 cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
169 cthdr.gstype = tvb_get_guint8 (tvb, offset++);
170 cthdr.options = tvb_get_guint8 (tvb, offset++);
172 tvb_memcpy (tvb, (guint8 *)&cthdr, offset, FCCT_PRMBL_SIZE);
173 cthdr.revision = tvb_get_guint8 (tvb, offset++);
174 cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
175 cthdr.opcode = ntohs (cthdr.opcode);
176 cthdr.maxres_size = ntohs (cthdr.maxres_size);
178 if (check_col (pinfo->cinfo, COL_INFO)) {
179 if (cthdr.opcode < FCCT_MSG_REQ_MAX) {
180 col_append_str (pinfo->cinfo, COL_INFO, " Request");
182 else if (cthdr.opcode == FCCT_MSG_ACC) {
183 col_append_str (pinfo->cinfo, COL_INFO, " Accept");
185 else if (cthdr.opcode == FCCT_MSG_RJT) {
186 col_append_fstr (pinfo->cinfo, COL_INFO, " Reject (%s)",
187 val_to_str (cthdr.rjt_code, fc_ct_rjt_code_vals, "0x%x"));
190 col_append_str (pinfo->cinfo, COL_INFO, " Reserved");
195 in_id = htonl (in_id) >> 8;
197 /* Determine server */
198 server = get_gs_server (cthdr.gstype, cthdr.gssubtype);
202 ti = proto_tree_add_protocol_format (tree, proto_fcct, tvb, 0, FCCT_PRMBL_SIZE,
204 fcct_tree = proto_item_add_subtree (ti, ett_fcct);
206 proto_tree_add_item (fcct_tree, hf_fcct_revision, tvb, offset++,
208 proto_tree_add_string (fcct_tree, hf_fcct_inid, tvb, offset, 3,
209 fc_to_str ((guint8 *)&in_id));
210 offset += 3; /* sizeof FC address */
212 proto_tree_add_item (fcct_tree, hf_fcct_gstype, tvb, offset++,
214 proto_tree_add_item (fcct_tree, hf_fcct_gssubtype, tvb, offset,
216 proto_tree_add_uint (fcct_tree, hf_fcct_server, tvb, offset++, 1,
218 proto_tree_add_item (fcct_tree, hf_fcct_options, tvb, offset++,
222 /* We do not change the starting offset for the next protocol in the
223 * chain since the fc_ct header is common to the sub-protocols.
225 next_tvb = tvb_new_subset (tvb, 0, -1, -1);
226 if (!dissector_try_port (fcct_gserver_table, server, next_tvb, pinfo,
228 call_dissector (data_handle, next_tvb, pinfo, tree);
232 /* Register the protocol with Wireshark */
234 /* this format is require because a script is used to build the C function
235 that calls all the protocol registration.
239 proto_register_fcct(void)
242 /* Setup list of header fields See Section 1.6.1 for details*/
243 static hf_register_info hf[] = {
245 {"Revision", "fcct.revision", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
247 {"IN_ID", "fcct.in_id", FT_STRING, BASE_HEX, NULL, 0x0, "", HFILL}},
249 {"GS Type", "fcct.gstype", FT_UINT8, BASE_HEX, VALS(fc_ct_gstype_vals),
251 { &hf_fcct_gssubtype,
252 {"GS Subtype", "fcct.gssubtype", FT_UINT8, BASE_HEX, NULL, 0x0,
255 {"Server", "fcct.server", FT_UINT8, BASE_HEX,
256 VALS (fc_ct_gsserver_vals), 0x0,
257 "Derived from GS Type & Subtype fields", HFILL}},
259 {"Options", "fcct.options", FT_UINT8, BASE_HEX, NULL, 0x0, "",
262 {"Auth SAID", "fcct.ext_said", FT_UINT32, BASE_HEX, NULL, 0x0, "",
265 {"Transaction ID", "fcct.ext_tid", FT_UINT32, BASE_HEX, NULL, 0x0, "",
267 { &hf_fcct_ext_reqname,
268 {"Requestor Port Name", "fcct_ext_reqnm", FT_BYTES, BASE_HEX, NULL,
270 { &hf_fcct_ext_tstamp,
271 {"Timestamp", "fcct_ext_tstamp", FT_BYTES, BASE_HEX, NULL, 0x0, "",
273 { &hf_fcct_ext_authblk,
274 {"Auth Hash Blk", "fcct_ext_authblk", FT_BYTES, BASE_HEX, NULL, 0x0,
278 /* Setup protocol subtree array */
279 static gint *ett[] = {
284 /* Register the protocol name and description */
285 proto_fcct = proto_register_protocol("Fibre Channel Common Transport", "FC_CT", "fcct");
287 /* Required function calls to register the header fields and subtrees used */
288 proto_register_field_array(proto_fcct, hf, array_length(hf));
289 proto_register_subtree_array(ett, array_length(ett));
291 fcct_gserver_table = register_dissector_table ("fcct.server",
296 /* If this dissector uses sub-dissector registration add a registration routine.
297 This format is required because a script is used to find these routines and
298 create the code that calls these routines.
301 proto_reg_handoff_fcct (void)
303 dissector_handle_t fcct_handle;
305 fcct_handle = create_dissector_handle (dissect_fcct, proto_fcct);
306 dissector_add("fc.ftype", FC_FTYPE_FCCT, fcct_handle);
308 data_handle = find_dissector ("data");