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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* This module provides rpc call/reply SRT (Server Response Time) statistics
37 #include <epan/packet_info.h>
38 #include <epan/epan.h>
39 #include <epan/stat_cmd_args.h>
41 #include <epan/conversation.h>
42 #include <epan/dissectors/packet-scsi.h>
43 #include <epan/dissectors/packet-fc.h>
44 #include <epan/dissectors/packet-scsi-sbc.h>
45 #include <epan/dissectors/packet-scsi-ssc.h>
46 #include <epan/dissectors/packet-scsi-smc.h>
47 #include <epan/dissectors/packet-scsi-osd.h>
49 #include "../simple_dialog.h"
50 #include "../globals.h"
51 #include "../stat_menu.h"
53 #include "ui/gtk/gui_stat_menu.h"
54 #include "ui/gtk/gui_utils.h"
55 #include "ui/gtk/dlg_utils.h"
56 #include "ui/gtk/main.h"
57 #include "ui/gtk/service_response_time_table.h"
58 #include "ui/gtk/tap_param_dlg.h"
59 #include "ui/gtk/gtkglobals.h"
61 #include "ui/gtk/old-gtk-compat.h"
63 /* used to keep track of the statistics for an entire scsi command set */
64 typedef struct _scsistat_t {
66 srt_stat_table srt_table;
68 const value_string *cdbnames;
72 static guint8 scsi_program=0;
76 SCSI_STAT_PROG_LABEL_SBC,
77 SCSI_STAT_PROG_LABEL_SSC,
78 SCSI_STAT_PROG_LABEL_MMC
83 scsistat_gen_title(scsistat_t *rs)
87 title = g_strdup_printf("SCSI Service Response Time statistics for %s: %s",
88 rs->prog, cf_get_display_name(&cfile));
93 scsistat_set_title(scsistat_t *rs)
97 title = scsistat_gen_title(rs);
98 gtk_window_set_title(GTK_WINDOW(rs->win), title);
103 scsistat_reset(void *arg)
105 scsistat_t *rs = (scsistat_t *)arg;
107 reset_srt_table_data(&rs->srt_table);
108 scsistat_set_title(rs);
113 scsistat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *arg2)
115 scsistat_t *rs = (scsistat_t *)arg;
116 const scsi_task_data_t *ri = (const scsi_task_data_t *)arg2;
118 /* we are only interested in response packets */
119 if(ri->type!=SCSI_PDU_TYPE_RSP){
122 /* we are only interested in a specific commandset */
123 if( (!ri->itl) || ((ri->itl->cmdset&SCSI_CMDSET_MASK)!=rs->cmdset) ){
126 /* check that the opcode looks sane */
127 if( (!ri->itlq) || (ri->itlq->scsi_opcode>255) ){
131 add_srt_table_data(&rs->srt_table, ri->itlq->scsi_opcode, &ri->itlq->fc_time, pinfo);
137 scsistat_draw(void *arg)
139 scsistat_t *rs = (scsistat_t *)arg;
141 draw_srt_table_data(&rs->srt_table);
146 /* since the gtk2 implementation of tap is multithreaded we must protect
147 * remove_tap_listener() from modifying the list while draw_tap_listener()
148 * is running. the other protected block is in main.c
150 * there should not be any other critical regions in gtk2
153 win_destroy_cb(GtkWindow *win _U_, gpointer data)
155 scsistat_t *rs=(scsistat_t *)data;
157 protect_thread_critical_region();
158 remove_tap_listener(rs);
159 unprotect_thread_critical_region();
161 free_srt_table_data(&rs->srt_table);
166 /* When called, this function will create a new instance of gtk2-scsistat.
169 gtk_scsistat_init(const char *optarg, void* userdata _U_)
176 GtkWidget *stat_label;
177 GtkWidget *filter_label;
181 const char *filter=NULL;
182 GString *error_string;
183 const char *hf_name=NULL;
186 if(sscanf(optarg,"scsi,srt,%d,%n",&program,&pos)==1){
193 fprintf(stderr, "wireshark: invalid \"-z scsi,srt,<cmdset>[,<filter>]\" argument\n");
197 scsi_program=program;
198 rs=(scsistat_t *)g_malloc(sizeof(scsistat_t));
202 rs->prog="SBC (disk)";
203 rs->cdbnames=scsi_sbc_vals;
204 hf_name="scsi.sbc.opcode";
207 rs->prog="SSC (tape)";
208 rs->cdbnames=scsi_ssc_vals;
209 hf_name="scsi.ssc.opcode";
212 rs->prog="MMC (cd/dvd)";
213 rs->cdbnames=scsi_mmc_vals;
214 hf_name="scsi.mmc.opcode";
217 rs->prog="SMC (tape robot)";
218 rs->cdbnames=scsi_smc_vals;
219 hf_name="scsi.smc.opcode";
222 rs->prog="OSD (object based)";
223 rs->cdbnames=scsi_osd_vals;
224 hf_name="scsi.osd.opcode";
228 rs->win = dlg_window_new("scsi-stat"); /* transient_for top_level */
229 gtk_window_set_destroy_with_parent (GTK_WINDOW(rs->win), TRUE);
230 gtk_window_set_default_size(GTK_WINDOW(rs->win), 550, 400);
231 scsistat_set_title(rs);
233 vbox=gtk_vbox_new(FALSE, 3);
234 gtk_container_add(GTK_CONTAINER(rs->win), vbox);
235 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
237 title_string = scsistat_gen_title(rs);
238 stat_label=gtk_label_new(title_string);
239 g_free(title_string);
240 gtk_box_pack_start(GTK_BOX(vbox), stat_label, FALSE, FALSE, 0);
242 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
243 filter_label=gtk_label_new(filter_string);
244 g_free(filter_string);
245 gtk_label_set_line_wrap(GTK_LABEL(filter_label), TRUE);
246 gtk_box_pack_start(GTK_BOX(vbox), filter_label, FALSE, FALSE, 0);
248 /* We must display TOP LEVEL Widget before calling init_srt_table() */
249 gtk_widget_show_all(rs->win);
251 init_srt_table(&rs->srt_table, 256, vbox, hf_name);
254 init_srt_table_row(&rs->srt_table, i, val_to_str(i, rs->cdbnames, "Unknown-0x%02x"));
258 error_string=register_tap_listener("scsi", rs, filter, 0, scsistat_reset, scsistat_packet, scsistat_draw);
260 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
261 g_string_free(error_string, TRUE);
262 free_srt_table_data(&rs->srt_table);
268 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
269 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
271 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
272 window_set_cancel_button(rs->win, close_bt, window_cancel_button_cb);
274 g_signal_connect(rs->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
275 g_signal_connect(rs->win, "destroy", G_CALLBACK(win_destroy_cb), rs);
277 gtk_widget_show_all(rs->win);
278 window_present(rs->win);
280 cf_retap_packets(&cfile);
281 gdk_window_raise(gtk_widget_get_window(rs->win));
284 static enum_val_t scsi_command_sets[] = {
285 { "sbc", "SBC (disk)", SCSI_DEV_SBC },
286 { "ssc", "SSC (tape)", SCSI_DEV_SSC },
287 { "mmc", "MMC (cd/dvd)", SCSI_DEV_CDROM },
288 { "smc", "SMC (tape robot)", SCSI_DEV_SMC },
289 { "osd", "OSD (object based)", SCSI_DEV_OSD },
293 static tap_param scsi_stat_params[] = {
294 { PARAM_ENUM, "Command set", scsi_command_sets },
295 { PARAM_FILTER, "Filter", NULL }
298 static tap_param_dlg scsi_stat_dlg = {
299 "SCSI SRT Statistics",
303 G_N_ELEMENTS(scsi_stat_params),
308 register_tap_listener_gtkscsistat(void)
310 register_dfilter_stat(&scsi_stat_dlg, "SCSI",
311 REGISTER_STAT_GROUP_RESPONSE_TIME);
314 void scsi_srt_cb(GtkAction *action, gpointer user_data _U_)
316 tap_param_dlg_cb(action, &scsi_stat_dlg);