2 * Routines for dissassembly of the Hyper SCSI protocol.
4 * $Id: packet-hyperscsi.c,v 1.4 2002/12/03 01:09:00 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
9 * Copyright 2002 Richard Sharpe <rsharpe@richardsharpe.com>
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 NEED_SNPRINTF_H
35 # include "snprintf.h"
38 #include <epan/packet.h>
40 static int proto_hyperscsi;
42 static int hf_hs_cmd = -1;
43 static int hf_hs_ver = -1;
44 static int hf_hs_res = -1;
45 static int hf_hs_tagno = -1;
46 static int hf_hs_lastfrag = -1;
47 static int hf_hs_fragno = -1;
49 static gint ett_hyperscsi = -1;
50 static gint ett_hs_hdr = -1;
51 static gint ett_hs_pdu = -1;
53 static const true_false_string tfs_lastfrag = {
58 #define HSCSI_OPCODE_REQUEST 0x00
59 #define HSCSI_OPCODE_REPLY 0x01
60 #define HSCSI_OPCODE_DEV_DISCOVERY 0x10
61 #define HSCSI_OPCODE_ADN_REQUEST 0x11
62 #define HSCSI_OPCODE_ADN_REPLY 0x12
63 #define HSCSI_OPCODE_DISCONNECT 0x13
64 #define HSCSI_OPCODE_ACK_SNR 0x20
65 #define HSCSI_OPCODE_ACK_REPLY 0x21
66 #define HSCSI_OPCODE_ADDR_REPORT 0x30
67 #define HSCSI_OPCODE_ADDR_REPLY 0x31
68 #define HSCSI_OPCODE_LOCAL_REQUEST 0x32
69 #define HSCSI_OPCODE_LOCAL_REPLY 0x33
70 #define HSCSI_OPCODE_REMOTE_REQUEST 0x34
71 #define HSCSI_OPCODE_REMOTE_REPLY 0x35
73 static const value_string hscsi_opcodes[] = {
74 { HSCSI_OPCODE_REQUEST, "Command Block Encap Request"},
75 { HSCSI_OPCODE_REPLY, "Command Block Encap Reply"},
76 { HSCSI_OPCODE_DEV_DISCOVERY, "Device Discovery Reply"},
77 { HSCSI_OPCODE_ADN_REQUEST, "Auth/Device Neg Request"},
78 { HSCSI_OPCODE_ADN_REPLY, "Auth/Device Neg Reply"},
79 { HSCSI_OPCODE_DISCONNECT, "Disconnect Request"},
80 { HSCSI_OPCODE_ACK_SNR, "Flow Control Setup/Ack Request"},
81 { HSCSI_OPCODE_ACK_REPLY, "Flow Control Ack Reply"},
85 #define OPCODE_MASK 0x7F
88 dissect_hyperscsi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
90 guint hs_hdr1, hs_hdr2, hs_hdr3;
95 proto_tree *hs_hdr_tree, *hs_pdu_tree;
96 proto_tree *hs_tree = NULL;
98 guint8 hs_cmd, hs_ver;
101 if (check_col(pinfo->cinfo, COL_PROTOCOL))
102 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HYPERSCSI");
103 if (check_col(pinfo->cinfo, COL_INFO))
104 col_clear(pinfo->cinfo, COL_INFO);
107 ti = proto_tree_add_item(tree, proto_hyperscsi, tvb, offset, -1, FALSE);
108 hs_tree = proto_item_add_subtree(ti, ett_hyperscsi);
111 hs_hdr1 = tvb_get_guint8(tvb, offset);
113 hs_hdr2 = tvb_get_guint8(tvb, offset);
115 hs_hdr3 = tvb_get_guint8(tvb, offset);
118 hs_res = hs_hdr1 >> 4;
119 hs_tagno = ((hs_hdr1 & 0x0F) << 5 ) | (hs_hdr2 >> 3);
120 hs_fragno = ((hs_hdr2 &0X03) << 8 ) | hs_hdr3;
123 * Add the header ... three bytes
127 ti = proto_tree_add_text(hs_tree, tvb, 0, 3, "HyperSCSI Header");
128 hs_hdr_tree = proto_item_add_subtree(ti, ett_hs_hdr);
131 * Now, add the header items
134 proto_tree_add_uint(hs_hdr_tree, hf_hs_res, tvb, 0, 1, hs_res);
135 proto_tree_add_uint(hs_hdr_tree, hf_hs_tagno, tvb, 0, 2, hs_tagno);
136 proto_tree_add_item(hs_hdr_tree, hf_hs_lastfrag, tvb, 1, 1, FALSE);
137 proto_tree_add_uint(hs_hdr_tree, hf_hs_fragno, tvb, 1, 2, hs_fragno);
145 hs_ver = tvb_get_guint8(tvb, offset++);
147 hs_cmd = tvb_get_guint8(tvb, offset++);
149 hs_cmd &= OPCODE_MASK;
151 opcode_str = match_strval(hs_cmd, hscsi_opcodes);
154 opcode_str = "Unknown HyperSCSI Request or Response";
156 if (check_col(pinfo->cinfo, COL_INFO)) {
157 col_append_str(pinfo->cinfo, COL_INFO, (char *)opcode_str);
161 ti = proto_tree_add_text(hs_tree, tvb, 3, -1, "HyperSCSI PDU");
162 hs_pdu_tree = proto_item_add_subtree(ti, ett_hs_pdu);
164 proto_tree_add_uint(hs_pdu_tree, hf_hs_ver, tvb, 3, 1, hs_ver);
166 proto_tree_add_uint_format(hs_pdu_tree, hf_hs_cmd, tvb, 4, 1, hs_cmd, "HyperSCSI Command: %s", opcode_str);
172 proto_register_hyperscsi(void)
175 static hf_register_info hf[] = {
177 { "Reserved", "hyperscsi.reserved", FT_UINT8, BASE_DEC, NULL, 0x0,
181 { "Tag No", "hyperscsi.tagno", FT_UINT16, BASE_DEC, NULL, 0x0,
185 { "Last Fragment", "hyperscsi.lastfrag", FT_BOOLEAN, 8, TFS(&tfs_lastfrag), 0x04, "", HFILL}},
188 { "Fragment No", "hyperscsi.fragno", FT_UINT16, BASE_DEC, NULL, 0x0,
192 { "HyperSCSI Version", "hyperscsi.version", FT_UINT8, BASE_DEC, NULL,
196 { "HyperSCSI Command", "hyperscsi.cmd", FT_UINT8, BASE_DEC, NULL, 0x0,
200 static gint *ett[] = {
206 proto_hyperscsi = proto_register_protocol("HyperSCSI", "HyperSCSI", "hyperscsi");
207 proto_register_field_array(proto_hyperscsi, hf, array_length(hf));
208 proto_register_subtree_array(ett, array_length(ett));
210 register_dissector("hyperscsi", dissect_hyperscsi, proto_hyperscsi);
213 #define ETHERTYPE_HYPERSCSI 0x889A
216 proto_reg_handoff_hyperscsi(void)
218 dissector_handle_t hs_handle;
220 hs_handle = find_dissector("hyperscsi");
221 dissector_add("ethertype", ETHERTYPE_HYPERSCSI, hs_handle);