add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / gtk / scsi_stat.c
blobb8c3892bd2579615a8c9f2dc122d7e270d1c73b6
1 /* scsi_stat.c
2 * scsi_stat 2006 Ronnie Sahlberg
4 * $Id$
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
26 * to Wireshark.
29 #include "config.h"
31 #include <stdio.h>
33 #include <gtk/gtk.h>
35 #include <epan/packet_info.h>
36 #include <epan/epan.h>
37 #include <epan/stat_cmd_args.h>
38 #include <epan/tap.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 {
63 GtkWidget *win;
64 srt_stat_table srt_table;
65 guint8 cmdset;
66 const value_string *cdbnames;
67 const char *prog;
68 } scsistat_t;
70 static guint8 scsi_program=0;
72 enum
74 SCSI_STAT_PROG_LABEL_SBC,
75 SCSI_STAT_PROG_LABEL_SSC,
76 SCSI_STAT_PROG_LABEL_MMC
80 static char *
81 scsistat_gen_title(scsistat_t *rs)
83 char *display_name;
84 char *title;
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);
89 g_free(display_name);
90 return title;
93 static void
94 scsistat_set_title(scsistat_t *rs)
96 char *title;
98 title = scsistat_gen_title(rs);
99 gtk_window_set_title(GTK_WINDOW(rs->win), title);
100 g_free(title);
103 static void
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);
113 static int
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){
121 return 0;
123 /* we are only interested in a specific commandset */
124 if( (!ri->itl) || ((ri->itl->cmdset&SCSI_CMDSET_MASK)!=rs->cmdset) ){
125 return 0;
127 /* check that the opcode looks sane */
128 if( (!ri->itlq) || (ri->itlq->scsi_opcode>255) ){
129 return 0;
132 add_srt_table_data(&rs->srt_table, ri->itlq->scsi_opcode, &ri->itlq->fc_time, pinfo);
134 return 1;
137 static void
138 scsistat_draw(void *arg)
140 scsistat_t *rs = (scsistat_t *)arg;
142 draw_srt_table_data(&rs->srt_table);
145 static void
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);
153 g_free(rs);
157 /* When called, this function will create a new instance of gtk2-scsistat.
159 static void
160 gtk_scsistat_init(const char *opt_arg, void* userdata _U_)
162 scsistat_t *rs;
163 guint32 i;
164 char *title_string;
165 char *filter_string;
166 GtkWidget *vbox;
167 GtkWidget *stat_label;
168 GtkWidget *filter_label;
169 GtkWidget *bbox;
170 GtkWidget *close_bt;
171 int program, pos;
172 const char *filter=NULL;
173 GString *error_string;
174 const char *hf_name=NULL;
176 pos=0;
177 if(sscanf(opt_arg,"scsi,srt,%d,%n",&program,&pos)==1){
178 if(pos){
179 filter=opt_arg+pos;
180 } else {
181 filter=NULL;
183 } else {
184 fprintf(stderr, "wireshark: invalid \"-z scsi,srt,<cmdset>[,<filter>]\" argument\n");
185 exit(1);
188 scsi_program=program;
189 rs=(scsistat_t *)g_malloc(sizeof(scsistat_t));
190 rs->cmdset=program;
191 switch(program){
192 case SCSI_DEV_SBC:
193 rs->prog="SBC (disk)";
194 rs->cdbnames=scsi_sbc_vals;
195 hf_name="scsi_sbc.opcode";
196 break;
197 case SCSI_DEV_SSC:
198 rs->prog="SSC (tape)";
199 rs->cdbnames=scsi_ssc_vals;
200 hf_name="scsi_ssc.opcode";
201 break;
202 case SCSI_DEV_CDROM:
203 rs->prog="MMC (cd/dvd)";
204 rs->cdbnames=scsi_mmc_vals;
205 hf_name="scsi_mmc.opcode";
206 break;
207 case SCSI_DEV_SMC:
208 rs->prog="SMC (tape robot)";
209 rs->cdbnames=scsi_smc_vals;
210 hf_name="scsi_smc.opcode";
211 break;
212 case SCSI_DEV_OSD:
213 rs->prog="OSD (object based)";
214 rs->cdbnames=scsi_osd_vals;
215 hf_name="scsi_osd.opcode";
216 break;
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);
244 for(i=0;i<256;i++){
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);
250 if(error_string){
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);
254 g_free(rs);
255 return;
258 /* Button row. */
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 },
281 { NULL, NULL, 0 }
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",
291 "scsi,srt",
292 gtk_scsistat_init,
294 G_N_ELEMENTS(scsi_stat_params),
295 scsi_stat_params
298 void
299 register_tap_listener_gtkscsistat(void)
301 register_param_stat(&scsi_stat_dlg, "SCSI",
302 REGISTER_STAT_GROUP_RESPONSE_TIME);