6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2002 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/strutil.h>
32 #include <epan/packet.h>
33 #include <epan/prefs.h>
34 #include <epan/emem.h>
35 #include <epan/conversation.h>
37 #include "packet-fc.h"
38 #include "packet-scsi.h"
39 #include "packet-scsi-osd.h"
41 static int proto_scsi_osd = -1;
42 int hf_scsi_osd_opcode = -1;
43 static int hf_scsi_osd_control = -1;
44 static int hf_scsi_osd_add_cdblen = -1;
45 static int hf_scsi_osd_svcaction = -1;
46 static int hf_scsi_osd_option = -1;
47 static int hf_scsi_osd_option_dpo = -1;
48 static int hf_scsi_osd_option_fua = -1;
49 static int hf_scsi_osd_getsetattrib = -1;
50 static int hf_scsi_osd_timestamps_control = -1;
53 static gint ett_osd_option = -1;
57 static const true_false_string option_dpo_tfs = {
61 static const true_false_string option_fua_tfs = {
68 dissect_osd_option(tvbuff_t *tvb, int offset, proto_tree *parent_tree)
70 proto_tree *tree=NULL;
74 option=tvb_get_guint8(tvb, offset);
77 it=proto_tree_add_item(parent_tree, hf_scsi_osd_option, tvb, offset, 1, 0);
78 tree = proto_item_add_subtree(it, ett_osd_option);
81 proto_tree_add_item(tree, hf_scsi_osd_option_dpo, tvb, offset, 1, 0);
83 proto_item_append_text(tree, " DPO");
86 proto_tree_add_item(tree, hf_scsi_osd_option_fua, tvb, offset, 1, 0);
88 proto_item_append_text(tree, " FUA");
93 static const value_string scsi_osd_getsetattrib_vals[] = {
94 {2, "Get an attributes page and set an attribute value"},
95 {3, "Get and set attributes using a list"},
100 dissect_osd_getsetattrib(tvbuff_t *tvb, int offset, proto_tree *tree)
102 proto_tree_add_item(tree, hf_scsi_osd_getsetattrib, tvb, offset, 1, 0);
106 static const value_string scsi_osd_timestamps_control_vals[] = {
107 {0x00, "Timestamps shall be updated"},
108 {0x7f, "Timestamps shall not be updated"},
113 dissect_osd_timestamps_control(tvbuff_t *tvb, int offset, proto_tree *tree)
115 proto_tree_add_item(tree, hf_scsi_osd_timestamps_control, tvb, offset, 1, 0);
126 dissect_osd_format_osd(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
127 guint offset, gboolean isreq, gboolean iscdb,
128 guint payload_len _U_, scsi_task_data_t *cdata _U_)
130 /* dissecting the CDB dissection starts at byte 10 of the CDB */
133 dissect_osd_option(tvb, offset, tree);
136 /* getset attributes byte */
137 dissect_osd_getsetattrib(tvb, offset, tree);
140 /* timestamps control */
141 dissect_osd_timestamps_control(tvb, offset, tree);
144 /* 23 reserved bytes */
150 /* dissecting the DATA OUT */
152 /* no data out for format osd */
155 /* dissecting the DATA IN */
156 if(!isreq && !iscdb){
157 /* no data in for format osd */
163 /* OSD Service Actions */
164 #define OSD_FORMAT_OSD 0x8801
165 static const value_string scsi_osd_svcaction_vals[] = {
166 {OSD_FORMAT_OSD, "Format OSD"},
170 /* OSD Service Action dissectors */
171 typedef struct _scsi_osd_svcaction_t {
173 scsi_dissector_t dissector;
174 } scsi_osd_svcaction_t;
175 static const scsi_osd_svcaction_t scsi_osd_svcaction[] = {
176 {OSD_FORMAT_OSD, dissect_osd_format_osd},
180 static scsi_dissector_t
181 find_svcaction_dissector(guint16 svcaction)
183 scsi_osd_svcaction_t *sa=scsi_osd_svcaction;
185 while(sa&&sa->dissector){
186 if(sa->svcaction==svcaction){
187 return sa->dissector;
197 dissect_osd_opcode(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
198 guint offset, gboolean isreq, gboolean iscdb,
199 guint payload_len, scsi_task_data_t *cdata)
202 scsi_dissector_t dissector;
208 /* dissecting the CDB */
209 if (isreq && iscdb) {
210 proto_tree_add_item (tree, hf_scsi_osd_control, tvb, offset, 1, 0);
213 /* 5 reserved bytes */
216 proto_tree_add_item (tree, hf_scsi_osd_add_cdblen, tvb, offset, 1, 0);
219 svcaction=tvb_get_ntohs(tvb, offset);
220 if(cdata && cdata->itlq){
221 /* We must store the service action for this itlq
222 * so we can indentify what the data contains
224 cdata->itlq->svcaction=svcaction;
226 proto_tree_add_item (tree, hf_scsi_osd_svcaction, tvb, offset, 2, 0);
230 if(check_col(pinfo->cinfo, COL_INFO)){
231 col_append_fstr(pinfo->cinfo, COL_INFO, "%s",
232 val_to_str(svcaction, scsi_osd_svcaction_vals, "Unknown OSD Serviceaction"));
234 dissector=find_svcaction_dissector(svcaction);
236 (*dissector)(tvb, pinfo, tree, offset, isreq, iscdb, payload_len, cdata);
241 /* If it was not a CDB, try to find the service action and pass it
242 * off to the service action dissector
244 if(cdata && cdata->itlq){
245 svcaction=cdata->itlq->svcaction;
247 if(check_col(pinfo->cinfo, COL_INFO)){
248 col_append_fstr(pinfo->cinfo, COL_INFO, "%s",
249 val_to_str(svcaction, scsi_osd_svcaction_vals, "Unknown OSD Serviceaction"));
253 it=proto_tree_add_uint_format(tree, hf_scsi_osd_svcaction, tvb, 0, 0, svcaction, "Service Action: 0x%04x", svcaction);
254 PROTO_ITEM_SET_GENERATED(it);
256 dissector=find_svcaction_dissector(svcaction);
258 (*dissector)(tvb, pinfo, tree, offset, isreq, iscdb, payload_len, cdata);
265 const value_string scsi_osd_vals[] = {
266 {SCSI_SPC2_INQUIRY , "Inquiry"},
267 {SCSI_SPC2_LOGSELECT , "Log Select"},
268 {SCSI_SPC2_LOGSENSE , "Log Sense"},
269 {SCSI_SPC2_MODESELECT10 , "Mode Select(10)"},
270 {SCSI_SPC2_MODESENSE10 , "Mode Sense(10)"},
271 {SCSI_SPC2_PERSRESVIN , "Persistent Reserve In"},
272 {SCSI_SPC2_PERSRESVOUT , "Persistent Reserve Out"},
273 {SCSI_SPC2_REPORTLUNS , "Report LUNs"},
274 {SCSI_OSD_OPCODE , "OSD Command" },
280 scsi_cdb_table_t scsi_osd_table[256] = {
299 /*OSD 0x12*/{dissect_spc3_inquiry},
357 /*OSD 0x4c*/{dissect_spc3_logselect},
358 /*OSD 0x4d*/{dissect_spc3_logsense},
366 /*OSD 0x55*/{dissect_spc3_modeselect10},
371 /*OSD 0x5a*/{dissect_spc3_modesense10},
375 /*OSD 0x5e*/{dissect_spc3_persistentreservein},
376 /*OSD 0x5f*/{dissect_spc3_persistentreserveout},
408 /*OSD 0x7f*/{dissect_osd_opcode},
441 /*OSD 0xa0*/{dissect_spc3_reportluns},
543 proto_register_scsi_osd(void)
545 static hf_register_info hf[] = {
546 { &hf_scsi_osd_opcode,
547 {"OSD Opcode", "scsi.osd.opcode", FT_UINT8, BASE_HEX,
548 VALS (scsi_osd_vals), 0x0, "", HFILL}},
549 { &hf_scsi_osd_control,
550 {"Control", "scsi.osd.cdb.control", FT_UINT8, BASE_HEX,
551 NULL, 0x0, "", HFILL}},
552 { &hf_scsi_osd_add_cdblen,
553 {"Additional CDB Length", "scsi.osd.addcdblen", FT_UINT8, BASE_DEC,
554 NULL, 0x0, "", HFILL}},
555 { &hf_scsi_osd_svcaction,
556 {"Service Action", "scsi.osd.svcaction", FT_UINT16, BASE_HEX,
557 VALS(scsi_osd_svcaction_vals), 0x0, "", HFILL}},
558 { &hf_scsi_osd_option,
559 {"Option", "scsi.osd.option", FT_UINT8, BASE_HEX,
560 NULL, 0x0, "", HFILL}},
561 { &hf_scsi_osd_option_dpo,
562 {"DPO", "scsi.osd.option.dpo", FT_BOOLEAN, 8,
563 TFS(&option_dpo_tfs), 0x10, "", HFILL}},
564 { &hf_scsi_osd_option_fua,
565 {"FUA", "scsi.osd.option.fua", FT_BOOLEAN, 8,
566 TFS(&option_fua_tfs), 0x08, "", HFILL}},
567 { &hf_scsi_osd_getsetattrib,
568 {"GET/SET CDBFMT", "scsi.osd.getset", FT_UINT8, BASE_HEX,
569 VALS(scsi_osd_getsetattrib_vals), 0x30, "", HFILL}},
570 { &hf_scsi_osd_timestamps_control,
571 {"Timestamps Control", "scsi.osd.timestamps_control", FT_UINT8, BASE_HEX,
572 VALS(scsi_osd_timestamps_control_vals), 0x0, "", HFILL}},
575 /* Setup protocol subtree array */
576 static gint *ett[] = {
580 /* Register the protocol name and description */
581 proto_scsi_osd = proto_register_protocol("SCSI_OSD", "SCSI_OSD", "scsi_osd");
583 /* Required function calls to register the header fields and subtrees used */
584 proto_register_field_array(proto_scsi_osd, hf, array_length(hf));
585 proto_register_subtree_array(ett, array_length(ett));
589 proto_reg_handoff_scsi_osd(void)