2 * Routines for FC Common Transport Protocol (used by GS3 services)
3 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
5 * $Id: packet-fcct.c,v 1.2 2003/06/30 21:50:17 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
48 #include <epan/packet.h>
50 #include "packet-fc.h"
51 #include "packet-fcct.h"
53 /* Initialize the protocol and registered fields */
54 static int proto_fcct = -1;
55 static int hf_fcct_revision = -1;
56 static int hf_fcct_inid = -1;
57 static int hf_fcct_gstype = -1;
58 static int hf_fcct_gssubtype = -1;
59 static int hf_fcct_options = -1;
60 static int hf_fcct_server = -1; /* derived field */
62 /* Extended preamble fields */
63 static int hf_fcct_ext_said = -1;
64 static int hf_fcct_ext_tid = -1;
65 static int hf_fcct_ext_reqname = -1;
66 static int hf_fcct_ext_tstamp = -1;
67 static int hf_fcct_ext_authblk = -1;
69 /* Initialize the subtree pointers */
70 static gint ett_fcct = -1;
71 static gint ett_fcct_ext = -1; /* for the extended header */
73 const value_string fc_ct_rjt_code_vals [] = {
74 {FCCT_RJT_INVCMDCODE, "Invalid Cmd Code"},
75 {FCCT_RJT_INVVERSION, "Invalid Version Level"},
76 {FCCT_RJT_LOGICALERR, "Logical Error"},
77 {FCCT_RJT_INVSIZE, "Invalid CT_IU Size"},
78 {FCCT_RJT_LOGICALBSY, "Logical Busy"},
79 {FCCT_RJT_PROTOERR, "Protocol Error"},
80 {FCCT_RJT_GENFAIL, "Unable to Perform Cmd"},
81 {FCCT_RJT_CMDNOTSUPP, "Cmd Not Supported"},
85 static const value_string fc_ct_gstype_vals[] = {
86 {FCCT_GSTYPE_KEYSVC, "Key Service"},
87 {FCCT_GSTYPE_ALIASSVC, "Alias Service"},
88 {FCCT_GSTYPE_MGMTSVC, "Management Service"},
89 {FCCT_GSTYPE_TIMESVC, "Time Service"},
90 {FCCT_GSTYPE_DIRSVC, "Directory Service"},
94 static const value_string fc_ct_gsserver_vals[] = {
95 {FCCT_GSRVR_DNS, "dNS"},
96 {FCCT_GSRVR_IP, "IP"},
97 {FCCT_GSRVR_FCS, "Fabric Config Server"},
98 {FCCT_GSRVR_UNS, "Unzoned Name Server"},
99 {FCCT_GSRVR_FZS, "Fabric Zone Server"},
100 {FCCT_GSRVR_TS, "Time Server"},
101 {FCCT_GSRVR_KS, "Key Server"},
102 {FCCT_GSRVR_AS, "Alias Server"},
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;
138 return FCCT_GSRVR_UNKNOWN;
142 /* Code to actually dissect the packets */
144 dissect_fcct (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
147 /* Set up structures needed to add the protocol subtree and manage it */
149 proto_tree *fcct_tree;
154 fc_ct_preamble cthdr;
156 /* Make entries in Protocol column and Info column on summary display */
157 if (check_col(pinfo->cinfo, COL_PROTOCOL))
158 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FC_CT");
161 cthdr.revision = tvb_get_guint8 (tvb, offset++);
162 cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
165 cthdr.gstype = tvb_get_guint8 (tvb, offset++);
166 cthdr.options = tvb_get_guint8 (tvb, offset++);
168 tvb_memcpy (tvb, (guint8 *)&cthdr, offset, FCCT_PRMBL_SIZE);
169 cthdr.revision = tvb_get_guint8 (tvb, offset++);
170 cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
171 cthdr.opcode = ntohs (cthdr.opcode);
172 cthdr.maxres_size = ntohs (cthdr.maxres_size);
174 if (check_col (pinfo->cinfo, COL_INFO)) {
175 if (cthdr.opcode < FCCT_MSG_REQ_MAX) {
176 col_append_str (pinfo->cinfo, COL_INFO, " Request");
178 else if (cthdr.opcode == FCCT_MSG_ACC) {
179 col_append_str (pinfo->cinfo, COL_INFO, " Accept");
181 else if (cthdr.opcode == FCCT_MSG_RJT) {
182 col_append_fstr (pinfo->cinfo, COL_INFO, " Reject (%s)",
183 val_to_str (cthdr.rjt_code, fc_ct_rjt_code_vals, "0x%x"));
186 col_append_str (pinfo->cinfo, COL_INFO, " Reserved");
191 in_id = htonl (in_id) >> 8;
193 /* Determine server */
194 server = get_gs_server (cthdr.gstype, cthdr.gssubtype);
198 ti = proto_tree_add_protocol_format (tree, proto_fcct, tvb, 0, FCCT_PRMBL_SIZE,
200 fcct_tree = proto_item_add_subtree (ti, ett_fcct);
202 proto_tree_add_item (fcct_tree, hf_fcct_revision, tvb, offset++,
204 proto_tree_add_string (fcct_tree, hf_fcct_inid, tvb, offset, 3,
205 fc_to_str ((guint8 *)&in_id));
206 offset += 3; /* sizeof FC address */
208 proto_tree_add_item (fcct_tree, hf_fcct_gstype, tvb, offset++,
210 proto_tree_add_item (fcct_tree, hf_fcct_gssubtype, tvb, offset,
212 proto_tree_add_uint (fcct_tree, hf_fcct_server, tvb, offset++, 1,
214 proto_tree_add_item (fcct_tree, hf_fcct_options, tvb, offset++,
218 /* We do not change the starting offset for the next protocol in the
219 * chain since the fc_ct header is common to the sub-protocols.
221 next_tvb = tvb_new_subset (tvb, 0, -1, -1);
222 if (!dissector_try_port (fcct_gserver_table, server, next_tvb, pinfo,
224 call_dissector (data_handle, next_tvb, pinfo, tree);
228 /* Register the protocol with Ethereal */
230 /* this format is require because a script is used to build the C function
231 that calls all the protocol registration.
235 proto_register_fcct(void)
238 /* Setup list of header fields See Section 1.6.1 for details*/
239 static hf_register_info hf[] = {
241 {"Revision", "fcct.revision", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
243 {"IN_ID", "fcct.in_id", FT_STRING, BASE_HEX, NULL, 0x0, "", HFILL}},
245 {"GS Type", "fcct.gstype", FT_UINT8, BASE_HEX, VALS(fc_ct_gstype_vals),
247 { &hf_fcct_gssubtype,
248 {"GS Subtype", "fcct.gssubtype", FT_UINT8, BASE_HEX, NULL, 0x0,
251 {"Server", "fcct.server", FT_UINT8, BASE_HEX,
252 VALS (fc_ct_gsserver_vals), 0x0,
253 "Derived from GS Type & Subtype fields", HFILL}},
255 {"Options", "fcct.options", FT_UINT8, BASE_HEX, NULL, 0x0, "",
258 {"Auth SAID", "fcct.ext_said", FT_UINT32, BASE_HEX, NULL, 0x0, "",
261 {"Transaction ID", "fcct.ext_tid", FT_UINT32, BASE_HEX, NULL, 0x0, "",
263 { &hf_fcct_ext_reqname,
264 {"Requestor Port Name", "fcct_ext_reqnm", FT_BYTES, BASE_HEX, NULL,
266 { &hf_fcct_ext_tstamp,
267 {"Timestamp", "fcct_ext_tstamp", FT_BYTES, BASE_HEX, NULL, 0x0, "",
269 { &hf_fcct_ext_authblk,
270 {"Auth Hash Blk", "fcct_ext_authblk", FT_BYTES, BASE_HEX, NULL, 0x0,
274 /* Setup protocol subtree array */
275 static gint *ett[] = {
280 /* Register the protocol name and description */
281 proto_fcct = proto_register_protocol("Fibre Channel Common Transport", "FC_CT", "fcct");
283 /* Required function calls to register the header fields and subtrees used */
284 proto_register_field_array(proto_fcct, hf, array_length(hf));
285 proto_register_subtree_array(ett, array_length(ett));
287 fcct_gserver_table = register_dissector_table ("fcct.server",
292 /* If this dissector uses sub-dissector registration add a registration routine.
293 This format is required because a script is used to find these routines and
294 create the code that calls these routines.
297 proto_reg_handoff_fcct (void)
299 dissector_handle_t fcct_handle;
301 fcct_handle = create_dissector_handle (dissect_fcct, proto_fcct);
302 dissector_add("fc.ftype", FC_FTYPE_FCCT, fcct_handle);
304 data_handle = find_dissector ("data");