aboutsummaryrefslogtreecommitdiffstats
path: root/packet-hyperscsi.c
blob: e7872b3b642c022bf32bf0884beb555e5edecd16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* packet-ip.c
 * Routines for dissassembly of the Hyper SCSI protocol.
 *
 * $Id: packet-hyperscsi.c,v 1.4 2002/12/03 01:09:00 jmayer Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 * Copyright 2002 Richard Sharpe <rsharpe@richardsharpe.com> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <string.h>
#include <glib.h>

#ifdef NEED_SNPRINTF_H
# include "snprintf.h"
#endif

#include <epan/packet.h>

static int proto_hyperscsi;

static int hf_hs_cmd = -1;
static int hf_hs_ver = -1;
static int hf_hs_res = -1;
static int hf_hs_tagno = -1;
static int hf_hs_lastfrag = -1;
static int hf_hs_fragno = -1;

static gint ett_hyperscsi = -1; 
static gint ett_hs_hdr = -1;
static gint ett_hs_pdu = -1;

static const true_false_string tfs_lastfrag = {
  "Last Fragment",
  "Not Last Fragment"
};

#define HSCSI_OPCODE_REQUEST                  0x00
#define HSCSI_OPCODE_REPLY                    0x01
#define HSCSI_OPCODE_DEV_DISCOVERY            0x10
#define HSCSI_OPCODE_ADN_REQUEST              0x11
#define HSCSI_OPCODE_ADN_REPLY                0x12
#define HSCSI_OPCODE_DISCONNECT               0x13
#define HSCSI_OPCODE_ACK_SNR                  0x20
#define HSCSI_OPCODE_ACK_REPLY                0x21
#define HSCSI_OPCODE_ADDR_REPORT              0x30
#define HSCSI_OPCODE_ADDR_REPLY               0x31
#define HSCSI_OPCODE_LOCAL_REQUEST            0x32
#define HSCSI_OPCODE_LOCAL_REPLY              0x33
#define HSCSI_OPCODE_REMOTE_REQUEST           0x34
#define HSCSI_OPCODE_REMOTE_REPLY             0x35

static const value_string hscsi_opcodes[] = {
  { HSCSI_OPCODE_REQUEST,         "Command Block Encap Request"}, 
  { HSCSI_OPCODE_REPLY,           "Command Block Encap Reply"},
  { HSCSI_OPCODE_DEV_DISCOVERY,   "Device Discovery Reply"},
  { HSCSI_OPCODE_ADN_REQUEST,     "Auth/Device Neg Request"},
  { HSCSI_OPCODE_ADN_REPLY,       "Auth/Device Neg Reply"},
  { HSCSI_OPCODE_DISCONNECT,      "Disconnect Request"},
  { HSCSI_OPCODE_ACK_SNR,         "Flow Control Setup/Ack Request"},
  { HSCSI_OPCODE_ACK_REPLY,       "Flow Control Ack Reply"},
  { 0, NULL}
};

#define OPCODE_MASK 0x7F

static void
dissect_hyperscsi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  guint      hs_hdr1, hs_hdr2, hs_hdr3;
  guint8     hs_res;
  guint16    hs_tagno;
  guint16    hs_fragno;
  gint       offset = 0;
  proto_tree *hs_hdr_tree, *hs_pdu_tree;
  proto_tree *hs_tree = NULL;
  proto_item *ti;
  guint8     hs_cmd, hs_ver;
  char       *opcode_str;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "HYPERSCSI");
  if (check_col(pinfo->cinfo, COL_INFO))
    col_clear(pinfo->cinfo, COL_INFO);

  if (tree) {
    ti = proto_tree_add_item(tree, proto_hyperscsi, tvb, offset, -1, FALSE);
    hs_tree = proto_item_add_subtree(ti, ett_hyperscsi);
  } 

  hs_hdr1 = tvb_get_guint8(tvb, offset);
  offset++;
  hs_hdr2 = tvb_get_guint8(tvb, offset);
  offset++;
  hs_hdr3 = tvb_get_guint8(tvb, offset);
  offset++;

  hs_res = hs_hdr1 >> 4;
  hs_tagno = ((hs_hdr1 & 0x0F) << 5 ) | (hs_hdr2 >> 3);
  hs_fragno = ((hs_hdr2 &0X03) << 8 ) | hs_hdr3;

  /*
   * Add the header ... three bytes
   */

  if (tree) {
    ti = proto_tree_add_text(hs_tree, tvb, 0, 3, "HyperSCSI Header");
    hs_hdr_tree = proto_item_add_subtree(ti, ett_hs_hdr);

    /*
     * Now, add the header items
     */

    proto_tree_add_uint(hs_hdr_tree, hf_hs_res, tvb, 0, 1, hs_res);
    proto_tree_add_uint(hs_hdr_tree, hf_hs_tagno, tvb, 0, 2, hs_tagno);
    proto_tree_add_item(hs_hdr_tree, hf_hs_lastfrag, tvb, 1, 1, FALSE);
    proto_tree_add_uint(hs_hdr_tree, hf_hs_fragno, tvb, 1, 2, hs_fragno);

  }

  /* 
   * Now, add the PDU 
   */

  hs_ver = tvb_get_guint8(tvb, offset++);

  hs_cmd = tvb_get_guint8(tvb, offset++);

  hs_cmd &= OPCODE_MASK;

  opcode_str = match_strval(hs_cmd, hscsi_opcodes);

  if (!opcode_str) 
    opcode_str = "Unknown HyperSCSI Request or Response";

  if (check_col(pinfo->cinfo, COL_INFO)) {
    col_append_str(pinfo->cinfo, COL_INFO, (char *)opcode_str);
  }

  if (tree) {
    ti = proto_tree_add_text(hs_tree, tvb, 3, -1, "HyperSCSI PDU");
    hs_pdu_tree = proto_item_add_subtree(ti, ett_hs_pdu);

    proto_tree_add_uint(hs_pdu_tree, hf_hs_ver, tvb, 3, 1, hs_ver);

    proto_tree_add_uint_format(hs_pdu_tree, hf_hs_cmd, tvb, 4, 1, hs_cmd, "HyperSCSI Command: %s", opcode_str);
  }

}

void
proto_register_hyperscsi(void)
{

  static hf_register_info hf[] = {
    { &hf_hs_res, 
      { "Reserved", "hyperscsi.reserved", FT_UINT8, BASE_DEC, NULL, 0x0, 
	"", HFILL}},

    { &hf_hs_tagno,
      { "Tag No", "hyperscsi.tagno", FT_UINT16, BASE_DEC, NULL, 0x0,
	"", HFILL }},

    { &hf_hs_lastfrag,
      { "Last Fragment", "hyperscsi.lastfrag", FT_BOOLEAN, 8, TFS(&tfs_lastfrag), 0x04, "", HFILL}},

    { &hf_hs_fragno, 
      { "Fragment No", "hyperscsi.fragno", FT_UINT16, BASE_DEC, NULL, 0x0,
	"", HFILL}},

    { &hf_hs_ver,
      { "HyperSCSI Version", "hyperscsi.version", FT_UINT8, BASE_DEC, NULL, 
	0x0, "", HFILL}},

    { &hf_hs_cmd,
      { "HyperSCSI Command", "hyperscsi.cmd", FT_UINT8, BASE_DEC, NULL, 0x0, 
	"", HFILL}},
  };

  static gint *ett[] = {
    &ett_hyperscsi,
    &ett_hs_hdr,
    &ett_hs_pdu,
  };
  
  proto_hyperscsi = proto_register_protocol("HyperSCSI", "HyperSCSI", "hyperscsi");
  proto_register_field_array(proto_hyperscsi, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));

  register_dissector("hyperscsi", dissect_hyperscsi, proto_hyperscsi);
}

#define ETHERTYPE_HYPERSCSI 0x889A

void
proto_reg_handoff_hyperscsi(void)
{
  dissector_handle_t hs_handle;

  hs_handle = find_dissector("hyperscsi");
  dissector_add("ethertype", ETHERTYPE_HYPERSCSI, hs_handle);

}