2 * scsi_stat 2006 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 /* This module provides rpc call/reply SRT (Server Response Time) statistics
35 #include <epan/packet_info.h>
36 #include <epan/epan.h>
37 #include <epan/stat_cmd_args.h>
39 #include <epan/conversation.h>
40 #include <epan/dissectors/packet-scsi.h>
41 #include <epan/dissectors/packet-fc.h>
42 #include <epan/dissectors/packet-scsi-sbc.h>
43 #include <epan/dissectors/packet-scsi-ssc.h>
44 #include <epan/dissectors/packet-scsi-smc.h>
45 #include <epan/dissectors/packet-scsi-osd.h>
47 #include "ui/simple_dialog.h"
48 #include "../globals.h"
49 #include "../stat_menu.h"
51 #include "ui/gtk/gui_stat_menu.h"
52 #include "ui/gtk/gui_utils.h"
53 #include "ui/gtk/dlg_utils.h"
54 #include "ui/gtk/main.h"
55 #include "ui/gtk/service_response_time_table.h"
56 #include "ui/gtk/tap_param_dlg.h"
57 #include "ui/gtk/gtkglobals.h"
59 #include "ui/gtk/old-gtk-compat.h"
61 /* used to keep track of the statistics for an entire scsi command set */
62 typedef struct _scsistat_t
{
64 srt_stat_table srt_table
;
66 const value_string
*cdbnames
;
70 static guint8 scsi_program
=0;
74 SCSI_STAT_PROG_LABEL_SBC
,
75 SCSI_STAT_PROG_LABEL_SSC
,
76 SCSI_STAT_PROG_LABEL_MMC
81 scsistat_gen_title(scsistat_t
*rs
)
86 display_name
= cf_get_display_name(&cfile
);
87 title
= g_strdup_printf("SCSI Service Response Time statistics for %s: %s",
88 rs
->prog
, display_name
);
94 scsistat_set_title(scsistat_t
*rs
)
98 title
= scsistat_gen_title(rs
);
99 gtk_window_set_title(GTK_WINDOW(rs
->win
), title
);
104 scsistat_reset(void *arg
)
106 scsistat_t
*rs
= (scsistat_t
*)arg
;
108 reset_srt_table_data(&rs
->srt_table
);
109 scsistat_set_title(rs
);
114 scsistat_packet(void *arg
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *arg2
)
116 scsistat_t
*rs
= (scsistat_t
*)arg
;
117 const scsi_task_data_t
*ri
= (const scsi_task_data_t
*)arg2
;
119 /* we are only interested in response packets */
120 if(ri
->type
!=SCSI_PDU_TYPE_RSP
){
123 /* we are only interested in a specific commandset */
124 if( (!ri
->itl
) || ((ri
->itl
->cmdset
&SCSI_CMDSET_MASK
)!=rs
->cmdset
) ){
127 /* check that the opcode looks sane */
128 if( (!ri
->itlq
) || (ri
->itlq
->scsi_opcode
>255) ){
132 add_srt_table_data(&rs
->srt_table
, ri
->itlq
->scsi_opcode
, &ri
->itlq
->fc_time
, pinfo
);
138 scsistat_draw(void *arg
)
140 scsistat_t
*rs
= (scsistat_t
*)arg
;
142 draw_srt_table_data(&rs
->srt_table
);
146 win_destroy_cb(GtkWindow
*win _U_
, gpointer data
)
148 scsistat_t
*rs
=(scsistat_t
*)data
;
150 remove_tap_listener(rs
);
152 free_srt_table_data(&rs
->srt_table
);
157 /* When called, this function will create a new instance of gtk2-scsistat.
160 gtk_scsistat_init(const char *opt_arg
, void* userdata _U_
)
167 GtkWidget
*stat_label
;
168 GtkWidget
*filter_label
;
172 const char *filter
=NULL
;
173 GString
*error_string
;
174 const char *hf_name
=NULL
;
177 if(sscanf(opt_arg
,"scsi,srt,%d,%n",&program
,&pos
)==1){
184 fprintf(stderr
, "wireshark: invalid \"-z scsi,srt,<cmdset>[,<filter>]\" argument\n");
188 scsi_program
=program
;
189 rs
=(scsistat_t
*)g_malloc(sizeof(scsistat_t
));
193 rs
->prog
="SBC (disk)";
194 rs
->cdbnames
=scsi_sbc_vals
;
195 hf_name
="scsi_sbc.opcode";
198 rs
->prog
="SSC (tape)";
199 rs
->cdbnames
=scsi_ssc_vals
;
200 hf_name
="scsi_ssc.opcode";
203 rs
->prog
="MMC (cd/dvd)";
204 rs
->cdbnames
=scsi_mmc_vals
;
205 hf_name
="scsi_mmc.opcode";
208 rs
->prog
="SMC (tape robot)";
209 rs
->cdbnames
=scsi_smc_vals
;
210 hf_name
="scsi_smc.opcode";
213 rs
->prog
="OSD (object based)";
214 rs
->cdbnames
=scsi_osd_vals
;
215 hf_name
="scsi_osd.opcode";
219 rs
->win
= dlg_window_new("scsi-stat"); /* transient_for top_level */
220 gtk_window_set_destroy_with_parent (GTK_WINDOW(rs
->win
), TRUE
);
221 gtk_window_set_default_size(GTK_WINDOW(rs
->win
), 550, 400);
222 scsistat_set_title(rs
);
224 vbox
=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 3, FALSE
);
225 gtk_container_add(GTK_CONTAINER(rs
->win
), vbox
);
226 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 12);
228 title_string
= scsistat_gen_title(rs
);
229 stat_label
=gtk_label_new(title_string
);
230 g_free(title_string
);
231 gtk_box_pack_start(GTK_BOX(vbox
), stat_label
, FALSE
, FALSE
, 0);
233 filter_string
= g_strdup_printf("Filter: %s", filter
? filter
: "");
234 filter_label
=gtk_label_new(filter_string
);
235 g_free(filter_string
);
236 gtk_label_set_line_wrap(GTK_LABEL(filter_label
), TRUE
);
237 gtk_box_pack_start(GTK_BOX(vbox
), filter_label
, FALSE
, FALSE
, 0);
239 /* We must display TOP LEVEL Widget before calling init_srt_table() */
240 gtk_widget_show_all(rs
->win
);
242 init_srt_table(&rs
->srt_table
, 256, vbox
, hf_name
);
245 init_srt_table_row(&rs
->srt_table
, i
, val_to_str(i
, rs
->cdbnames
, "Unknown-0x%02x"));
249 error_string
=register_tap_listener("scsi", rs
, filter
, 0, scsistat_reset
, scsistat_packet
, scsistat_draw
);
251 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
, "%s", error_string
->str
);
252 g_string_free(error_string
, TRUE
);
253 free_srt_table_data(&rs
->srt_table
);
259 bbox
= dlg_button_row_new(GTK_STOCK_CLOSE
, NULL
);
260 gtk_box_pack_end(GTK_BOX(vbox
), bbox
, FALSE
, FALSE
, 0);
262 close_bt
= (GtkWidget
*)g_object_get_data(G_OBJECT(bbox
), GTK_STOCK_CLOSE
);
263 window_set_cancel_button(rs
->win
, close_bt
, window_cancel_button_cb
);
265 g_signal_connect(rs
->win
, "delete_event", G_CALLBACK(window_delete_event_cb
), NULL
);
266 g_signal_connect(rs
->win
, "destroy", G_CALLBACK(win_destroy_cb
), rs
);
268 gtk_widget_show_all(rs
->win
);
269 window_present(rs
->win
);
271 cf_retap_packets(&cfile
);
272 gdk_window_raise(gtk_widget_get_window(rs
->win
));
275 static const enum_val_t scsi_command_sets
[] = {
276 { "sbc", "SBC (disk)", SCSI_DEV_SBC
},
277 { "ssc", "SSC (tape)", SCSI_DEV_SSC
},
278 { "mmc", "MMC (cd/dvd)", SCSI_DEV_CDROM
},
279 { "smc", "SMC (tape robot)", SCSI_DEV_SMC
},
280 { "osd", "OSD (object based)", SCSI_DEV_OSD
},
284 static tap_param scsi_stat_params
[] = {
285 { PARAM_ENUM
, "Command set", scsi_command_sets
},
286 { PARAM_FILTER
, "Filter", NULL
}
289 static tap_param_dlg scsi_stat_dlg
= {
290 "SCSI SRT Statistics",
294 G_N_ELEMENTS(scsi_stat_params
),
299 register_tap_listener_gtkscsistat(void)
301 register_param_stat(&scsi_stat_dlg
, "SCSI",
302 REGISTER_STAT_GROUP_RESPONSE_TIME
);